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

78 lines
2.6 KiB
C++
Raw Normal View History

2007-07-19 19:01:42 +02:00
#ifndef ARABICA_XSLT_NAMESPACE_ALIAS_HANDLER_HPP
#define ARABICA_XSLT_NAMESPACE_ALIAS_HANDLER_HPP
2007-09-05 00:55:47 +02:00
#include <XML/XMLCharacterClasses.hpp>
2007-07-19 19:01:42 +02:00
namespace Arabica
{
namespace XSLT
{
2012-11-06 20:05:52 +01:00
template<class string_type, class string_adaptor>
class NamespaceAliasHandler : public SAX::DefaultHandler<string_type, string_adaptor>
2007-07-19 19:01:42 +02:00
{
public:
2012-11-06 20:05:52 +01:00
NamespaceAliasHandler(CompilationContext<string_type, string_adaptor>& context) :
2007-07-19 19:01:42 +02:00
context_(context),
done_(false)
{
} // NamespaceAliasHandler
2012-11-06 20:05:52 +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(!done_)
{
2010-01-10 23:02:43 +01:00
static const ValueRule rules[] = { { "stylesheet-prefix", true, 0, 0 },
{ "result-prefix", true, 0, 0 },
{ 0, false, 0, 0 } };
2007-07-19 19:01:42 +02:00
2012-11-06 20:05:52 +01:00
std::map<string_type, string_type> attrs = gatherAttributes(qName, atts, rules);
string_type stylesheet_prefix = attrs["stylesheet-prefix"];
string_type result_prefix = attrs["result-prefix"];
2007-07-19 19:01:42 +02:00
if(stylesheet_prefix == "#default")
2008-08-08 23:45:53 +02:00
stylesheet_prefix = "";
2007-07-19 19:01:42 +02:00
if(result_prefix == "#default")
2008-08-08 23:45:53 +02:00
result_prefix = "";
2007-07-19 19:01:42 +02:00
2012-11-06 20:05:52 +01:00
std::map<string_type, string_type> namespaces = context_.inScopeNamespaces();
2007-07-19 19:01:42 +02:00
if((namespaces.find(stylesheet_prefix) == namespaces.end()) &&
2008-08-08 23:45:53 +02:00
(!stylesheet_prefix.empty()))
throw SAX::SAXException("xslt:namespace-alias " + stylesheet_prefix + " is not a declared namespace prefix");
2007-07-19 19:01:42 +02:00
if((namespaces.find(result_prefix) == namespaces.end()) &&
2008-08-08 23:45:53 +02:00
(!result_prefix.empty()))
throw SAX::SAXException("xslt:namespace-alias " + result_prefix + " is not a declared namespace prefix");
2007-07-19 19:01:42 +02:00
context_.addNamespaceAlias(namespaces[stylesheet_prefix], result_prefix, namespaces[result_prefix]);
return;
} // if(!done_)
throw SAX::SAXException(qName + " can not contain elements");
} // startElement
2012-11-06 20:05:52 +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_.pop();
} // endElement
2012-11-06 20:05:52 +01:00
virtual void characters(const string_type& ch)
2007-07-19 19:01:42 +02:00
{
verifyNoCharacterData(ch, "xsl:namespace-alias");
2007-07-19 19:01:42 +02:00
} // characters
private:
2012-11-06 20:05:52 +01:00
CompilationContext<string_type, string_adaptor>& context_;
2007-07-19 19:01:42 +02:00
bool done_;
}; // class NamespaceAliasHandler
} //namespace XSLT
} //namespace Arabica
#endif