2009-03-17 22:08:26 +01:00
|
|
|
#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>
|
2009-03-17 22:08:26 +01:00
|
|
|
{
|
2012-11-12 22:46:08 +01:00
|
|
|
typedef StylesheetConstant<string_type, string_adaptor> SC;
|
2012-11-15 23:03:42 +01:00
|
|
|
typedef AttributeValidators<string_type, string_adaptor> AV;
|
2012-11-12 22:46:08 +01:00
|
|
|
|
2009-03-17 22:08:26 +01:00
|
|
|
public:
|
2012-11-06 20:09:20 +01:00
|
|
|
OutputHandler(CompilationContext<string_type, string_adaptor>& context) :
|
2009-03-17 22:08:26 +01:00
|
|
|
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)
|
2009-03-17 22:08:26 +01:00
|
|
|
{
|
|
|
|
if(settings_.empty())
|
|
|
|
{
|
2012-11-15 23:03:42 +01:00
|
|
|
static const AV rules = AV::rule(SC::method, false, SC::xml, AllowedValues<string_type>(SC::xml, SC::html, SC::text))
|
|
|
|
.rule(SC::version, false, SC::Version)
|
|
|
|
.rule(SC::encoding, false, SC::utf8)
|
|
|
|
.rule(SC::omit_xml_declaration, false, SC::no, AllowedValues<string_type>(SC::yes, SC::no))
|
|
|
|
.rule(SC::standalone, false, string_adaptor::empty_string(), AllowedValues<string_type>(SC::yes, SC::no))
|
|
|
|
.rule(SC::doctype_public, false, string_adaptor::empty_string())
|
|
|
|
.rule(SC::doctype_system, false, string_adaptor::empty_string())
|
|
|
|
.rule(SC::cdata_section_elements, false, string_adaptor::empty_string())
|
|
|
|
.rule(SC::indent, false, SC::no, AllowedValues<string_type>(SC::yes, SC::no))
|
|
|
|
.rule(SC::media_type, false, string_adaptor::empty_string());
|
|
|
|
|
|
|
|
settings_ = rules.gather(qName, atts);
|
2012-11-12 22:46:08 +01:00
|
|
|
cdataElements_ = extractCDATAElements(settings_[SC::cdata_section_elements]);
|
2009-03-17 22:08:26 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
} // if(settings_ == 0)
|
|
|
|
|
2012-11-12 22:46:08 +01:00
|
|
|
throw SAX::SAXException(string_adaptor::asStdString(qName) + " can not contain elements");
|
2009-03-17 22:08:26 +01:00
|
|
|
} // startElement
|
|
|
|
|
2012-11-06 20:09:20 +01:00
|
|
|
virtual void endElement(const string_type& /* namespaceURI */,
|
|
|
|
const string_type& /* localName */,
|
|
|
|
const string_type& /* qName */)
|
2009-03-17 22:08:26 +01:00
|
|
|
{
|
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
|
|
|
|
|
2012-11-06 20:09:20 +01:00
|
|
|
virtual void characters(const string_type& ch)
|
2009-03-17 22:08:26 +01:00
|
|
|
{
|
2012-11-12 22:46:08 +01:00
|
|
|
verifyNoCharacterData<string_type, string_adaptor>(ch, SC::output);
|
2009-03-17 22:08:26 +01:00
|
|
|
} // 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
|
2009-04-07 11:29:56 +02:00
|
|
|
{
|
2012-11-06 20:29:22 +01:00
|
|
|
CDATAElements elements;
|
2009-04-07 11:29:56 +02:00
|
|
|
|
2012-11-21 07:59:40 +01:00
|
|
|
if(string_adaptor::empty(cdata_section_elements))
|
2009-04-07 14:39:31 +02:00
|
|
|
return elements;
|
|
|
|
|
2012-11-21 07:59:40 +01:00
|
|
|
string_type norm_cdata_sec_elements = text::normalize_whitespace<string_type, string_adaptor>(cdata_section_elements);
|
2012-11-21 12:12:35 +01:00
|
|
|
std::basic_stringstream<typename string_adaptor::value_type> is;
|
|
|
|
is << norm_cdata_sec_elements;
|
2009-04-07 11:29:56 +02:00
|
|
|
while(!is.eof())
|
|
|
|
{
|
2012-11-21 07:59:40 +01:00
|
|
|
std::basic_string<typename string_adaptor::value_type> e;
|
2009-04-07 11:29:56 +02:00
|
|
|
is >> e;
|
|
|
|
|
2012-11-21 07:59:40 +01:00
|
|
|
XML::QualifiedName<string_type, string_adaptor> qualifiedName = context_.processElementQName(string_adaptor::construct(e));
|
2012-11-06 21:15:35 +01:00
|
|
|
elements.insert(QName<string_type, string_adaptor>::create(qualifiedName));
|
2009-04-07 11:29:56 +02:00
|
|
|
} // 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_;
|
2009-03-17 22:08:26 +01:00
|
|
|
}; // class OutputHandler
|
|
|
|
|
|
|
|
} // namespace XSLT
|
|
|
|
} // namespace Arabica
|
|
|
|
|
|
|
|
#endif
|