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

83 lines
2.3 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
{
class CopyHandler : public ItemContainerHandler<Copy>
{
public:
CopyHandler(CompilationContext& context) :
ItemContainerHandler<Copy>(context)
{
} // CopyHandler
2010-01-10 22:25:35 +01:00
virtual Copy* createContainer(const std::string& /* namespaceURI */,
const std::string& /* localName */,
2007-07-19 19:01:42 +02:00
const std::string& qName,
const SAX::Attributes<std::string>& 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 } };
2007-07-19 19:01:42 +02:00
std::string sets = gatherAttributes(qName, atts, rules)["use-attribute-sets"];
return new Copy(sets);
} // createContainer
}; // class WhenHandler
class CopyOfHandler : public SAX::DefaultHandler<std::string>
2007-07-19 19:01:42 +02:00
{
public:
CopyOfHandler(CompilationContext& context) :
context_(context),
copyOf_(0)
{
} // CopyOfHandler
2010-01-10 22:25:35 +01:00
virtual void startElement(const std::string& /* namespaceURI */,
const std::string& /* localName */,
2007-07-19 19:01:42 +02:00
const std::string& qName,
const SAX::Attributes<std::string>& 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 } };
2007-07-19 19:01:42 +02:00
std::string select = gatherAttributes(qName, atts, rules)["select"];
copyOf_ = new CopyOf(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
2010-01-10 22:25:35 +01:00
virtual void endElement(const std::string& /* namespaceURI */,
const std::string& /* localName */,
const std::string& /* qName */)
2007-07-19 19:01:42 +02:00
{
context_.parentContainer().add_item(copyOf_);
context_.pop();
} // endElement
virtual void characters(const std::string& ch)
{
2010-05-19 21:22:22 +02:00
verifyNoCharacterData(ch, "xsl:copy-of");
2007-07-19 19:01:42 +02:00
} // characters
private:
CompilationContext& context_;
CopyOf* copyOf_;
}; // class CopyOfHandler
} // namespace XSLT
} // namespace Arabica
#endif