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

184 lines
6.9 KiB
C++
Raw Normal View History

2007-07-19 19:01:42 +02:00
#ifndef ARABICA_XSLT_ITEM_CONTAINER_HPP
#define ARABICA_XSLT_ITEM_CONTAINER_HPP
#include "xslt_create_handler.hpp"
#include "../xslt_text.hpp"
namespace Arabica
{
namespace XSLT
{
2012-11-04 23:34:40 +01:00
template<class string_type, class string_adaptor>
const ChildElement<string_type, string_adaptor>* AllowedChildren();
template<class string_type, class string_adaptor>
SAX::DefaultHandler<string_type, string_adaptor>* createInlineElementHandler(CompilationContext<string_type, string_adaptor>& context);
2007-07-19 19:01:42 +02:00
template<class container_type>
2012-11-04 23:34:40 +01:00
class ItemContainerHandler : public SAX::DefaultHandler<typename container_type::string_type, typename container_type::string_adaptor>
2007-07-19 19:01:42 +02:00
{
2012-11-04 23:39:16 +01:00
public:
typedef typename container_type::string_type string_type;
typedef typename container_type::string_adaptor string_adaptor;
2007-07-19 19:01:42 +02:00
protected:
2012-11-04 23:39:16 +01:00
ItemContainerHandler(CompilationContext<string_type, string_adaptor>& context) :
2007-07-19 19:01:42 +02:00
context_(context),
container_(0)
{
} // ItemContainerHandler
2012-11-04 23:39:16 +01:00
ItemContainerHandler(CompilationContext<string_type, string_adaptor>& context, container_type* container) :
context_(context),
container_(container)
{
} // ItemContainerHandler
2012-11-04 23:39:16 +01:00
virtual container_type* createContainer(const string_type& namespaceURI,
const string_type& localName,
const string_type& qName,
const SAX::Attributes<string_type, string_adaptor>& atts) = 0;
2007-07-19 19:01:42 +02:00
2012-11-04 23:39:16 +01:00
CompilationContext<string_type, string_adaptor>& context() const { return context_; }
2007-07-19 19:01:42 +02:00
container_type* container() const { return container_; }
public:
2012-11-04 23:39:16 +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(container_ == 0)
{
container_ = createContainer(namespaceURI, localName, qName, atts);
return;
} // if(item_ == 0)
if(createChild(namespaceURI, localName, qName, atts))
return;
throw SAX::SAXException(qName + " <- Sorry, don't know about that yet :)");
} // startElement
2012-11-04 23:39:16 +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(container_);
context_.pop();
} // endElement
2012-11-04 23:39:16 +01:00
virtual void characters(const string_type& ch)
2007-07-19 19:01:42 +02:00
{
2012-11-04 23:39:16 +01:00
for(typename string_type::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i)
2007-07-19 19:01:42 +02:00
if(!Arabica::XML::is_space(*i))
{
2012-11-04 23:39:16 +01:00
container_->add_item(new Text<string_type, string_adaptor>(ch));
2007-07-19 19:01:42 +02:00
return;
} // if ...
} // characters
protected:
2012-11-04 23:39:16 +01:00
virtual bool createChild(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(namespaceURI == StylesheetConstant::NamespaceURI())
{
2012-11-04 23:39:16 +01:00
for(const ChildElement<string_type, string_adaptor>* c = AllowedChildren<string_type, string_adaptor>(); c->name != 0; ++c)
2007-07-19 19:01:42 +02:00
if(c->name == localName)
{
context_.push(container_,
c->createHandler(context_),
namespaceURI,
localName,
qName,
2007-07-19 19:01:42 +02:00
atts);
return true;
} // if ...
return false;
} // if(namespaceURI ...
context_.push(container_,
createInlineElementHandler(context_),
namespaceURI,
localName,
qName,
2007-07-19 19:01:42 +02:00
atts);
return true;
} // createChild
private:
2012-11-04 23:39:16 +01:00
CompilationContext<string_type, string_adaptor>& context_;
2007-07-19 19:01:42 +02:00
container_type* container_;
}; // class ItemContainerHandler
} // namespace XSLT
} // namespace Arabica
#include "xslt_apply_imports_handler.hpp"
#include "xslt_apply_templates_handler.hpp"
#include "xslt_attribute_handler.hpp"
#include "xslt_call_template_handler.hpp"
#include "xslt_choose_handler.hpp"
#include "xslt_comment_handler.hpp"
#include "xslt_copy_handler.hpp"
#include "xslt_element_handler.hpp"
#include "xslt_for_each_handler.hpp"
#include "xslt_if_handler.hpp"
#include "xslt_message_handler.hpp"
#include "xslt_processing_instruction_handler.hpp"
#include "xslt_text_handler.hpp"
#include "xslt_value_of_handler.hpp"
#include "xslt_variable_handler.hpp"
#include "xslt_inline_element_handler.hpp"
namespace Arabica
{
namespace XSLT
{
2012-11-04 23:34:40 +01:00
template<class string_type, class string_adaptor>
const ChildElement<string_type, string_adaptor>* AllowedChildren()
2007-07-19 19:01:42 +02:00
{
2012-11-04 23:34:40 +01:00
static const ChildElement<string_type, string_adaptor> allowedChildren[] =
2007-07-19 19:01:42 +02:00
{
2012-11-04 23:34:40 +01:00
{ "apply-imports", CreateHandler<ApplyImportsHandler<string_type, string_adaptor> > },
{ "apply-templates", CreateHandler<ApplyTemplatesHandler<string_type, string_adaptor> > },
{ "attribute", CreateHandler<AttributeHandler<string_type, string_adaptor> > },
{ "call-template", CreateHandler<CallTemplateHandler<string_type, string_adaptor> > },
{ "choose", CreateHandler<ChooseHandler<string_type, string_adaptor> > },
{ "comment", CreateHandler<CommentHandler<string_type, string_adaptor> > },
{ "copy", CreateHandler<CopyHandler<string_type, string_adaptor> > },
{ "copy-of", CreateHandler<CopyOfHandler<string_type, string_adaptor> > },
{ "element", CreateHandler<ElementHandler<string_type, string_adaptor> > },
{ "fallback", CreateHandler<NotImplementedYetHandler<string_type, string_adaptor> >},
{ "for-each", CreateHandler<ForEachHandler<string_type, string_adaptor> > },
{ "if", CreateHandler<IfHandler<string_type, string_adaptor> > },
{ "message", CreateHandler<MessageHandler<string_type, string_adaptor> >},
{ "number", CreateHandler<NotImplementedYetHandler<string_type, string_adaptor> >},
{ "processing-instruction", CreateHandler<ProcessingInstructionHandler<string_type, string_adaptor> > },
{ "text", CreateHandler<TextHandler<string_type, string_adaptor> > },
{ "value-of", CreateHandler<ValueOfHandler<string_type, string_adaptor> > },
{ "variable", CreateHandler<VariableHandler<Variable<string_type, string_adaptor> > > },
2007-07-19 19:01:42 +02:00
{ 0, 0 }
};
return allowedChildren;
} // AllowedChildren
2012-11-04 23:34:40 +01:00
template<class string_type, class string_adaptor>
SAX::DefaultHandler<string_type, string_adaptor>* createInlineElementHandler(CompilationContext<string_type, string_adaptor>& context)
2007-07-19 19:01:42 +02:00
{
2012-11-04 23:34:40 +01:00
return new InlineElementHandler<string_type, string_adaptor>(context);
2007-07-19 19:01:42 +02:00
} // InlineElementHandler
} // namespace XSLT
} // namespace Arabica
#endif