diff --git a/include/XPath/impl/xpath_compile_context.hpp b/include/XPath/impl/xpath_compile_context.hpp index 5a78c8a4..033fc26d 100644 --- a/include/XPath/impl/xpath_compile_context.hpp +++ b/include/XPath/impl/xpath_compile_context.hpp @@ -1,56 +1,56 @@ -#ifndef ARABICA_XPATH_COMPILE_CONTEXT_HPP -#define ARABICA_XPATH_COMPILE_CONTEXT_HPP - -namespace Arabica -{ -namespace XPath -{ - -template class XPath; -template class NamespaceContext; -template class FunctionResolver; - -namespace impl -{ - -template -class CompilationContext : private NamespaceContext -{ -public: - CompilationContext(const XPath& xpathCompiler, - const NamespaceContext& namespaceContext, - const FunctionResolver& functionResolver) : - xpath_(xpathCompiler), - namespaceContext_(namespaceContext), - functionResolver_(functionResolver) - { - } // CompilationContext - - const XPath& xpath() const { return xpath_; } - const NamespaceContext& namespaceContext() const { return *this; } - const FunctionResolver& functionResolver() const { return functionResolver_; } - -private: - virtual string_type namespaceURI(const string_type& prefix) const - { - string_type uri = namespaceContext_.namespaceURI(prefix); - if(string_adaptor::empty(uri)) - throw Arabica::XPath::UnboundNamespacePrefixException(string_adaptor::asStdString(prefix)); - return uri; - } // namespaceURI - - - const XPath& xpath_; - const NamespaceContext& namespaceContext_; - const FunctionResolver& functionResolver_; - - CompilationContext(const CompilationContext&); - CompilationContext& operator=(const CompilationContext&); - bool operator==(const CompilationContext&) const; -}; // class CompilationContext - -} // namespace impl -} // namespace XPath -} // namespace Arabica - -#endif +#ifndef ARABICA_XPATH_COMPILE_CONTEXT_HPP +#define ARABICA_XPATH_COMPILE_CONTEXT_HPP + +namespace Arabica +{ +namespace XPath +{ + +template class XPath; +template class NamespaceContext; +template class FunctionResolver; + +namespace impl +{ + +template +class CompilationContext : private NamespaceContext +{ +public: + CompilationContext(const XPath& xpathCompiler, + const NamespaceContext& namespaceContext, + const FunctionResolver& functionResolver) : + xpath_(xpathCompiler), + namespaceContext_(namespaceContext), + functionResolver_(functionResolver) + { + } // CompilationContext + + const XPath& xpath() const { return xpath_; } + const NamespaceContext& namespaceContext() const { return *this; } + const FunctionResolver& functionResolver() const { return functionResolver_; } + +private: + virtual string_type namespaceURI(const string_type& prefix) const + { + string_type uri = namespaceContext_.namespaceURI(prefix); + if(string_adaptor::empty(uri)) + throw Arabica::XPath::UnboundNamespacePrefixException(string_adaptor::asStdString(prefix)); + return uri; + } // namespaceURI + + + const XPath& xpath_; + const NamespaceContext& namespaceContext_; + const FunctionResolver& functionResolver_; + + CompilationContext(const CompilationContext&); + CompilationContext& operator=(const CompilationContext&); + bool operator==(const CompilationContext&) const; +}; // class CompilationContext + +} // namespace impl +} // namespace XPath +} // namespace Arabica + +#endif diff --git a/include/XSLT/impl/handler/xslt_create_handler.hpp b/include/XSLT/impl/handler/xslt_create_handler.hpp index 2b1ab2e7..ac51ba18 100755 --- a/include/XSLT/impl/handler/xslt_create_handler.hpp +++ b/include/XSLT/impl/handler/xslt_create_handler.hpp @@ -6,7 +6,7 @@ #include #include "../xslt_compilation_context.hpp" -#include "../xslt_stylesheet.hpp" +#include "../xslt_compiled_stylesheet.hpp" #include "xslt_constants.hpp" namespace Arabica diff --git a/include/XSLT/impl/xslt_apply_templates.hpp b/include/XSLT/impl/xslt_apply_templates.hpp index 99abf5b6..6a620fe1 100755 --- a/include/XSLT/impl/xslt_apply_templates.hpp +++ b/include/XSLT/impl/xslt_apply_templates.hpp @@ -1,7 +1,7 @@ #ifndef ARABICA_XSLT_APPLY_TEMPLATES_HPP #define ARABICA_XSLT_APPLY_TEMPLATES_HPP -#include "xslt_stylesheet.hpp" +#include "xslt_compiled_stylesheet.hpp" #include "xslt_sort.hpp" #include "xslt_with_param.hpp" diff --git a/include/XSLT/impl/xslt_call_template.hpp b/include/XSLT/impl/xslt_call_template.hpp index eb20e975..cdbde36a 100644 --- a/include/XSLT/impl/xslt_call_template.hpp +++ b/include/XSLT/impl/xslt_call_template.hpp @@ -1,7 +1,7 @@ #ifndef ARABICA_XSLT_CALL_TEMPLATE_HPP #define ARABICA_XSLT_CALL_TEMPLATE_HPP -#include "xslt_stylesheet.hpp" +#include "xslt_compiled_stylesheet.hpp" #include "xslt_with_param.hpp" namespace Arabica diff --git a/include/XSLT/impl/xslt_compilation_context.hpp b/include/XSLT/impl/xslt_compilation_context.hpp index 669f344b..5202f4a8 100755 --- a/include/XSLT/impl/xslt_compilation_context.hpp +++ b/include/XSLT/impl/xslt_compilation_context.hpp @@ -14,7 +14,7 @@ namespace Arabica { namespace XSLT { -class Stylesheet; +class CompiledStylesheet; class ItemContainer; class CompilationContext : @@ -23,7 +23,7 @@ class CompilationContext : { public: CompilationContext(StylesheetParser& parser, - Stylesheet& stylesheet) : + CompiledStylesheet& stylesheet) : parser_(parser), stylesheet_(stylesheet), autoNs_(1), @@ -56,7 +56,7 @@ public: return xpath_.compile_match(match); } // xpath_match Arabica::XPath::XPathExpressionPtr xpath_attribute_value_template(const std::string& expr) const { return xpath_.compile_attribute_value_template(expr); } - Stylesheet& stylesheet() const { return stylesheet_; } + CompiledStylesheet& stylesheet() const { return stylesheet_; } std::pair processInternalQName(const std::string& qName) const { @@ -181,7 +181,7 @@ private: StylesheetParser& parser_; Arabica::XPath::XPath xpath_; - Stylesheet& stylesheet_; + CompiledStylesheet& stylesheet_; std::stack*> handlerStack_; std::stack parentStack_; std::map namespaceRemap_; diff --git a/include/XSLT/impl/xslt_stylesheet.hpp b/include/XSLT/impl/xslt_compiled_stylesheet.hpp similarity index 88% rename from include/XSLT/impl/xslt_stylesheet.hpp rename to include/XSLT/impl/xslt_compiled_stylesheet.hpp index 750e79c9..856b1fb8 100755 --- a/include/XSLT/impl/xslt_stylesheet.hpp +++ b/include/XSLT/impl/xslt_compiled_stylesheet.hpp @@ -1,5 +1,5 @@ -#ifndef ARABICA_XSLT_STYLESHEET_HPP -#define ARABICA_XSLT_STYLESHEET_HPP +#ifndef ARABICA_XSLT_COMPILED_STYLESHEET_HPP +#define ARABICA_XSLT_COMPILED_STYLESHEET_HPP #include #include @@ -8,13 +8,14 @@ #include "xslt_execution_context.hpp" #include "xslt_template.hpp" #include "xslt_top_level_param.hpp" +#include "xslt_stylesheet.hpp" namespace Arabica { namespace XSLT { -class Stylesheet +class CompiledStylesheet : public Stylesheet { typedef Arabica::XPath::BoolValue > BoolValue; typedef Arabica::XPath::NumericValue > NumericValue; @@ -22,14 +23,16 @@ class Stylesheet typedef Arabica::XPath::XPathValuePtr ValuePtr; public: - Stylesheet() : + CompiledStylesheet() : output_(new StreamSink(std::cout)), - error_output_(&std::cerr) + error_output_(&std::cerr), + current_import_precedence_(0), + total_imports_(0) { push_import_precedence(); - } // Stylesheet + } // CompiledStylesheet - ~Stylesheet() + virtual ~CompiledStylesheet() { // let's clean up! for(ItemStack::const_iterator isi = items_.begin(), ise = items_.end(); isi != ise; ++isi) @@ -39,36 +42,36 @@ public: delete *pi; for(TemplateList::const_iterator ti = all_templates_.begin(), te = all_templates_.end(); ti != te; ++ti) delete *ti; - } // ~Stylesheet + } // ~CompiledStylesheet - void set_parameter(const std::string& name, bool value) + virtual void set_parameter(const std::string& name, bool value) { set_parameter(name, ValuePtr(new BoolValue(value))); } // set_parameter - void set_parameter(const std::string& name, double value) + virtual void set_parameter(const std::string& name, double value) { set_parameter(name, ValuePtr(new NumericValue(value))); } // set_parameter - void set_parameter(const std::string& name, const char* value) + virtual void set_parameter(const std::string& name, const char* value) { set_parameter(name, ValuePtr(new StringValue(value))); } // set_parameter - void set_parameter(const std::string& name, const std::string& value) + virtual void set_parameter(const std::string& name, const std::string& value) { set_parameter(name, ValuePtr(new StringValue(value))); } // set_parameter - void set_output(Sink& sink) + virtual void set_output(Sink& sink) { output_.reset(sink); } // set_output - void set_error_output(std::ostream& os) + virtual void set_error_output(std::ostream& os) { error_output_ = &os; } // set_error_output - void execute(DOM::Node& initialNode) const + virtual void execute(const DOM::Node& initialNode) const { if(initialNode == 0) throw std::runtime_error("Input document is empty"); @@ -318,16 +321,19 @@ private: ItemStack items_; ParamList params_; + std::vector current_import_precedence_; + int total_imports_; + mutable std::pair current_mode_; mutable int current_generation_; Output::Settings output_settings_; SinkHolder output_; mutable std::ostream* error_output_; -}; // class Stylesheet +}; // class CompiledStylesheet } // namespace XSLT } // namespace Arabica -#endif // ARABICA_XSLT_STYLESHEET_HPP +#endif // ARABICA_XSLT_COMPILED_STYLESHEET_HPP diff --git a/include/XSLT/impl/xslt_execution_context.hpp b/include/XSLT/impl/xslt_execution_context.hpp index ea7c4f19..3c0e4736 100755 --- a/include/XSLT/impl/xslt_execution_context.hpp +++ b/include/XSLT/impl/xslt_execution_context.hpp @@ -10,7 +10,7 @@ namespace Arabica namespace XSLT { -class Stylesheet; +class CompiledStylesheet; class ExecutionContext; class Variable_declaration @@ -34,7 +34,7 @@ private: class ExecutionContext { public: - ExecutionContext(const Stylesheet& stylesheet, + ExecutionContext(const CompiledStylesheet& stylesheet, Sink& output, std::ostream& error_output) : stylesheet_(stylesheet), @@ -63,7 +63,7 @@ public: xpathContext_.setLast(rhs.xpathContext().last()); } // ExecutionContext - const Stylesheet& stylesheet() const { return stylesheet_; } + const CompiledStylesheet& stylesheet() const { return stylesheet_; } Output& sink() { @@ -104,7 +104,7 @@ private: void popStackFrame() { stack_.popScope(); } private: - const Stylesheet& stylesheet_; + const CompiledStylesheet& stylesheet_; VariableStack stack_; int variable_precedence_; Arabica::XPath::ExecutionContext xpathContext_; diff --git a/include/XSLT/impl/xslt_stylesheet_compiler.hpp b/include/XSLT/impl/xslt_stylesheet_compiler.hpp index bd35c5ea..0b581e85 100755 --- a/include/XSLT/impl/xslt_stylesheet_compiler.hpp +++ b/include/XSLT/impl/xslt_stylesheet_compiler.hpp @@ -6,7 +6,7 @@ #include #include "xslt_stylesheet_parser.hpp" -#include "xslt_stylesheet.hpp" +#include "xslt_compiled_stylesheet.hpp" #include "xslt_compilation_context.hpp" #include "handler/xslt_template_handler.hpp" #include "handler/xslt_include_handler.hpp" @@ -169,20 +169,19 @@ public: { error_ = ""; - std::auto_ptr stylesheet(new Stylesheet()); + std::auto_ptr stylesheet(new CompiledStylesheet()); - CompilationContext context(parser_, - *stylesheet.get()); + StylesheetParser parser; + CompilationContext context(parser, *stylesheet.get()); StylesheetHandler stylesheetHandler(context); - - parser_.setContentHandler(stylesheetHandler); - //parser_.setErrorHandler(*this); + parser.setContentHandler(stylesheetHandler); + //parser.setErrorHandler(*this); //if(entityResolver_) - // parser_.setEntityResolver(*entityResolver_); + // parser.setEntityResolver(*entityResolver_); try { - parser_.parse(source); + parser.parse(source); } // try catch(std::exception& ex) { @@ -191,7 +190,7 @@ public: stylesheet.reset(); } // catch - return stylesheet; + return std::auto_ptr(stylesheet.release()); } // compile const std::string& error() const @@ -200,14 +199,6 @@ public: } // error private: - virtual void fatalError(const SAX::SAXException& exception) - { - std::cerr << "Error: " << exception.what() << std::endl; - stylesheet_.reset(); - } // fatalError - - StylesheetParser parser_; - std::auto_ptr stylesheet_; std::string error_; }; // class StylesheetCompiler