2009-03-17 22:08:26 +01:00
|
|
|
#ifndef ARABICA_XSLT_OUTPUT_HANDLER_HPP
|
|
|
|
#define ARABICA_XSLT_OUTPUT_HANDLER_HPP
|
|
|
|
|
|
|
|
#include "xslt_value_validation.hpp"
|
|
|
|
|
|
|
|
namespace Arabica
|
|
|
|
{
|
|
|
|
namespace XSLT
|
|
|
|
{
|
|
|
|
|
|
|
|
class OutputHandler : public SAX::DefaultHandler<std::string>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OutputHandler(CompilationContext& context) :
|
|
|
|
context_(context)
|
|
|
|
{
|
|
|
|
} // OutputHandler
|
|
|
|
|
|
|
|
virtual void startElement(const std::string& namespaceURI,
|
|
|
|
const std::string& localName,
|
|
|
|
const std::string& qName,
|
|
|
|
const SAX::Attributes<std::string>& atts)
|
|
|
|
{
|
|
|
|
if(settings_.empty())
|
|
|
|
{
|
|
|
|
static const char* AllowedMethods[] = { "xml", "html", "text", 0 };
|
|
|
|
static const ValueRule rules[] = { { "method", false, "xml", AllowedMethods },
|
|
|
|
{ "version", false, "1.0" },
|
|
|
|
{ "encoding", false, "UTF-8" },
|
|
|
|
{ "omit-xml-declaration", false, No, AllowedYesNo },
|
|
|
|
{ "standalone", false, "", AllowedYesNo },
|
|
|
|
{ "doctype-public", false, ""},
|
|
|
|
{ "doctype-system", false, ""},
|
|
|
|
{ "cdata-section-elements", false, ""},
|
|
|
|
{ "indent", false, No, AllowedYesNo },
|
|
|
|
{ "media-type", false, "" },
|
|
|
|
{ 0, false, 0 } };
|
|
|
|
settings_ = gatherAttributes(qName, atts, rules);
|
2009-04-07 11:29:56 +02:00
|
|
|
cdataElements_ = extractCDATAElements(settings_["cdata-section-elements"]);
|
2009-03-17 22:08:26 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
} // if(settings_ == 0)
|
|
|
|
|
|
|
|
throw SAX::SAXException(qName + " can not contain elements");
|
|
|
|
} // startElement
|
|
|
|
|
|
|
|
virtual void endElement(const std::string& namespaceURI,
|
|
|
|
const std::string& localName,
|
|
|
|
const std::string& qName)
|
|
|
|
{
|
2009-04-07 11:29:56 +02:00
|
|
|
context_.stylesheet().output_settings(settings_, cdataElements_);
|
2009-03-17 22:08:26 +01:00
|
|
|
context_.pop();
|
|
|
|
} // endElement
|
|
|
|
|
|
|
|
virtual void characters(const std::string& ch)
|
|
|
|
{
|
2009-03-17 10:07:22 +01:00
|
|
|
for(std::string::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i)
|
|
|
|
if(!Arabica::XML::is_space(*i))
|
2009-04-07 11:29:56 +02:00
|
|
|
throw SAX::SAXException("xsl:output element must be empty");
|
2009-03-17 22:08:26 +01:00
|
|
|
} // characters
|
|
|
|
|
|
|
|
private:
|
2009-04-07 11:29:56 +02:00
|
|
|
Output::CDATAElements extractCDATAElements(const std::string& cdata_section_elements) const
|
|
|
|
{
|
|
|
|
Output::CDATAElements elements;
|
|
|
|
|
2009-04-07 14:39:31 +02:00
|
|
|
if(cdata_section_elements.empty())
|
|
|
|
return elements;
|
|
|
|
|
2010-01-02 23:21:38 +01:00
|
|
|
std::istringstream is(text::normalize_whitespace<std::string, Arabica::default_string_adaptor<std::string> >(cdata_section_elements));
|
2009-04-07 11:29:56 +02:00
|
|
|
while(!is.eof())
|
|
|
|
{
|
|
|
|
std::string e;
|
|
|
|
is >> e;
|
|
|
|
|
2009-04-07 14:39:31 +02:00
|
|
|
XML::QualifiedName<std::string> qualifiedName = context_.processElementQName(e);
|
2009-04-07 11:29:56 +02:00
|
|
|
elements.insert(QName::create(qualifiedName));
|
|
|
|
} // while
|
|
|
|
|
|
|
|
return elements;
|
|
|
|
} // extractCDATAElements
|
|
|
|
|
2009-03-17 22:08:26 +01:00
|
|
|
CompilationContext& context_;
|
|
|
|
Output::Settings settings_;
|
2009-04-07 11:29:56 +02:00
|
|
|
Output::CDATAElements cdataElements_;
|
2009-03-17 22:08:26 +01:00
|
|
|
}; // class OutputHandler
|
|
|
|
|
|
|
|
} // namespace XSLT
|
|
|
|
} // namespace Arabica
|
|
|
|
|
|
|
|
#endif
|