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

65 lines
1.7 KiB
C++
Raw Normal View History

2009-02-16 23:10:00 +01:00
#ifndef ARABICA_XSLT_KEY_HANDLER_HPP
#define ARABICA_XSLT_KEY_HANDLER_HPP
#include "../xslt_key.hpp"
#include <XML/XMLCharacterClasses.hpp>
namespace Arabica
{
namespace XSLT
{
class KeyHandler : public SAX::DefaultHandler<std::string>
{
public:
KeyHandler(CompilationContext& context) :
context_(context),
key_(0)
{
} // KeyHandler
2010-01-10 23:02:43 +01:00
virtual void startElement(const std::string& /* namespaceURI */,
const std::string& /* localName */,
2009-02-16 23:10:00 +01:00
const std::string& qName,
const SAX::Attributes<std::string>& atts)
{
if(key_ != 0)
throw SAX::SAXException(qName + " can not contain elements");
2010-01-10 23:02:43 +01:00
static const ValueRule rules[] = { { "name", true, 0, 0 },
{ "match", true, 0, 0 },
{ "use", true, 0, 0 },
{ 0, false, 0, 0 } };
2009-02-16 23:10:00 +01:00
std::map<std::string, std::string> attrs = gatherAttributes(qName, atts, rules);
name_ = context_.processInternalQName(attrs["name"]).clarkName();
2009-02-16 23:10:00 +01:00
Key::MatchExprList matches = context_.xpath_match(attrs["match"]);
Arabica::XPath::XPathExpression<std::string> use = context_.xpath_expression(attrs["use"]);
key_ = new Key(matches, use);
} // startElement
2010-01-10 23:02:43 +01:00
virtual void endElement(const std::string& /* namespaceURI */,
const std::string& /* localName */,
const std::string& /* qName */)
2009-02-16 23:10:00 +01:00
{
context_.stylesheet().add_key(name_, key_);
context_.pop();
} // endElement
virtual void characters(const std::string& ch)
{
2010-05-19 21:22:22 +02:00
verifyNoCharacterData(ch, "xsl:key");
2009-02-16 23:10:00 +01:00
} // characters
private:
CompilationContext& context_;
std::string name_;
2009-02-16 23:10:00 +01:00
Key* key_;
}; // class KeyHandler
} // namespace XSLT
} // namespace Arabica
#endif