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

87 lines
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
{
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
{
typedef StylesheetConstant<string_type, string_adaptor> SC;
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
{
static const ValueRule<string_type> rules[] = { { SC::use_attribute_sets, false, 0, 0 },
{ string_adaptor::empty_string(), false, 0, 0 } };
string_type sets = gatherAttributes(qName, atts, rules)[SC::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
{
typedef StylesheetConstant<string_type, string_adaptor> SC;
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)
{
static const ValueRule<string_type> rules[] = { { SC::select, true, 0, 0 },
{ string_adaptor::empty_string(), false, 0, 0 } };
string_type select = gatherAttributes(qName, atts, rules)[SC::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(string_adaptor::asStdString(qName) + " can not contain elements");
2007-07-19 19:01:42 +02:00
} // 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<string_type, string_adaptor>(ch, SC::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