2003-09-11 12:26:53 +02:00
|
|
|
#ifndef ARABICA_GARDEN_H
|
|
|
|
#define ARABICA_GARDEN_H
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2003-09-09 13:14:48 +02:00
|
|
|
#include <SAX/ArabicaConfig.h>
|
2003-04-04 18:54:54 +02:00
|
|
|
#include <boost/spirit.hpp>
|
2003-04-04 21:30:29 +02:00
|
|
|
#include <boost/bind.hpp>
|
2003-04-04 18:54:54 +02:00
|
|
|
#include <vector>
|
2002-06-21 13:16:28 +02:00
|
|
|
#include <string>
|
|
|
|
#include <stack>
|
2005-08-08 07:41:43 +02:00
|
|
|
#include <map>
|
2002-06-21 13:16:28 +02:00
|
|
|
#include <SAX/XMLReader.h>
|
|
|
|
#include <SAX/SAXParseException.h>
|
|
|
|
#include <SAX/SAXNotRecognizedException.h>
|
|
|
|
#include <SAX/helpers/InputSourceResolver.h>
|
|
|
|
#include <SAX/helpers/AttributesImpl.h>
|
2005-08-15 23:09:13 +02:00
|
|
|
#include <Utils/StringAdaptor.h>
|
2006-09-20 13:43:30 +02:00
|
|
|
#include <Utils/getparam.hpp>
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
namespace SAX {
|
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type,
|
|
|
|
class T0 = Arabica::nil_t,
|
|
|
|
class T1 = Arabica::nil_t>
|
2003-04-04 18:54:54 +02:00
|
|
|
class Garden : public basic_XMLReader<string_type>
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
public:
|
2003-04-04 18:54:54 +02:00
|
|
|
typedef string_type stringT;
|
2006-09-20 13:43:30 +02:00
|
|
|
typedef typename Arabica::get_param<Arabica::string_adaptor_tag,
|
|
|
|
Arabica::default_string_adaptor<string_type>,
|
|
|
|
T0,
|
|
|
|
T1>::type string_adaptor_type;
|
|
|
|
typedef string_adaptor_type string_adaptorT;
|
|
|
|
typedef string_adaptor_type SA;
|
2002-06-21 13:16:28 +02:00
|
|
|
typedef basic_EntityResolver<stringT> EntityResolverT;
|
|
|
|
typedef basic_DTDHandler<stringT> DTDHandlerT;
|
|
|
|
typedef basic_ContentHandler<stringT> ContentHandlerT;
|
|
|
|
typedef basic_InputSource<stringT> InputSourceT;
|
|
|
|
typedef basic_AttributesImpl<stringT> AttributesImplT;
|
2003-09-09 15:09:48 +02:00
|
|
|
typedef typename basic_XMLReader<stringT>::PropertyBase PropertyBase;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
Garden();
|
|
|
|
|
|
|
|
virtual bool getFeature(const stringT& name) const;
|
|
|
|
virtual void setFeature(const stringT& name, bool value);
|
|
|
|
|
|
|
|
virtual void setEntityResolver(EntityResolverT& resolver) { entityResolver_ = &resolver; }
|
|
|
|
virtual EntityResolverT* getEntityResolver() const { return entityResolver_; }
|
|
|
|
|
|
|
|
virtual void setDTDHandler(DTDHandlerT& handler) { dtdHandler_ = &handler; }
|
|
|
|
virtual DTDHandlerT* getDTDHandler() const { return dtdHandler_; }
|
|
|
|
|
|
|
|
virtual void setContentHandler(ContentHandlerT& handler) { contentHandler_ = &handler; }
|
|
|
|
virtual ContentHandlerT* getContentHandler() const { return contentHandler_; }
|
|
|
|
|
|
|
|
virtual void setErrorHandler(SAX::ErrorHandler& handler) { errorHandler_ = &handler; }
|
|
|
|
virtual SAX::ErrorHandler* getErrorHandler() const { return errorHandler_; }
|
|
|
|
|
|
|
|
virtual void parse(InputSourceT& input);
|
|
|
|
|
|
|
|
virtual std::auto_ptr<PropertyBase> doGetProperty(const stringT& name);
|
|
|
|
virtual void doSetProperty(const stringT& name, std::auto_ptr<PropertyBase> value);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void reportError(const std::string& message, bool fatal = false);
|
|
|
|
|
2003-09-09 15:09:48 +02:00
|
|
|
typedef typename stringT::value_type char_t;
|
2003-04-04 18:54:54 +02:00
|
|
|
typedef std::vector<char_t> vector_t;
|
2003-09-09 15:09:48 +02:00
|
|
|
typedef typename vector_t::iterator iterator_t;
|
2003-04-04 18:54:54 +02:00
|
|
|
typedef boost::spirit::scanner<iterator_t> scanner_t;
|
|
|
|
typedef boost::spirit::rule<scanner_t> rule_t;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
void openElement(iterator_t s, iterator_t e);
|
|
|
|
void closeElement(iterator_t s, iterator_t e);
|
|
|
|
void closeEmptyElement(iterator_t s, iterator_t e);
|
|
|
|
void endElementName(iterator_t s, iterator_t e);
|
|
|
|
void endElement(iterator_t s, iterator_t e);
|
|
|
|
void attributeName(iterator_t s, iterator_t e);
|
|
|
|
void attributeValue(iterator_t s, iterator_t e);
|
|
|
|
void elementContent(iterator_t s, iterator_t e);
|
|
|
|
void piTarget(iterator_t s, iterator_t e);
|
|
|
|
void piData(iterator_t s, iterator_t e);
|
|
|
|
void piEnd(iterator_t s, iterator_t e);
|
|
|
|
void entityRef(iterator_t s, iterator_t e);
|
|
|
|
void decimalCharacterRef(iterator_t s, iterator_t e);
|
|
|
|
void hexCharacterRef(iterator_t s, iterator_t e);
|
|
|
|
void characterRef(iterator_t s, iterator_t e, int base);
|
|
|
|
|
|
|
|
// Start grammar definition
|
2003-04-04 18:54:54 +02:00
|
|
|
rule_t prolog, element, Misc, Reference,
|
2002-06-21 13:16:28 +02:00
|
|
|
CDSect, CDStart, CData, CDEnd,
|
|
|
|
PI, PITarget, PIData,
|
|
|
|
doctypedecl, XMLDecl, SDDecl, VersionInfo, EncodingDecl,
|
|
|
|
VersionNum, Eq, EmptyElemTag, STag, content, ETag, Attribute,
|
|
|
|
AttValue, CharData, Comment,
|
|
|
|
CharRef, EntityRef, EncName, document_,
|
2003-04-04 21:30:29 +02:00
|
|
|
Name, Comment1, Spaces;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
stringT str(iterator_t s, iterator_t e, int trim = 0);
|
|
|
|
|
|
|
|
//////////////////////////////
|
|
|
|
// member variables
|
|
|
|
EntityResolverT* entityResolver_;
|
|
|
|
DTDHandlerT* dtdHandler_;
|
|
|
|
ContentHandlerT* contentHandler_;
|
|
|
|
ErrorHandler* errorHandler_;
|
|
|
|
|
|
|
|
std::stack<stringT> elements_;
|
|
|
|
AttributesImplT attrs_;
|
2003-09-09 15:09:48 +02:00
|
|
|
typedef typename AttributesImplT::Attr Attr;
|
|
|
|
Attr currentAttr_;
|
2002-06-21 13:16:28 +02:00
|
|
|
stringT piTarget_;
|
|
|
|
stringT piData_;
|
|
|
|
stringT entityRef_;
|
|
|
|
std::map<stringT, stringT> declaredEntities_;
|
|
|
|
std::map<char, int> conversion_;
|
|
|
|
}; // parser
|
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
Garden<string_type, T0, T1>::Garden() :
|
2002-06-21 13:16:28 +02:00
|
|
|
entityResolver_(0),
|
|
|
|
dtdHandler_(0),
|
|
|
|
contentHandler_(0),
|
|
|
|
errorHandler_(0)
|
|
|
|
{
|
|
|
|
// define the parsing rules
|
2003-04-04 18:54:54 +02:00
|
|
|
typedef boost::spirit::chset<char_t> chset_t;
|
|
|
|
typedef boost::spirit::chlit<char_t> chlit_t;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
// characters
|
|
|
|
chset_t Char("\x9\xA\xD\x20-\xFF");
|
2003-04-04 21:30:29 +02:00
|
|
|
chset_t SpaceChar("\x20\x9\xD\xA");
|
|
|
|
Spaces = +(SpaceChar);
|
2002-06-21 13:16:28 +02:00
|
|
|
chset_t Letter("\x41-\x5A\x61-\x7A\xC0-\xD6\xD8-\xF6\xF8-\xFF");
|
|
|
|
chset_t Digit("0-9");
|
|
|
|
chlit_t Extender('\xB7');
|
|
|
|
chset_t NameChar = Letter | Digit | chset_t("._:-") | Extender;
|
|
|
|
Name = (Letter | '_' | ':') >> *(NameChar);
|
|
|
|
|
|
|
|
document_ = prolog >> element >> *Misc;
|
|
|
|
|
2003-04-04 18:54:54 +02:00
|
|
|
chset_t CharDataChar (boost::spirit::anychar_p - (chset_t('<') | chset_t('&')));
|
2006-09-20 13:43:30 +02:00
|
|
|
CharData = (*(CharDataChar - boost::spirit::str_p("]]>")))[boost::bind(&Garden<string_type, T0, T1>::elementContent, this, _1, _2)];
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
// Section 2.5 - Comments
|
2003-04-04 18:54:54 +02:00
|
|
|
Comment = boost::spirit::str_p("<!--") >> Comment1 >> boost::spirit::str_p("-->");
|
|
|
|
Comment1 = *((Char - boost::spirit::ch_p('-')) | (boost::spirit::ch_p('-') >> (Char - boost::spirit::ch_p('-'))));
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
// Section 2.6 - Processing Instructions
|
2006-09-20 13:43:30 +02:00
|
|
|
PI = boost::spirit::str_p("<?") >> (PITarget)[boost::bind(&Garden<string_type, T0, T1>::piTarget, this, _1, _2)] >> !Spaces >> (PIData)[boost::bind(&Garden<string_type, T0, T1>::piData, this, _1, _2)] >> (boost::spirit::str_p("?>"))[boost::bind(&Garden<string_type, T0, T1>::piEnd, this, _1, _2)];
|
2003-04-04 21:30:29 +02:00
|
|
|
PITarget = Name - boost::spirit::as_lower_d[boost::spirit::str_p("xml")];
|
|
|
|
PIData = !(!Spaces >> (*(Char - boost::spirit::str_p("?>"))));
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
// Section 2.7 - CDATA
|
2006-09-20 13:43:30 +02:00
|
|
|
CDSect = CDStart >> (CData)[boost::bind(&Garden<string_type, T0, T1>::elementContent, this, _1, _2)] >> CDEnd;
|
2003-04-04 18:54:54 +02:00
|
|
|
CDStart = boost::spirit::str_p("<![CDATA[");
|
|
|
|
CData = *(Char - boost::spirit::str_p("]]>"));
|
|
|
|
CDEnd = boost::spirit::str_p("]]>");
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2003-04-04 21:30:29 +02:00
|
|
|
// bits before the root elemenet
|
|
|
|
prolog = !XMLDecl >> *Misc >> !(doctypedecl >> *Misc);
|
|
|
|
XMLDecl = boost::spirit::str_p("<?xml") >> VersionInfo >> !EncodingDecl >> !SDDecl >> !Spaces >> boost::spirit::str_p("?>");
|
|
|
|
VersionInfo = Spaces >> boost::spirit::str_p("version") >> Eq >> (boost::spirit::ch_p('\'') >> VersionNum >>'\''
|
2003-04-04 18:54:54 +02:00
|
|
|
| boost::spirit::ch_p('"') >> VersionNum >> '"');
|
2002-06-21 13:16:28 +02:00
|
|
|
chset_t VersionNumCh("A-Za-z0-9_.:-");
|
|
|
|
VersionNum = +(VersionNumCh);
|
2003-04-04 18:54:54 +02:00
|
|
|
doctypedecl = boost::spirit::str_p("<!DOCTYPE") >> *(Char - (chset_t('[') | '>')) >> !('[' >> *(Char - ']') >> ']') >> '>';
|
2003-04-04 21:30:29 +02:00
|
|
|
SDDecl = Spaces >> boost::spirit::str_p("standalone") >> Eq >> ((boost::spirit::ch_p('\'') >> (boost::spirit::str_p("yes") | boost::spirit::str_p("no")) >> '\'')
|
2003-04-04 18:54:54 +02:00
|
|
|
| (boost::spirit::ch_p('"') >> (boost::spirit::str_p("yes") | boost::spirit::str_p("no")) >> '"'));
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2003-04-04 21:30:29 +02:00
|
|
|
// odd bits
|
|
|
|
Eq = !Spaces >> '=' >> !Spaces;
|
|
|
|
Misc = Comment | Spaces | PI;
|
|
|
|
|
|
|
|
// Elements
|
2006-09-20 13:43:30 +02:00
|
|
|
element = STag >> (EmptyElemTag | (boost::spirit::str_p(">"))[boost::bind(&Garden<string_type, T0, T1>::closeElement, this, _1, _2)] >> content >> ETag);
|
|
|
|
STag = '<' >> (Name)[boost::bind(&Garden<string_type, T0, T1>::openElement, this, _1, _2)] >> *(Spaces >> Attribute) >> !Spaces;
|
|
|
|
Attribute = (Name)[boost::bind(&Garden<string_type, T0, T1>::attributeName, this, _1, _2)] >> Eq >> AttValue;
|
|
|
|
EmptyElemTag = (boost::spirit::str_p("/>"))[boost::bind(&Garden<string_type, T0, T1>::closeEmptyElement, this, _1, _2)];
|
|
|
|
ETag = (boost::spirit::str_p("</") >> (Name)[boost::bind(&Garden<string_type, T0, T1>::endElementName, this, _1, _2)] >> !Spaces >> '>')[boost::bind(&Garden<string_type, T0, T1>::endElement, this, _1, _2)];
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
AttValue = '"' >> (*((boost::spirit::anychar_p - (chset_t('<') | '&' | '"')) | Reference))[boost::bind(&Garden<string_type, T0, T1>::attributeValue, this, _1, _2)] >> '"'
|
|
|
|
| '\'' >> (*((boost::spirit::anychar_p - (chset_t('<') | '&' | '\'')) | Reference))[boost::bind(&Garden<string_type, T0, T1>::attributeValue, this, _1, _2)] >> '\'';
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
content = !CharData >> *((element | Reference | CDSect | Comment | PI) >> !CharData);
|
|
|
|
|
|
|
|
// Section 4.1 - Character and entity references
|
2006-09-20 13:43:30 +02:00
|
|
|
CharRef = boost::spirit::str_p("&#") >> (+boost::spirit::digit_p >> ';')[boost::bind(&Garden<string_type, T0, T1>::decimalCharacterRef, this, _1, _2)] |
|
|
|
|
boost::spirit::str_p("&#x") >> (+boost::spirit::xdigit_p >> ';')[boost::bind(&Garden<string_type, T0, T1>::hexCharacterRef, this, _1, _2)];
|
2002-06-21 13:16:28 +02:00
|
|
|
Reference = EntityRef | CharRef;
|
2006-09-20 13:43:30 +02:00
|
|
|
EntityRef = '&' >> (Name >> boost::spirit::ch_p(';'))[boost::bind(&Garden<string_type, T0, T1>::entityRef, this, _1, _2)];
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2003-04-04 21:30:29 +02:00
|
|
|
EncodingDecl = Spaces >> boost::spirit::str_p("encoding") >> Eq >> (boost::spirit::ch_p('"') >> EncName >> '"' |
|
2003-04-04 18:54:54 +02:00
|
|
|
boost::spirit::ch_p('\'') >> EncName >> '\'');
|
2002-06-21 13:16:28 +02:00
|
|
|
chset_t EncNameCh = VersionNumCh - chset_t(':');
|
2003-04-04 18:54:54 +02:00
|
|
|
EncName = boost::spirit::alpha_p >> *(EncNameCh);
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
/////////////////
|
|
|
|
declaredEntities_.insert(std::make_pair<stringT, stringT>("lt", "<"));
|
|
|
|
declaredEntities_.insert(std::make_pair<stringT, stringT>("gt", ">"));
|
|
|
|
declaredEntities_.insert(std::make_pair<stringT, stringT>("amp", "&"));
|
|
|
|
declaredEntities_.insert(std::make_pair<stringT, stringT>("apos", "'"));
|
|
|
|
declaredEntities_.insert(std::make_pair<stringT, stringT>("quot", "\""));
|
|
|
|
|
|
|
|
conversion_.insert(std::make_pair('0', 0));
|
|
|
|
conversion_.insert(std::make_pair('1', 1));
|
|
|
|
conversion_.insert(std::make_pair('2', 2));
|
|
|
|
conversion_.insert(std::make_pair('3', 3));
|
|
|
|
conversion_.insert(std::make_pair('4', 4));
|
|
|
|
conversion_.insert(std::make_pair('5', 5));
|
|
|
|
conversion_.insert(std::make_pair('6', 6));
|
|
|
|
conversion_.insert(std::make_pair('7', 7));
|
|
|
|
conversion_.insert(std::make_pair('8', 8));
|
|
|
|
conversion_.insert(std::make_pair('9', 9));
|
|
|
|
conversion_.insert(std::make_pair('a', 10));
|
|
|
|
conversion_.insert(std::make_pair('b', 11));
|
|
|
|
conversion_.insert(std::make_pair('c', 12));
|
|
|
|
conversion_.insert(std::make_pair('d', 13));
|
|
|
|
conversion_.insert(std::make_pair('e', 14));
|
|
|
|
conversion_.insert(std::make_pair('f', 15));
|
|
|
|
conversion_.insert(std::make_pair('A', 10));
|
|
|
|
conversion_.insert(std::make_pair('B', 11));
|
|
|
|
conversion_.insert(std::make_pair('C', 12));
|
|
|
|
conversion_.insert(std::make_pair('D', 13));
|
|
|
|
conversion_.insert(std::make_pair('E', 14));
|
|
|
|
conversion_.insert(std::make_pair('F', 15));
|
|
|
|
} // XMLparser
|
|
|
|
|
|
|
|
//////////////////////////////////////
|
|
|
|
// features
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
bool Garden<string_type, T0, T1>::getFeature(const stringT& name) const
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
throw SAXNotRecognizedException(name);
|
|
|
|
} // getFeature
|
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::setFeature(const stringT& name, bool value)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
throw SAXNotRecognizedException(name);
|
|
|
|
} // setFeature
|
|
|
|
|
|
|
|
///////////////////////////////////////
|
|
|
|
// properties
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
std::auto_ptr<typename Garden<string_type, T0, T1>::PropertyBase> Garden<string_type, T0, T1>::doGetProperty(const stringT& name)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
throw SAXNotRecognizedException(name);
|
|
|
|
} // doGetProperty
|
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::doSetProperty(const stringT& name, std::auto_ptr<typename basic_XMLReader<string_type>::PropertyBase> value)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
throw SAXNotRecognizedException(name);
|
|
|
|
} // doSetProperty
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
// parse
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::parse(InputSourceT& input)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
2005-08-15 23:09:13 +02:00
|
|
|
Arabica::default_string_adaptor<stringT> SA;
|
2005-08-11 14:13:13 +02:00
|
|
|
InputSourceResolver is(input, SA);
|
|
|
|
if(is.resolve() == 0)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
reportError("Could not resolve XML document", true);
|
|
|
|
return;
|
|
|
|
} // if(is.resolver() == 0)
|
|
|
|
|
|
|
|
// Turn of white space skipping on the stream
|
|
|
|
is.resolve()->unsetf(std::ios::skipws);
|
|
|
|
|
2003-04-04 18:54:54 +02:00
|
|
|
vector_t data(std::istream_iterator<char_t>(*is.resolve()), std::istream_iterator<char_t>());
|
|
|
|
|
|
|
|
iterator_t first = data.begin();
|
|
|
|
iterator_t last = data.end();
|
|
|
|
scanner_t scanner(first, last);
|
2005-07-20 22:45:56 +02:00
|
|
|
typedef typename boost::spirit::parser_result<rule_t, scanner_t>::type result_t;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
if(contentHandler_)
|
|
|
|
contentHandler_->startDocument();
|
2005-07-20 22:45:56 +02:00
|
|
|
result_t r = document_.parse(scanner);
|
2002-06-21 13:16:28 +02:00
|
|
|
if(contentHandler_)
|
|
|
|
contentHandler_->endDocument();
|
|
|
|
|
2003-04-04 18:54:54 +02:00
|
|
|
if(!(r && first == last))
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
std::cout << input.getSystemId() << " Fails Parsing\n" << std::endl;
|
|
|
|
for (int i = 0; i < 50; ++i)
|
|
|
|
{
|
|
|
|
std::cout << *first++;
|
|
|
|
}
|
|
|
|
std::cout << std::endl;
|
|
|
|
} // if ...
|
|
|
|
} // parse
|
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::openElement(iterator_t s, iterator_t e)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
elements_.push(str(s, e));
|
|
|
|
attrs_.clear();
|
|
|
|
} // openElement
|
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::closeElement(iterator_t s, iterator_t e)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
if(contentHandler_)
|
|
|
|
contentHandler_->startElement("", elements_.top(), "", attrs_);
|
|
|
|
} // closeElement
|
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::closeEmptyElement(iterator_t s, iterator_t e)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
if(contentHandler_)
|
|
|
|
{
|
|
|
|
contentHandler_->startElement("", elements_.top(), "", attrs_);
|
|
|
|
contentHandler_->endElement("", elements_.top(), "");
|
|
|
|
elements_.pop();
|
|
|
|
} // if ...
|
|
|
|
} // closeEmptyElement
|
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::endElementName(iterator_t s, iterator_t e)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
stringT name = str(s, e);
|
|
|
|
if(name != elements_.top())
|
|
|
|
reportError("Expect end element " + elements_.top(), true);
|
|
|
|
} // endElementName
|
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::endElement(iterator_t s, iterator_t e)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
if(contentHandler_)
|
|
|
|
contentHandler_->endElement("", elements_.top(), "");
|
|
|
|
elements_.pop();
|
|
|
|
} // endElement
|
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::attributeName(iterator_t s, iterator_t e)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
2005-08-11 14:13:13 +02:00
|
|
|
currentAttr_ = typename AttributesImplT::Attr();
|
2002-06-21 13:16:28 +02:00
|
|
|
currentAttr_.localName_ = str(s, e);
|
|
|
|
} // attributeName
|
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::attributeValue(iterator_t s, iterator_t e)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
currentAttr_.value_ = str(s, e);
|
|
|
|
currentAttr_.type_ = "CDATA";
|
|
|
|
attrs_.addAttribute(currentAttr_);
|
|
|
|
} // attributeValue
|
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::elementContent(iterator_t s, iterator_t e)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
if(contentHandler_ && (s != e))
|
|
|
|
contentHandler_->characters(str(s, e));
|
2006-09-20 13:43:30 +02:00
|
|
|
} // Garden<string_type, T0, T1>::elementContent
|
2003-04-04 18:54:54 +02:00
|
|
|
|
2002-06-21 13:16:28 +02:00
|
|
|
// processing instructions
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::piTarget(iterator_t s, iterator_t e)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
piTarget_ = str(s, e);
|
|
|
|
piData_.erase();
|
|
|
|
} // piTarget
|
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::piData(iterator_t s, iterator_t e)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
piData_ = str(s, e);
|
|
|
|
} // piData
|
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::piEnd(iterator_t s, iterator_t e)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
if(contentHandler_)
|
|
|
|
contentHandler_->processingInstruction(piTarget_, piData_);
|
|
|
|
} // piEnd
|
|
|
|
|
|
|
|
//entity refs
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::entityRef(iterator_t s, iterator_t e)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
if(contentHandler_)
|
|
|
|
{
|
|
|
|
stringT name(str(s, e, 1));
|
|
|
|
|
2005-08-08 07:41:43 +02:00
|
|
|
typedef typename std::map<stringT, stringT>::iterator entity_iterator;
|
|
|
|
|
|
|
|
entity_iterator ent = declaredEntities_.find(name);
|
2002-06-21 13:16:28 +02:00
|
|
|
if(ent != declaredEntities_.end())
|
|
|
|
{
|
|
|
|
contentHandler_->characters((*ent).second);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reportError("Undeclared entity " + name);
|
|
|
|
return;
|
|
|
|
} // if ...
|
|
|
|
|
|
|
|
contentHandler_->skippedEntity(name);
|
|
|
|
} // if ...
|
|
|
|
} // entityRef
|
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::decimalCharacterRef(iterator_t s, iterator_t e)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
characterRef(s, e, 10);
|
|
|
|
} // decimalCharacterRef
|
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::hexCharacterRef(iterator_t s, iterator_t e)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
characterRef(s, e, 16);
|
|
|
|
} // hexCharacterRef
|
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::characterRef(iterator_t s, iterator_t e, int base)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
if(!contentHandler_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int val = 0;
|
|
|
|
char next = *s;
|
|
|
|
while(++s != e)
|
|
|
|
{
|
|
|
|
val *= base;
|
|
|
|
val += conversion_[next];
|
|
|
|
next = *s;
|
|
|
|
}
|
|
|
|
|
|
|
|
contentHandler_->characters(stringT(1, val));
|
|
|
|
} // characterRef
|
|
|
|
|
|
|
|
///////////////////////////////
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
typename Garden<string_type, T0, T1>::stringT Garden<string_type, T0, T1>::str(iterator_t s, iterator_t e, int trim)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
stringT str;
|
|
|
|
std::copy(s, e, std::inserter(str, str.begin()));
|
|
|
|
if(trim)
|
|
|
|
str.erase(str.end() - trim);
|
|
|
|
return str;
|
|
|
|
} // str
|
|
|
|
|
2006-09-20 13:43:30 +02:00
|
|
|
template<class string_type, class T0, class T1>
|
|
|
|
void Garden<string_type, T0, T1>::reportError(const std::string& message, bool fatal)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
if(!errorHandler_)
|
|
|
|
return;
|
|
|
|
|
2003-04-04 18:54:54 +02:00
|
|
|
SAX::basic_SAXParseException<stringT> e(message);
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
if(fatal)
|
|
|
|
errorHandler_->fatalError(e);
|
|
|
|
else
|
|
|
|
errorHandler_->error(e);
|
|
|
|
} // reportError
|
|
|
|
|
|
|
|
} // namespace SAX
|
|
|
|
|
|
|
|
#endif
|