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

85 lines
2.7 KiB
C++
Raw Normal View History

2007-07-19 19:01:42 +02:00
#ifndef ARABICA_XSLT_COPY_HANDLER_HPP
#define ARABICA_XSLT_COPY_HANDLER_HPP
#include "../xslt_copy.hpp"
namespace Arabica
{
namespace XSLT
{
2012-11-04 18:12:14 +01:00
template<class string_type, class string_adaptor>
class CopyHandler : public ItemContainerHandler<Copy<string_type, string_adaptor> >
2007-07-19 19:01:42 +02:00
{
public:
2012-11-04 18:12:14 +01:00
CopyHandler(CompilationContext<string_type, string_adaptor>& context) :
ItemContainerHandler<Copy<string_type, string_adaptor> >(context)
2007-07-19 19:01:42 +02:00
{
} // CopyHandler
2012-11-04 18:12:14 +01:00
virtual Copy<string_type, string_adaptor>* createContainer(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
{
2010-01-10 22:25:35 +01:00
static const ValueRule rules[] = { { "use-attribute-sets", false, 0, 0 },
{ 0, false, 0, 0 } };
2012-11-04 18:12:14 +01:00
string_type sets = gatherAttributes(qName, atts, rules)["use-attribute-sets"];
2007-07-19 19:01:42 +02:00
2012-11-04 18:12:14 +01:00
return new Copy<string_type, string_adaptor>(sets);
2007-07-19 19:01:42 +02:00
} // createContainer
}; // class WhenHandler
2012-11-04 18:12:14 +01:00
template<class string_type, class string_adaptor>
class CopyOfHandler : public SAX::DefaultHandler<string_type, string_adaptor>
2007-07-19 19:01:42 +02:00
{
public:
2012-11-04 18:12:14 +01:00
CopyOfHandler(CompilationContext<string_type, string_adaptor>& context) :
2007-07-19 19:01:42 +02:00
context_(context),
copyOf_(0)
{
} // CopyOfHandler
2012-11-04 18:12:14 +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(copyOf_ == 0)
{
2010-01-10 22:25:35 +01:00
static const ValueRule rules[] = { { "select", true, 0, 0 },
{ 0, false, 0, 0 } };
2012-11-04 18:12:14 +01:00
string_type select = gatherAttributes(qName, atts, rules)["select"];
2007-07-19 19:01:42 +02:00
2012-11-04 18:12:14 +01:00
copyOf_ = new CopyOf<string_type, string_adaptor>(context_.xpath_expression(select));
2007-07-19 19:01:42 +02:00
return;
} // if(copyOf_ == 0)
throw SAX::SAXException(qName + " can not contain elements");
} // startElement
2012-11-04 18:12:14 +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
{
context_.parentContainer().add_item(copyOf_);
context_.pop();
} // endElement
2012-11-04 18:12:14 +01:00
virtual void characters(const string_type& ch)
2007-07-19 19:01:42 +02:00
{
verifyNoCharacterData(ch, "xsl:copy-of");
2007-07-19 19:01:42 +02:00
} // characters
private:
2012-11-04 18:12:14 +01:00
CompilationContext<string_type, string_adaptor>& context_;
CopyOf<string_type, string_adaptor>* copyOf_;
2007-07-19 19:01:42 +02:00
}; // class CopyOfHandler
} // namespace XSLT
} // namespace Arabica
#endif