2007-07-19 19:01:42 +02:00
|
|
|
#ifndef ARABICA_XSLT_TEXT_HANDLER_HPP
|
|
|
|
#define ARABICA_XSLT_TEXT_HANDLER_HPP
|
|
|
|
|
|
|
|
#include "../xslt_text.hpp"
|
|
|
|
|
|
|
|
namespace Arabica
|
|
|
|
{
|
|
|
|
namespace XSLT
|
|
|
|
{
|
|
|
|
|
2012-11-03 00:00:31 +01:00
|
|
|
template<class string_type, class string_adaptor>
|
|
|
|
class TextHandler : public SAX::DefaultHandler<string_type, string_adaptor>
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
2012-11-12 22:46:08 +01:00
|
|
|
typedef StylesheetConstant<string_type, string_adaptor> SC;
|
2012-11-15 23:03:42 +01:00
|
|
|
typedef AttributeValidators<string_type, string_adaptor> AV;
|
2007-07-19 19:01:42 +02:00
|
|
|
public:
|
2012-11-03 00:00:31 +01:00
|
|
|
TextHandler(CompilationContext<string_type, string_adaptor>& context) :
|
2007-07-19 19:01:42 +02:00
|
|
|
context_(context),
|
|
|
|
text_(0)
|
|
|
|
{
|
|
|
|
} // TextHandler
|
|
|
|
|
2012-11-03 00:00:31 +01:00
|
|
|
virtual void startElement(const string_type& /* namespaceURI */,
|
|
|
|
const string_type& /* localName */,
|
|
|
|
const string_type& qName,
|
|
|
|
const SAX::Attributes<string_type, string_adaptor>& atts)
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
|
|
|
if(text_ == 0)
|
|
|
|
{
|
2012-11-15 23:03:42 +01:00
|
|
|
static const AV rules = AV::rule(SC::disable_output_escaping, false, SC::no, AllowedValues<string_type>(SC::yes, SC::no));
|
|
|
|
text_ = new Text<string_type, string_adaptor>(rules.gather(qName, atts)[SC::disable_output_escaping] == SC::yes);
|
2007-07-19 19:01:42 +02:00
|
|
|
return;
|
|
|
|
} // if(text_ == 0)
|
|
|
|
|
2012-11-12 22:46:08 +01:00
|
|
|
throw SAX::SAXException(string_adaptor::asStdString(qName) + " can not contain elements");
|
2007-07-19 19:01:42 +02:00
|
|
|
} // startElement
|
|
|
|
|
2012-11-03 00:00:31 +01:00
|
|
|
virtual void endElement(const string_type& /* namespaceURI */,
|
|
|
|
const string_type& /* localName */,
|
|
|
|
const string_type& /* qName */)
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
|
|
|
text_->set(buffer_);
|
|
|
|
context_.parentContainer().add_item(text_);
|
|
|
|
context_.pop();
|
|
|
|
} // endElement
|
|
|
|
|
2012-11-03 00:00:31 +01:00
|
|
|
virtual void characters(const string_type& ch)
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
|
|
|
buffer_ += ch;
|
|
|
|
} // characters
|
|
|
|
|
|
|
|
private:
|
2012-11-03 00:00:31 +01:00
|
|
|
CompilationContext<string_type, string_adaptor>& context_;
|
|
|
|
Text<string_type, string_adaptor>* text_;
|
|
|
|
string_type buffer_;
|
2007-07-19 19:01:42 +02:00
|
|
|
}; // class TextHandler
|
|
|
|
|
|
|
|
} // namespace XSLT
|
|
|
|
} // namespace Arabica
|
|
|
|
#endif // ARABICA_XSLT_TEXT_TEMPLATE_HPP
|
|
|
|
|