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

92 lines
3.3 KiB
C++
Raw Normal View History

#ifndef ARABICA_XSLT_OUTPUT_HANDLER_HPP
#define ARABICA_XSLT_OUTPUT_HANDLER_HPP
namespace Arabica
{
namespace XSLT
{
2012-11-06 20:09:20 +01:00
template<class string_type, class string_adaptor>
class OutputHandler : public SAX::DefaultHandler<string_type, string_adaptor>
{
public:
2012-11-06 20:09:20 +01:00
OutputHandler(CompilationContext<string_type, string_adaptor>& context) :
context_(context)
{
} // OutputHandler
2012-11-06 20:09:20 +01:00
virtual void startElement(const string_type& /* namespaceURI */,
const string_type& /* localName */,
const string_type& qName,
const SAX::Attributes<string_type, string_adaptor>& atts)
{
if(settings_.empty())
{
static const char* AllowedMethods[] = { "xml", "html", "text", 0 };
static const ValueRule rules[] = { { "method", false, "xml", AllowedMethods },
2010-01-10 23:02:43 +01:00
{ "version", false, "1.0", 0 },
{ "encoding", false, "UTF-8", 0 },
{ "omit-xml-declaration", false, No, AllowedYesNo },
{ "standalone", false, "", AllowedYesNo },
2010-01-10 23:02:43 +01:00
{ "doctype-public", false, "", 0},
{ "doctype-system", false, "", 0},
{ "cdata-section-elements", false, "", 0},
{ "indent", false, No, AllowedYesNo },
2010-01-10 23:02:43 +01:00
{ "media-type", false, "", 0 },
{ 0, false, 0, 0 } };
settings_ = gatherAttributes(qName, atts, rules);
cdataElements_ = extractCDATAElements(settings_["cdata-section-elements"]);
return;
} // if(settings_ == 0)
throw SAX::SAXException(qName + " can not contain elements");
} // startElement
2012-11-06 20:09:20 +01:00
virtual void endElement(const string_type& /* namespaceURI */,
const string_type& /* localName */,
const string_type& /* qName */)
{
context_.stylesheet().output_settings(settings_, cdataElements_);
context_.pop();
} // endElement
2012-11-06 20:09:20 +01:00
virtual void characters(const string_type& ch)
{
verifyNoCharacterData(ch, "xsl:output");
} // characters
private:
2012-11-06 20:29:22 +01:00
typedef typename Output<string_type, string_adaptor>::CDATAElements CDATAElements;
typedef typename Output<string_type, string_adaptor>::Settings Settings;
CDATAElements extractCDATAElements(const string_type& cdata_section_elements) const
{
2012-11-06 20:29:22 +01:00
CDATAElements elements;
if(cdata_section_elements.empty())
return elements;
2012-11-06 20:09:20 +01:00
std::istringstream is(text::normalize_whitespace<string_type, string_adaptor>(cdata_section_elements));
while(!is.eof())
{
2012-11-06 20:09:20 +01:00
string_type e;
is >> e;
2012-11-06 20:09:20 +01:00
XML::QualifiedName<string_type, string_adaptor> qualifiedName = context_.processElementQName(e);
2012-11-06 21:15:35 +01:00
elements.insert(QName<string_type, string_adaptor>::create(qualifiedName));
} // while
return elements;
} // extractCDATAElements
2012-11-06 20:09:20 +01:00
CompilationContext<string_type, string_adaptor>& context_;
2012-11-06 20:29:22 +01:00
Settings settings_;
CDATAElements cdataElements_;
}; // class OutputHandler
} // namespace XSLT
} // namespace Arabica
#endif