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

77 lines
2.5 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
{
class NamespaceAliasHandler : public SAX::DefaultHandler<std::string>
2007-07-19 19:01:42 +02:00
{
public:
NamespaceAliasHandler(CompilationContext<std::string>& context) :
2007-07-19 19:01:42 +02:00
context_(context),
done_(false)
{
} // NamespaceAliasHandler
2010-01-10 23:02:43 +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(!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
std::map<std::string, std::string> attrs = gatherAttributes(qName, atts, rules);
std::string stylesheet_prefix = attrs["stylesheet-prefix"];
std::string result_prefix = attrs["result-prefix"];
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
std::map<std::string, std::string> namespaces = context_.inScopeNamespaces();
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
2010-01-10 23:02:43 +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_.pop();
} // endElement
virtual void characters(const std::string& ch)
{
verifyNoCharacterData(ch, "xsl:namespace-alias");
2007-07-19 19:01:42 +02:00
} // characters
private:
CompilationContext<std::string>& context_;
2007-07-19 19:01:42 +02:00
bool done_;
}; // class NamespaceAliasHandler
} //namespace XSLT
} //namespace Arabica
#endif