arabica/include/XSLT/impl/handler/xslt_value_of_handler.hpp

66 lines
2.2 KiB
C++
Raw Normal View History

2007-07-19 17:01:42 +00:00
#ifndef ARABICA_XSLT_VALUE_OF_HANDLER_HPP
#define ARABICA_XSLT_VALUE_OF_HANDLER_HPP
2007-09-04 22:55:47 +00:00
#include <XML/XMLCharacterClasses.hpp>
2007-07-19 17:01:42 +00:00
#include "../xslt_value_of.hpp"
namespace Arabica
{
namespace XSLT
{
2012-11-02 23:07:17 +00:00
template<class string_type, class string_adaptor>
class ValueOfHandler : public SAX::DefaultHandler<string_type, string_adaptor>
2007-07-19 17:01:42 +00:00
{
typedef StylesheetConstant<string_type, string_adaptor> SC;
2012-11-15 22:03:42 +00:00
typedef AttributeValidators<string_type, string_adaptor> AV;
2007-07-19 17:01:42 +00:00
public:
2012-11-02 23:07:17 +00:00
ValueOfHandler(CompilationContext<string_type, string_adaptor>& context) :
2007-07-19 17:01:42 +00:00
context_(context),
valueOf_(0)
{
} // ValueOfHandler
2012-11-02 23:07:17 +00: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 17:01:42 +00:00
{
if(valueOf_ == 0)
{
2012-11-15 22:03:42 +00:00
static const AV rules = AV::rule(SC::select, true)
.rule(SC::disable_output_escaping, false, SC::no, AllowedValues<string_type>(SC::yes, SC::no));
2007-07-19 17:01:42 +00:00
2012-11-15 22:03:42 +00:00
std::map<string_type, string_type> attrs = rules.gather(qName, atts);
valueOf_ = new ValueOf<string_type, string_adaptor>(context_.xpath_expression(attrs[SC::select]),
attrs[SC::disable_output_escaping] == SC::yes);
2007-07-19 17:01:42 +00:00
return;
} // if(valueOf_ == 0)
throw SAX::SAXException(string_adaptor::asStdString(qName) + " can not contain elements");
2007-07-19 17:01:42 +00:00
} // startElement
2012-11-02 23:07:17 +00:00
virtual void endElement(const string_type& /* namespaceURI */,
const string_type& /* localName */,
const string_type& /* qName */)
2007-07-19 17:01:42 +00:00
{
context_.parentContainer().add_item(valueOf_);
context_.pop();
} // endElement
2012-11-02 23:07:17 +00:00
virtual void characters(const string_type& ch)
2007-07-19 17:01:42 +00:00
{
verifyNoCharacterData<string_type, string_adaptor>(ch, SC::value_of);
2007-07-19 17:01:42 +00:00
} // characters
private:
2012-11-02 23:07:17 +00:00
CompilationContext<string_type, string_adaptor>& context_;
ValueOf<string_type, string_adaptor>* valueOf_;
2007-07-19 17:01:42 +00:00
}; // class ValueOfHandler
} //namespace XSLT
} //namespace Arabica
#endif