pulled out stylesheet parser into a seperate class

This commit is contained in:
jez 2007-08-22 12:38:20 +00:00
parent b1149906ab
commit f036ba1b64
3 changed files with 78 additions and 32 deletions

View file

@ -6,6 +6,8 @@
#include <XPath/XPath.hpp>
#include <stack>
#include "xslt_stylesheet_parser.hpp"
namespace Arabica
{
namespace XSLT
@ -17,7 +19,7 @@ class ItemContainer;
class CompilationContext
{
public:
CompilationContext(SAX::NamespaceTracker<std::string>& parser,
CompilationContext(StylesheetParser& parser,
Arabica::XPath::XPath<std::string>& xpathCompiler,
Stylesheet& stylesheet) :
parser_(parser),
@ -42,19 +44,18 @@ public:
handlerStack_.push(&root);
} // root
SAX::basic_XMLReader<std::string>& parser() const { return parser_; }
StylesheetParser& parser() const { return parser_; }
const Arabica::XPath::XPath<std::string>& xpath() const { return xpath_; }
Stylesheet& stylesheet() const { return stylesheet_; }
std::pair<std::string, std::string> processQName(const std::string& qName) const
{
return parser_.process(qName);
return parser_.processQName(qName);
} // processQName
std::string makeAbsolute(const std::string& href) const
{
SAX::XMLBaseTracker<std::string>* tracker = static_cast<SAX::XMLBaseTracker<std::string>*>(parser_.getParent());
return tracker->makeAbsolute(href);
return parser_.makeAbsolute(href);
} // makeAbsolute
void push(ItemContainer* parent,
@ -121,7 +122,7 @@ public:
private:
typedef std::pair<std::string, std::string> Namespace;
SAX::NamespaceTracker<std::string>& parser_;
StylesheetParser& parser_;
const Arabica::XPath::XPath<std::string>& xpath_;
Stylesheet& stylesheet_;
std::stack<SAX::DefaultHandler*> handlerStack_;

View file

@ -3,10 +3,8 @@
#include <XML/XMLCharacterClasses.h>
#include <memory>
#include <SAX/filter/NamespaceTracker.hpp>
#include <SAX/filter/XMLBaseTracker.hpp>
#include <SAX/filter/TextCoalescer.hpp>
#include "xslt_stylesheet_parser.hpp"
#include "xslt_stylesheet.hpp"
#include "xslt_compilation_context.hpp"
#include "xslt_functions.hpp"
@ -129,29 +127,11 @@ const ChildElement StylesheetHandler::allowedChildren[] =
{ 0, 0 }
}; // StylesheetHandler::allowedChildren
class NamespaceTracker : public SAX::NamespaceTracker<std::string>,
public XPath::NamespaceContext<std::string, Arabica::default_string_adaptor<std::string> >
{
typedef SAX::basic_XMLReader<std::string> XMLReaderT;
public:
NamespaceTracker(XMLReaderT& parent) :
SAX::NamespaceTracker<std::string, Arabica::default_string_adaptor<std::string> >(parent)
{
} // NamespaceTracker
virtual std::string namespaceURI(const std::string& prefix) const
{
return this->getURI(prefix);
} // namespaceURI
}; // class NamespaceTracker
class StylesheetCompiler
{
public:
StylesheetCompiler() :
handler_(0),
stylesheet_(new Stylesheet)
{
} // StylesheetCompiler
@ -164,10 +144,7 @@ public:
{
error_ = "";
SAX::XMLReader<std::string> base_parser;
SAX::TextCoalescer<std::string> text_coalescer(base_parser);
SAX::XMLBaseTracker<std::string> xmlbase_tracker(text_coalescer);
NamespaceTracker parser(xmlbase_tracker);
StylesheetParser parser;
Arabica::XPath::XPath<std::string> xpathCompiler;
xpathCompiler.setNamespaceContext(parser);
@ -210,7 +187,6 @@ private:
} // fatalError
std::auto_ptr<Stylesheet> stylesheet_;
std::auto_ptr<SAX::ContentHandler> handler_;
std::string error_;
XsltFunctionResolver fnResolver_;
}; // class StylesheetCompiler

View file

@ -0,0 +1,69 @@
#ifndef ARABICA_XSLT_STYLESHEETPARSER_HPP
#define ARABICA_XSLT_STYLESHEETPARSER_HPP
#include <SAX/filter/NamespaceTracker.hpp>
#include <SAX/filter/XMLBaseTracker.hpp>
#include <SAX/filter/TextCoalescer.hpp>
#include <XPath/impl/xpath_namespace_context.hpp>
namespace Arabica
{
namespace XSLT
{
class StylesheetParser : public XPath::NamespaceContext<std::string, Arabica::default_string_adaptor<std::string> >
{
public:
StylesheetParser() { }
void setContentHandler(SAX::ContentHandler& handler)
{
namespace_tracker_.setContentHandler(handler);
} // setContentHandler
void parse(SAX::InputSource& source)
{
SAX::XMLReader<std::string> base_parser;
text_coalescer_.setParent(base_parser);
xmlbase_tracker_.setParent(text_coalescer_);
namespace_tracker_.setParent(xmlbase_tracker_);
namespace_tracker_.parse(source);
} // parse
virtual std::string namespaceURI(const std::string& prefix) const
{
return namespace_tracker_.getURI(prefix);
} // namespaceURI
std::pair<std::string, std::string> processQName(const std::string& qName) const
{
return namespace_tracker_.process(qName);
} // processQName
std::map<std::string, std::string> inScopeNamespaces() const
{
return namespace_tracker_.inScopeNamespaces();
} // inScopeNamespaces
std::string makeAbsolute(const std::string& href)
{
return xmlbase_tracker_.makeAbsolute(href);
} // makeAbsolute
private:
SAX::TextCoalescer<std::string> text_coalescer_;
SAX::XMLBaseTracker<std::string> xmlbase_tracker_;
SAX::NamespaceTracker<std::string> namespace_tracker_;
StylesheetParser(const StylesheetParser&);
StylesheetParser operator=(const StylesheetParser&);
bool operator==(const StylesheetParser&);
}; // class StylesheetParser
} // namespace XSLT
} // namespace Arabica
#endif // ARABICA_XSLT_STYLESHEETPARSER_HPP