diff --git a/include/SAX/XMLReader.h b/include/SAX/XMLReader.h index a20f23b1..c411db13 100644 --- a/include/SAX/XMLReader.h +++ b/include/SAX/XMLReader.h @@ -14,8 +14,11 @@ #include #include #include +#include +#include #include + namespace SAX { @@ -66,6 +69,8 @@ public: typedef basic_ContentHandler ContentHandlerT; typedef basic_InputSource InputSourceT; typedef basic_ErrorHandler ErrorHandlerT; + typedef basic_DeclHandler DeclHandlerT; + typedef basic_LexicalHandler LexicalHandlerT; virtual ~basic_XMLReader() { } @@ -251,6 +256,24 @@ public: */ virtual ErrorHandlerT* getErrorHandler() const = 0; + virtual void setDeclHandler(DeclHandlerT& handler) = 0; + /** + * Return the current decl handler. + * + * @return The current decl handler, or 0 if none has been registered + * @see #setDeclHandler + */ + virtual DeclHandlerT* getDeclHandler() const = 0; + + virtual void setLexicalHandler(LexicalHandlerT& handler) = 0; + /** + * Return the current lexical handler. + * + * @return The current lexical handler, or 0 if none has been registered + * @see #setLexicalHandler + */ + virtual LexicalHandlerT* getLexicalHandler() const = 0; + ////////////////////////////////////////////////// // Parsing /** diff --git a/include/SAX/ext/DefaultHandler2.h b/include/SAX/ext/DefaultHandler2.h index f0fed1be..11344105 100644 --- a/include/SAX/ext/DefaultHandler2.h +++ b/include/SAX/ext/DefaultHandler2.h @@ -9,6 +9,8 @@ #include #include +#pragma message("DefaultHandler2 is deprecated. You can now use DefaultHandler instead.") + namespace SAX { /** @@ -36,9 +38,7 @@ namespace SAX { * @see basic_DeclHandler */ template -class basic_DefaultHandler2 : public basic_DefaultHandler, - public basic_LexicalHandler, - public basic_DeclHandler +class basic_DefaultHandler2 : public basic_DefaultHandler { public: typedef string_type stringT; @@ -46,222 +46,6 @@ public: basic_DefaultHandler2() { } virtual ~basic_DefaultHandler2() { } - ////////////////////////////////////////////////////////// - // LexicalHandler - /** - * Report the start of DTD declarations, if any. - * - *

This method is intended to report the beginning of the - * DOCTYPE declaration; if the document has no DOCTYPE declaration, - * this method will not be invoked.

- * - *

All declarations reported through - * {@link basic_DTDHandler DTDHandler} or - * {@link basic_DeclHandler DeclHandler} events must appear - * between the startDTD and {@link #endDTD endDTD} events. - * Declarations are assumed to belong to the internal DTD subset - * unless they appear between {@link #startEntity startEntity} - * and {@link #endEntity endEntity} events. Comments and - * processing instructions from the DTD should also be reported - * between the startDTD and endDTD events, in their original - * order of (logical) occurrence; they are not required to - * appear in their correct locations relative to DTDHandler - * or DeclHandler events, however.

- * - *

Note that the start/endDTD events will appear within - * the start/endDocument events from ContentHandler and - * before the first - * {@link basic_ContentHandler#startElement startElement} - * event.

- * - * @param name The document type name. - * @param publicId The declared public identifier for the - * external DTD subset, or an empty string if none was declared. - * @param systemId The declared system identifier for the - * external DTD subset, or an empty string if none was declared. - * @see #endDTD - * @see #startEntity - */ - virtual void startDTD(const stringT& name, - const stringT& publicId, - const stringT& systemId) { } - - /** - * Report the end of DTD declarations. - * - *

This method is intended to report the end of the - * DOCTYPE declaration; if the document has no DOCTYPE declaration, - * this method will not be invoked.

- * - * @see #startDTD - */ - virtual void endDTD() { } - - /** - * Report the beginning of some internal and external XML entities. - * - *

The reporting of parameter entities (including - * the external DTD subset) is optional, and SAX2 drivers that - * support LexicalHandler may not support it; you can use the - * http://xml.org/sax/features/lexical-handler/parameter-entities - * feature to query or control the reporting of parameter entities.

- * - *

General entities are reported with their regular names, - * parameter entities have '%' prepended to their names, and - * the external DTD subset has the pseudo-entity name "[dtd]".

- * - *

When a SAX2 driver is providing these events, all other - * events must be properly nested within start/end entity - * events. There is no additional requirement that events from - * {@link basic_DeclHandler DeclHandler} or - * {@link basic_DTDHandler DTDHandler} be properly ordered.

- * - *

Note that skipped entities will be reported through the - * {@link basic_ContentHandler#skippedEntity skippedEntity} - * event, which is part of the ContentHandler interface.

- * - *

Because of the streaming event model that SAX uses, some - * entity boundaries cannot be reported under any - * circumstances:

- * - *
    - *
  • general entities within attribute values
  • - *
  • parameter entities within declarations
  • - *
- * - *

These will be silently expanded, with no indication of where - * the original entity boundaries were.

- * - *

Note also that the boundaries of character references (which - * are not really entities anyway) are not reported.

- * - *

All start/endEntity events must be properly nested. - * - * @param name The name of the entity. If it is a parameter - * entity, the name will begin with '%', and if it is the - * external DTD subset, it will be "[dtd]". - * @see #endEntity - * @see basic_DeclHandler#internalEntityDecl - * @see basic_DeclHandler#externalEntityDecl - */ - virtual void startEntity(const stringT& name) { } - /** - * Report the end of an entity. - * - * @param name The name of the entity that is ending. - * @see #startEntity - */ - virtual void endEntity(const stringT& name) { } - - /** - * Report the start of a CDATA section. - * - *

The contents of the CDATA section will be reported through - * the regular {@link basic_ContentHandler#characters - * characters} event; this event is intended only to report - * the boundary.

- * - * @see #endCDATA - */ - virtual void startCDATA() { } - /** - * Report the end of a CDATA section. - * - * @see #startCDATA - */ - virtual void endCDATA() { } - - /** - * Report an XML comment anywhere in the document. - * - *

This callback will be used for comments inside or outside the - * document element, including comments in the external DTD - * subset (if read). Comments in the DTD must be properly - * nested inside start/endDTD and start/endEntity events (if - * used).

- * - * @param text A string holding the comment. - */ - virtual void comment(const stringT& text) { } - - //////////////////////////////////////////////////////////// - // DeclHandler - /** - * Report an element type declaration. - * - *

The content model will consist of the string "EMPTY", the - * string "ANY", or a parenthesised group, optionally followed - * by an occurrence indicator. The model will be normalized so - * that all parameter entities are fully resolved and all whitespace - * is removed,and will include the enclosing parentheses. Other - * normalization (such as removing redundant parentheses or - * simplifying occurrence indicators) is at the discretion of the - * parser.

- * - * @param name The element type name. - * @param model The content model as a normalized string. - */ - virtual void elementDecl(const stringT& name, const stringT& model) { } - /** - * Report an attribute type declaration. - * - *

Only the effective (first) declaration for an attribute will - * be reported. The type will be one of the strings "CDATA", - * "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", - * "ENTITIES", a parenthesized token group with - * the separator "|" and all whitespace removed, or the word - * "NOTATION" followed by a space followed by a parenthesized - * token group with all whitespace removed.

- * - *

Any parameter entities in the attribute value will be - * expanded, but general entities will not.

- * - * @param elementName The name of the associated element. - * @param attributeName The name of the attribute. - * @param type A string representing the attribute type. - * @param valueDefault A string representing the attribute default - * ("#IMPLIED", "#REQUIRED", or "#FIXED") or empty string if - * none of these applies. - * @param value A string representing the attribute's default value, - * or empty string if there is none. - */ - virtual void attributeDecl(const stringT& elementName, - const stringT& attributeName, - const stringT& type, - const stringT& valueDefault, - const stringT& value) { } - /** - * Report an internal entity declaration. - * - *

Only the effective (first) declaration for each entity - * will be reported. All parameter entities in the value - * will be expanded, but general entities will not.

- * - * @param name The name of the entity. If it is a parameter - * entity, the name will begin with '%'. - * @param value The replacement text of the entity. - * @see #externalEntityDecl - * @see basic_DTDHandler#unparsedEntityDecl - */ - virtual void internalEntityDecl(const stringT& name, const stringT& value) { } - /** - * Report a parsed external entity declaration. - * - *

Only the effective (first) declaration for each entity - * will be reported.

- * - * @param name The name of the entity. If it is a parameter - * entity, the name will begin with '%'. - * @param publicId The declared public identifier of the entity, or - * an empty string if none was declared. - * @param systemId The declared system identifier of the entity. - * @see #internalEntityDecl - * @see basic_DTDHandler#unparsedEntityDecl - */ - virtual void externalEntityDecl(const stringT& name, - const stringT& publicId, - const stringT& systemId) { } private: basic_DefaultHandler2(const basic_DefaultHandler2&); basic_DefaultHandler2& operator=(const basic_DefaultHandler2&); diff --git a/include/SAX/helpers/DefaultHandler.h b/include/SAX/helpers/DefaultHandler.h index a8d1aa79..7784ec10 100644 --- a/include/SAX/helpers/DefaultHandler.h +++ b/include/SAX/helpers/DefaultHandler.h @@ -13,6 +13,8 @@ #include #include #include +#include +#include namespace SAX { @@ -51,7 +53,9 @@ template class basic_DefaultHandler : public basic_EntityResolver, public basic_DTDHandler, public basic_ContentHandler, - public basic_ErrorHandler + public basic_ErrorHandler, + public basic_LexicalHandler, + public basic_DeclHandler { public: typedef string_type stringT; @@ -367,6 +371,222 @@ public: // one of them, I presume, is wrong } // fatalError + ////////////////////////////////////////////////////////// + // LexicalHandler + /** + * Report the start of DTD declarations, if any. + * + *

This method is intended to report the beginning of the + * DOCTYPE declaration; if the document has no DOCTYPE declaration, + * this method will not be invoked.

+ * + *

All declarations reported through + * {@link basic_DTDHandler DTDHandler} or + * {@link basic_DeclHandler DeclHandler} events must appear + * between the startDTD and {@link #endDTD endDTD} events. + * Declarations are assumed to belong to the internal DTD subset + * unless they appear between {@link #startEntity startEntity} + * and {@link #endEntity endEntity} events. Comments and + * processing instructions from the DTD should also be reported + * between the startDTD and endDTD events, in their original + * order of (logical) occurrence; they are not required to + * appear in their correct locations relative to DTDHandler + * or DeclHandler events, however.

+ * + *

Note that the start/endDTD events will appear within + * the start/endDocument events from ContentHandler and + * before the first + * {@link basic_ContentHandler#startElement startElement} + * event.

+ * + * @param name The document type name. + * @param publicId The declared public identifier for the + * external DTD subset, or an empty string if none was declared. + * @param systemId The declared system identifier for the + * external DTD subset, or an empty string if none was declared. + * @see #endDTD + * @see #startEntity + */ + virtual void startDTD(const stringT& name, + const stringT& publicId, + const stringT& systemId) { } + + /** + * Report the end of DTD declarations. + * + *

This method is intended to report the end of the + * DOCTYPE declaration; if the document has no DOCTYPE declaration, + * this method will not be invoked.

+ * + * @see #startDTD + */ + virtual void endDTD() { } + + /** + * Report the beginning of some internal and external XML entities. + * + *

The reporting of parameter entities (including + * the external DTD subset) is optional, and SAX2 drivers that + * support LexicalHandler may not support it; you can use the + * http://xml.org/sax/features/lexical-handler/parameter-entities + * feature to query or control the reporting of parameter entities.

+ * + *

General entities are reported with their regular names, + * parameter entities have '%' prepended to their names, and + * the external DTD subset has the pseudo-entity name "[dtd]".

+ * + *

When a SAX2 driver is providing these events, all other + * events must be properly nested within start/end entity + * events. There is no additional requirement that events from + * {@link basic_DeclHandler DeclHandler} or + * {@link basic_DTDHandler DTDHandler} be properly ordered.

+ * + *

Note that skipped entities will be reported through the + * {@link basic_ContentHandler#skippedEntity skippedEntity} + * event, which is part of the ContentHandler interface.

+ * + *

Because of the streaming event model that SAX uses, some + * entity boundaries cannot be reported under any + * circumstances:

+ * + *
    + *
  • general entities within attribute values
  • + *
  • parameter entities within declarations
  • + *
+ * + *

These will be silently expanded, with no indication of where + * the original entity boundaries were.

+ * + *

Note also that the boundaries of character references (which + * are not really entities anyway) are not reported.

+ * + *

All start/endEntity events must be properly nested. + * + * @param name The name of the entity. If it is a parameter + * entity, the name will begin with '%', and if it is the + * external DTD subset, it will be "[dtd]". + * @see #endEntity + * @see basic_DeclHandler#internalEntityDecl + * @see basic_DeclHandler#externalEntityDecl + */ + virtual void startEntity(const stringT& name) { } + /** + * Report the end of an entity. + * + * @param name The name of the entity that is ending. + * @see #startEntity + */ + virtual void endEntity(const stringT& name) { } + + /** + * Report the start of a CDATA section. + * + *

The contents of the CDATA section will be reported through + * the regular {@link basic_ContentHandler#characters + * characters} event; this event is intended only to report + * the boundary.

+ * + * @see #endCDATA + */ + virtual void startCDATA() { } + /** + * Report the end of a CDATA section. + * + * @see #startCDATA + */ + virtual void endCDATA() { } + + /** + * Report an XML comment anywhere in the document. + * + *

This callback will be used for comments inside or outside the + * document element, including comments in the external DTD + * subset (if read). Comments in the DTD must be properly + * nested inside start/endDTD and start/endEntity events (if + * used).

+ * + * @param text A string holding the comment. + */ + virtual void comment(const stringT& text) { } + + //////////////////////////////////////////////////////////// + // DeclHandler + /** + * Report an element type declaration. + * + *

The content model will consist of the string "EMPTY", the + * string "ANY", or a parenthesised group, optionally followed + * by an occurrence indicator. The model will be normalized so + * that all parameter entities are fully resolved and all whitespace + * is removed,and will include the enclosing parentheses. Other + * normalization (such as removing redundant parentheses or + * simplifying occurrence indicators) is at the discretion of the + * parser.

+ * + * @param name The element type name. + * @param model The content model as a normalized string. + */ + virtual void elementDecl(const stringT& name, const stringT& model) { } + /** + * Report an attribute type declaration. + * + *

Only the effective (first) declaration for an attribute will + * be reported. The type will be one of the strings "CDATA", + * "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", + * "ENTITIES", a parenthesized token group with + * the separator "|" and all whitespace removed, or the word + * "NOTATION" followed by a space followed by a parenthesized + * token group with all whitespace removed.

+ * + *

Any parameter entities in the attribute value will be + * expanded, but general entities will not.

+ * + * @param elementName The name of the associated element. + * @param attributeName The name of the attribute. + * @param type A string representing the attribute type. + * @param valueDefault A string representing the attribute default + * ("#IMPLIED", "#REQUIRED", or "#FIXED") or empty string if + * none of these applies. + * @param value A string representing the attribute's default value, + * or empty string if there is none. + */ + virtual void attributeDecl(const stringT& elementName, + const stringT& attributeName, + const stringT& type, + const stringT& valueDefault, + const stringT& value) { } + /** + * Report an internal entity declaration. + * + *

Only the effective (first) declaration for each entity + * will be reported. All parameter entities in the value + * will be expanded, but general entities will not.

+ * + * @param name The name of the entity. If it is a parameter + * entity, the name will begin with '%'. + * @param value The replacement text of the entity. + * @see #externalEntityDecl + * @see basic_DTDHandler#unparsedEntityDecl + */ + virtual void internalEntityDecl(const stringT& name, const stringT& value) { } + /** + * Report a parsed external entity declaration. + * + *

Only the effective (first) declaration for each entity + * will be reported.

+ * + * @param name The name of the entity. If it is a parameter + * entity, the name will begin with '%'. + * @param publicId The declared public identifier of the entity, or + * an empty string if none was declared. + * @param systemId The declared system identifier of the entity. + * @see #internalEntityDecl + * @see basic_DTDHandler#unparsedEntityDecl + */ + virtual void externalEntityDecl(const stringT& name, + const stringT& publicId, + const stringT& systemId) { } private: basic_DefaultHandler(const basic_DefaultHandler&); basic_DefaultHandler& operator=(const basic_DefaultHandler&); diff --git a/include/SAX/helpers/XMLFilterImpl.h b/include/SAX/helpers/XMLFilterImpl.h index c55100ee..913926a9 100644 --- a/include/SAX/helpers/XMLFilterImpl.h +++ b/include/SAX/helpers/XMLFilterImpl.h @@ -1,8 +1,7 @@ #ifndef ARABICA_XML_FILTER_IMPL_H #define ARABICA_XML_FILTER_IMPL_H -// XMLFilter.h -// $Id$ +// XMLFilterImpl.h #include #include @@ -37,10 +36,12 @@ namespace SAX */ template > class basic_XMLFilterImpl : public basic_XMLFilter, - public basic_EntityResolver, - public basic_DTDHandler, - public basic_ContentHandler, - public basic_ErrorHandler + public basic_EntityResolver, + public basic_DTDHandler, + public basic_ContentHandler, + public basic_ErrorHandler, + public basic_DeclHandler, + public basic_LexicalHandler { public: typedef string_type stringT; @@ -52,6 +53,8 @@ public: typedef basic_InputSource InputSourceT; typedef basic_Locator LocatorT; typedef basic_ErrorHandler ErrorHandlerT; + typedef basic_DeclHandler DeclHandlerT; + typedef basic_LexicalHandler LexicalHandlerT; typedef typename basic_ErrorHandler::SAXParseExceptionT SAXParseExceptionT; @@ -202,6 +205,11 @@ public: */ virtual ErrorHandlerT* getErrorHandler() const { return errorHandler_; } + virtual void setDeclHandler(DeclHandlerT& handler) { declHandler_ = &handler; } + virtual DeclHandlerT* getDeclHandler() const { return declHandler_; } + virtual void setLexicalHandler(LexicalHandlerT& handler) { lexicalHandler_ = &handler; } + virtual LexicalHandlerT* getLexicalHandler() const { return lexicalHandler_; } + /** * Parse a document. * @@ -270,8 +278,7 @@ public: const stringT& publicId, const stringT& systemId) { - if(dtdHandler_) - dtdHandler_->notationDecl(name, publicId, systemId); + dtdHandler_->notationDecl(name, publicId, systemId); } // notationDecl /** @@ -288,8 +295,7 @@ public: const stringT& systemId, const stringT& notationName) { - if(dtdHandler_) - dtdHandler_->unparsedEntityDecl(name, publicId, systemId, notationName); + dtdHandler_->unparsedEntityDecl(name, publicId, systemId, notationName); } // unparsedEntityDecl ////////////////////////////////////////////////// @@ -303,8 +309,7 @@ public: virtual void setDocumentLocator(const LocatorT& locator) { locator_ = &locator; - if(contentHandler_) - contentHandler_->setDocumentLocator(locator); + contentHandler_->setDocumentLocator(locator); } // setDocumentLocator /** @@ -314,8 +319,7 @@ public: */ virtual void startDocument() { - if(contentHandler_) - contentHandler_->startDocument(); + contentHandler_->startDocument(); } // startDocument /** @@ -325,8 +329,7 @@ public: */ virtual void endDocument() { - if(contentHandler_) - contentHandler_->endDocument(); + contentHandler_->endDocument(); } // endDocument /** @@ -338,8 +341,7 @@ public: */ virtual void startPrefixMapping(const stringT& prefix, const stringT& uri) { - if(contentHandler_) - contentHandler_->startPrefixMapping(prefix, uri); + contentHandler_->startPrefixMapping(prefix, uri); } // startPrefixMapping /** @@ -350,8 +352,7 @@ public: */ virtual void endPrefixMapping(const stringT& prefix) { - if(contentHandler_) - contentHandler_->endPrefixMapping(prefix); + contentHandler_->endPrefixMapping(prefix); } // endPrefixMapping /** @@ -367,8 +368,7 @@ public: virtual void startElement(const stringT& namespaceURI, const stringT& localName, const stringT& qName, const typename ContentHandlerT::AttributesT& atts) { - if(contentHandler_) - contentHandler_->startElement(namespaceURI, localName, qName, atts); + contentHandler_->startElement(namespaceURI, localName, qName, atts); } // startElement /** @@ -383,8 +383,7 @@ public: virtual void endElement(const stringT& namespaceURI, const stringT& localName, const stringT& qName) { - if(contentHandler_) - contentHandler_->endElement(namespaceURI, localName, qName); + contentHandler_->endElement(namespaceURI, localName, qName); } // endElement /** @@ -395,8 +394,7 @@ public: */ virtual void characters(const stringT& ch) { - if(contentHandler_) - contentHandler_->characters(ch); + contentHandler_->characters(ch); } // characters /** @@ -407,8 +405,7 @@ public: */ virtual void ignorableWhitespace(const stringT& ch) { - if(contentHandler_) - contentHandler_->ignorableWhitespace(ch); + contentHandler_->ignorableWhitespace(ch); } // ignorableWhitespace /** @@ -420,8 +417,7 @@ public: */ virtual void processingInstruction(const stringT& target, const stringT& data) { - if(contentHandler_) - contentHandler_->processingInstruction(target, data); + contentHandler_->processingInstruction(target, data); } // processingInstruction /** @@ -432,8 +428,7 @@ public: */ virtual void skippedEntity(const stringT& name) { - if(contentHandler_) - contentHandler_->skippedEntity(name); + contentHandler_->skippedEntity(name); } // skippedEntity ////////////////////////////////////////////////// @@ -446,8 +441,7 @@ public: */ virtual void warning(const SAXParseExceptionT& exception) { - if(errorHandler_) - errorHandler_->warning(exception); + errorHandler_->warning(exception); } // warning /** @@ -458,8 +452,7 @@ public: */ virtual void error(const SAXParseExceptionT& exception) { - if(errorHandler_) - errorHandler_->error(exception); + errorHandler_->error(exception); } // error /** @@ -470,10 +463,108 @@ public: */ virtual void fatalError(const SAXParseExceptionT& exception) { - if(errorHandler_) - errorHandler_->fatalError(exception); + errorHandler_->fatalError(exception); } // fatalError + //////////////////////////////////////////////////////////// + // DeclHandler + /** + * Filter an element type declaration. + */ + virtual void elementDecl(const stringT& name, const stringT& model) + { + declHandler_->elementDecl(name, model); + } // elementDecl + + /** + * Filter an attribute type declaration. + */ + virtual void attributeDecl(const stringT& elementName, + const stringT& attributeName, + const stringT& type, + const stringT& valueDefault, + const stringT& value) + { + declHandler_->attributeDecl(elementName, attributeName, type, valueDefault, value); + } // attributeDecl + + /** + * Filter an internal entity declaration. + */ + virtual void internalEntityDecl(const stringT& name, const stringT& value) + { + declHandler_->internalEntityDecl(name, value); + } // internalEntityDecl + + /** + * Filter a parsed external entity declaration. + */ + virtual void externalEntityDecl(const stringT& name, + const stringT& publicId, + const stringT& systemId) + { + declHandler_->externalEntityDecl(name, publicId, systemId); + } // externalEntityDecl + + ////////////////////////////////////////////////////////// + // LexicalHandler + /** + * Filter the start of DTD declarations, if any. + */ + virtual void startDTD(const stringT& name, + const stringT& publicId, + const stringT& systemId) + { + lexicalHandler_->startDTD(name, publicId, systemId); + } // startDTD + + /** + * Filter the end of DTD declarations. + */ + virtual void endDTD() + { + lexicalHandler_->endDTD(); + } // endDTD + + /** + * Filter the beginning of some internal and external XML entities. + */ + virtual void startEntity(const stringT& name) + { + lexicalHandler_->startEntity(name); + } // startEntity + + /** + * Filter the end of an entity. + */ + virtual void endEntity(const stringT& name) + { + lexicalHandler_->endEntity(name); + } // endEntity + + /** + * Filter the start of a CDATA section. + */ + virtual void startCDATA() + { + lexicalHandler_->startCDATA(); + } // startCDATA + + /** + * Filter the end of a CDATA section. + */ + virtual void endCDATA() + { + lexicalHandler_->endCDATA(); + } // endCDATA + + /** + * Filter an XML comment anywhere in the document. + */ + virtual void comment(const stringT& text) + { + lexicalHandler_->comment(text); + } // comment private: void setDefaults() @@ -482,6 +573,8 @@ private: setDTDHandler(defaultHandler_); setContentHandler(defaultHandler_); setErrorHandler(defaultHandler_); + setDeclHandler(defaultHandler_); + setLexicalHandler(defaultHandler_); } // setDefaults void setupParse() @@ -490,6 +583,8 @@ private: parent_->setDTDHandler(*this); parent_->setContentHandler(*this); parent_->setErrorHandler(*this); + parent_->setDeclHandler(*this); + parent_->setLexicalHandler(*this); } // setupParse basic_XMLFilterImpl(const basic_XMLFilterImpl&); @@ -501,6 +596,8 @@ private: DTDHandlerT* dtdHandler_; ContentHandlerT* contentHandler_; ErrorHandlerT* errorHandler_; + DeclHandlerT* declHandler_; + LexicalHandlerT* lexicalHandler_; const LocatorT* locator_; basic_DefaultHandler defaultHandler_; }; // class basic_XMLFilter diff --git a/include/SAX/wrappers/saxexpat.h b/include/SAX/wrappers/saxexpat.h index 79725abb..1b846a3f 100644 --- a/include/SAX/wrappers/saxexpat.h +++ b/include/SAX/wrappers/saxexpat.h @@ -14,8 +14,6 @@ #include #include #include -#include -#include #include #include #include @@ -247,6 +245,10 @@ class expat_wrapper : public SAX::basic_XMLReader, virtual contentHandlerT* getContentHandler() const { return contentHandler_; } virtual void setErrorHandler(errorHandlerT& handler) { errorHandler_ = &handler; } virtual errorHandlerT* getErrorHandler() const { return errorHandler_; } + virtual void setDeclHandler(declHandlerT& handler) { declHandler_ = &handler; } + virtual declHandlerT* getDeclHandler() const { return declHandler_; } + virtual void setLexicalHandler(lexicalHandlerT& handler) { lexicalHandler_ = &handler; } + virtual lexicalHandlerT* getLexicalHandler() const { return lexicalHandler_; } ////////////////////////////////////////////////// // Parsing @@ -716,7 +718,7 @@ void expat_wrapper::endElement(const char* qName) typename namespaceSupportT::Parts name = processName(SA::construct_from_utf8(qName), false); contentHandler_->endElement(name.URI, name.localName, name.rawName); typename namespaceSupportT::stringListT prefixes = nsSupport_.getDeclaredPrefixes(); - for(size_t i = 1, end = prefixes.size(); i < end; ++i) + for(size_t i = 0, end = prefixes.size(); i < end; ++i) contentHandler_->endPrefixMapping(prefixes[i]); nsSupport_.popContext(); } // endElement diff --git a/include/SAX/wrappers/saxlibxml2.h b/include/SAX/wrappers/saxlibxml2.h index 65894b39..0fe4ede0 100644 --- a/include/SAX/wrappers/saxlibxml2.h +++ b/include/SAX/wrappers/saxlibxml2.h @@ -18,8 +18,6 @@ #include #include -#include -#include #include #include #include @@ -55,6 +53,7 @@ class libxml2_base virtual void SAXerror(const std::string& error) = 0; virtual void SAXfatalError(const std::string& fatal) = 0; virtual void SAXprocessingInstruction(const xmlChar* target, const xmlChar* data) = 0; + virtual void SAXcomment(const xmlChar* comment) = 0; virtual void SAXstartElement(const xmlChar* name, const xmlChar** attrs) = 0; virtual void SAXendElement(const xmlChar* name) = 0; virtual void SAXnotationDecl(const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId) = 0; @@ -73,6 +72,7 @@ class libxml2_base friend void lwit_error(void* user_data, const char* fmt, ...); friend void lwit_fatalError(void* user_data, const char* fmt, ...); friend void lwit_processingInstruction(void *user_data, const xmlChar* target, const xmlChar* data); + friend void lwit_comment(void *user_data, const xmlChar* comment); friend void lwit_startElement(void *user_data, const xmlChar* name, const xmlChar** attrs); friend void lwit_endElement(void* user_data, const xmlChar* name); friend void lwit_notationDecl(void* user_data, const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId); @@ -90,6 +90,7 @@ void lwit_endElement(void *user_data, const xmlChar* name); void lwit_characters(void* user_data, const xmlChar* ch, int len); void lwit_ignorableWhitespace(void *user_data, const xmlChar* ch, int len); void lwit_processingInstruction(void *user_data, const xmlChar* target, const xmlChar* data); +void lwit_comment(void *user_data, const xmlChar* comment); void lwit_warning(void *user_data, const char* fmt, ...); void lwit_error(void* user_data, const char* fmt, ...); void lwit_fatalError(void* user_data, const char* fmt, ...); @@ -157,6 +158,10 @@ class libxml2_wrapper : public basic_XMLReader, virtual basic_ContentHandler* getContentHandler() const { return contentHandler_; } virtual void setErrorHandler(errorHandlerT& handler) { errorHandler_ = &handler; } virtual errorHandlerT* getErrorHandler() const { return errorHandler_; } + virtual void setDeclHandler(declHandlerT& handler) { declHandler_ = &handler; } + virtual declHandlerT* getDeclHandler() const { return declHandler_; } + virtual void setLexicalHandler(lexicalHandlerT& handler) { lexicalHandler_ = &handler; } + virtual lexicalHandlerT* getLexicalHandler() const { return lexicalHandler_; } //////////////////////////////////////////////// // parsing @@ -184,6 +189,7 @@ class libxml2_wrapper : public basic_XMLReader, virtual void SAXerror(const std::string& error); virtual void SAXfatalError(const std::string& fatal); virtual void SAXprocessingInstruction(const xmlChar* target, const xmlChar* data); + virtual void SAXcomment(const xmlChar* comment); virtual void SAXstartElement(const xmlChar* name, const xmlChar** attrs); virtual void SAXstartElementNoNS(const xmlChar* name, const xmlChar** attrs); virtual void SAXendElement(const xmlChar* name); @@ -209,6 +215,7 @@ class libxml2_wrapper : public basic_XMLReader, errorHandlerT* errorHandler_; namespaceSupportT nsSupport_; declHandlerT* declHandler_; + lexicalHandlerT* lexicalHandler_; xmlParserCtxtPtr context_; xmlSAXLocatorPtr locator_; @@ -337,7 +344,10 @@ std::auto_ptr::PropertyBaseT> libxml2_wrapper(prop); } if(name == properties_.lexicalHandler) - throw SAX::SAXNotSupportedException(std::string("Property not supported ") + string_adaptorT::asStdString(name)); + { + getLexicalHandlerT* prop = new getLexicalHandlerT(lexicalHandler_); + return std::auto_ptr(prop); + } throw SAX::SAXNotRecognizedException(std::string("Property not recognized ") + string_adaptorT::asStdString(name)); } // doGetProperty @@ -355,7 +365,14 @@ void libxml2_wrapper::doSetProperty(const stringT& name, std::a declHandler_ = &(prop->get()); } if(name == properties_.lexicalHandler) - throw SAX::SAXNotSupportedException(std::string("Property not supported ") + string_adaptorT::asStdString(name)); + { + setLexicalHandlerT* prop = dynamic_cast(value.get()); + + if(!prop) + throw std::bad_cast(); + + lexicalHandler_ = &(prop->get()); + } throw SAX::SAXNotRecognizedException(std::string("Property not recognized ") + string_adaptorT::asStdString(name)); } // doSetProperty @@ -505,6 +522,13 @@ void libxml2_wrapper::SAXprocessingInstruction(const xmlChar* t string_adaptorT::construct_from_utf8(reinterpret_cast(data))); } // SAXprocessingInstruction +template +void libxml2_wrapper::SAXcomment(const xmlChar* comment) +{ + if(lexicalHandler_) + lexicalHandler_->comment(string_adaptorT::construct_from_utf8(reinterpret_cast(comment))); +} // SAXcomment + template void libxml2_wrapper::SAXstartElement(const xmlChar* qName, const xmlChar** atts) { @@ -602,7 +626,7 @@ void libxml2_wrapper::SAXendElement(const xmlChar* qName) typename basic_NamespaceSupport::Parts name = processName(string_adaptorT::construct_from_utf8(reinterpret_cast(qName)), false); contentHandler_->endElement(name.URI, name.localName, name.rawName); typename basic_NamespaceSupport::stringListT prefixes = nsSupport_.getDeclaredPrefixes(); - for(size_t i = 1, end = prefixes.size(); i < end; ++i) + for(size_t i = 0, end = prefixes.size(); i < end; ++i) contentHandler_->endPrefixMapping(prefixes[i]); nsSupport_.popContext(); } // SAXendElement diff --git a/include/SAX/wrappers/saxmsxml2.h b/include/SAX/wrappers/saxmsxml2.h index 1c1aaffa..b9ed5d60 100644 --- a/include/SAX/wrappers/saxmsxml2.h +++ b/include/SAX/wrappers/saxmsxml2.h @@ -2,24 +2,6 @@ #define ARABICA_SAX_MSXML2_H //--------------------------------------------------------------------------- // A SAX2 wrapper class for MSXML component. -// -// $Id$ -// -// Changes: -// 21-Jul-2002 Major tweaks to use #include
rather then -// #import . The latter is sensitive to -// the exact name/version of the library provided by -// Microsoft and various options provided to the type -// library reader. (Found the issue when I attempted -// to build with MSXML4 rather then MSXML3.) [kas] -// -// 31-Jul-2002 Created the default PROGID define. M$. in their -// wisdom, removed the version independent IDs starting -// in version 4.0 of the MSXML library. Saves a lot of -// 'DLL hell' problems but creates others for maintainers. -// The initialization code will now try the 4.0 ID and -// then the older (version independant) name. [kas] -// //--------------------------------------------------------------------------- #include @@ -28,8 +10,6 @@ #include #include #include -#include -#include #include #include #include @@ -118,6 +98,10 @@ class msxml2_wrapper : public SAX::basic_XMLReader virtual SAX::basic_ContentHandler* getContentHandler() const { return contentHandler_.getContentHandler(); } virtual void setErrorHandler(SAX::basic_ErrorHandler& handler); virtual SAX::basic_ErrorHandler* getErrorHandler() const; + virtual void setDeclHandler(declHandlerT& handler) { declHandler_.setDeclHandler(handler); } + virtual declHandlerT* getDeclHandler() const { return declHandler_.getDeclHandler(); } + virtual void setLexicalHandler(lexicalHandlerT& handler) { lexicalHandler_.setLexicalHandler(handler); } + virtual lexicalHandlerT* getLexicalHandler() const { return lexicalHandler_.getLexicalHandler(); } ////////////////////////////////////////////////// // Parsing diff --git a/include/SAX/wrappers/saxxerces.h b/include/SAX/wrappers/saxxerces.h index 602df76a..e7e5a245 100644 --- a/include/SAX/wrappers/saxxerces.h +++ b/include/SAX/wrappers/saxxerces.h @@ -163,6 +163,10 @@ class xerces_wrapper : public SAX::basic_ProgressiveParser virtual ContentHandlerT* getContentHandler() const { return contentHandlerAdaptor_.getContentHandler(); } virtual void setErrorHandler(ErrorHandlerT& handler) { errorHandlerAdaptor_.setErrorHandler(handler); } virtual ErrorHandlerT* getErrorHandler() const { return errorHandlerAdaptor_.getErrorHandler(); } + virtual void setDeclHandler(DeclHandlerT& handler) { declHandlerAdaptor_.setDeclHandler(handler); } + virtual DeclHandlerT* getDeclHandler() const { return declHandlerAdaptor_.getDeclHandler(); } + virtual void setLexicalHandler(LexicalHandlerT& handler) { lexicalHandlerAdaptor_.setLexicalHandler(handler); } + virtual LexicalHandlerT* getLexicalHandler() const { return lexicalHandlerAdaptor_.getLexicalHandler(); } ////////////////////////////////////////////////// // Parsing