diff --git a/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp b/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp index e8059a37dedd76457e1f497608d3891bf80549a7..06d88141214c2eb9c87c54a40f5add1cb31c5e58 100644 --- a/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp +++ b/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp @@ -7,19 +7,19 @@ CFG=XercesLib - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run -!MESSAGE +!MESSAGE !MESSAGE NMAKE /f "XercesLib.mak". -!MESSAGE +!MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE +!MESSAGE !MESSAGE NMAKE /f "XercesLib.mak" CFG="XercesLib - Win32 Debug" -!MESSAGE +!MESSAGE !MESSAGE Possible choices for configuration are: -!MESSAGE +!MESSAGE !MESSAGE "XercesLib - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") !MESSAGE "XercesLib - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE +!MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 @@ -84,7 +84,7 @@ LINK32=link.exe # ADD LINK32 kernel32.lib user32.lib advapi32.lib ws2_32.lib /nologo /base:"0x12000000" /subsystem:windows /dll /debug /machine:I386 /out:"..\..\..\..\..\Build\Win32\VC6\Debug/xerces-c_2_0_0D.dll" /implib:"..\..\..\..\..\Build\Win32\VC6\Debug/xerces-c_1D.lib" /pdbtype:sept /version:2.0.0 # SUBTRACT LINK32 /pdb:none -!ENDIF +!ENDIF # Begin Target @@ -1144,6 +1144,14 @@ SOURCE=..\..\..\..\..\src\xercesc\sax\SAXParseException.hpp # PROP Default_Filter ".cpp,.hpp" # Begin Source File +SOURCE=..\..\..\..\..\src\xercesc\parsers\AbstractDOMParser.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\..\src\xercesc\parsers\AbstractDOMParser.hpp +# End Source File +# Begin Source File + SOURCE=..\..\..\..\..\src\xercesc\parsers\SAX2XMLReaderImpl.cpp # End Source File # Begin Source File diff --git a/src/xercesc/dom/deprecated/DOMParser.cpp b/src/xercesc/dom/deprecated/DOMParser.cpp index 147055239dc68694e9d26fc0aaf4929424ec6a7d..9e120d59392564dc6568e302954246226ac6f3dc 100644 --- a/src/xercesc/dom/deprecated/DOMParser.cpp +++ b/src/xercesc/dom/deprecated/DOMParser.cpp @@ -233,11 +233,9 @@ void DOMParser::setEntityResolver(EntityResolver* const handler) fEntityResolver = handler; if (fEntityResolver) { fScanner->setEntityHandler(this); - fScanner->setEntityResolver(fEntityResolver); } else { fScanner->setEntityHandler(0); - fScanner->setEntityResolver(0); } } diff --git a/src/xercesc/dom/impl/DOMDocumentTypeImpl.hpp b/src/xercesc/dom/impl/DOMDocumentTypeImpl.hpp index fc5f4b168687c6acbe1a3b61be810e8e308c9b61..4c1c33b0de980f8e37361584e4dbdc68365d72d9 100644 --- a/src/xercesc/dom/impl/DOMDocumentTypeImpl.hpp +++ b/src/xercesc/dom/impl/DOMDocumentTypeImpl.hpp @@ -103,7 +103,7 @@ private: virtual void setInternalSubset(const XMLCh *value); bool isIntSubsetReading() const; - friend class XercesDOMParser; + friend class AbstractDOMParser; public: DOMDocumentTypeImpl(DOMDocument *, const XMLCh *); diff --git a/src/xercesc/dom/impl/DOMTextImpl.hpp b/src/xercesc/dom/impl/DOMTextImpl.hpp index acd53aa8f4201aff9b14165e18dd7b5e2d7b9976..3d4dc9d5db7905ae5bde0d778421ebadb6448e17 100644 --- a/src/xercesc/dom/impl/DOMTextImpl.hpp +++ b/src/xercesc/dom/impl/DOMTextImpl.hpp @@ -113,7 +113,7 @@ public: protected: virtual void setIgnorableWhitespace(bool ignorable); - friend class XercesDOMParser; + friend class AbstractDOMParser; }; #endif diff --git a/src/xercesc/internal/XMLScanner.cpp b/src/xercesc/internal/XMLScanner.cpp index 866107139066e3e3c7cc6457acc42b28d715e5df..a56ca783c7d2eb62c9905e1b006c914aaa9f2418 100644 --- a/src/xercesc/internal/XMLScanner.cpp +++ b/src/xercesc/internal/XMLScanner.cpp @@ -203,7 +203,6 @@ XMLScanner::XMLScanner(XMLValidator* const valToAdopt) : , fDocHandler(0) , fDocTypeHandler(0) , fEntityHandler(0) - , fEntityResolver(0) , fErrorReporter(0) , fErrorHandler(0) , fIDRefList(0) @@ -267,7 +266,6 @@ XMLScanner::XMLScanner( XMLDocumentHandler* const docHandler , fDocHandler(docHandler) , fDocTypeHandler(docTypeHandler) , fEntityHandler(entityHandler) - , fEntityResolver(0) , fErrorReporter(errHandler) , fErrorHandler(0) , fIDRefList(0) @@ -477,18 +475,6 @@ void XMLScanner::scanDocument(const InputSource& src, const bool reuseGrammar) fReaderMgr.reset(); } - catch(const SAXException&) - { - // - // We have to propogate SAX exceptions. - // - // Make sure that the reader manager gets reset, then rethrow this - // exception since it means nothing much to us. - // - fReaderMgr.reset(); - throw; - } - catch(const XMLException& excToCatch) { // @@ -661,13 +647,6 @@ bool XMLScanner::scanFirst( const InputSource& src return false; } - // We have to propogate SAX exceptions - catch(const SAXException&) - { - fReaderMgr.reset(); - throw; - } - catch(const XMLException& excToCatch) { // @@ -1045,7 +1024,6 @@ void XMLScanner::initValidator(XMLValidator* theValidator) { if (theValidator->handlesSchema()) { ((SchemaValidator*) theValidator)->setGrammarResolver(fGrammarResolver); - ((SchemaValidator*) theValidator)->setErrorHandler(fErrorHandler); ((SchemaValidator*) theValidator)->setExitOnFirstFatal(fExitOnFirstFatal); } } diff --git a/src/xercesc/internal/XMLScanner.hpp b/src/xercesc/internal/XMLScanner.hpp index 25743c369a81da646efea5829e2358e108ed415a..a720b220b8922c521ac27e4f38e180a62c5e2f4c 100644 --- a/src/xercesc/internal/XMLScanner.hpp +++ b/src/xercesc/internal/XMLScanner.hpp @@ -56,6 +56,13 @@ /* * $Log$ + * Revision 1.3 2002/05/22 20:54:33 knoaman + * Prepare for DOM L3 : + * - Make use of the XMLEntityHandler/XMLErrorReporter interfaces, instead of using + * EntityHandler/ErrorHandler directly. + * - Add 'AbstractDOMParser' class to provide common functionality for XercesDOMParser + * and DOMBuilder. + * * Revision 1.2 2002/03/25 20:25:32 knoaman * Move particle derivation checking from TraverseSchema to SchemaValidator. * @@ -221,7 +228,6 @@ class XMLDocumentHandler; class DocTypeHandler; class XMLElementDecl; class XMLEntityHandler; -class EntityResolver; class XMLErrorReporter; class ErrorHandler; class XMLMsgLoader; @@ -469,7 +475,6 @@ public : void setDocTypeHandler(DocTypeHandler* const docTypeHandler); void setDoNamespaces(const bool doNamespaces); void setEntityHandler(XMLEntityHandler* const docTypeHandler); - void setEntityResolver(EntityResolver* const handler); void setErrorReporter(XMLErrorReporter* const errHandler); void setErrorHandler(ErrorHandler* const handler); void setExitOnFirstFatal(const bool newValue); @@ -722,10 +727,6 @@ private : // The client code's entity handler. If zero, then no entity handler // callouts are done. We don't adopt it. // - // fEntityResolver - // The client code's entity resolver. Need to store this info for - // Schema parse entity resolving. - // // fErrorReporter // The client code's error reporter. If zero, then no error reporter // callouts are done. We don't adopt it. @@ -933,7 +934,6 @@ private : DocTypeHandler* fDocTypeHandler; ElemStack fElemStack; XMLEntityHandler* fEntityHandler; - EntityResolver* fEntityResolver; XMLErrorReporter* fErrorReporter; ErrorHandler* fErrorHandler; RefHashTableOf<XMLRefInfo>* fIDRefList; @@ -1193,7 +1193,6 @@ inline void XMLScanner::setErrorReporter(XMLErrorReporter* const errHandler) inline void XMLScanner::setErrorHandler(ErrorHandler* const handler) { fErrorHandler = handler; - fSchemaValidator->setErrorHandler(handler); } inline void XMLScanner::setEntityHandler(XMLEntityHandler* const entityHandler) @@ -1202,11 +1201,6 @@ inline void XMLScanner::setEntityHandler(XMLEntityHandler* const entityHandler) fReaderMgr.setEntityHandler(entityHandler); } -inline void XMLScanner::setEntityResolver(EntityResolver* const handler) -{ - fEntityResolver = handler; -} - inline void XMLScanner::setExitOnFirstFatal(const bool newValue) { fExitOnFirstFatal = newValue; diff --git a/src/xercesc/internal/XMLScanner2.cpp b/src/xercesc/internal/XMLScanner2.cpp index 2a5387c750944776f038ae8a9258116258ba0525..29553af6ea3ade53d462d8c8bab5cb31925b27b4 100644 --- a/src/xercesc/internal/XMLScanner2.cpp +++ b/src/xercesc/internal/XMLScanner2.cpp @@ -76,7 +76,6 @@ #include <xercesc/util/XMLUniDefs.hpp> #include <xercesc/util/XMLUni.hpp> #include <xercesc/util/XMLURL.hpp> -#include <xercesc/sax/InputSource.hpp> #include <xercesc/framework/LocalFileInputSource.hpp> #include <xercesc/framework/URLInputSource.hpp> #include <xercesc/framework/XMLErrorReporter.hpp> @@ -87,9 +86,7 @@ #include <xercesc/framework/XMLValidator.hpp> #include <xercesc/internal/XMLScanner.hpp> #include <xercesc/internal/EndOfEntityException.hpp> -#include <xercesc/internal/XMLInternalErrorHandler.hpp> #include <xercesc/dom/DOMException.hpp> -#include <xercesc/sax/EntityResolver.hpp> #include <xercesc/validators/common/ContentLeafNameTypeVector.hpp> #include <xercesc/validators/datatype/DatatypeValidator.hpp> #include <xercesc/validators/schema/SchemaSymbols.hpp> @@ -226,7 +223,7 @@ XMLScanner::buildAttList(const RefVectorOf<KVStringPair>& providedAttrs XMLAttDef* attDefForWildCard = 0; XMLAttDef* attDef = 0; - + if (fGrammarType == Grammar::SchemaGrammarType) { //retrieve the att def @@ -1413,11 +1410,11 @@ void XMLScanner::resolveSchemaGrammar(const XMLCh* const loc, const XMLCh* const if (!grammar || grammar->getGrammarType() == Grammar::DTDGrammarType) { XSDDOMParser parser; - XMLInternalErrorHandler internalErrorHandler(fErrorHandler); + parser.setValidationScheme(XercesDOMParser::Val_Never); parser.setDoNamespaces(true); - parser.setErrorHandler((ErrorHandler*) &internalErrorHandler); - parser.setEntityResolver(fEntityResolver); + parser.setUserEntityHandler(fEntityHandler); + parser.setUserErrorReporter(fErrorReporter); // Create a buffer for expanding the system id XMLBufBid bbSys(&fBufMgr); @@ -1427,29 +1424,22 @@ void XMLScanner::resolveSchemaGrammar(const XMLCh* const loc, const XMLCh* const // Allow the entity handler to expand the system id if they choose // to do so. // + InputSource* srcToFill = 0; if (fEntityHandler) { if (!fEntityHandler->expandSystemId(loc, expSysId)) expSysId.set(loc); + + fEntityHandler->resolveEntity( XMLUni::fgZeroLenString + , expSysId.getRawBuffer()); } else { expSysId.set(loc); } - // Call the entity resolver interface to get an input source - InputSource* srcToFill = 0; - if (fEntityResolver) - { - srcToFill = fEntityResolver->resolveEntity - ( - XMLUni::fgZeroLenString - , expSysId.getRawBuffer() - ); - } - // - // If they didn't create a source via the entity resolver, then we + // If they didn't create a source via the entity handler, then we // have to create one on our own. // if (!srcToFill) @@ -1489,12 +1479,12 @@ void XMLScanner::resolveSchemaGrammar(const XMLCh* const loc, const XMLCh* const const bool flag = srcToFill->getIssueFatalErrorIfNotFound(); srcToFill->setIssueFatalErrorIfNotFound(false); - parser.parse(*srcToFill) ; + parser.parse(*srcToFill); // Reset the InputSource srcToFill->setIssueFatalErrorIfNotFound(flag); - if (internalErrorHandler.getSawFatal() && fExitOnFirstFatal) + if (parser.getSawFatal() && fExitOnFirstFatal) emitError(XMLErrs::SchemaScanFatalError); DOMDocument* document = parser.getDocument(); //Our Grammar @@ -1535,7 +1525,7 @@ void XMLScanner::resolveSchemaGrammar(const XMLCh* const loc, const XMLCh* const } grammar = new SchemaGrammar(); - TraverseSchema traverseSchema(root, fURIStringPool, (SchemaGrammar*) grammar, fGrammarResolver, this, fValidator, srcToFill->getSystemId(), fEntityResolver, fErrorHandler); + TraverseSchema traverseSchema(root, fURIStringPool, (SchemaGrammar*) grammar, fGrammarResolver, this, fValidator, srcToFill->getSystemId(), fEntityHandler, fErrorReporter); if (fGrammarType == Grammar::DTDGrammarType) { fGrammar = grammar; diff --git a/src/xercesc/parsers/AbstractDOMParser.cpp b/src/xercesc/parsers/AbstractDOMParser.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5541d73e77cbeae4777567c7667171e0a208fe34 --- /dev/null +++ b/src/xercesc/parsers/AbstractDOMParser.cpp @@ -0,0 +1,1167 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Xerces" and "Apache Software Foundation" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache\@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation, and was + * originally based on software copyright (c) 2001, International + * Business Machines, Inc., http://www.ibm.com . For more information + * on the Apache Software Foundation, please see + * <http://www.apache.org/>. + */ + +/** +* This file contains code to build the DOM tree. It registers a document +* handler with the scanner. In these handler methods, appropriate DOM nodes +* are created and added to the DOM tree. +* +* $Id$ +* +*/ + + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <xercesc/sax/EntityResolver.hpp> +#include <xercesc/util/XMLUniDefs.hpp> +#include <xercesc/framework/XMLNotationDecl.hpp> +#include <xercesc/util/IOException.hpp> +#include <xercesc/internal/XMLScanner.hpp> +#include <xercesc/validators/DTD/DTDValidator.hpp> +#include <xercesc/parsers/AbstractDOMParser.hpp> +#include <xercesc/dom/DOMImplementation.hpp> +#include <xercesc/dom/DOMElement.hpp> +#include <xercesc/dom/impl/DOMAttrImpl.hpp> +#include <xercesc/dom/DOMCDATASection.hpp> +#include <xercesc/dom/DOMComment.hpp> +#include <xercesc/dom/impl/DOMTextImpl.hpp> +#include <xercesc/dom/impl/DOMDocumentImpl.hpp> +#include <xercesc/dom/impl/DOMDocumentTypeImpl.hpp> +#include <xercesc/dom/DOMDocumentType.hpp> +#include <xercesc/dom/impl/DOMElementImpl.hpp> +#include <xercesc/dom/impl/DOMEntityImpl.hpp> +#include <xercesc/dom/impl/DOMEntityReferenceImpl.hpp> +#include <xercesc/dom/impl/DOMNotationImpl.hpp> +#include <xercesc/dom/DOMNamedNodeMap.hpp> +#include <xercesc/dom/DOMProcessingInstruction.hpp> +#include <xercesc/dom/impl/DOMNodeIDMap.hpp> + + +#include <xercesc/validators/common/ContentSpecNode.hpp> +#include <xercesc/validators/DTD/DTDAttDefList.hpp> + +// --------------------------------------------------------------------------- +// AbstractDOMParser: Constructors and Destructor +// --------------------------------------------------------------------------- +AbstractDOMParser::AbstractDOMParser(XMLValidator* const valToAdopt) : + + fCreateEntityReferenceNodes(true) +, fIncludeIgnorableWhitespace(true) +, fWithinElement(false) +, fParseInProgress(false) +, fScanner(0) +, fCurrentParent(0) +, fCurrentNode(0) +, fDocument(0) +, fNodeStack(0) +, fDocumentType(0) +, fDocumentVector(0) +{ + // + // Create a scanner and tell it what validator to use. Then set us + // as the document event handler so we can fill the DOM document. + // + fScanner = new XMLScanner(valToAdopt); + fScanner->setDocHandler(this); + fScanner->setDocTypeHandler(this); + + fNodeStack = new ValueStackOf<DOMNode*>(64); + this->reset(); + + +} + + +AbstractDOMParser::~AbstractDOMParser() +{ + if (fDocumentVector) + delete fDocumentVector; + + delete fDocument; + delete fNodeStack; + delete fScanner; +} + + +void AbstractDOMParser::reset() +{ + // if fDocument exists already, store the old pointer in the vector for deletion later + if (fDocument) { + if (!fDocumentVector) { + // allocate the vector if not exists yet + fDocumentVector = new RefVectorOf<DOMDocumentImpl>(10, true) ; + } + fDocumentVector->addElement(fDocument); + } + + fDocument = 0; + resetDocType(); + + fCurrentParent = 0; + fCurrentNode = 0; + fParseInProgress = false; + fWithinElement = false; + fNodeStack->removeAllElements(); +}; + + + +// --------------------------------------------------------------------------- +// AbstractDOMParser: Getter methods +// --------------------------------------------------------------------------- +DOMDocument* AbstractDOMParser::getDocument() +{ + return fDocument; +} + +const XMLValidator& AbstractDOMParser::getValidator() const +{ + return *fScanner->getValidator(); +} + +bool AbstractDOMParser::getDoNamespaces() const +{ + return fScanner->getDoNamespaces(); +} + +bool AbstractDOMParser::getExitOnFirstFatalError() const +{ + return fScanner->getExitOnFirstFatal(); +} + +bool AbstractDOMParser::getValidationConstraintFatal() const +{ + return fScanner->getValidationConstraintFatal(); +} + +AbstractDOMParser::ValSchemes AbstractDOMParser::getValidationScheme() const +{ + const XMLScanner::ValSchemes scheme = fScanner->getValidationScheme(); + + if (scheme == XMLScanner::Val_Always) + return Val_Always; + else if (scheme == XMLScanner::Val_Never) + return Val_Never; + + return Val_Auto; +} + +bool AbstractDOMParser::getDoSchema() const +{ + return fScanner->getDoSchema(); +} + +bool AbstractDOMParser::getValidationSchemaFullChecking() const +{ + return fScanner->getValidationSchemaFullChecking(); +} + +int AbstractDOMParser::getErrorCount() const +{ + return fScanner->getErrorCount(); +} + +XMLCh* AbstractDOMParser::getExternalSchemaLocation() const +{ + return fScanner->getExternalSchemaLocation(); +} + +XMLCh* AbstractDOMParser::getExternalNoNamespaceSchemaLocation() const +{ + return fScanner->getExternalNoNamespaceSchemaLocation(); +} + +// --------------------------------------------------------------------------- +// AbstractDOMParser: Setter methods +// --------------------------------------------------------------------------- +void AbstractDOMParser::setDoNamespaces(const bool newState) +{ + fScanner->setDoNamespaces(newState); +} + +void AbstractDOMParser::setExitOnFirstFatalError(const bool newState) +{ + fScanner->setExitOnFirstFatal(newState); +} + +void AbstractDOMParser::setValidationConstraintFatal(const bool newState) +{ + fScanner->setValidationConstraintFatal(newState); +} + +void AbstractDOMParser::setValidationScheme(const ValSchemes newScheme) +{ + if (newScheme == Val_Never) + fScanner->setValidationScheme(XMLScanner::Val_Never); + else if (newScheme == Val_Always) + fScanner->setValidationScheme(XMLScanner::Val_Always); + else + fScanner->setValidationScheme(XMLScanner::Val_Auto); +} + +void AbstractDOMParser::setDoSchema(const bool newState) +{ + fScanner->setDoSchema(newState); +} + +void AbstractDOMParser::setValidationSchemaFullChecking(const bool schemaFullChecking) +{ + fScanner->setValidationSchemaFullChecking(schemaFullChecking); +} + +void AbstractDOMParser::setExternalSchemaLocation(const XMLCh* const schemaLocation) +{ + fScanner->setExternalSchemaLocation(schemaLocation); +} +void AbstractDOMParser::setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation) +{ + fScanner->setExternalNoNamespaceSchemaLocation(noNamespaceSchemaLocation); +} + +void AbstractDOMParser::setExternalSchemaLocation(const char* const schemaLocation) +{ + fScanner->setExternalSchemaLocation(schemaLocation); +} +void AbstractDOMParser::setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation) +{ + fScanner->setExternalNoNamespaceSchemaLocation(noNamespaceSchemaLocation); +} + + +// --------------------------------------------------------------------------- +// AbstractDOMParser: Parsing methods +// --------------------------------------------------------------------------- +void AbstractDOMParser::parse(const InputSource& source, const bool reuseGrammar) +{ + // Avoid multiple entrance + if (fParseInProgress) + ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress); + + try + { + fParseInProgress = true; + fScanner->scanDocument(source, reuseGrammar); + fParseInProgress = false; + } + + catch(...) + { + fParseInProgress = false; + throw; + } +} + +void AbstractDOMParser::parse(const XMLCh* const systemId, const bool reuseGrammar) +{ + // Avoid multiple entrance + if (fParseInProgress) + ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress); + + try + { + fParseInProgress = true; + fScanner->scanDocument(systemId, reuseGrammar); + fParseInProgress = false; + } + + catch(...) + { + fParseInProgress = false; + throw; + } +} + +void AbstractDOMParser::parse(const char* const systemId, const bool reuseGrammar) +{ + // Avoid multiple entrance + if (fParseInProgress) + ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress); + + try + { + fParseInProgress = true; + fScanner->scanDocument(systemId, reuseGrammar); + fParseInProgress = false; + } + + catch(...) + { + fParseInProgress = false; + throw; + } +} + + + +// --------------------------------------------------------------------------- +// AbstractDOMParser: Progressive parse methods +// --------------------------------------------------------------------------- +bool AbstractDOMParser::parseFirst( const XMLCh* const systemId + , XMLPScanToken& toFill + , const bool reuseGrammar) +{ + // + // Avoid multiple entrance. We cannot enter here while a regular parse + // is in progress. + // + if (fParseInProgress) + ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress); + + return fScanner->scanFirst(systemId, toFill, reuseGrammar); +} + +bool AbstractDOMParser::parseFirst( const char* const systemId + , XMLPScanToken& toFill + , const bool reuseGrammar) +{ + // + // Avoid multiple entrance. We cannot enter here while a regular parse + // is in progress. + // + if (fParseInProgress) + ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress); + + return fScanner->scanFirst(systemId, toFill, reuseGrammar); +} + +bool AbstractDOMParser::parseFirst( const InputSource& source + , XMLPScanToken& toFill + , const bool reuseGrammar) +{ + // + // Avoid multiple entrance. We cannot enter here while a regular parse + // is in progress. + // + if (fParseInProgress) + ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress); + + return fScanner->scanFirst(source, toFill, reuseGrammar); +} + +bool AbstractDOMParser::parseNext(XMLPScanToken& token) +{ + return fScanner->scanNext(token); +} + +void AbstractDOMParser::parseReset(XMLPScanToken& token) +{ + // Reset the scanner, and then reset the parser + fScanner->scanReset(token); + reset(); +} + + +// --------------------------------------------------------------------------- +// AbstractDOMParser: Utilities +// --------------------------------------------------------------------------- +void AbstractDOMParser::resetDocumentPool() +{ + // We cannot enter here while a regular parse is in progress. + if (fParseInProgress) + ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress); + + if (fDocumentVector) + fDocumentVector->removeAllElements(); + + delete fDocument; + fDocument = 0; +} + + +// --------------------------------------------------------------------------- +// AbstractDOMParser: Implementation of XMLDocumentHandler interface +// --------------------------------------------------------------------------- +void AbstractDOMParser::docCharacters( const XMLCh* const chars + , const unsigned int length + , const bool cdataSection) +{ + // Ignore chars outside of content + if (!fWithinElement) + return; + + // revisit. Is it really safe to null-terminate here? + // Does the scanner do it already? + // If scanner goes up to the very end of an unterminated + // buffer, we may be stepping on something bad here. + // Probably best to modify the scanner to null terminate. + XMLCh savedChar = chars[length]; + XMLCh *ncChars = (XMLCh *)chars; // cast off const + ncChars[length] = 0; + if (cdataSection == true) + { + DOMCDATASection *node = fDocument->createCDATASection(chars); + fCurrentParent->appendChild(node); + fCurrentNode = node; + } + else + { + if (fCurrentNode->getNodeType() == DOMNode::TEXT_NODE) + { + DOMText *node = (DOMText *)fCurrentNode; + node->appendData(chars); + } + else + { + DOMText *node = fDocument->createTextNode(chars); + fCurrentParent->appendChild(node); + fCurrentNode = node; + } + } + ncChars[length] = savedChar; + return; +} + + +void AbstractDOMParser::docComment(const XMLCh* const comment) +{ + DOMComment *dcom = fDocument->createComment(comment); + fCurrentParent->appendChild(dcom); + fCurrentNode = dcom; +} + + +void AbstractDOMParser::docPI( const XMLCh* const target + , const XMLCh* const data) +{ + DOMProcessingInstruction *pi = fDocument->createProcessingInstruction + ( + target + , data + ); + fCurrentParent->appendChild(pi); + fCurrentNode = pi; +} + + +void AbstractDOMParser::endEntityReference(const XMLEntityDecl& entDecl) +{ + if (fCreateEntityReferenceNodes == true) + { + if (fCurrentParent->getNodeType() == DOMNode::ENTITY_REFERENCE_NODE) { + DOMEntityReferenceImpl *erImpl = (DOMEntityReferenceImpl *) fCurrentParent; + erImpl->setReadOnly(true, true); + } + fCurrentParent = fNodeStack->pop(); + fCurrentNode = fCurrentParent; + } +} + + +void AbstractDOMParser::endElement( const XMLElementDecl& elemDecl + , const unsigned int urlId + , const bool isRoot) +{ + fCurrentNode = fCurrentParent; + fCurrentParent = fNodeStack->pop(); + + // If we've hit the end of content, clear the flag + if (fNodeStack->empty()) + fWithinElement = false; +} + + +void AbstractDOMParser::ignorableWhitespace(const XMLCh* const chars + , const unsigned int length + , const bool cdataSection) +{ + // Ignore chars before the root element + if (!fWithinElement || !fIncludeIgnorableWhitespace) + return; + + // revisit. Not safe to slam in a null like this. + XMLCh savedChar = chars[length]; + XMLCh *ncChars = (XMLCh *)chars; // cast off const + ncChars[length] = chNull; + + if (fCurrentNode->getNodeType() == DOMNode::TEXT_NODE) + { + DOMText *node = (DOMText *)fCurrentNode; + node->appendData(chars); + } + else + { + DOMTextImpl *node = (DOMTextImpl *)fDocument->createTextNode(chars); + node->setIgnorableWhitespace(true); + fCurrentParent->appendChild(node); + + fCurrentNode = node; + } + ncChars[length] = savedChar; +} + + +void AbstractDOMParser::resetDocument() +{ + // + // The reset methods are called before a new parse event occurs. + // Reset this parsers state to clear out anything that may be left + // from a previous use, in particular the DOM document itself. + // + this->reset(); + fDocument = (DOMDocumentImpl *)DOMImplementation::getImplementation()->createDocument(); +} + + +void AbstractDOMParser::startDocument() +{ + // Just set the document as the current parent and current node + fCurrentParent = fDocument; + fCurrentNode = fDocument; + // set DOM error checking off + fDocument->setErrorChecking(false); +} + + +void AbstractDOMParser::endDocument() +{ + // set DOM error checking back on + fDocument->setErrorChecking(true); +} + + +void AbstractDOMParser::startElement(const XMLElementDecl& elemDecl + , const unsigned int urlId + , const XMLCh* const elemPrefix + , const RefVectorOf<XMLAttr>& attrList + , const unsigned int attrCount + , const bool isEmpty + , const bool isRoot) +{ + DOMElement *elem; + + if (fScanner -> getDoNamespaces()) { //DOM Level 2, doNamespaces on + XMLBuffer buf; + XMLCh* namespaceURI = 0; + if (urlId != fScanner->getEmptyNamespaceId()) { //TagName has a prefix + fScanner->getURIText(urlId, buf); //get namespaceURI + namespaceURI = buf.getRawBuffer(); + } + elem = createElementNSNode(namespaceURI, elemDecl.getFullName()); + DOMElementImpl *elemImpl = (DOMElementImpl *) elem; + for (unsigned int index = 0; index < attrCount; ++index) { + static const XMLCh XMLNS[] = { + chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s, chNull + }; + const XMLAttr* oneAttrib = attrList.elementAt(index); + unsigned int attrURIId = oneAttrib -> getURIId(); + namespaceURI = 0; + if (!XMLString::compareString(oneAttrib -> getName(), XMLNS)) //for xmlns=... + attrURIId = fScanner->getXMLNSNamespaceId(); + if (attrURIId != fScanner->getEmptyNamespaceId()) { //TagName has a prefix + fScanner->getURIText(attrURIId, buf); //get namespaceURI + namespaceURI = buf.getRawBuffer(); + } + // revisit. Optimize to init the named node map to the + // right size up front. + DOMAttrImpl *attr = (DOMAttrImpl *) + fDocument->createAttributeNS(namespaceURI, oneAttrib->getQName()); + attr->setValue(oneAttrib -> getValue()); + elemImpl->setAttributeNode(attr); + + //DOMAttrImpl *attr = elemImpl->setAttributeNS(namespaceURI, oneAttrib -> getQName(), + // oneAttrib -> getValue()); + + // Attributes of type ID. If this is one, add it to the hashtable of IDs + // that is constructed for use by GetElementByID(). + // + if (oneAttrib->getType()==XMLAttDef::ID) + { + if (fDocument->fNodeIDMap == 0) + fDocument->fNodeIDMap = new (fDocument) DOMNodeIDMap(500, fDocument); + fDocument->fNodeIDMap->add(attr); + attr->fNode.isIdAttr(true); + } + + attr->setSpecified(oneAttrib->getSpecified()); + } + } + else { //DOM Level 1 + elem = fDocument->createElement(elemDecl.getFullName()); + DOMElementImpl *elemImpl = (DOMElementImpl *) elem; + for (unsigned int index = 0; index < attrCount; ++index) { + const XMLAttr* oneAttrib = attrList.elementAt(index); + //AttrImpl *attr = elemImpl->setAttribute(oneAttrib->getName(), oneAttrib->getValue()); + DOMAttrImpl *attr = (DOMAttrImpl *) + fDocument->createAttribute(oneAttrib->getName()); + attr->setValue(oneAttrib -> getValue()); + elemImpl->setAttributeNode(attr); + attr->setSpecified(oneAttrib->getSpecified()); + + // Attributes of type ID. If this is one, add it to the hashtable of IDs + // that is constructed for use by GetElementByID(). + // + if (oneAttrib->getType()==XMLAttDef::ID) + { + if (fDocument->fNodeIDMap == 0) + fDocument->fNodeIDMap = new (fDocument) DOMNodeIDMap(500, fDocument); + fDocument->fNodeIDMap->add(attr); + attr->fNode.isIdAttr(true); + } + } + } + + fCurrentParent->appendChild(elem); + + fNodeStack->push(fCurrentParent); + fCurrentParent = elem; + fCurrentNode = elem; + fWithinElement = true; + + // If an empty element, do end right now (no endElement() will be called) + if (isEmpty) + endElement(elemDecl, urlId, isRoot); +} + + +void AbstractDOMParser::startEntityReference(const XMLEntityDecl& entDecl) +{ + if (fCreateEntityReferenceNodes == true) + { + const XMLCh * entName = entDecl.getName(); + DOMEntityReference *er = fDocument->createEntityReference(entName); + + //set the readOnly flag to false before appending node, will be reset in endEntityReference + DOMEntityReferenceImpl *erImpl = (DOMEntityReferenceImpl *) er; + erImpl->setReadOnly(false, true); + + fCurrentParent->appendChild(er); + fNodeStack->push(fCurrentParent); + fCurrentParent = er; + fCurrentNode = er; + + // this entityRef needs to be stored in Entity map too. + // We'd decide later whether the entity nodes should be created by a + // separated method in parser or not. For now just stick it in if + // the ref nodes are created + DOMNamedNodeMap *entities = fDocumentType->getEntities(); + DOMEntityImpl* entity = (DOMEntityImpl*)entities->getNamedItem(entName); + entity->setEntityRef(er); + + } +} + + +void AbstractDOMParser::XMLDecl(const XMLCh* const version + , const XMLCh* const encoding + , const XMLCh* const standalone + , const XMLCh* const actualEncStr) +{ + // placehold for DOM Level 3 +} + +// --------------------------------------------------------------------------- +// AbstractDOMParser: Helper methods +// --------------------------------------------------------------------------- +DOMElement* AbstractDOMParser::createElementNSNode(const XMLCh *namespaceURI, + const XMLCh *qualifiedName) +{ + return fDocument->createElementNS(namespaceURI, qualifiedName); +} +// --------------------------------------------------------------------------- +// AbstractDOMParser: Deprecated methods +// --------------------------------------------------------------------------- +bool AbstractDOMParser::getDoValidation() const +{ + // + // We don't want to tie the public parser classes to the enum used + // by the scanner, so we use a separate one and map. + // + // DON'T mix the new and old methods!! + // + const XMLScanner::ValSchemes scheme = fScanner->getValidationScheme(); + if (scheme == XMLScanner::Val_Always) + return true; + return false; +} + +void AbstractDOMParser::setDoValidation(const bool newState) +{ + fScanner->setDoValidation + ( + newState ? XMLScanner::Val_Always : XMLScanner::Val_Never + ); +} + +//doctypehandler interfaces +void AbstractDOMParser::attDef +( + const DTDElementDecl& elemDecl + , const DTDAttDef& attDef + , const bool ignoring + ) +{ + if (fDocumentType->isIntSubsetReading()) + { + XMLBuffer attString; + if (elemDecl.hasAttDefs()) + { + attString.append(chOpenAngle); + attString.append(chBang); + attString.append(XMLUni::fgAttListString); + attString.append(chSpace); + attString.append(elemDecl.getFullName()); + + attString.append(chSpace); + attString.append(attDef.getFullName()); + + // Get the type and display it + const XMLAttDef::AttTypes type = attDef.getType(); + switch(type) + { + case XMLAttDef::CData : + attString.append(chSpace); + attString.append(XMLUni::fgCDATAString); + break; + case XMLAttDef::ID : + attString.append(chSpace); + attString.append(XMLUni::fgIDString); + break; + case XMLAttDef::IDRef : + attString.append(chSpace); + attString.append(XMLUni::fgIDRefString); + break; + case XMLAttDef::IDRefs : + attString.append(chSpace); + attString.append(XMLUni::fgIDRefsString); + break; + case XMLAttDef::Entity : + attString.append(chSpace); + attString.append(XMLUni::fgEntityString); + break; + case XMLAttDef::Entities : + attString.append(chSpace); + attString.append(XMLUni::fgEntitiesString); + break; + case XMLAttDef::NmToken : + attString.append(chSpace); + attString.append(XMLUni::fgNmTokenString); + break; + case XMLAttDef::NmTokens : + attString.append(chSpace); + attString.append(XMLUni::fgNmTokensString); + break; + + case XMLAttDef::Notation : + attString.append(chSpace); + attString.append(XMLUni::fgNotationString); + break; + + case XMLAttDef::Enumeration : + attString.append(chSpace); + const XMLCh* enumString = attDef.getEnumeration(); + int length = XMLString::stringLen(enumString); + if (length > 0) { + + XMLBuffer anotherEnumString; + + anotherEnumString.append(chOpenParen ); + for(int i=0; i<length; i++) { + if (enumString[i] == chSpace) + anotherEnumString.append(chPipe); + else + anotherEnumString.append(enumString[i]); + } + anotherEnumString.append(chCloseParen); + attString.append(anotherEnumString.getRawBuffer()); + } + break; + } + //get te default types of the attlist + const XMLAttDef::DefAttTypes def = attDef.getDefaultType(); + switch(def) + { + case XMLAttDef::Required : + attString.append(chSpace); + attString.append(XMLUni::fgRequiredString); + break; + case XMLAttDef::Implied : + attString.append(chSpace); + attString.append(XMLUni::fgImpliedString); + break; + case XMLAttDef::Fixed : + attString.append(chSpace); + attString.append(XMLUni::fgFixedString); + break; + } + + const XMLCh* defaultValue = attDef.getValue(); + if (defaultValue != 0) { + attString.append(chSpace); + attString.append(chDoubleQuote); + attString.append(defaultValue); + attString.append(chDoubleQuote); + } + + attString.append(chCloseAngle); + fDocumentType->setInternalSubset(attString.getRawBuffer()); + } + } +} + +void AbstractDOMParser::doctypeComment +( + const XMLCh* const comment +) +{ + if (fDocumentType->isIntSubsetReading()) + { + if (comment != 0) + { + XMLBuffer comString; + comString.append(XMLUni::fgCommentString); + comString.append(chSpace); + comString.append(comment); + comString.append(chSpace); + comString.append(chDash); + comString.append(chDash); + comString.append(chCloseAngle); + fDocumentType->setInternalSubset(comString.getRawBuffer()); + } + } +} + +void AbstractDOMParser::doctypeDecl +( + const DTDElementDecl& elemDecl + , const XMLCh* const publicId + , const XMLCh* const systemId + , const bool hasIntSubset +) +{ + fDocumentType = (DOMDocumentTypeImpl *) fDocument->createDocumentType(elemDecl.getFullName(), publicId, systemId); + fDocument->setDocumentType(fDocumentType); + +} + +void AbstractDOMParser::doctypePI +( + const XMLCh* const target + , const XMLCh* const data +) +{ + if (fDocumentType->isIntSubsetReading()) + { + //add these chars to internalSubset variable + XMLBuffer pi; + pi.append(chOpenAngle); + pi.append(chQuestion); + pi.append(target); + pi.append(chSpace); + pi.append(data); + pi.append(chQuestion); + pi.append(chCloseAngle); + + fDocumentType->setInternalSubset(pi.getRawBuffer()); + } + +} + + +void AbstractDOMParser::doctypeWhitespace +( + const XMLCh* const chars + , const unsigned int length +) +{ + if (fDocumentType->isIntSubsetReading()) + fDocumentType->setInternalSubset(chars); +} + +void AbstractDOMParser::elementDecl +( + const DTDElementDecl& decl + , const bool isIgnored +) +{ + if (fDocumentType->isIntSubsetReading()) + { + XMLBuffer elemDecl; + + elemDecl.append(chOpenAngle); + elemDecl.append(chBang); + elemDecl.append(XMLUni::fgElemString); + elemDecl.append(chSpace); + elemDecl.append(decl.getFullName()); + + //get the ContentSpec information + const XMLCh* contentModel = decl.getFormattedContentModel(); + if (contentModel != 0) { + elemDecl.append(chSpace); + elemDecl.append(contentModel); + } + + elemDecl.append(chCloseAngle); + fDocumentType->setInternalSubset(elemDecl.getRawBuffer()); + } +} + +void AbstractDOMParser::endAttList +( + const DTDElementDecl& elemDecl +) +{ + // this section sets up default attributes. + // default attribute nodes are stored in a NamedNodeMap DocumentTypeImpl::elements + // default attribute data attached to the document is used to conform to the + // DOM spec regarding creating element nodes & removing attributes with default values + // see DocumentTypeImpl + if (elemDecl.hasAttDefs()) + { + XMLAttDefList* defAttrs = &elemDecl.getAttDefList(); + XMLAttDef* attr = 0; + + DOMAttrImpl * insertAttr = 0; + DOMElement *elem = fDocument->createElement(elemDecl.getFullName()); + DOMElementImpl *elemImpl = (DOMElementImpl *) elem; + + while (defAttrs->hasMoreElements()) + { + attr = &defAttrs->nextElement(); + if (attr->getValue() != 0) + { + if (fScanner->getDoNamespaces()) + { + // DOM Level 2 wants all namespace declaration attributes + // to be bound to "http://www.w3.org/2000/xmlns/" + // So as long as the XML parser doesn't do it, it needs to + // done here. + const XMLCh* qualifiedName = attr->getFullName(); + int index = DOMDocumentImpl::indexofQualifiedName(qualifiedName); + + XMLBuffer buf; + static const XMLCh XMLNS[] = { + chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s, chNull}; + + if (index > 0) { + // there is prefix + // map to XML URI for all cases except when prefix == "xmlns" + XMLCh* prefix; + XMLCh temp[1000]; + + if (index > 999) + prefix = new XMLCh[index+1]; + else + prefix = temp; + + XMLString::subString(prefix ,qualifiedName, 0, index); + + if (!XMLString::compareString(prefix,XMLNS)) + buf.append(XMLUni::fgXMLNSURIName); + else + buf.append(XMLUni::fgXMLURIName); + + if (index > 999) + delete prefix; + } + else { + // No prefix + if (!XMLString::compareString(qualifiedName,XMLNS)) + buf.append(XMLUni::fgXMLNSURIName); + } + + insertAttr = (DOMAttrImpl *) fDocument->createAttributeNS( + buf.getRawBuffer(), // NameSpaceURI + qualifiedName); // qualified name + + } + else + { + // Namespaces is turned off... + insertAttr = (DOMAttrImpl *) fDocument->createAttribute(attr->getFullName()); + } + insertAttr->setValue(attr->getValue()); + elemImpl->setAttributeNode(insertAttr); + insertAttr->setSpecified(false); + } + } + fDocumentType->getElements()->setNamedItem(elemImpl); + } +} + +void AbstractDOMParser::endIntSubset() +{ + fDocumentType->intSubsetReading = false; +} + +void AbstractDOMParser::endExtSubset() +{ +} + +void AbstractDOMParser::entityDecl +( + const DTDEntityDecl& entityDecl + , const bool isPEDecl + , const bool isIgnored +) +{ + DOMEntityImpl* entity = (DOMEntityImpl *) fDocument->createEntity(entityDecl.getName()); + + entity->setPublicId(entityDecl.getPublicId()); + entity->setSystemId(entityDecl.getSystemId()); + entity->setNotationName(entityDecl.getNotationName()); + + DOMEntityImpl *previousDef = (DOMEntityImpl *) + fDocumentType->getEntities()->setNamedItem( entity ); + + #ifdef _revisit + // + // If this new entity node is replacing an entity node that was already + // in the entities named node map (happens if documents redefine the + // predefined entited such as lt), we need to delete the original + // entitiy node, assuming no-one else was referencing it. + // + if (previousDef != 0 && previousDef->nodeRefCount == 0) + NodeImpl::deleteIf(previousDef); + #endif + + if (fDocumentType->isIntSubsetReading()) + { + //add thes chars to internalSubset variable + XMLBuffer entityName; + entityName.append(chOpenAngle); + entityName.append(chBang); + entityName.append(XMLUni::fgEntityString); + entityName.append(chSpace); + + entityName.append(entityDecl.getName()); + + const XMLCh* id = entity->getPublicId(); + if (id != 0) { + entityName.append(chSpace); + entityName.append(XMLUni::fgPubIDString); + entityName.append(chSpace); + entityName.append(chDoubleQuote); + entityName.append(id); + entityName.append(chDoubleQuote); + } + id = entity->getSystemId(); + if (id != 0) { + entityName.append(chSpace); + entityName.append(XMLUni::fgSysIDString); + entityName.append(chSpace); + entityName.append(chDoubleQuote); + entityName.append(id); + entityName.append(chDoubleQuote); + + } + id = entity->getNotationName(); + if (id != 0) { + entityName.append(chSpace); + entityName.append(XMLUni::fgNDATAString); + entityName.append(chSpace); + entityName.append(chDoubleQuote); + entityName.append(id); + entityName.append(chDoubleQuote); + } + id = entityDecl.getValue(); + if (id !=0) { + entityName.append(chSpace); + entityName.append(chDoubleQuote); + entityName.append(id); + entityName.append(chDoubleQuote); + } + + entityName.append(chCloseAngle); + fDocumentType->setInternalSubset(entityName.getRawBuffer()); + } + +} + +void AbstractDOMParser::resetDocType() +{ + fDocumentType = 0; +} + +void AbstractDOMParser::notationDecl +( + const XMLNotationDecl& notDecl + , const bool isIgnored +) +{ + DOMNotationImpl* notation = (DOMNotationImpl *)fDocument->createNotation(notDecl.getName()); + notation->setPublicId(notDecl.getPublicId()); + notation->setSystemId(notDecl.getSystemId()); + + fDocumentType->getNotations()->setNamedItem( notation ); + +} + +void AbstractDOMParser::startAttList +( + const DTDElementDecl& elemDecl +) +{ +} + +void AbstractDOMParser::startIntSubset() +{ + fDocumentType->intSubsetReading = true; +} + +void AbstractDOMParser::startExtSubset() +{ +} + +void AbstractDOMParser::TextDecl +( + const XMLCh* const versionStr + , const XMLCh* const encodingStr +) +{ +} diff --git a/src/xercesc/parsers/AbstractDOMParser.hpp b/src/xercesc/parsers/AbstractDOMParser.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f34263ff25e427875836e8e827b5bfc35469bcd9 --- /dev/null +++ b/src/xercesc/parsers/AbstractDOMParser.hpp @@ -0,0 +1,1346 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Xerces" and "Apache Software Foundation" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache\@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation, and was + * originally based on software copyright (c) 2001, International + * Business Machines, Inc., http://www.ibm.com . For more information + * on the Apache Software Foundation, please see + * <http://www.apache.org/>. + */ + +/* + * $Id$ + * + */ +#if !defined(ABSTRACTDOMPARSER_HPP) +#define ABSTRACTDOMPARSER_HPP + + +#include <xercesc/dom/DOMDocument.hpp> +#include <xercesc/framework/XMLDocumentHandler.hpp> +#include <xercesc/framework/XMLErrorReporter.hpp> +#include <xercesc/framework/XMLEntityHandler.hpp> +#include <xercesc/util/ValueStackOf.hpp> +#include <xercesc/validators/DTD/DocTypeHandler.hpp> +#include <xercesc/dom/DOMDocumentType.hpp> +#include <xercesc/validators/DTD/DTDElementDecl.hpp> + +class XMLPScanToken; +class XMLScanner; +class XMLValidator; +class DOMDocumentImpl; +class DOMDocumentTypeImpl; +class DOMElement; + + +/** + * This class implements the Document Object Model (DOM) interface. + * It is used as a base for DOM parsers (i.e. XercesDOMParser, DOMBuilder). + */ +class PARSERS_EXPORT AbstractDOMParser : + + public XMLDocumentHandler + , public XMLErrorReporter + , public XMLEntityHandler + , public DocTypeHandler +{ +public : + // ----------------------------------------------------------------------- + // Class types + // ----------------------------------------------------------------------- + enum ValSchemes + { + Val_Never + , Val_Always + , Val_Auto + }; + + + // ----------------------------------------------------------------------- + // Constructors and Detructor + // ----------------------------------------------------------------------- + + /** @name Destructor */ + //@{ + + /** + * Destructor + */ + virtual ~AbstractDOMParser(); + + //@} + + /** Reset the parser + * + * This method resets the state of the DOM driver and makes + * it ready for a fresh parse run. + */ + void reset(); + + /** Reset the documents vector pool and release all the associated memory + * back to the system. + * + * When parsing a document using a DOM parser, all memory allocated + * for a DOM tree is associated to the DOM document. + * + * If you do multiple parse using the same DOM parser instance, then + * multiple DOM documents will be generated and saved in a vector pool. + * All these documents (and thus all the allocated memory) + * won't be deleted until the parser instance is destroyed. + * + * If you don't need these DOM documents anymore and don't want to + * destroy the DOM parser instance at this moment, then you can call this method + * to reset the document vector pool and release all the allocated memory + * back to the system. + * + * It is an error to call this method if you are in the middle of a + * parse (e.g. in the mid of a progressive parse). + * + * @exception IOException An exception from the parser if this function + * is called when a parse is in progress. + * + */ + void resetDocumentPool(); + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + + /** @name Getter methods */ + //@{ + + /** Get the DOM document + * + * This method returns the DOMDocument object representing the + * root of the document tree. This object provides the primary + * access to the document's data. + * + * @return The DOMDocument object which represents the entire + * XML document. + */ + DOMDocument* getDocument(); + + /** Get a const reference to the validator + * + * This method returns a reference to the parser's installed + * validator. + * + * @return A const reference to the installed validator object. + */ + const XMLValidator& getValidator() const; + + /** + * This method returns an enumerated value that indicates the current + * validation scheme set on this parser. + * + * @return The ValSchemes value current set on this parser. + * @see #setValidationScheme + */ + ValSchemes getValidationScheme() const; + + /** Get the 'do schema' flag + * + * This method returns the state of the parser's schema processing + * flag. + * + * @return true, if the parser is currently configured to + * understand schema, false otherwise. + * + * @see #setDoSchema + */ + bool getDoSchema() const; + + /** Get the 'full schema constraint checking' flag + * + * This method returns the state of the parser's full schema constraint + * checking flag. + * + * @return true, if the parser is currently configured to + * have full schema constraint checking, false otherwise. + * + * @see #setValidationSchemaFullChecking + */ + bool getValidationSchemaFullChecking() const; + + /** Get error count from the last parse operation. + * + * This method returns the error count from the last parse + * operation. Note that this count is actually stored in the + * scanner, so this method simply returns what the + * scanner reports. + * + * @return number of errors encountered during the latest + * parse operation. + * + */ + int getErrorCount() const; + + /** Get the 'do namespaces' flag + * + * This method returns the state of the parser's namespace processing + * flag. + * + * @return true, if the parser is currently configured to + * understand namespaces, false otherwise. + * + * @see #setDoNamespaces + */ + bool getDoNamespaces() const; + + /** Get the 'exit on first error' flag + * + * This method returns the state of the parser's + * exit-on-First-Fatal-Error flag. If this flag is true, then the + * parse will exit the first time it sees any non-wellformed XML or + * any validity error. The default state is true. + * + * @return true, if the parser is currently configured to + * exit on the first fatal error, false otherwise. + * + * @see #setExitOnFirstFatalError + */ + bool getExitOnFirstFatalError() const; + + /** + * This method returns the state of the parser's + * validation-constraint-fatal flag. + * + * @return true, if the parser is currently configured to + * set validation constraint errors as fatal, false + * otherwise. + * + * @see #setValidationContraintFatal + */ + bool getValidationConstraintFatal() const; + + /** Get the 'expand entity references' flag. + * DEPRECATED Use getCreateEntityReferenceNodes() instead. + * + * This method returns the state of the parser's expand entity + * references flag. + * + * @return 'true' if the expand entity reference flag is set on + * the parser, 'false' otherwise. + * + * @see #setExpandEntityReferences + * @see #setCreateEntityReferenceNodes + * @see #getCreateEntityReferenceNodes + */ + bool getExpandEntityReferences() const; + + /** Get the 'include entity references' flag + * + * This method returns the flag that specifies whether the parser is + * creating entity reference nodes in the DOM tree being produced. + * + * @return The state of the create entity reference node + * flag. + * @see #setCreateEntityReferenceNodes + */ + bool getCreateEntityReferenceNodes()const; + + /** Get the 'include ignorable whitespace' flag. + * + * This method returns the state of the parser's include ignorable + * whitespace flag. + * + * @return 'true' if the include ignorable whitespace flag is set on + * the parser, 'false' otherwise. + * + * @see #setIncludeIgnorableWhitespace + */ + bool getIncludeIgnorableWhitespace() const; + + /** Get the set of Namespace/SchemaLocation that is specified externaly. + * + * This method returns the list of Namespace/SchemaLocation that was + * specified using setExternalSchemaLocation. + * + * The parser owns the returned string, and the memory allocated for + * the returned string will be destroyed when the parser is deleted. + * + * To ensure assessiblity of the returned information after the parser + * is deleted, callers need to copy and store the returned information + * somewhere else. + * + * @return a pointer to the list of Namespace/SchemaLocation that was + * specified externally. The pointer spans the same life-time as + * the parser. A null pointer is returned if nothing + * was specified externally. + * + * @see #setExternalSchemaLocation(const XMLCh* const) + */ + XMLCh* getExternalSchemaLocation() const; + + /** Get the noNamespace SchemaLocation that is specified externaly. + * + * This method returns the no target namespace XML Schema Location + * that was specified using setExternalNoNamespaceSchemaLocation. + * + * The parser owns the returned string, and the memory allocated for + * the returned string will be destroyed when the parser is deleted. + * + * To ensure assessiblity of the returned information after the parser + * is deleted, callers need to copy and store the returned information + * somewhere else. + * + * @return a pointer to the no target namespace Schema Location that was + * specified externally. The pointer spans the same life-time as + * the parser. A null pointer is returned if nothing + * was specified externally. + * + * @see #setExternalNoNamespaceSchemaLocation(const XMLCh* const) + */ + XMLCh* getExternalNoNamespaceSchemaLocation() const; + + //@} + + + // ----------------------------------------------------------------------- + // Setter methods + // ----------------------------------------------------------------------- + + /** @name Setter methods */ + //@{ + + /** Set the 'do namespaces' flag + * + * This method allows users to enable or disable the parser's + * namespace processing. When set to true, parser starts enforcing + * all the constraints and rules specified by the NameSpace + * specification. + * + * The parser's default state is: false. + * + * This flag is ignored by the underlying scanner if the installed + * validator indicates that namespace constraints should be + * enforced. + * + * @param newState The value specifying whether NameSpace rules should + * be enforced or not. + * + * @see #getDoNamespaces + */ + void setDoNamespaces(const bool newState); + + /** Set the 'exit on first error' flag + * + * This method allows users to set the parser's behaviour when it + * encounters the first fatal error. If set to true, the parser + * will exit at the first fatal error. If false, then it will + * report the error and continue processing. + * + * The default value is 'true' and the parser exits on the + * first fatal error. + * + * @param newState The value specifying whether the parser should + * continue or exit when it encounters the first + * fatal error. + * + * @see #getExitOnFirstFatalError + */ + void setExitOnFirstFatalError(const bool newState); + + /** + * This method allows users to set the parser's behaviour when it + * encounters a validtion constraint error. If set to true, and the + * the parser is set to exit when it encounter the first fatal error, + * the parser will exit at the first encounter. If false, then it will + * report the error and continue processing. + * + * <p>The default value is 'false'.</p> + * + * @param newState The value specifying whether the parser should + * continue or exit when it encounters a validation + * constraint error. + * + * @see #getValidationConstraintFatal + */ + void setValidationConstraintFatal(const bool newState); + + /** Set the 'expand entity references' flag + * + * DEPRECATED. USE setCreateEntityReferenceNodes instead. + * This method allows the user to specify whether the parser should + * expand all entity reference nodes. When the 'do expansion' flag is + * true, the DOM tree does not have any entity reference nodes. It is + * replaced by the sub-tree representing the replacement text of the + * entity. When the 'do expansion' flag is false, the DOM tree + * contains an extra entity reference node, whose children is the + * sub tree of the replacement text. + * <p>The default value is 'false'. + * + * @param expand The new state of the expand entity reference + * flag. + * @see #setCreateEntityReferenceNodes + */ + void setExpandEntityReferences(const bool expand); + + /** Set the 'include entity references' flag + * + * This method allows the user to specify whether the parser should + * create entity reference nodes in the DOM tree being produced. + * When the 'create' flag is + * true, the parser will create EntityReference nodes in the DOM tree. + * The EntityReference nodes and their child nodes will be read-only. + * When the 'create' flag is false, no EntityReference nodes will be created. + * <p>The replacement text + * of the entity is included in either case, either as a + * child of the Entity Reference node or in place at the location + * of the reference. + * <p>The default value is 'true'. + * + * @param create The new state of the create entity reference nodes + * flag. + * @see #getCreateEntityReferenceNodes + */ + void setCreateEntityReferenceNodes(const bool create); + + /** Set the 'include ignorable whitespace' flag + * + * This method allows the user to specify whether a validating parser + * should include ignorable whitespaces as text nodes. It has no effect + * on non-validating parsers which always include non-markup text. + * <p>When set to true (also the default), ignorable whitespaces will be + * added to the DOM tree as text nodes. The method + * DOMText::isIgnorableWhitespace() will return true for those text + * nodes only. + * <p>When set to false, all ignorable whitespace will be discarded and + * no text node is added to the DOM tree. Note: applications intended + * to process the "xml:space" attribute should not set this flag to false. + * And this flag also overrides any schema datateye whitespace facets, + * that is, all ignorable whitespace will be discarded even though + * 'preserve' is set in schema datatype whitespace facets. + * + * @param include The new state of the include ignorable whitespace + * flag. + * + * @see #getIncludeIgnorableWhitespace + */ + void setIncludeIgnorableWhitespace(const bool include); + + /** + * This method allows users to set the validation scheme to be used + * by this parser. The value is one of the ValSchemes enumerated values + * defined by this class: + * + * <br> Val_Never - turn off validation + * <br> Val_Always - turn on validation + * <br> Val_Auto - turn on validation if any internal/external + * DTD subset have been seen + * + * <p>The parser's default state is: Val_Auto.</p> + * + * @param newScheme The new validation scheme to use. + * + * @see #getValidationScheme + */ + void setValidationScheme(const ValSchemes newScheme); + + /** Set the 'do schema' flag + * + * This method allows users to enable or disable the parser's + * schema processing. When set to false, parser will not process + * any schema found. + * + * The parser's default state is: false. + * + * @param newState The value specifying whether schema support should + * be enforced or not. + * + * @see #getDoSchema + */ + void setDoSchema(const bool newState); + + /** + * This method allows the user to turn full Schema constraint checking on/off. + * Only takes effect if Schema validation is enabled. + * If turned off, partial constraint checking is done. + * + * Full schema constraint checking includes those checking that may + * be time-consuming or memory intensive. Currently, particle unique + * attribution constraint checking and particle derivation resriction checking + * are controlled by this option. + * + * The parser's default state is: false. + * + * @param schemaFullChecking True to turn on full schema constraint checking. + * + * @see #getValidationSchemaFullChecking + */ + void setValidationSchemaFullChecking(const bool schemaFullChecking); + + /** + * This method allows the user to specify a list of schemas to use. + * If the targetNamespace of a schema specified using this method matches + * the targetNamespace of a schema occuring in the instance document in + * the schemaLocation attribute, or if the targetNamespace matches the + * namespace attribute of the "import" element, the schema specified by the + * user using this method will be used (i.e., the schemaLocation attribute + * in the instance document or on the "import" element will be effectively ignored). + * + * If this method is called more than once, only the last one takes effect. + * + * The syntax is the same as for schemaLocation attributes in instance + * documents: e.g, "http://www.example.com file_name.xsd". The user can + * specify more than one XML Schema in the list. + * + * @param schemaLocation the list of schemas to use + * + * @see #getExternalSchemaLocation + */ + + void setExternalSchemaLocation(const XMLCh* const schemaLocation); + + /** + * This method is same as setExternalSchemaLocation(const XMLCh* const). + * It takes native char string as parameter + * + * @param schemaLocation the list of schemas to use + * + * @see #setExternalSchemaLocation(const XMLCh* const) + */ + void setExternalSchemaLocation(const char* const schemaLocation); + + /** + * This method allows the user to specify the no target namespace XML + * Schema Location externally. If specified, the instance document's + * noNamespaceSchemaLocation attribute will be effectively ignored. + * + * If this method is called more than once, only the last one takes effect. + * + * The syntax is the same as for the noNamespaceSchemaLocation attribute + * that may occur in an instance document: e.g."file_name.xsd". + * + * @param noNamespaceSchemaLocation the XML Schema Location with no target namespace + * + * @see #getExternalNoNamespaceSchemaLocation + */ + void setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation); + + /** + * This method is same as setExternalNoNamespaceSchemaLocation(const XMLCh* const). + * It takes native char string as parameter + * + * @param noNamespaceSchemaLocation the XML Schema Location with no target namespace + * + * @see #setExternalNoNamespaceSchemaLocation(const XMLCh* const) + */ + void setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation); + + //@} + + + // ----------------------------------------------------------------------- + // Parsing methods + // ----------------------------------------------------------------------- + + /** @name Parsing methods */ + //@{ + + /** Parse via an input source object + * + * This method invokes the parsing process on the XML file specified + * by the InputSource parameter. This API is borrowed from the + * SAX Parser interface. + * + * @param source A const reference to the InputSource object which + * points to the XML file to be parsed. + * @param reuseGrammar The flag indicating whether the existing Grammar + * should be reused or not for this parsing run. + * If true, there cannot be any internal subset. + * @exception SAXException Any SAX exception, possibly + * wrapping another exception. + * @exception XMLException An exception from the parser or client + * handler code. + * @exception DOMException A DOM exception as per DOM spec. + * @see InputSource#InputSource + */ + virtual void parse(const InputSource& source, const bool reuseGrammar = false); + + /** Parse via a file path or URL + * + * This method invokes the parsing process on the XML file specified by + * the Unicode string parameter 'systemId'. This method is borrowed + * from the SAX Parser interface. + * + * @param systemId A const XMLCh pointer to the Unicode string which + * contains the path to the XML file to be parsed. + * @param reuseGrammar The flag indicating whether the existing Grammar + * should be reused or not for this parsing run. + * If true, there cannot be any internal subset. + * + * @exception SAXException Any SAX exception, possibly + * wrapping another exception. + * @exception XMLException An exception from the parser or client + * handler code. + * @exception DOMException A DOM exception as per DOM spec. + * @see #parse(InputSource,...) + */ + virtual void parse(const XMLCh* const systemId, const bool reuseGrammar = false); + + /** Parse via a file path or URL (in the local code page) + * + * This method invokes the parsing process on the XML file specified by + * the native char* string parameter 'systemId'. + * + * @param systemId A const char pointer to a native string which + * contains the path to the XML file to be parsed. + * @param reuseGrammar The flag indicating whether the existing Grammar + * should be reused or not for this parsing run. + * If true, there cannot be any internal subset. + * + * @exception SAXException Any SAX exception, possibly + * wrapping another exception. + * @exception XMLException An exception from the parser or client + * handler code. + * @exception DOMException A DOM exception as per DOM spec. + * @see #parse(InputSource,...) + */ + virtual void parse(const char* const systemId, const bool reuseGrammar = false); + + /** Begin a progressive parse operation + * + * This method is used to start a progressive parse on a XML file. + * To continue parsing, subsequent calls must be to the parseNext + * method. + * + * It scans through the prolog and returns a token to be used on + * subsequent scanNext() calls. If the return value is true, then the + * token is legal and ready for further use. If it returns false, then + * the scan of the prolog failed and the token is not going to work on + * subsequent scanNext() calls. + * + * @param systemId A pointer to a Unicode string represting the path + * to the XML file to be parsed. + * @param toFill A token maintaing state information to maintain + * internal consistency between invocation of 'parseNext' + * calls. + * @param reuseGrammar The flag indicating whether the existing Grammar + * should be reused or not for this parsing process. + * If true, there cannot be any internal subset. + * @return 'true', if successful in parsing the prolog. It indicates the + * user can go ahead with parsing the rest of the file. It + * returns 'false' to indicate that the parser could not parse + * the prolog. + * + * @see #parseNext + * @see #parseFirst(char*,...) + * @see #parseFirst(InputSource&,...) + */ + bool parseFirst + ( + const XMLCh* const systemId + , XMLPScanToken& toFill + , const bool reuseGrammar = false + ); + + /** Begin a progressive parse operation + * + * This method is used to start a progressive parse on a XML file. + * To continue parsing, subsequent calls must be to the parseNext + * method. + * + * It scans through the prolog and returns a token to be used on + * subsequent scanNext() calls. If the return value is true, then the + * token is legal and ready for further use. If it returns false, then + * the scan of the prolog failed and the token is not going to work on + * subsequent scanNext() calls. + * + * @param systemId A pointer to a regular native string represting + * the path to the XML file to be parsed. + * @param toFill A token maintaing state information to maintain + * internal consistency between invocation of 'parseNext' + * calls. + * @param reuseGrammar The flag indicating whether the existing Grammar + * should be reused or not for this parsing run. + * If true, there cannot be any internal subset. + * + * @return 'true', if successful in parsing the prolog. It indicates the + * user can go ahead with parsing the rest of the file. It + * returns 'false' to indicate that the parser could not parse + * the prolog. + * + * @see #parseNext + * @see #parseFirst(XMLCh*,...) + * @see #parseFirst(InputSource&,...) + */ + bool parseFirst + ( + const char* const systemId + , XMLPScanToken& toFill + , const bool reuseGrammar = false + ); + + /** Begin a progressive parse operation + * + * This method is used to start a progressive parse on a XML file. + * To continue parsing, subsequent calls must be to the parseNext + * method. + * + * It scans through the prolog and returns a token to be used on + * subsequent scanNext() calls. If the return value is true, then the + * token is legal and ready for further use. If it returns false, then + * the scan of the prolog failed and the token is not going to work on + * subsequent scanNext() calls. + * + * @param source A const reference to the InputSource object which + * points to the XML file to be parsed. + * @param toFill A token maintaing state information to maintain + * internal consistency between invocation of 'parseNext' + * calls. + * @param reuseGrammar The flag indicating whether the existing Grammar + * should be reused or not for this parsing process. + * If true, there cannot be any internal subset. + * + * @return 'true', if successful in parsing the prolog. It indicates the + * user can go ahead with parsing the rest of the file. It + * returns 'false' to indicate that the parser could not parse + * the prolog. + * + * @see #parseNext + * @see #parseFirst(XMLCh*,...) + * @see #parseFirst(char*,...) + */ + bool parseFirst + ( + const InputSource& source + , XMLPScanToken& toFill + , const bool reuseGrammar = false + ); + + /** Continue a progressive parse operation + * + * This method is used to continue with progressive parsing of + * XML files started by a call to 'parseFirst' method. + * + * It parses the XML file and stops as soon as it comes across + * a XML token (as defined in the XML specification). + * + * @param token A token maintaing state information to maintain + * internal consistency between invocation of 'parseNext' + * calls. + * + * @return 'true', if successful in parsing the next XML token. + * It indicates the user can go ahead with parsing the rest + * of the file. It returns 'false' to indicate that the parser + * could not find next token as per the XML specification + * production rule. + * + * @see #parseFirst(XMLCh*,...) + * @see #parseFirst(char*,...) + * @see #parseFirst(InputSource&,...) + */ + bool parseNext(XMLPScanToken& token); + + /** Reset the parser after a progressive parse + * + * If a progressive parse loop exits before the end of the document + * is reached, the parser has no way of knowing this. So it will leave + * open any files or sockets or memory buffers that were in use at + * the time that the parse loop exited. + * + * The next parse operation will cause these open files and such to + * be closed, but the next parse operation might occur at some unknown + * future point. To avoid this problem, you should reset the parser if + * you exit the loop early. + * + * If you exited because of an error, then this cleanup will be done + * for you. Its only when you exit the file prematurely of your own + * accord, because you've found what you wanted in the file most + * likely. + * + * @param token A token maintaing state information to maintain + * internal consistency between invocation of 'parseNext' + * calls. + * + * @see #parseFirst(XMLCh*,...) + * @see #parseFirst(char*,...) + * @see #parseFirst(InputSource&,...) + */ + void parseReset(XMLPScanToken& token); + + //@} + + // ----------------------------------------------------------------------- + // Implementation of the XMLDocumentHandler interface. + // ----------------------------------------------------------------------- + + /** @name Implementation of the XMLDocumentHandler interface. */ + //@{ + + /** Handle document character events + * + * This method is used to report all the characters scanned by the + * parser. This DOM implementation stores this data in the appropriate + * DOM node, creating one if necessary. + * + * @param chars A const pointer to a Unicode string representing the + * character data. + * @param length The length of the Unicode string returned in 'chars'. + * @param cdataSection A flag indicating if the characters represent + * content from the CDATA section. + */ + virtual void docCharacters + ( + const XMLCh* const chars + , const unsigned int length + , const bool cdataSection + ); + + /** Handle a document comment event + * + * This method is used to report any comments scanned by the parser. + * A new comment node is created which stores this data. + * + * @param comment A const pointer to a null terminated Unicode + * string representing the comment text. + */ + virtual void docComment + ( + const XMLCh* const comment + ); + + /** Handle a document PI event + * + * This method is used to report any PI scanned by the parser. A new + * PI node is created and appended as a child of the current node in + * the tree. + * + * @param target A const pointer to a Unicode string representing the + * target of the PI declaration. + * @param data A const pointer to a Unicode string representing the + * data of the PI declaration. See the PI production rule + * in the XML specification for details. + */ + virtual void docPI + ( + const XMLCh* const target + , const XMLCh* const data + ); + + /** Handle the end of document event + * + * This method is used to indicate the end of the current document. + */ + virtual void endDocument(); + + /** Handle and end of element event + * + * This method is used to indicate the end tag of an element. The + * DOM parser pops the current element off the top of the element + * stack, and make it the new current element. + * + * @param elemDecl A const reference to the object containing element + * declaration information. + * @param urlId An id referring to the namespace prefix, if + * namespaces setting is switched on. + * @param isRoot A flag indicating whether this element was the + * root element. + */ + virtual void endElement + ( + const XMLElementDecl& elemDecl + , const unsigned int urlId + , const bool isRoot + ); + + /** Handle and end of entity reference event + * + * This method is used to indicate that an end of an entity reference + * was just scanned. + * + * @param entDecl A const reference to the object containing the + * entity declaration information. + */ + virtual void endEntityReference + ( + const XMLEntityDecl& entDecl + ); + + /** Handle an ignorable whitespace vent + * + * This method is used to report all the whitespace characters, which + * are determined to be 'ignorable'. This distinction between characters + * is only made, if validation is enabled. + * + * Any whitespace before content is ignored. If the current node is + * already of type DOMNode::TEXT_NODE, then these whitespaces are + * appended, otherwise a new Text node is created which stores this + * data. Essentially all contiguous ignorable characters are collected + * in one node. + * + * @param chars A const pointer to a Unicode string representing the + * ignorable whitespace character data. + * @param length The length of the Unicode string 'chars'. + * @param cdataSection A flag indicating if the characters represent + * content from the CDATA section. + */ + virtual void ignorableWhitespace + ( + const XMLCh* const chars + , const unsigned int length + , const bool cdataSection + ); + + /** Handle a document reset event + * + * This method allows the user installed Document Handler to 'reset' + * itself, freeing all the memory resources. The scanner calls this + * method before starting a new parse event. + */ + virtual void resetDocument(); + + /** Handle a start document event + * + * This method is used to report the start of the parsing process. + */ + virtual void startDocument(); + + /** Handle a start element event + * + * This method is used to report the start of an element. It is + * called at the end of the element, by which time all attributes + * specified are also parsed. A new DOM Element node is created + * along with as many attribute nodes as required. This new element + * is added appended as a child of the current node in the tree, and + * then replaces it as the current node (if the isEmpty flag is false.) + * + * @param elemDecl A const reference to the object containing element + * declaration information. + * @param urlId An id referring to the namespace prefix, if + * namespaces setting is switched on. + * @param elemPrefix A const pointer to a Unicode string containing + * the namespace prefix for this element. Applicable + * only when namespace processing is enabled. + * @param attrList A const reference to the object containing the + * list of attributes just scanned for this element. + * @param attrCount A count of number of attributes in the list + * specified by the parameter 'attrList'. + * @param isEmpty A flag indicating whether this is an empty element + * or not. If empty, then no endElement() call will + * be made. + * @param isRoot A flag indicating whether this element was the + * root element. + * @see DocumentHandler#startElement + */ + virtual void startElement + ( + const XMLElementDecl& elemDecl + , const unsigned int urlId + , const XMLCh* const elemPrefix + , const RefVectorOf<XMLAttr>& attrList + , const unsigned int attrCount + , const bool isEmpty + , const bool isRoot + ); + + /** Handle a start entity reference event + * + * This method is used to indicate the start of an entity reference. + * If the expand entity reference flag is true, then a new + * DOM Entity reference node is created. + * + * @param entDecl A const reference to the object containing the + * entity declaration information. + */ + virtual void startEntityReference + ( + const XMLEntityDecl& entDecl + ); + + /** Handle an XMLDecl event + * + * This method is used to report the XML decl scanned by the parser. + * Refer to the XML specification to see the meaning of parameters. + * + * <b><font color="#FF0000">This method is a no-op for this DOM + * implementation.</font></b> + * + * @param versionStr A const pointer to a Unicode string representing + * version string value. + * @param encodingStr A const pointer to a Unicode string representing + * the encoding string value. + * @param standaloneStr A const pointer to a Unicode string + * representing the standalone string value. + * @param actualEncStr A const pointer to a Unicode string + * representing the actual encoding string + * value. + */ + virtual void XMLDecl + ( + const XMLCh* const versionStr + , const XMLCh* const encodingStr + , const XMLCh* const standaloneStr + , const XMLCh* const actualEncStr + ); + //@} + + + /** @name Deprecated Methods */ + //@{ + /** + * This method returns the state of the parser's validation + * handling flag which controls whether validation checks + * are enforced or not. + * + * @return true, if the parser is currently configured to + * do validation, false otherwise. + * + * @see #setDoValidation + */ + bool getDoValidation() const; + + /** + * This method allows users to enable or disable the parser's validation + * checks. + * + * <p>By default, the parser does not to any validation. The default + * value is false.</p> + * + * @param newState The value specifying whether the parser should + * do validity checks or not against the DTD in the + * input XML document. + * + * @see #getDoValidation + */ + void setDoValidation(const bool newState); + + /** + * Deprecated doctypehandler interfaces + */ + virtual void attDef + ( + const DTDElementDecl& elemDecl + , const DTDAttDef& attDef + , const bool ignoring + ); + + virtual void doctypeComment + ( + const XMLCh* const comment + ); + + virtual void doctypeDecl + ( + const DTDElementDecl& elemDecl + , const XMLCh* const publicId + , const XMLCh* const systemId + , const bool hasIntSubset + ); + + virtual void doctypePI + ( + const XMLCh* const target + , const XMLCh* const data + ); + + virtual void doctypeWhitespace + ( + const XMLCh* const chars + , const unsigned int length + ); + + virtual void elementDecl + ( + const DTDElementDecl& decl + , const bool isIgnored + ); + + virtual void endAttList + ( + const DTDElementDecl& elemDecl + ); + + virtual void endIntSubset(); + + virtual void endExtSubset(); + + virtual void entityDecl + ( + const DTDEntityDecl& entityDecl + , const bool isPEDecl + , const bool isIgnored + ); + + virtual void resetDocType(); + + virtual void notationDecl + ( + const XMLNotationDecl& notDecl + , const bool isIgnored + ); + + virtual void startAttList + ( + const DTDElementDecl& elemDecl + ); + + virtual void startIntSubset(); + + virtual void startExtSubset(); + + virtual void TextDecl + ( + const XMLCh* const versionStr + , const XMLCh* const encodingStr + ); + + + //@} + + +protected : + // ----------------------------------------------------------------------- + // Protected getter methods + // ----------------------------------------------------------------------- + + /** @name Constructors */ + //@{ + /** Construct a AbstractDOMParser, with an optional validator + * + * Constructor with an instance of validator class to use for + * validation. If you don't provide a validator, a default one will + * be created for you in the scanner. + * + * @param valToAdopt Pointer to the validator instance to use. The + * parser is responsible for freeing the memory. + */ + AbstractDOMParser(XMLValidator* const valToAdopt = 0); + + //@} + + /** @name Protected getter methods */ + //@{ + /** Get the current DOM node + * + * This provides derived classes with access to the current node, i.e. + * the node to which new nodes are being added. + */ + DOMNode* getCurrentNode(); + + /** Get the XML scanner + * + * This provides derived classes with access to the XML scanner. + */ + XMLScanner* getScanner() const; + + /** Get the parse in progress flag + * + * This provides derived classes with access to the parse in progress + * flag. + */ + bool getParseInProgress() const; + + //@} + + + // ----------------------------------------------------------------------- + // Protected setter methods + // ----------------------------------------------------------------------- + + /** @name Protected setter methods */ + //@{ + + /** Set the current DOM node + * + * This method sets the current node maintained inside the parser to + * the one specified. + * + * @param toSet The DOM node which will be the current node. + */ + void setCurrentNode(DOMNode* toSet); + + /** Set the document node + * + * This method sets the DOM Document node to the one specified. + * + * @param toSet The new DOM Document node for this XML document. + */ + void setDocument(DOMDocument* toSet); + //@} + + // ----------------------------------------------------------------------- + // Protected Helper methods + // ----------------------------------------------------------------------- + virtual DOMElement* createElementNSNode(const XMLCh *fNamespaceURI, + const XMLCh *qualifiedName); + + +private : + // ----------------------------------------------------------------------- + // Private data members + // + // fCurrentNode + // fCurrentParent + // Used to track the current node during nested element events. Since + // the tree must be built from a set of disjoint callbacks, we need + // these to keep up with where we currently are. + // + // fDocument + // The root document object, filled with the document contents. + // + // fCreateEntityReferenceNode + // Indicates whether entity reference nodes should be created. + // + // fIncludeIgnorableWhitespace + // Indicates whether ignorable whiltespace should be added to + // the DOM tree for validating parsers. + // + // fScanner + // The scanner used for this parser. This is created during the + // constructor. + // + // fNodeStack + // Used to track previous parent nodes during nested element events. + // + // fParseInProgress + // Used to prevent multiple entrance to the parser while its doing + // a parse. + // + // fWithinElement + // A flag to indicate that the parser is within at least one level + // of element processing. + // + // fDocumentType + // Used to store and update the documentType variable information + // in fDocument + // + // fDocumentVector + // Store all the previous fDocument(s) (thus not the current fDocument) + // created in this parser. It is destroyed when the parser is destructed. + // ----------------------------------------------------------------------- + bool fCreateEntityReferenceNodes; + bool fIncludeIgnorableWhitespace; + bool fWithinElement; + bool fParseInProgress; + XMLScanner* fScanner; + DOMNode* fCurrentParent; + DOMNode* fCurrentNode; + DOMDocumentImpl* fDocument; + ValueStackOf<DOMNode*>* fNodeStack; + DOMDocumentTypeImpl* fDocumentType; + RefVectorOf<DOMDocumentImpl>* fDocumentVector; +}; + + + +// --------------------------------------------------------------------------- +// AbstractDOMParser: Getter methods +// --------------------------------------------------------------------------- +inline bool AbstractDOMParser::getExpandEntityReferences() const +{ + return !fCreateEntityReferenceNodes; +} +inline bool AbstractDOMParser::getCreateEntityReferenceNodes() const +{ + return fCreateEntityReferenceNodes; +} + +inline bool AbstractDOMParser::getIncludeIgnorableWhitespace() const +{ + return fIncludeIgnorableWhitespace; +} + +inline bool AbstractDOMParser::getParseInProgress() const +{ + return fParseInProgress; +} + +inline XMLScanner* AbstractDOMParser::getScanner() const +{ + return fScanner; +} + +// --------------------------------------------------------------------------- +// AbstractDOMParser: Setter methods +// --------------------------------------------------------------------------- +inline void AbstractDOMParser::setExpandEntityReferences(const bool expand) +{ + fCreateEntityReferenceNodes = !expand; +} + +inline void AbstractDOMParser::setCreateEntityReferenceNodes(const bool create) +{ + fCreateEntityReferenceNodes = create; +} + +inline void AbstractDOMParser::setIncludeIgnorableWhitespace(const bool include) +{ + fIncludeIgnorableWhitespace = include; +} + + +// --------------------------------------------------------------------------- +// AbstractDOMParser: Protected getter methods +// --------------------------------------------------------------------------- +inline DOMNode* AbstractDOMParser::getCurrentNode() +{ + return fCurrentNode; +} + + +// --------------------------------------------------------------------------- +// AbstractDOMParser: Protected setter methods +// --------------------------------------------------------------------------- +inline void AbstractDOMParser::setCurrentNode(DOMNode* toSet) +{ + fCurrentNode = toSet; +} + +inline void AbstractDOMParser::setDocument(DOMDocument* toSet) +{ + fDocument = (DOMDocumentImpl *)toSet; +} + +#endif + + + diff --git a/src/xercesc/parsers/Makefile.in b/src/xercesc/parsers/Makefile.in index d8ceb0de9836eb2db4bf402707c9b75a2c115442..2db370d70bbc884f79917894f0edd4abfb294002 100644 --- a/src/xercesc/parsers/Makefile.in +++ b/src/xercesc/parsers/Makefile.in @@ -77,6 +77,7 @@ include ../Makefile.incl MODULE = parsers PARSERS_CPP_PUBHEADERS = \ + AbstractDOMParser.hpp \ XercesDOMParser.hpp \ SAXParser.hpp \ SAX2XMLReaderImpl.hpp @@ -86,6 +87,7 @@ PARSERS_CPP_PRIVHEADERS = PARSERS_C_FILES = PARSERS_CPP_OBJECTS = \ + AbstractDOMParser.$(TO) \ XercesDOMParser.$(TO) \ SAXParser.$(TO) \ SAX2XMLReaderImpl.$(TO) diff --git a/src/xercesc/parsers/SAX2XMLReaderImpl.cpp b/src/xercesc/parsers/SAX2XMLReaderImpl.cpp index 15c6c8e04acc13f16416fe1ed0f32ef516d0f913..6f56de32790715ade157b4031ca21d6fb73afcf5 100644 --- a/src/xercesc/parsers/SAX2XMLReaderImpl.cpp +++ b/src/xercesc/parsers/SAX2XMLReaderImpl.cpp @@ -56,6 +56,13 @@ /* * $Log$ + * Revision 1.3 2002/05/22 20:53:41 knoaman + * Prepare for DOM L3 : + * - Make use of the XMLEntityHandler/XMLErrorReporter interfaces, instead of using + * EntityHandler/ErrorHandler directly. + * - Add 'AbstractDOMParser' class to provide common functionality for XercesDOMParser + * and DOMBuilder. + * * Revision 1.2 2002/02/13 16:09:24 knoaman * Move SAX2 features/properties names constants to XMLUni. * @@ -444,11 +451,9 @@ void SAX2XMLReaderImpl::setEntityResolver(EntityResolver* const resolver) fEntityResolver = resolver; if (fEntityResolver) { fScanner->setEntityHandler(this); - fScanner->setEntityResolver(fEntityResolver); } else { fScanner->setEntityHandler(0); - fScanner->setEntityResolver(0); } } diff --git a/src/xercesc/parsers/SAXParser.cpp b/src/xercesc/parsers/SAXParser.cpp index 98232cca99b27b53eb54ff2a864922ad84f6e967..106f2a80ed5ea490f6c5be73a16caa701c10a8d9 100644 --- a/src/xercesc/parsers/SAXParser.cpp +++ b/src/xercesc/parsers/SAXParser.cpp @@ -56,8 +56,15 @@ /* * $Log$ - * Revision 1.1 2002/02/01 22:22:07 peiyongz - * Initial revision + * Revision 1.2 2002/05/22 20:53:41 knoaman + * Prepare for DOM L3 : + * - Make use of the XMLEntityHandler/XMLErrorReporter interfaces, instead of using + * EntityHandler/ErrorHandler directly. + * - Add 'AbstractDOMParser' class to provide common functionality for XercesDOMParser + * and DOMBuilder. + * + * Revision 1.1.1.1 2002/02/01 22:22:07 peiyongz + * sane_include * * Revision 1.23 2001/11/20 18:51:44 tng * Schema: schemaLocation and noNamespaceSchemaLocation to be specified outside the instance document. New methods setExternalSchemaLocation and setExternalNoNamespaceSchemaLocation are added (for SAX2, two new properties are added). @@ -532,11 +539,9 @@ void SAXParser::setEntityResolver(EntityResolver* const resolver) fEntityResolver = resolver; if (fEntityResolver) { fScanner->setEntityHandler(this); - fScanner->setEntityResolver(fEntityResolver); } else { fScanner->setEntityHandler(0); - fScanner->setEntityResolver(0); } } diff --git a/src/xercesc/parsers/XercesDOMParser.cpp b/src/xercesc/parsers/XercesDOMParser.cpp index a584ad28f2e11e46ba6096557885357a8f1a1e67..eedc6aca9ff50ba3d183fc7112daf91c337f8eb9 100644 --- a/src/xercesc/parsers/XercesDOMParser.cpp +++ b/src/xercesc/parsers/XercesDOMParser.cpp @@ -69,181 +69,43 @@ // Includes // --------------------------------------------------------------------------- #include <xercesc/sax/EntityResolver.hpp> -#include <xercesc/util/XMLUniDefs.hpp> #include <xercesc/sax/ErrorHandler.hpp> #include <xercesc/sax/SAXParseException.hpp> -#include <xercesc/framework/XMLNotationDecl.hpp> -#include <xercesc/util/IOException.hpp> #include <xercesc/internal/XMLScanner.hpp> -#include <xercesc/validators/DTD/DTDValidator.hpp> #include <xercesc/parsers/XercesDOMParser.hpp> -#include <xercesc/dom/DOMImplementation.hpp> -#include <xercesc/dom/DOMElement.hpp> -#include <xercesc/dom/impl/DOMAttrImpl.hpp> -#include <xercesc/dom/DOMCDATASection.hpp> -#include <xercesc/dom/DOMComment.hpp> -#include <xercesc/dom/impl/DOMTextImpl.hpp> -#include <xercesc/dom/impl/DOMDocumentImpl.hpp> -#include <xercesc/dom/impl/DOMDocumentTypeImpl.hpp> -#include <xercesc/dom/DOMDocumentType.hpp> -#include <xercesc/dom/impl/DOMElementImpl.hpp> -#include <xercesc/dom/impl/DOMEntityImpl.hpp> -#include <xercesc/dom/impl/DOMEntityReferenceImpl.hpp> -#include <xercesc/dom/impl/DOMNotationImpl.hpp> -#include <xercesc/dom/DOMNamedNodeMap.hpp> -#include <xercesc/dom/DOMProcessingInstruction.hpp> -#include <xercesc/dom/impl/DOMNodeIDMap.hpp> -#include <xercesc/validators/common/ContentSpecNode.hpp> -#include <xercesc/validators/DTD/DTDAttDefList.hpp> - // --------------------------------------------------------------------------- // XercesDOMParser: Constructors and Destructor // --------------------------------------------------------------------------- XercesDOMParser::XercesDOMParser(XMLValidator* const valToAdopt) : -fErrorHandler(0) +AbstractDOMParser(valToAdopt) +, fErrorHandler(0) , fEntityResolver(0) -, fCreateEntityReferenceNodes(true) -, fIncludeIgnorableWhitespace(true) -, fNodeStack(0) -, fScanner(0) -, fDocument(0) -, fDocumentVector(0) { - // - // Create a scanner and tell it what validator to use. Then set us - // as the document event handler so we can fill the DOM document. - // - fScanner = new XMLScanner(valToAdopt); - fScanner->setDocHandler(this); - fScanner->setDocTypeHandler(this); - - fNodeStack = new ValueStackOf<DOMNode*>(64); - this->reset(); - - } XercesDOMParser::~XercesDOMParser() { - if (fDocumentVector) - delete fDocumentVector; - - delete fDocument; - delete fNodeStack; - delete fScanner; } -void XercesDOMParser::reset() -{ - // if fDocument exists already, store the old pointer in the vector for deletion later - if (fDocument) { - if (!fDocumentVector) { - // allocate the vector if not exists yet - fDocumentVector = new RefVectorOf<DOMDocumentImpl>(10, true) ; - } - fDocumentVector->addElement(fDocument); - } - - fDocument = 0; - resetDocType(); - - fCurrentParent = 0; - fCurrentNode = 0; - fParseInProgress = false; - fWithinElement = false; - fNodeStack->removeAllElements(); -}; - - - -// --------------------------------------------------------------------------- -// XercesDOMParser: Getter methods -// --------------------------------------------------------------------------- -DOMDocument* XercesDOMParser::getDocument() -{ - return fDocument; -} - -const XMLValidator& XercesDOMParser::getValidator() const -{ - return *fScanner->getValidator(); -} - -bool XercesDOMParser::getDoNamespaces() const -{ - return fScanner->getDoNamespaces(); -} - -bool XercesDOMParser::getExitOnFirstFatalError() const -{ - return fScanner->getExitOnFirstFatal(); -} - -bool XercesDOMParser::getValidationConstraintFatal() const -{ - return fScanner->getValidationConstraintFatal(); -} - -XercesDOMParser::ValSchemes XercesDOMParser::getValidationScheme() const -{ - const XMLScanner::ValSchemes scheme = fScanner->getValidationScheme(); - - if (scheme == XMLScanner::Val_Always) - return Val_Always; - else if (scheme == XMLScanner::Val_Never) - return Val_Never; - - return Val_Auto; -} - -bool XercesDOMParser::getDoSchema() const -{ - return fScanner->getDoSchema(); -} - -bool XercesDOMParser::getValidationSchemaFullChecking() const -{ - return fScanner->getValidationSchemaFullChecking(); -} - -int XercesDOMParser::getErrorCount() const -{ - return fScanner->getErrorCount(); -} - -XMLCh* XercesDOMParser::getExternalSchemaLocation() const -{ - return fScanner->getExternalSchemaLocation(); -} - -XMLCh* XercesDOMParser::getExternalNoNamespaceSchemaLocation() const -{ - return fScanner->getExternalNoNamespaceSchemaLocation(); -} - // --------------------------------------------------------------------------- // XercesDOMParser: Setter methods // --------------------------------------------------------------------------- -void XercesDOMParser::setDoNamespaces(const bool newState) -{ - fScanner->setDoNamespaces(newState); -} - void XercesDOMParser::setErrorHandler(ErrorHandler* const handler) { fErrorHandler = handler; + XMLScanner* scanner = getScanner(); if (fErrorHandler) { - fScanner->setErrorReporter(this); - fScanner->setErrorHandler(fErrorHandler); + scanner->setErrorReporter(this); + scanner->setErrorHandler(fErrorHandler); } else { - fScanner->setErrorReporter(0); - fScanner->setErrorHandler(0); + scanner->setErrorReporter(0); + scanner->setErrorHandler(0); } } @@ -251,214 +113,25 @@ void XercesDOMParser::setEntityResolver(EntityResolver* const handler) { fEntityResolver = handler; if (fEntityResolver) { - fScanner->setEntityHandler(this); - fScanner->setEntityResolver(fEntityResolver); + getScanner()->setEntityHandler(this); } else { - fScanner->setEntityHandler(0); - fScanner->setEntityResolver(0); - } -} - -void XercesDOMParser::setExitOnFirstFatalError(const bool newState) -{ - fScanner->setExitOnFirstFatal(newState); -} - -void XercesDOMParser::setValidationConstraintFatal(const bool newState) -{ - fScanner->setValidationConstraintFatal(newState); -} - -void XercesDOMParser::setValidationScheme(const ValSchemes newScheme) -{ - if (newScheme == Val_Never) - fScanner->setValidationScheme(XMLScanner::Val_Never); - else if (newScheme == Val_Always) - fScanner->setValidationScheme(XMLScanner::Val_Always); - else - fScanner->setValidationScheme(XMLScanner::Val_Auto); -} - -void XercesDOMParser::setDoSchema(const bool newState) -{ - fScanner->setDoSchema(newState); -} - -void XercesDOMParser::setValidationSchemaFullChecking(const bool schemaFullChecking) -{ - fScanner->setValidationSchemaFullChecking(schemaFullChecking); -} - -void XercesDOMParser::setExternalSchemaLocation(const XMLCh* const schemaLocation) -{ - fScanner->setExternalSchemaLocation(schemaLocation); -} -void XercesDOMParser::setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation) -{ - fScanner->setExternalNoNamespaceSchemaLocation(noNamespaceSchemaLocation); -} - -void XercesDOMParser::setExternalSchemaLocation(const char* const schemaLocation) -{ - fScanner->setExternalSchemaLocation(schemaLocation); -} -void XercesDOMParser::setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation) -{ - fScanner->setExternalNoNamespaceSchemaLocation(noNamespaceSchemaLocation); -} - - -// --------------------------------------------------------------------------- -// XercesDOMParser: Parsing methods -// --------------------------------------------------------------------------- -void XercesDOMParser::parse(const InputSource& source, const bool reuseGrammar) -{ - // Avoid multiple entrance - if (fParseInProgress) - ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress); - - try - { - fParseInProgress = true; - fScanner->scanDocument(source, reuseGrammar); - fParseInProgress = false; - } - - catch(...) - { - fParseInProgress = false; - throw; - } -} - -void XercesDOMParser::parse(const XMLCh* const systemId, const bool reuseGrammar) -{ - // Avoid multiple entrance - if (fParseInProgress) - ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress); - - try - { - fParseInProgress = true; - fScanner->scanDocument(systemId, reuseGrammar); - fParseInProgress = false; - } - - catch(...) - { - fParseInProgress = false; - throw; + getScanner()->setEntityHandler(0); } } -void XercesDOMParser::parse(const char* const systemId, const bool reuseGrammar) -{ - // Avoid multiple entrance - if (fParseInProgress) - ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress); - - try - { - fParseInProgress = true; - fScanner->scanDocument(systemId, reuseGrammar); - fParseInProgress = false; - } - - catch(...) - { - fParseInProgress = false; - throw; - } -} - - - -// --------------------------------------------------------------------------- -// XercesDOMParser: Progressive parse methods -// --------------------------------------------------------------------------- -bool XercesDOMParser::parseFirst( const XMLCh* const systemId - , XMLPScanToken& toFill - , const bool reuseGrammar) -{ - // - // Avoid multiple entrance. We cannot enter here while a regular parse - // is in progress. - // - if (fParseInProgress) - ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress); - - return fScanner->scanFirst(systemId, toFill, reuseGrammar); -} - -bool XercesDOMParser::parseFirst( const char* const systemId - , XMLPScanToken& toFill - , const bool reuseGrammar) -{ - // - // Avoid multiple entrance. We cannot enter here while a regular parse - // is in progress. - // - if (fParseInProgress) - ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress); - - return fScanner->scanFirst(systemId, toFill, reuseGrammar); -} - -bool XercesDOMParser::parseFirst( const InputSource& source - , XMLPScanToken& toFill - , const bool reuseGrammar) -{ - // - // Avoid multiple entrance. We cannot enter here while a regular parse - // is in progress. - // - if (fParseInProgress) - ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress); - - return fScanner->scanFirst(source, toFill, reuseGrammar); -} - -bool XercesDOMParser::parseNext(XMLPScanToken& token) -{ - return fScanner->scanNext(token); -} - -void XercesDOMParser::parseReset(XMLPScanToken& token) -{ - // Reset the scanner, and then reset the parser - fScanner->scanReset(token); - reset(); -} - -// --------------------------------------------------------------------------- -// XercesDOMParser: Utilities -// --------------------------------------------------------------------------- -void XercesDOMParser::resetDocumentPool() -{ - // We cannot enter here while a regular parse is in progress. - if (fParseInProgress) - ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress); - - if (fDocumentVector) - fDocumentVector->removeAllElements(); - - delete fDocument; - fDocument = 0; -} - // --------------------------------------------------------------------------- // XercesDOMParser: Implementation of the XMLErrorReporter interface // --------------------------------------------------------------------------- -void XercesDOMParser::error( const unsigned int code - , const XMLCh* const msgDomain - , const XMLErrorReporter::ErrTypes errType - , const XMLCh* const errorText - , const XMLCh* const systemId - , const XMLCh* const publicId - , const unsigned int lineNum - , const unsigned int colNum) +void XercesDOMParser::error( const unsigned int code + , const XMLCh* const msgDomain + , const XMLErrorReporter::ErrTypes errType + , const XMLCh* const errorText + , const XMLCh* const systemId + , const XMLCh* const publicId + , const unsigned int lineNum + , const unsigned int colNum) { SAXParseException toThrow = SAXParseException ( @@ -508,746 +181,3 @@ XercesDOMParser::resolveEntity(const XMLCh* const publicId, const XMLCh* const s return 0; } - - -// --------------------------------------------------------------------------- -// XercesDOMParser: Implementation of XMLDocumentHandler interface -// --------------------------------------------------------------------------- -void XercesDOMParser::docCharacters( const XMLCh* const chars - , const unsigned int length - , const bool cdataSection) -{ - // Ignore chars outside of content - if (!fWithinElement) - return; - - // revisit. Is it really safe to null-terminate here? - // Does the scanner do it already? - // If scanner goes up to the very end of an unterminated - // buffer, we may be stepping on something bad here. - // Probably best to modify the scanner to null terminate. - XMLCh savedChar = chars[length]; - XMLCh *ncChars = (XMLCh *)chars; // cast off const - ncChars[length] = 0; - if (cdataSection == true) - { - DOMCDATASection *node = fDocument->createCDATASection(chars); - fCurrentParent->appendChild(node); - fCurrentNode = node; - } - else - { - if (fCurrentNode->getNodeType() == DOMNode::TEXT_NODE) - { - DOMText *node = (DOMText *)fCurrentNode; - node->appendData(chars); - } - else - { - DOMText *node = fDocument->createTextNode(chars); - fCurrentParent->appendChild(node); - fCurrentNode = node; - } - } - ncChars[length] = savedChar; - return; -} - - -void XercesDOMParser::docComment(const XMLCh* const comment) -{ - DOMComment *dcom = fDocument->createComment(comment); - fCurrentParent->appendChild(dcom); - fCurrentNode = dcom; -} - - -void XercesDOMParser::docPI( const XMLCh* const target - , const XMLCh* const data) -{ - DOMProcessingInstruction *pi = fDocument->createProcessingInstruction - ( - target - , data - ); - fCurrentParent->appendChild(pi); - fCurrentNode = pi; -} - - -void XercesDOMParser::endEntityReference(const XMLEntityDecl& entDecl) -{ - if (fCreateEntityReferenceNodes == true) - { - if (fCurrentParent->getNodeType() == DOMNode::ENTITY_REFERENCE_NODE) { - DOMEntityReferenceImpl *erImpl = (DOMEntityReferenceImpl *) fCurrentParent; - erImpl->setReadOnly(true, true); - } - fCurrentParent = fNodeStack->pop(); - fCurrentNode = fCurrentParent; - } -} - - -void XercesDOMParser::endElement( const XMLElementDecl& elemDecl - , const unsigned int urlId - , const bool isRoot) -{ - fCurrentNode = fCurrentParent; - fCurrentParent = fNodeStack->pop(); - - // If we've hit the end of content, clear the flag - if (fNodeStack->empty()) - fWithinElement = false; -} - - -void XercesDOMParser::ignorableWhitespace(const XMLCh* const chars - , const unsigned int length - , const bool cdataSection) -{ - // Ignore chars before the root element - if (!fWithinElement || !fIncludeIgnorableWhitespace) - return; - - // revisit. Not safe to slam in a null like this. - XMLCh savedChar = chars[length]; - XMLCh *ncChars = (XMLCh *)chars; // cast off const - ncChars[length] = chNull; - - if (fCurrentNode->getNodeType() == DOMNode::TEXT_NODE) - { - DOMText *node = (DOMText *)fCurrentNode; - node->appendData(chars); - } - else - { - DOMTextImpl *node = (DOMTextImpl *)fDocument->createTextNode(chars); - node->setIgnorableWhitespace(true); - fCurrentParent->appendChild(node); - - fCurrentNode = node; - } - ncChars[length] = savedChar; -} - - -void XercesDOMParser::resetDocument() -{ - // - // The reset methods are called before a new parse event occurs. - // Reset this parsers state to clear out anything that may be left - // from a previous use, in particular the DOM document itself. - // - this->reset(); - fDocument = (DOMDocumentImpl *)DOMImplementation::getImplementation()->createDocument(); -} - - -void XercesDOMParser::startDocument() -{ - // Just set the document as the current parent and current node - fCurrentParent = fDocument; - fCurrentNode = fDocument; - // set DOM error checking off - fDocument->setErrorChecking(false); -} - - -void XercesDOMParser::endDocument() -{ - // set DOM error checking back on - fDocument->setErrorChecking(true); -} - - -void XercesDOMParser::startElement(const XMLElementDecl& elemDecl - , const unsigned int urlId - , const XMLCh* const elemPrefix - , const RefVectorOf<XMLAttr>& attrList - , const unsigned int attrCount - , const bool isEmpty - , const bool isRoot) -{ - DOMElement *elem; - - if (fScanner -> getDoNamespaces()) { //DOM Level 2, doNamespaces on - XMLBuffer buf; - XMLCh* namespaceURI = 0; - if (urlId != fScanner->getEmptyNamespaceId()) { //TagName has a prefix - fScanner->getURIText(urlId, buf); //get namespaceURI - namespaceURI = buf.getRawBuffer(); - } - elem = createElementNSNode(namespaceURI, elemDecl.getFullName()); - DOMElementImpl *elemImpl = (DOMElementImpl *) elem; - for (unsigned int index = 0; index < attrCount; ++index) { - static const XMLCh XMLNS[] = { - chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s, chNull - }; - const XMLAttr* oneAttrib = attrList.elementAt(index); - unsigned int attrURIId = oneAttrib -> getURIId(); - namespaceURI = 0; - if (!XMLString::compareString(oneAttrib -> getName(), XMLNS)) //for xmlns=... - attrURIId = fScanner->getXMLNSNamespaceId(); - if (attrURIId != fScanner->getEmptyNamespaceId()) { //TagName has a prefix - fScanner->getURIText(attrURIId, buf); //get namespaceURI - namespaceURI = buf.getRawBuffer(); - } - // revisit. Optimize to init the named node map to the - // right size up front. - DOMAttrImpl *attr = (DOMAttrImpl *) - fDocument->createAttributeNS(namespaceURI, oneAttrib->getQName()); - attr->setValue(oneAttrib -> getValue()); - elemImpl->setAttributeNode(attr); - - //DOMAttrImpl *attr = elemImpl->setAttributeNS(namespaceURI, oneAttrib -> getQName(), - // oneAttrib -> getValue()); - - // Attributes of type ID. If this is one, add it to the hashtable of IDs - // that is constructed for use by GetElementByID(). - // - if (oneAttrib->getType()==XMLAttDef::ID) - { - if (fDocument->fNodeIDMap == 0) - fDocument->fNodeIDMap = new (fDocument) DOMNodeIDMap(500, fDocument); - fDocument->fNodeIDMap->add(attr); - attr->fNode.isIdAttr(true); - } - - attr->setSpecified(oneAttrib->getSpecified()); - } - } - else { //DOM Level 1 - elem = fDocument->createElement(elemDecl.getFullName()); - DOMElementImpl *elemImpl = (DOMElementImpl *) elem; - for (unsigned int index = 0; index < attrCount; ++index) { - const XMLAttr* oneAttrib = attrList.elementAt(index); - //AttrImpl *attr = elemImpl->setAttribute(oneAttrib->getName(), oneAttrib->getValue()); - DOMAttrImpl *attr = (DOMAttrImpl *) - fDocument->createAttribute(oneAttrib->getName()); - attr->setValue(oneAttrib -> getValue()); - elemImpl->setAttributeNode(attr); - attr->setSpecified(oneAttrib->getSpecified()); - - // Attributes of type ID. If this is one, add it to the hashtable of IDs - // that is constructed for use by GetElementByID(). - // - if (oneAttrib->getType()==XMLAttDef::ID) - { - if (fDocument->fNodeIDMap == 0) - fDocument->fNodeIDMap = new (fDocument) DOMNodeIDMap(500, fDocument); - fDocument->fNodeIDMap->add(attr); - attr->fNode.isIdAttr(true); - } - } - } - - fCurrentParent->appendChild(elem); - - fNodeStack->push(fCurrentParent); - fCurrentParent = elem; - fCurrentNode = elem; - fWithinElement = true; - - // If an empty element, do end right now (no endElement() will be called) - if (isEmpty) - endElement(elemDecl, urlId, isRoot); -} - - -void XercesDOMParser::startEntityReference(const XMLEntityDecl& entDecl) -{ - if (fCreateEntityReferenceNodes == true) - { - const XMLCh * entName = entDecl.getName(); - DOMEntityReference *er = fDocument->createEntityReference(entName); - - //set the readOnly flag to false before appending node, will be reset in endEntityReference - DOMEntityReferenceImpl *erImpl = (DOMEntityReferenceImpl *) er; - erImpl->setReadOnly(false, true); - - fCurrentParent->appendChild(er); - fNodeStack->push(fCurrentParent); - fCurrentParent = er; - fCurrentNode = er; - - // this entityRef needs to be stored in Entity map too. - // We'd decide later whether the entity nodes should be created by a - // separated method in parser or not. For now just stick it in if - // the ref nodes are created - DOMNamedNodeMap *entities = fDocumentType->getEntities(); - DOMEntityImpl* entity = (DOMEntityImpl*)entities->getNamedItem(entName); - entity->setEntityRef(er); - - } -} - - -void XercesDOMParser::XMLDecl(const XMLCh* const version - , const XMLCh* const encoding - , const XMLCh* const standalone - , const XMLCh* const actualEncStr) -{ - // placehold for DOM Level 3 -} - -// --------------------------------------------------------------------------- -// XercesDOMParser: Helper methods -// --------------------------------------------------------------------------- -DOMElement* XercesDOMParser::createElementNSNode(const XMLCh *namespaceURI, - const XMLCh *qualifiedName) -{ - return fDocument->createElementNS(namespaceURI, qualifiedName); -} -// --------------------------------------------------------------------------- -// XercesDOMParser: Deprecated methods -// --------------------------------------------------------------------------- -bool XercesDOMParser::getDoValidation() const -{ - // - // We don't want to tie the public parser classes to the enum used - // by the scanner, so we use a separate one and map. - // - // DON'T mix the new and old methods!! - // - const XMLScanner::ValSchemes scheme = fScanner->getValidationScheme(); - if (scheme == XMLScanner::Val_Always) - return true; - return false; -} - -void XercesDOMParser::setDoValidation(const bool newState) -{ - fScanner->setDoValidation - ( - newState ? XMLScanner::Val_Always : XMLScanner::Val_Never - ); -} - -//doctypehandler interfaces -void XercesDOMParser::attDef -( - const DTDElementDecl& elemDecl - , const DTDAttDef& attDef - , const bool ignoring - ) -{ - if (fDocumentType->isIntSubsetReading()) - { - XMLBuffer attString; - if (elemDecl.hasAttDefs()) - { - attString.append(chOpenAngle); - attString.append(chBang); - attString.append(XMLUni::fgAttListString); - attString.append(chSpace); - attString.append(elemDecl.getFullName()); - - attString.append(chSpace); - attString.append(attDef.getFullName()); - - // Get the type and display it - const XMLAttDef::AttTypes type = attDef.getType(); - switch(type) - { - case XMLAttDef::CData : - attString.append(chSpace); - attString.append(XMLUni::fgCDATAString); - break; - case XMLAttDef::ID : - attString.append(chSpace); - attString.append(XMLUni::fgIDString); - break; - case XMLAttDef::IDRef : - attString.append(chSpace); - attString.append(XMLUni::fgIDRefString); - break; - case XMLAttDef::IDRefs : - attString.append(chSpace); - attString.append(XMLUni::fgIDRefsString); - break; - case XMLAttDef::Entity : - attString.append(chSpace); - attString.append(XMLUni::fgEntityString); - break; - case XMLAttDef::Entities : - attString.append(chSpace); - attString.append(XMLUni::fgEntitiesString); - break; - case XMLAttDef::NmToken : - attString.append(chSpace); - attString.append(XMLUni::fgNmTokenString); - break; - case XMLAttDef::NmTokens : - attString.append(chSpace); - attString.append(XMLUni::fgNmTokensString); - break; - - case XMLAttDef::Notation : - attString.append(chSpace); - attString.append(XMLUni::fgNotationString); - break; - - case XMLAttDef::Enumeration : - attString.append(chSpace); - const XMLCh* enumString = attDef.getEnumeration(); - int length = XMLString::stringLen(enumString); - if (length > 0) { - - XMLBuffer anotherEnumString; - - anotherEnumString.append(chOpenParen ); - for(int i=0; i<length; i++) { - if (enumString[i] == chSpace) - anotherEnumString.append(chPipe); - else - anotherEnumString.append(enumString[i]); - } - anotherEnumString.append(chCloseParen); - attString.append(anotherEnumString.getRawBuffer()); - } - break; - } - //get te default types of the attlist - const XMLAttDef::DefAttTypes def = attDef.getDefaultType(); - switch(def) - { - case XMLAttDef::Required : - attString.append(chSpace); - attString.append(XMLUni::fgRequiredString); - break; - case XMLAttDef::Implied : - attString.append(chSpace); - attString.append(XMLUni::fgImpliedString); - break; - case XMLAttDef::Fixed : - attString.append(chSpace); - attString.append(XMLUni::fgFixedString); - break; - } - - const XMLCh* defaultValue = attDef.getValue(); - if (defaultValue != 0) { - attString.append(chSpace); - attString.append(chDoubleQuote); - attString.append(defaultValue); - attString.append(chDoubleQuote); - } - - attString.append(chCloseAngle); - fDocumentType->setInternalSubset(attString.getRawBuffer()); - } - } -} - -void XercesDOMParser::doctypeComment -( - const XMLCh* const comment -) -{ - if (fDocumentType->isIntSubsetReading()) - { - if (comment != 0) - { - XMLBuffer comString; - comString.append(XMLUni::fgCommentString); - comString.append(chSpace); - comString.append(comment); - comString.append(chSpace); - comString.append(chDash); - comString.append(chDash); - comString.append(chCloseAngle); - fDocumentType->setInternalSubset(comString.getRawBuffer()); - } - } -} - -void XercesDOMParser::doctypeDecl -( - const DTDElementDecl& elemDecl - , const XMLCh* const publicId - , const XMLCh* const systemId - , const bool hasIntSubset -) -{ - fDocumentType = (DOMDocumentTypeImpl *) fDocument->createDocumentType(elemDecl.getFullName(), publicId, systemId); - fDocument->setDocumentType(fDocumentType); - -} - -void XercesDOMParser::doctypePI -( - const XMLCh* const target - , const XMLCh* const data -) -{ - if (fDocumentType->isIntSubsetReading()) - { - //add these chars to internalSubset variable - XMLBuffer pi; - pi.append(chOpenAngle); - pi.append(chQuestion); - pi.append(target); - pi.append(chSpace); - pi.append(data); - pi.append(chQuestion); - pi.append(chCloseAngle); - - fDocumentType->setInternalSubset(pi.getRawBuffer()); - } - -} - - -void XercesDOMParser::doctypeWhitespace -( - const XMLCh* const chars - , const unsigned int length -) -{ - if (fDocumentType->isIntSubsetReading()) - fDocumentType->setInternalSubset(chars); -} - -void XercesDOMParser::elementDecl -( - const DTDElementDecl& decl - , const bool isIgnored -) -{ - if (fDocumentType->isIntSubsetReading()) - { - XMLBuffer elemDecl; - - elemDecl.append(chOpenAngle); - elemDecl.append(chBang); - elemDecl.append(XMLUni::fgElemString); - elemDecl.append(chSpace); - elemDecl.append(decl.getFullName()); - - //get the ContentSpec information - const XMLCh* contentModel = decl.getFormattedContentModel(); - if (contentModel != 0) { - elemDecl.append(chSpace); - elemDecl.append(contentModel); - } - - elemDecl.append(chCloseAngle); - fDocumentType->setInternalSubset(elemDecl.getRawBuffer()); - } -} - -void XercesDOMParser::endAttList -( - const DTDElementDecl& elemDecl -) -{ - // this section sets up default attributes. - // default attribute nodes are stored in a NamedNodeMap DocumentTypeImpl::elements - // default attribute data attached to the document is used to conform to the - // DOM spec regarding creating element nodes & removing attributes with default values - // see DocumentTypeImpl - if (elemDecl.hasAttDefs()) - { - XMLAttDefList* defAttrs = &elemDecl.getAttDefList(); - XMLAttDef* attr = 0; - - DOMAttrImpl * insertAttr = 0; - DOMElement *elem = fDocument->createElement(elemDecl.getFullName()); - DOMElementImpl *elemImpl = (DOMElementImpl *) elem; - - while (defAttrs->hasMoreElements()) - { - attr = &defAttrs->nextElement(); - if (attr->getValue() != 0) - { - if (fScanner->getDoNamespaces()) - { - // DOM Level 2 wants all namespace declaration attributes - // to be bound to "http://www.w3.org/2000/xmlns/" - // So as long as the XML parser doesn't do it, it needs to - // done here. - const XMLCh* qualifiedName = attr->getFullName(); - int index = DOMDocumentImpl::indexofQualifiedName(qualifiedName); - - XMLBuffer buf; - static const XMLCh XMLNS[] = { - chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s, chNull}; - - if (index > 0) { - // there is prefix - // map to XML URI for all cases except when prefix == "xmlns" - XMLCh* prefix; - XMLCh temp[1000]; - - if (index > 999) - prefix = new XMLCh[index+1]; - else - prefix = temp; - - XMLString::subString(prefix ,qualifiedName, 0, index); - - if (!XMLString::compareString(prefix,XMLNS)) - buf.append(XMLUni::fgXMLNSURIName); - else - buf.append(XMLUni::fgXMLURIName); - - if (index > 999) - delete prefix; - } - else { - // No prefix - if (!XMLString::compareString(qualifiedName,XMLNS)) - buf.append(XMLUni::fgXMLNSURIName); - } - - insertAttr = (DOMAttrImpl *) fDocument->createAttributeNS( - buf.getRawBuffer(), // NameSpaceURI - qualifiedName); // qualified name - - } - else - { - // Namespaces is turned off... - insertAttr = (DOMAttrImpl *) fDocument->createAttribute(attr->getFullName()); - } - insertAttr->setValue(attr->getValue()); - elemImpl->setAttributeNode(insertAttr); - insertAttr->setSpecified(false); - } - } - fDocumentType->getElements()->setNamedItem(elemImpl); - } -} - -void XercesDOMParser::endIntSubset() -{ - fDocumentType->intSubsetReading = false; -} - -void XercesDOMParser::endExtSubset() -{ -} - -void XercesDOMParser::entityDecl -( - const DTDEntityDecl& entityDecl - , const bool isPEDecl - , const bool isIgnored -) -{ - DOMEntityImpl* entity = (DOMEntityImpl *) fDocument->createEntity(entityDecl.getName()); - - entity->setPublicId(entityDecl.getPublicId()); - entity->setSystemId(entityDecl.getSystemId()); - entity->setNotationName(entityDecl.getNotationName()); - - DOMEntityImpl *previousDef = (DOMEntityImpl *) - fDocumentType->getEntities()->setNamedItem( entity ); - - #ifdef _revisit - // - // If this new entity node is replacing an entity node that was already - // in the entities named node map (happens if documents redefine the - // predefined entited such as lt), we need to delete the original - // entitiy node, assuming no-one else was referencing it. - // - if (previousDef != 0 && previousDef->nodeRefCount == 0) - NodeImpl::deleteIf(previousDef); - #endif - - if (fDocumentType->isIntSubsetReading()) - { - //add thes chars to internalSubset variable - XMLBuffer entityName; - entityName.append(chOpenAngle); - entityName.append(chBang); - entityName.append(XMLUni::fgEntityString); - entityName.append(chSpace); - - entityName.append(entityDecl.getName()); - - const XMLCh* id = entity->getPublicId(); - if (id != 0) { - entityName.append(chSpace); - entityName.append(XMLUni::fgPubIDString); - entityName.append(chSpace); - entityName.append(chDoubleQuote); - entityName.append(id); - entityName.append(chDoubleQuote); - } - id = entity->getSystemId(); - if (id != 0) { - entityName.append(chSpace); - entityName.append(XMLUni::fgSysIDString); - entityName.append(chSpace); - entityName.append(chDoubleQuote); - entityName.append(id); - entityName.append(chDoubleQuote); - - } - id = entity->getNotationName(); - if (id != 0) { - entityName.append(chSpace); - entityName.append(XMLUni::fgNDATAString); - entityName.append(chSpace); - entityName.append(chDoubleQuote); - entityName.append(id); - entityName.append(chDoubleQuote); - } - id = entityDecl.getValue(); - if (id !=0) { - entityName.append(chSpace); - entityName.append(chDoubleQuote); - entityName.append(id); - entityName.append(chDoubleQuote); - } - - entityName.append(chCloseAngle); - fDocumentType->setInternalSubset(entityName.getRawBuffer()); - } - -} - -void XercesDOMParser::resetDocType() -{ - fDocumentType = 0; -} - -void XercesDOMParser::notationDecl -( - const XMLNotationDecl& notDecl - , const bool isIgnored -) -{ - DOMNotationImpl* notation = (DOMNotationImpl *)fDocument->createNotation(notDecl.getName()); - notation->setPublicId(notDecl.getPublicId()); - notation->setSystemId(notDecl.getSystemId()); - - fDocumentType->getNotations()->setNamedItem( notation ); - -} - -void XercesDOMParser::startAttList -( - const DTDElementDecl& elemDecl -) -{ -} - -void XercesDOMParser::startIntSubset() -{ - fDocumentType->intSubsetReading = true; -} - -void XercesDOMParser::startExtSubset() -{ -} - -void XercesDOMParser::TextDecl -( - const XMLCh* const versionStr - , const XMLCh* const encodingStr -) -{ -} diff --git a/src/xercesc/parsers/XercesDOMParser.hpp b/src/xercesc/parsers/XercesDOMParser.hpp index bc4ca1ff896bdbc96aeea093be4758f837a84634..4fb306f52f934ab53a848948be0c4721c0828b4b 100644 --- a/src/xercesc/parsers/XercesDOMParser.hpp +++ b/src/xercesc/parsers/XercesDOMParser.hpp @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001 The Apache Software Foundation. All rights + * Copyright (c) 2001-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -63,27 +63,13 @@ #define XercesDOMParser_HPP -#include <xercesc/dom/DOMDocument.hpp> -#include <xercesc/framework/XMLDocumentHandler.hpp> -#include <xercesc/framework/XMLErrorReporter.hpp> -#include <xercesc/framework/XMLEntityHandler.hpp> -#include <xercesc/util/ValueStackOf.hpp> - -#include <xercesc/validators/DTD/DocTypeHandler.hpp> -#include <xercesc/dom/DOMDocumentType.hpp> -#include <xercesc/validators/DTD/DTDElementDecl.hpp> +#include <xercesc/parsers/AbstractDOMParser.hpp> class EntityResolver; class ErrorHandler; -class XMLPScanToken; -class XMLScanner; -class XMLValidator; -class DOMDocumentImpl; -class DOMDocumentTypeImpl; -class DOMElement; -/** + /** * This class implements the Document Object Model (DOM) interface. * It should be used by applications which choose to parse and * process the XML document using the DOM api's. This implementation @@ -93,25 +79,9 @@ class DOMElement; * <p>It can be used to instantiate a validating or non-validating * parser, by setting a member flag.</p> */ -class PARSERS_EXPORT XercesDOMParser : - - public XMLDocumentHandler - , public XMLErrorReporter - , public XMLEntityHandler - , public DocTypeHandler +class PARSERS_EXPORT XercesDOMParser : public AbstractDOMParser { public : - // ----------------------------------------------------------------------- - // Class types - // ----------------------------------------------------------------------- - enum ValSchemes - { - Val_Never - , Val_Always - , Val_Auto - }; - - // ----------------------------------------------------------------------- // Constructors and Detructor // ----------------------------------------------------------------------- @@ -136,38 +106,6 @@ public : //@} - /** Reset the parser - * - * This method resets the state of the DOM driver and makes - * it ready for a fresh parse run. - */ - void reset(); - - /** Reset the documents vector pool and release all the associated memory - * back to the system. - * - * When parsing a document using an XercesDOMParser, all memory allocated - * for a DOM tree is associated to the DOM document. - * - * If you do multiple parse using the same XercesDOMParser instance, then - * multiple DOM documents will be generated and saved in a vector pool. - * All these documents (and thus all the allocated memory) - * won't be deleted until the parser instance is destroyed. - * - * If you don't need these DOM documents anymore and don't want to - * destroy the XercesDOMParser instance at this moment, then you can call this method - * to reset the document vector pool and release all the allocated memory - * back to the system. - * - * It is an error to call this method if you are in the middle of a - * parse (e.g. in the mid of a progressive parse). - * - * @exception IOException An exception from the parser if this function - * is called when a parse is in progress. - * - */ - void resetDocumentPool(); - // ----------------------------------------------------------------------- // Getter methods @@ -176,17 +114,6 @@ public : /** @name Getter methods */ //@{ - /** Get the DOM document - * - * This method returns the DOMDocument object representing the - * root of the document tree. This object provides the primary - * access to the document's data. - * - * @return The DOMDocument object which represents the entire - * XML document. - */ - DOMDocument* getDocument(); - /** Get a pointer to the error handler * * This method returns the installed error handler. If no handler @@ -223,179 +150,6 @@ public : */ const EntityResolver* getEntityResolver() const; - /** Get a const reference to the validator - * - * This method returns a reference to the parser's installed - * validator. - * - * @return A const reference to the installed validator object. - */ - const XMLValidator& getValidator() const; - - /** - * This method returns an enumerated value that indicates the current - * validation scheme set on this parser. - * - * @return The ValSchemes value current set on this parser. - * @see #setValidationScheme - */ - ValSchemes getValidationScheme() const; - - /** Get the 'do schema' flag - * - * This method returns the state of the parser's schema processing - * flag. - * - * @return true, if the parser is currently configured to - * understand schema, false otherwise. - * - * @see #setDoSchema - */ - bool getDoSchema() const; - - /** Get the 'full schema constraint checking' flag - * - * This method returns the state of the parser's full schema constraint - * checking flag. - * - * @return true, if the parser is currently configured to - * have full schema constraint checking, false otherwise. - * - * @see #setValidationSchemaFullChecking - */ - bool getValidationSchemaFullChecking() const; - - /** Get error count from the last parse operation. - * - * This method returns the error count from the last parse - * operation. Note that this count is actually stored in the - * scanner, so this method simply returns what the - * scanner reports. - * - * @return number of errors encountered during the latest - * parse operation. - * - */ - int getErrorCount() const; - - /** Get the 'do namespaces' flag - * - * This method returns the state of the parser's namespace processing - * flag. - * - * @return true, if the parser is currently configured to - * understand namespaces, false otherwise. - * - * @see #setDoNamespaces - */ - bool getDoNamespaces() const; - - /** Get the 'exit on first error' flag - * - * This method returns the state of the parser's - * exit-on-First-Fatal-Error flag. If this flag is true, then the - * parse will exit the first time it sees any non-wellformed XML or - * any validity error. The default state is true. - * - * @return true, if the parser is currently configured to - * exit on the first fatal error, false otherwise. - * - * @see #setExitOnFirstFatalError - */ - bool getExitOnFirstFatalError() const; - - /** - * This method returns the state of the parser's - * validation-constraint-fatal flag. - * - * @return true, if the parser is currently configured to - * set validation constraint errors as fatal, false - * otherwise. - * - * @see #setValidationContraintFatal - */ - bool getValidationConstraintFatal() const; - - /** Get the 'expand entity references' flag. - * DEPRECATED Use getCreateEntityReferenceNodes() instead. - * - * This method returns the state of the parser's expand entity - * references flag. - * - * @return 'true' if the expand entity reference flag is set on - * the parser, 'false' otherwise. - * - * @see #setExpandEntityReferences - * @see #setCreateEntityReferenceNodes - * @see #getCreateEntityReferenceNodes - */ - bool getExpandEntityReferences() const; - - /** Get the 'include entity references' flag - * - * This method returns the flag that specifies whether the parser is - * creating entity reference nodes in the DOM tree being produced. - * - * @return The state of the create entity reference node - * flag. - * @see #setCreateEntityReferenceNodes - */ - bool getCreateEntityReferenceNodes()const; - - /** Get the 'include ignorable whitespace' flag. - * - * This method returns the state of the parser's include ignorable - * whitespace flag. - * - * @return 'true' if the include ignorable whitespace flag is set on - * the parser, 'false' otherwise. - * - * @see #setIncludeIgnorableWhitespace - */ - bool getIncludeIgnorableWhitespace() const; - - /** Get the set of Namespace/SchemaLocation that is specified externaly. - * - * This method returns the list of Namespace/SchemaLocation that was - * specified using setExternalSchemaLocation. - * - * The parser owns the returned string, and the memory allocated for - * the returned string will be destroyed when the parser is deleted. - * - * To ensure assessiblity of the returned information after the parser - * is deleted, callers need to copy and store the returned information - * somewhere else. - * - * @return a pointer to the list of Namespace/SchemaLocation that was - * specified externally. The pointer spans the same life-time as - * the parser. A null pointer is returned if nothing - * was specified externally. - * - * @see #setExternalSchemaLocation(const XMLCh* const) - */ - XMLCh* getExternalSchemaLocation() const; - - /** Get the noNamespace SchemaLocation that is specified externaly. - * - * This method returns the no target namespace XML Schema Location - * that was specified using setExternalNoNamespaceSchemaLocation. - * - * The parser owns the returned string, and the memory allocated for - * the returned string will be destroyed when the parser is deleted. - * - * To ensure assessiblity of the returned information after the parser - * is deleted, callers need to copy and store the returned information - * somewhere else. - * - * @return a pointer to the no target namespace Schema Location that was - * specified externally. The pointer spans the same life-time as - * the parser. A null pointer is returned if nothing - * was specified externally. - * - * @see #setExternalNoNamespaceSchemaLocation(const XMLCh* const) - */ - XMLCh* getExternalNoNamespaceSchemaLocation() const; - //@} @@ -438,469 +192,8 @@ public : */ void setEntityResolver(EntityResolver* const handler); - /** Set the 'do namespaces' flag - * - * This method allows users to enable or disable the parser's - * namespace processing. When set to true, parser starts enforcing - * all the constraints and rules specified by the NameSpace - * specification. - * - * The parser's default state is: false. - * - * This flag is ignored by the underlying scanner if the installed - * validator indicates that namespace constraints should be - * enforced. - * - * @param newState The value specifying whether NameSpace rules should - * be enforced or not. - * - * @see #getDoNamespaces - */ - void setDoNamespaces(const bool newState); - - /** Set the 'exit on first error' flag - * - * This method allows users to set the parser's behaviour when it - * encounters the first fatal error. If set to true, the parser - * will exit at the first fatal error. If false, then it will - * report the error and continue processing. - * - * The default value is 'true' and the parser exits on the - * first fatal error. - * - * @param newState The value specifying whether the parser should - * continue or exit when it encounters the first - * fatal error. - * - * @see #getExitOnFirstFatalError - */ - void setExitOnFirstFatalError(const bool newState); - - /** - * This method allows users to set the parser's behaviour when it - * encounters a validtion constraint error. If set to true, and the - * the parser is set to exit when it encounter the first fatal error, - * the parser will exit at the first encounter. If false, then it will - * report the error and continue processing. - * - * <p>The default value is 'false'.</p> - * - * @param newState The value specifying whether the parser should - * continue or exit when it encounters a validation - * constraint error. - * - * @see #getValidationConstraintFatal - */ - void setValidationConstraintFatal(const bool newState); - - /** Set the 'expand entity references' flag - * - * DEPRECATED. USE setCreateEntityReferenceNodes instead. - * This method allows the user to specify whether the parser should - * expand all entity reference nodes. When the 'do expansion' flag is - * true, the DOM tree does not have any entity reference nodes. It is - * replaced by the sub-tree representing the replacement text of the - * entity. When the 'do expansion' flag is false, the DOM tree - * contains an extra entity reference node, whose children is the - * sub tree of the replacement text. - * <p>The default value is 'false'. - * - * @param expand The new state of the expand entity reference - * flag. - * @see #setCreateEntityReferenceNodes - */ - void setExpandEntityReferences(const bool expand); - - /** Set the 'include entity references' flag - * - * This method allows the user to specify whether the parser should - * create entity reference nodes in the DOM tree being produced. - * When the 'create' flag is - * true, the parser will create EntityReference nodes in the DOM tree. - * The EntityReference nodes and their child nodes will be read-only. - * When the 'create' flag is false, no EntityReference nodes will be created. - * <p>The replacement text - * of the entity is included in either case, either as a - * child of the Entity Reference node or in place at the location - * of the reference. - * <p>The default value is 'true'. - * - * @param create The new state of the create entity reference nodes - * flag. - * @see #getCreateEntityReferenceNodes - */ - void setCreateEntityReferenceNodes(const bool create); - - /** Set the 'include ignorable whitespace' flag - * - * This method allows the user to specify whether a validating parser - * should include ignorable whitespaces as text nodes. It has no effect - * on non-validating parsers which always include non-markup text. - * <p>When set to true (also the default), ignorable whitespaces will be - * added to the DOM tree as text nodes. The method - * DOMText::isIgnorableWhitespace() will return true for those text - * nodes only. - * <p>When set to false, all ignorable whitespace will be discarded and - * no text node is added to the DOM tree. Note: applications intended - * to process the "xml:space" attribute should not set this flag to false. - * And this flag also overrides any schema datateye whitespace facets, - * that is, all ignorable whitespace will be discarded even though - * 'preserve' is set in schema datatype whitespace facets. - * - * @param include The new state of the include ignorable whitespace - * flag. - * - * @see #getIncludeIgnorableWhitespace - */ - void setIncludeIgnorableWhitespace(const bool include); - - /** - * This method allows users to set the validation scheme to be used - * by this parser. The value is one of the ValSchemes enumerated values - * defined by this class: - * - * <br> Val_Never - turn off validation - * <br> Val_Always - turn on validation - * <br> Val_Auto - turn on validation if any internal/external - * DTD subset have been seen - * - * <p>The parser's default state is: Val_Auto.</p> - * - * @param newScheme The new validation scheme to use. - * - * @see #getValidationScheme - */ - void setValidationScheme(const ValSchemes newScheme); - - /** Set the 'do schema' flag - * - * This method allows users to enable or disable the parser's - * schema processing. When set to false, parser will not process - * any schema found. - * - * The parser's default state is: false. - * - * @param newState The value specifying whether schema support should - * be enforced or not. - * - * @see #getDoSchema - */ - void setDoSchema(const bool newState); - - /** - * This method allows the user to turn full Schema constraint checking on/off. - * Only takes effect if Schema validation is enabled. - * If turned off, partial constraint checking is done. - * - * Full schema constraint checking includes those checking that may - * be time-consuming or memory intensive. Currently, particle unique - * attribution constraint checking and particle derivation resriction checking - * are controlled by this option. - * - * The parser's default state is: false. - * - * @param schemaFullChecking True to turn on full schema constraint checking. - * - * @see #getValidationSchemaFullChecking - */ - void setValidationSchemaFullChecking(const bool schemaFullChecking); - - /** - * This method allows the user to specify a list of schemas to use. - * If the targetNamespace of a schema specified using this method matches - * the targetNamespace of a schema occuring in the instance document in - * the schemaLocation attribute, or if the targetNamespace matches the - * namespace attribute of the "import" element, the schema specified by the - * user using this method will be used (i.e., the schemaLocation attribute - * in the instance document or on the "import" element will be effectively ignored). - * - * If this method is called more than once, only the last one takes effect. - * - * The syntax is the same as for schemaLocation attributes in instance - * documents: e.g, "http://www.example.com file_name.xsd". The user can - * specify more than one XML Schema in the list. - * - * @param schemaLocation the list of schemas to use - * - * @see #getExternalSchemaLocation - */ - - void setExternalSchemaLocation(const XMLCh* const schemaLocation); - - /** - * This method is same as setExternalSchemaLocation(const XMLCh* const). - * It takes native char string as parameter - * - * @param schemaLocation the list of schemas to use - * - * @see #setExternalSchemaLocation(const XMLCh* const) - */ - void setExternalSchemaLocation(const char* const schemaLocation); - - /** - * This method allows the user to specify the no target namespace XML - * Schema Location externally. If specified, the instance document's - * noNamespaceSchemaLocation attribute will be effectively ignored. - * - * If this method is called more than once, only the last one takes effect. - * - * The syntax is the same as for the noNamespaceSchemaLocation attribute - * that may occur in an instance document: e.g."file_name.xsd". - * - * @param noNamespaceSchemaLocation the XML Schema Location with no target namespace - * - * @see #getExternalNoNamespaceSchemaLocation - */ - void setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation); - - /** - * This method is same as setExternalNoNamespaceSchemaLocation(const XMLCh* const). - * It takes native char string as parameter - * - * @param noNamespaceSchemaLocation the XML Schema Location with no target namespace - * - * @see #setExternalNoNamespaceSchemaLocation(const XMLCh* const) - */ - void setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation); - //@} - - // ----------------------------------------------------------------------- - // Parsing methods - // ----------------------------------------------------------------------- - - /** @name Parsing methods */ - //@{ - - /** Parse via an input source object - * - * This method invokes the parsing process on the XML file specified - * by the InputSource parameter. This API is borrowed from the - * SAX Parser interface. - * - * @param source A const reference to the InputSource object which - * points to the XML file to be parsed. - * @param reuseGrammar The flag indicating whether the existing Grammar - * should be reused or not for this parsing run. - * If true, there cannot be any internal subset. - * @exception SAXException Any SAX exception, possibly - * wrapping another exception. - * @exception XMLException An exception from the parser or client - * handler code. - * @exception DOMException A DOM exception as per DOM spec. - * @see InputSource#InputSource - * @see #setEntityResolver - * @see #setErrorHandler - */ - void parse(const InputSource& source, const bool reuseGrammar = false); - - /** Parse via a file path or URL - * - * This method invokes the parsing process on the XML file specified by - * the Unicode string parameter 'systemId'. This method is borrowed - * from the SAX Parser interface. - * - * @param systemId A const XMLCh pointer to the Unicode string which - * contains the path to the XML file to be parsed. - * @param reuseGrammar The flag indicating whether the existing Grammar - * should be reused or not for this parsing run. - * If true, there cannot be any internal subset. - * - * @exception SAXException Any SAX exception, possibly - * wrapping another exception. - * @exception XMLException An exception from the parser or client - * handler code. - * @exception DOMException A DOM exception as per DOM spec. - * @see #parse(InputSource,...) - */ - void parse(const XMLCh* const systemId, const bool reuseGrammar = false); - - /** Parse via a file path or URL (in the local code page) - * - * This method invokes the parsing process on the XML file specified by - * the native char* string parameter 'systemId'. - * - * @param systemId A const char pointer to a native string which - * contains the path to the XML file to be parsed. - * @param reuseGrammar The flag indicating whether the existing Grammar - * should be reused or not for this parsing run. - * If true, there cannot be any internal subset. - * - * @exception SAXException Any SAX exception, possibly - * wrapping another exception. - * @exception XMLException An exception from the parser or client - * handler code. - * @exception DOMException A DOM exception as per DOM spec. - * @see #parse(InputSource,...) - */ - void parse(const char* const systemId, const bool reuseGrammar = false); - - /** Begin a progressive parse operation - * - * This method is used to start a progressive parse on a XML file. - * To continue parsing, subsequent calls must be to the parseNext - * method. - * - * It scans through the prolog and returns a token to be used on - * subsequent scanNext() calls. If the return value is true, then the - * token is legal and ready for further use. If it returns false, then - * the scan of the prolog failed and the token is not going to work on - * subsequent scanNext() calls. - * - * @param systemId A pointer to a Unicode string represting the path - * to the XML file to be parsed. - * @param toFill A token maintaing state information to maintain - * internal consistency between invocation of 'parseNext' - * calls. - * @param reuseGrammar The flag indicating whether the existing Grammar - * should be reused or not for this parsing process. - * If true, there cannot be any internal subset. - * @return 'true', if successful in parsing the prolog. It indicates the - * user can go ahead with parsing the rest of the file. It - * returns 'false' to indicate that the parser could not parse - * the prolog. - * - * @see #parseNext - * @see #parseFirst(char*,...) - * @see #parseFirst(InputSource&,...) - */ - bool parseFirst - ( - const XMLCh* const systemId - , XMLPScanToken& toFill - , const bool reuseGrammar = false - ); - - /** Begin a progressive parse operation - * - * This method is used to start a progressive parse on a XML file. - * To continue parsing, subsequent calls must be to the parseNext - * method. - * - * It scans through the prolog and returns a token to be used on - * subsequent scanNext() calls. If the return value is true, then the - * token is legal and ready for further use. If it returns false, then - * the scan of the prolog failed and the token is not going to work on - * subsequent scanNext() calls. - * - * @param systemId A pointer to a regular native string represting - * the path to the XML file to be parsed. - * @param toFill A token maintaing state information to maintain - * internal consistency between invocation of 'parseNext' - * calls. - * @param reuseGrammar The flag indicating whether the existing Grammar - * should be reused or not for this parsing run. - * If true, there cannot be any internal subset. - * - * @return 'true', if successful in parsing the prolog. It indicates the - * user can go ahead with parsing the rest of the file. It - * returns 'false' to indicate that the parser could not parse - * the prolog. - * - * @see #parseNext - * @see #parseFirst(XMLCh*,...) - * @see #parseFirst(InputSource&,...) - */ - bool parseFirst - ( - const char* const systemId - , XMLPScanToken& toFill - , const bool reuseGrammar = false - ); - - /** Begin a progressive parse operation - * - * This method is used to start a progressive parse on a XML file. - * To continue parsing, subsequent calls must be to the parseNext - * method. - * - * It scans through the prolog and returns a token to be used on - * subsequent scanNext() calls. If the return value is true, then the - * token is legal and ready for further use. If it returns false, then - * the scan of the prolog failed and the token is not going to work on - * subsequent scanNext() calls. - * - * @param source A const reference to the InputSource object which - * points to the XML file to be parsed. - * @param toFill A token maintaing state information to maintain - * internal consistency between invocation of 'parseNext' - * calls. - * @param reuseGrammar The flag indicating whether the existing Grammar - * should be reused or not for this parsing process. - * If true, there cannot be any internal subset. - * - * @return 'true', if successful in parsing the prolog. It indicates the - * user can go ahead with parsing the rest of the file. It - * returns 'false' to indicate that the parser could not parse - * the prolog. - * - * @see #parseNext - * @see #parseFirst(XMLCh*,...) - * @see #parseFirst(char*,...) - */ - bool parseFirst - ( - const InputSource& source - , XMLPScanToken& toFill - , const bool reuseGrammar = false - ); - - /** Continue a progressive parse operation - * - * This method is used to continue with progressive parsing of - * XML files started by a call to 'parseFirst' method. - * - * It parses the XML file and stops as soon as it comes across - * a XML token (as defined in the XML specification). - * - * @param token A token maintaing state information to maintain - * internal consistency between invocation of 'parseNext' - * calls. - * - * @return 'true', if successful in parsing the next XML token. - * It indicates the user can go ahead with parsing the rest - * of the file. It returns 'false' to indicate that the parser - * could not find next token as per the XML specification - * production rule. - * - * @see #parseFirst(XMLCh*,...) - * @see #parseFirst(char*,...) - * @see #parseFirst(InputSource&,...) - */ - bool parseNext(XMLPScanToken& token); - - /** Reset the parser after a progressive parse - * - * If a progressive parse loop exits before the end of the document - * is reached, the parser has no way of knowing this. So it will leave - * open any files or sockets or memory buffers that were in use at - * the time that the parse loop exited. - * - * The next parse operation will cause these open files and such to - * be closed, but the next parse operation might occur at some unknown - * future point. To avoid this problem, you should reset the parser if - * you exit the loop early. - * - * If you exited because of an error, then this cleanup will be done - * for you. Its only when you exit the file prematurely of your own - * accord, because you've found what you wanted in the file most - * likely. - * - * @param token A token maintaing state information to maintain - * internal consistency between invocation of 'parseNext' - * calls. - * - * @see #parseFirst(XMLCh*,...) - * @see #parseFirst(char*,...) - * @see #parseFirst(InputSource&,...) - */ - void parseReset(XMLPScanToken& token); - - //@} - - - // ----------------------------------------------------------------------- // Implementation of the XMLErrorReporter interface. // ----------------------------------------------------------------------- @@ -1046,455 +339,18 @@ public : //@} - - // ----------------------------------------------------------------------- - // Implementation of the XMLDocumentHandler interface. - // ----------------------------------------------------------------------- - - /** @name Implementation of the XMLDocumentHandler interface. */ - //@{ - - /** Handle document character events - * - * This method is used to report all the characters scanned by the - * parser. This DOM implementation stores this data in the appropriate - * DOM node, creating one if necessary. - * - * @param chars A const pointer to a Unicode string representing the - * character data. - * @param length The length of the Unicode string returned in 'chars'. - * @param cdataSection A flag indicating if the characters represent - * content from the CDATA section. - */ - virtual void docCharacters - ( - const XMLCh* const chars - , const unsigned int length - , const bool cdataSection - ); - - /** Handle a document comment event - * - * This method is used to report any comments scanned by the parser. - * A new comment node is created which stores this data. - * - * @param comment A const pointer to a null terminated Unicode - * string representing the comment text. - */ - virtual void docComment - ( - const XMLCh* const comment - ); - - /** Handle a document PI event - * - * This method is used to report any PI scanned by the parser. A new - * PI node is created and appended as a child of the current node in - * the tree. - * - * @param target A const pointer to a Unicode string representing the - * target of the PI declaration. - * @param data A const pointer to a Unicode string representing the - * data of the PI declaration. See the PI production rule - * in the XML specification for details. - */ - virtual void docPI - ( - const XMLCh* const target - , const XMLCh* const data - ); - - /** Handle the end of document event - * - * This method is used to indicate the end of the current document. - */ - virtual void endDocument(); - - /** Handle and end of element event - * - * This method is used to indicate the end tag of an element. The - * DOMParse pops the current element off the top of the element - * stack, and make it the new current element. - * - * @param elemDecl A const reference to the object containing element - * declaration information. - * @param urlId An id referring to the namespace prefix, if - * namespaces setting is switched on. - * @param isRoot A flag indicating whether this element was the - * root element. - */ - virtual void endElement - ( - const XMLElementDecl& elemDecl - , const unsigned int urlId - , const bool isRoot - ); - - /** Handle and end of entity reference event - * - * This method is used to indicate that an end of an entity reference - * was just scanned. - * - * @param entDecl A const reference to the object containing the - * entity declaration information. - */ - virtual void endEntityReference - ( - const XMLEntityDecl& entDecl - ); - - /** Handle an ignorable whitespace vent - * - * This method is used to report all the whitespace characters, which - * are determined to be 'ignorable'. This distinction between characters - * is only made, if validation is enabled. - * - * Any whitespace before content is ignored. If the current node is - * already of type DOMNode::TEXT_NODE, then these whitespaces are - * appended, otherwise a new Text node is created which stores this - * data. Essentially all contiguous ignorable characters are collected - * in one node. - * - * @param chars A const pointer to a Unicode string representing the - * ignorable whitespace character data. - * @param length The length of the Unicode string 'chars'. - * @param cdataSection A flag indicating if the characters represent - * content from the CDATA section. - */ - virtual void ignorableWhitespace - ( - const XMLCh* const chars - , const unsigned int length - , const bool cdataSection - ); - - /** Handle a document reset event - * - * This method allows the user installed Document Handler to 'reset' - * itself, freeing all the memory resources. The scanner calls this - * method before starting a new parse event. - */ - virtual void resetDocument(); - - /** Handle a start document event - * - * This method is used to report the start of the parsing process. - */ - virtual void startDocument(); - - /** Handle a start element event - * - * This method is used to report the start of an element. It is - * called at the end of the element, by which time all attributes - * specified are also parsed. A new DOM Element node is created - * along with as many attribute nodes as required. This new element - * is added appended as a child of the current node in the tree, and - * then replaces it as the current node (if the isEmpty flag is false.) - * - * @param elemDecl A const reference to the object containing element - * declaration information. - * @param urlId An id referring to the namespace prefix, if - * namespaces setting is switched on. - * @param elemPrefix A const pointer to a Unicode string containing - * the namespace prefix for this element. Applicable - * only when namespace processing is enabled. - * @param attrList A const reference to the object containing the - * list of attributes just scanned for this element. - * @param attrCount A count of number of attributes in the list - * specified by the parameter 'attrList'. - * @param isEmpty A flag indicating whether this is an empty element - * or not. If empty, then no endElement() call will - * be made. - * @param isRoot A flag indicating whether this element was the - * root element. - * @see DocumentHandler#startElement - */ - virtual void startElement - ( - const XMLElementDecl& elemDecl - , const unsigned int urlId - , const XMLCh* const elemPrefix - , const RefVectorOf<XMLAttr>& attrList - , const unsigned int attrCount - , const bool isEmpty - , const bool isRoot - ); - - /** Handle a start entity reference event - * - * This method is used to indicate the start of an entity reference. - * If the expand entity reference flag is true, then a new - * DOM Entity reference node is created. - * - * @param entDecl A const reference to the object containing the - * entity declaration information. - */ - virtual void startEntityReference - ( - const XMLEntityDecl& entDecl - ); - - /** Handle an XMLDecl event - * - * This method is used to report the XML decl scanned by the parser. - * Refer to the XML specification to see the meaning of parameters. - * - * <b><font color="#FF0000">This method is a no-op for this DOM - * implementation.</font></b> - * - * @param versionStr A const pointer to a Unicode string representing - * version string value. - * @param encodingStr A const pointer to a Unicode string representing - * the encoding string value. - * @param standaloneStr A const pointer to a Unicode string - * representing the standalone string value. - * @param actualEncStr A const pointer to a Unicode string - * representing the actual encoding string - * value. - */ - virtual void XMLDecl - ( - const XMLCh* const versionStr - , const XMLCh* const encodingStr - , const XMLCh* const standaloneStr - , const XMLCh* const actualEncStr - ); - //@} - - - /** @name Deprecated Methods */ - //@{ - /** - * This method returns the state of the parser's validation - * handling flag which controls whether validation checks - * are enforced or not. - * - * @return true, if the parser is currently configured to - * do validation, false otherwise. - * - * @see #setDoValidation - */ - bool getDoValidation() const; - - /** - * This method allows users to enable or disable the parser's validation - * checks. - * - * <p>By default, the parser does not to any validation. The default - * value is false.</p> - * - * @param newState The value specifying whether the parser should - * do validity checks or not against the DTD in the - * input XML document. - * - * @see #getDoValidation - */ - void setDoValidation(const bool newState); - - /** - * Deprecated doctypehandler interfaces - */ - virtual void attDef - ( - const DTDElementDecl& elemDecl - , const DTDAttDef& attDef - , const bool ignoring - ); - - virtual void doctypeComment - ( - const XMLCh* const comment - ); - - virtual void doctypeDecl - ( - const DTDElementDecl& elemDecl - , const XMLCh* const publicId - , const XMLCh* const systemId - , const bool hasIntSubset - ); - - virtual void doctypePI - ( - const XMLCh* const target - , const XMLCh* const data - ); - - virtual void doctypeWhitespace - ( - const XMLCh* const chars - , const unsigned int length - ); - - virtual void elementDecl - ( - const DTDElementDecl& decl - , const bool isIgnored - ); - - virtual void endAttList - ( - const DTDElementDecl& elemDecl - ); - - virtual void endIntSubset(); - - virtual void endExtSubset(); - - virtual void entityDecl - ( - const DTDEntityDecl& entityDecl - , const bool isPEDecl - , const bool isIgnored - ); - - virtual void resetDocType(); - - virtual void notationDecl - ( - const XMLNotationDecl& notDecl - , const bool isIgnored - ); - - virtual void startAttList - ( - const DTDElementDecl& elemDecl - ); - - virtual void startIntSubset(); - - virtual void startExtSubset(); - - virtual void TextDecl - ( - const XMLCh* const versionStr - , const XMLCh* const encodingStr - ); - - - //@} - - -protected : - // ----------------------------------------------------------------------- - // Protected getter methods - // ----------------------------------------------------------------------- - - /** @name Protected getter methods */ - //@{ - /** Get the current DOM node - * - * This provides derived classes with access to the current node, i.e. - * the node to which new nodes are being added. - */ - DOMNode* getCurrentNode(); - - //@} - - - // ----------------------------------------------------------------------- - // Protected setter methods - // ----------------------------------------------------------------------- - - /** @name Protected setter methods */ - //@{ - - /** Set the current DOM node - * - * This method sets the current node maintained inside the parser to - * the one specified. - * - * @param toSet The DOM node which will be the current node. - */ - void setCurrentNode(DOMNode* toSet); - - /** Set the document node - * - * This method sets the DOM Document node to the one specified. - * - * @param toSet The new DOM Document node for this XML document. - */ - void setDocument(DOMDocument* toSet); - //@} - - // ----------------------------------------------------------------------- - // Protected Helper methods - // ----------------------------------------------------------------------- - virtual DOMElement* createElementNSNode(const XMLCh *fNamespaceURI, - const XMLCh *qualifiedName); - - - // ----------------------------------------------------------------------- - // Protected data members - // - // fScanner - // The scanner used for this parser. This is created during the - // constructor. - // ----------------------------------------------------------------------- - XMLScanner* fScanner; - - private : // ----------------------------------------------------------------------- // Private data members // - // fCurrentNode - // fCurrentParent - // Used to track the current node during nested element events. Since - // the tree must be built from a set of disjoint callbacks, we need - // these to keep up with where we currently are. - // - // fDocument - // The root document object, filled with the document contents. - // // fEntityResolver // The installed SAX entity resolver, if any. Null if none. // // fErrorHandler // The installed SAX error handler, if any. Null if none. - // - // fCreateEntityReferenceNode - // Indicates whether entity reference nodes should be created. - // - // fIncludeIgnorableWhitespace - // Indicates whether ignorable whiltespace should be added to - // the DOM tree for validating parsers. - // - // fNodeStack - // Used to track previous parent nodes during nested element events. - // - // fParseInProgress - // Used to prevent multiple entrance to the parser while its doing - // a parse. - // - // fScanner - // The scanner used for this parser. This is created during the - // constructor. - // - // fWithinElement - // A flag to indicate that the parser is within at least one level - // of element processing. - // - // fDocumentType - // Used to store and update the documentType variable information - // in fDocument - // - // fDocumentVector - // Store all the previous fDocument(s) (thus not the current fDocument) - // created in this parser. It is destroyed when the parser is destructed. - // ----------------------------------------------------------------------- - DOMNode* fCurrentParent; - DOMNode* fCurrentNode; - DOMDocumentImpl* fDocument; + //----------------------------------------------------------------------- EntityResolver* fEntityResolver; ErrorHandler* fErrorHandler; - bool fCreateEntityReferenceNodes; - bool fIncludeIgnorableWhitespace; - ValueStackOf<DOMNode*>* fNodeStack; - bool fParseInProgress; - bool fWithinElement; - DOMDocumentTypeImpl* fDocumentType; - RefVectorOf<DOMDocumentImpl>* fDocumentVector; }; @@ -1547,60 +403,5 @@ inline const EntityResolver* XercesDOMParser::getEntityResolver() const return fEntityResolver; } -inline bool XercesDOMParser::getExpandEntityReferences() const -{ - return !fCreateEntityReferenceNodes; -} -inline bool XercesDOMParser::getCreateEntityReferenceNodes() const -{ - return fCreateEntityReferenceNodes; -} - -inline bool XercesDOMParser::getIncludeIgnorableWhitespace() const -{ - return fIncludeIgnorableWhitespace; -} - - -// --------------------------------------------------------------------------- -// XercesDOMParser: Setter methods -// --------------------------------------------------------------------------- -inline void XercesDOMParser::setExpandEntityReferences(const bool expand) -{ - fCreateEntityReferenceNodes = !expand; -} - -inline void XercesDOMParser::setCreateEntityReferenceNodes(const bool create) -{ - fCreateEntityReferenceNodes = create; -} - -inline void XercesDOMParser::setIncludeIgnorableWhitespace(const bool include) -{ - fIncludeIgnorableWhitespace = include; -} - - -// --------------------------------------------------------------------------- -// XercesDOMParser: Protected getter methods -// --------------------------------------------------------------------------- -inline DOMNode* XercesDOMParser::getCurrentNode() -{ - return fCurrentNode; -} - - -// --------------------------------------------------------------------------- -// XercesDOMParser: Protected setter methods -// --------------------------------------------------------------------------- -inline void XercesDOMParser::setCurrentNode(DOMNode* toSet) -{ - fCurrentNode = toSet; -} - -inline void XercesDOMParser::setDocument(DOMDocument* toSet) -{ - fDocument = (DOMDocumentImpl*)toSet; -} #endif diff --git a/src/xercesc/validators/schema/SchemaValidator.hpp b/src/xercesc/validators/schema/SchemaValidator.hpp index dbb2216dfb4d6b96da71d97d2b24792482069a48..b1951e4c4c94fe1793b1ea97d6f3f3ac690397c3 100644 --- a/src/xercesc/validators/schema/SchemaValidator.hpp +++ b/src/xercesc/validators/schema/SchemaValidator.hpp @@ -56,6 +56,13 @@ /* * $Log$ + * Revision 1.5 2002/05/22 20:54:14 knoaman + * Prepare for DOM L3 : + * - Make use of the XMLEntityHandler/XMLErrorReporter interfaces, instead of using + * EntityHandler/ErrorHandler directly. + * - Add 'AbstractDOMParser' class to provide common functionality for XercesDOMParser + * and DOMBuilder. + * * Revision 1.4 2002/04/19 13:33:23 knoaman * Fix for bug 8236. * @@ -135,7 +142,7 @@ public: , const unsigned int uriId); void setNillable(bool isNil); - void setErrorHandler(ErrorHandler* const handler); + void setErrorReporter(XMLErrorReporter* const errorReporter); void setExitOnFirstFatal(const bool newValue); // ----------------------------------------------------------------------- @@ -349,6 +356,11 @@ inline void SchemaValidator::setNillable(bool isNil) { fNil = isNil; } +inline void SchemaValidator::setExitOnFirstFatal(const bool newValue) { + + fSchemaErrorReporter.setExitOnFirstFatal(newValue); +} + // --------------------------------------------------------------------------- // Virtual interface // --------------------------------------------------------------------------- @@ -360,6 +372,12 @@ inline void SchemaValidator::setGrammar(Grammar* aGrammar) { fSchemaGrammar = (SchemaGrammar*) aGrammar; } +inline void SchemaValidator::setErrorReporter(XMLErrorReporter* const errorReporter) { + + XMLValidator::setErrorReporter(errorReporter); + fSchemaErrorReporter.setErrorReporter(errorReporter); +} + // --------------------------------------------------------------------------- // SchemaValidator: DTD handler interface // --------------------------------------------------------------------------- @@ -392,14 +410,4 @@ SchemaValidator::isOccurrenceRangeOK(const int min1, const int max1, return false; } -inline void SchemaValidator::setErrorHandler(ErrorHandler* const handler) { - - fSchemaErrorReporter.setErrorHandler(handler); -} - -inline void SchemaValidator::setExitOnFirstFatal(const bool newValue) { - - fSchemaErrorReporter.setExitOnFirstFatal(newValue); -} - #endif diff --git a/src/xercesc/validators/schema/TraverseSchema.cpp b/src/xercesc/validators/schema/TraverseSchema.cpp index 6addbee14c3c1b6082c387f0e5878208c5127365..2a245e019e40ebbed151fd09f6aa72b5bd93e391 100644 --- a/src/xercesc/validators/schema/TraverseSchema.cpp +++ b/src/xercesc/validators/schema/TraverseSchema.cpp @@ -62,7 +62,7 @@ // Includes // --------------------------------------------------------------------------- #include <xercesc/validators/schema/TraverseSchema.hpp> -#include <xercesc/sax/EntityResolver.hpp> +#include <xercesc/framework/XMLEntityHandler.hpp> #include <xercesc/validators/schema/identity/IC_Key.hpp> #include <xercesc/validators/schema/identity/IC_KeyRef.hpp> #include <xercesc/validators/schema/identity/IC_Unique.hpp> @@ -80,7 +80,6 @@ #include <xercesc/validators/schema/NamespaceScope.hpp> #include <xercesc/validators/schema/SchemaAttDefList.hpp> #include <xercesc/internal/XMLScanner.hpp> -#include <xercesc/internal/XMLInternalErrorHandler.hpp> #include <xercesc/framework/LocalFileInputSource.hpp> #include <xercesc/framework/URLInputSource.hpp> #include <xercesc/validators/schema/identity/XPathException.hpp> @@ -185,8 +184,8 @@ TraverseSchema::TraverseSchema( DOMElement* const schemaRoot , XMLScanner* const xmlScanner , XMLValidator* const xmlValidator , const XMLCh* const schemaURL - , EntityResolver* const entityResolver - , ErrorHandler* const errorHandler) + , XMLEntityHandler* const entityHandler + , XMLErrorReporter* const errorReporter) : fFullConstraintChecking(false) , fTargetNSURI(-1) , fEmptyNamespaceURI(-1) @@ -198,8 +197,8 @@ TraverseSchema::TraverseSchema( DOMElement* const schemaRoot , fDatatypeRegistry(0) , fGrammarResolver(grammarResolver) , fSchemaGrammar(schemaGrammar) - , fEntityResolver(entityResolver) - , fErrorHandler(errorHandler) + , fEntityHandler(entityHandler) + , fErrorReporter(errorReporter) , fURIStringPool(uriStringPool) , fStringPool(0) , fValidator(xmlValidator) @@ -406,12 +405,12 @@ void TraverseSchema::traverseSchemaHeader(const DOMElement* const schemaRoot) { elemAttrDefaultQualified |= Elem_Def_Qualified; } - if (!XMLString::compareString(schemaRoot->getAttribute(SchemaSymbols::fgATT_ATTRIBUTEFORMDEFAULT), + if (!XMLString::compareString(schemaRoot->getAttribute(SchemaSymbols::fgATT_ATTRIBUTEFORMDEFAULT), SchemaSymbols::fgATTVAL_QUALIFIED)) { elemAttrDefaultQualified |= Attr_Def_Qualified; } - fSchemaInfo->setElemAttrDefaultQualified(elemAttrDefaultQualified); + fSchemaInfo->setElemAttrDefaultQualified(elemAttrDefaultQualified); fSchemaInfo->setBlockDefault(parseBlockSet(schemaRoot, ES_Block, true)); fSchemaInfo->setFinalDefault(parseFinalSet(schemaRoot, ECS_Final, true)); } @@ -503,26 +502,24 @@ void TraverseSchema::preprocessInclude(const DOMElement* const elem) { // ------------------------------------------------------------------ // Parse input source // ------------------------------------------------------------------ - XMLInternalErrorHandler internalErrorHandler(fErrorHandler); - if (!fParser) fParser = new XSDDOMParser; fParser->setValidationScheme(XercesDOMParser::Val_Never); fParser->setDoNamespaces(true); - fParser->setErrorHandler((ErrorHandler*) &internalErrorHandler); - fParser->setEntityResolver(fEntityResolver); + fParser->setUserEntityHandler(fEntityHandler); + fParser->setUserErrorReporter(fErrorReporter); // Should just issue warning if the schema is not found const bool flag = srcToFill->getIssueFatalErrorIfNotFound(); srcToFill->setIssueFatalErrorIfNotFound(false); - fParser->parse(*srcToFill) ; + fParser->parse(*srcToFill); // Reset the InputSource srcToFill->setIssueFatalErrorIfNotFound(flag); - if (internalErrorHandler.getSawFatal() && fScanner->getExitOnFirstFatal()) + if (fParser->getSawFatal() && fScanner->getExitOnFirstFatal()) reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::SchemaScanFatalError); // ------------------------------------------------------------------ @@ -685,15 +682,13 @@ void TraverseSchema::preprocessImport(const DOMElement* const elem) { // ------------------------------------------------------------------ // Parse input source // ------------------------------------------------------------------ - XMLInternalErrorHandler internalErrorHandler(fErrorHandler); - if (!fParser) fParser = new XSDDOMParser; fParser->setValidationScheme(XercesDOMParser::Val_Never); fParser->setDoNamespaces(true); - fParser->setErrorHandler((ErrorHandler*) &internalErrorHandler); - fParser->setEntityResolver(fEntityResolver); + fParser->setUserEntityHandler(fEntityHandler); + fParser->setUserErrorReporter(fErrorReporter); // Should just issue warning if the schema is not found const bool flag = srcToFill->getIssueFatalErrorIfNotFound(); @@ -704,7 +699,7 @@ void TraverseSchema::preprocessImport(const DOMElement* const elem) { // Reset the InputSource srcToFill->setIssueFatalErrorIfNotFound(flag); - if (internalErrorHandler.getSawFatal() && fScanner->getExitOnFirstFatal()) + if (fParser->getSawFatal() && fScanner->getExitOnFirstFatal()) reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::SchemaScanFatalError); // ------------------------------------------------------------------ @@ -970,7 +965,7 @@ int TraverseSchema::traverseSimpleTypeDecl(const DOMElement* const childElem, // Process contents // ------------------------------------------------------------------ const XMLCh* name = getElementAttValue(childElem,SchemaSymbols::fgATT_NAME); - bool nameEmpty = (XMLString::stringLen(name) == 0); + bool nameEmpty = (XMLString::stringLen(name) == 0); if (topLevel && nameEmpty) { reportSchemaError(childElem, XMLUni::fgXMLErrDomain, XMLErrs::NoNameGlobalElement, @@ -1416,7 +1411,7 @@ TraverseSchema::traverseGroupDecl(const DOMElement* const elem, fBuffer.set(fullName); fBuffer.append(SchemaSymbols::fgRedefIdentifier); - groupInfo->setBaseGroup(fGroupRegistry->get(fBuffer.getRawBuffer())); + groupInfo->setBaseGroup(fGroupRegistry->get(fBuffer.getRawBuffer())); } } @@ -2656,7 +2651,7 @@ const XMLCh* TraverseSchema::traverseNotationDecl(const DOMElement* const elem) reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::Notation_InvalidDecl, name); } - fNotationRegistry->put((void*) fStringPool->getValueForId(fStringPool->addOrFind(name)), + fNotationRegistry->put((void*) fStringPool->getValueForId(fStringPool->addOrFind(name)), fTargetNSURI, 0); //we don't really care if something inside <notation> is wrong.. @@ -3331,7 +3326,7 @@ void TraverseSchema::traverseSimpleContentDecl(const XMLCh* const typeName, } else { - const XMLCh* facetNameStr = + const XMLCh* facetNameStr = fStringPool->getValueForId(fStringPool->addOrFind(facetName)); facets->put((void*) facetNameStr, new KVStringPair(facetNameStr, attValue)); @@ -3918,7 +3913,7 @@ bool TraverseSchema::traverseIdentityConstraint(IdentityConstraint* const ic, fBuffer.reset(); unsigned int startIndex = 0; - + while (startIndex < xpathLen) { if (!XMLString::startsWith(xpathExpr + startIndex, fgForwardSlash) @@ -3932,7 +3927,7 @@ bool TraverseSchema::traverseIdentityConstraint(IdentityConstraint* const ic, break; fBuffer.append(xpathExpr + startIndex, chOffset + 1 - startIndex); - startIndex = chOffset + 1; + startIndex = chOffset + 1; } if (startIndex < xpathLen) @@ -5458,7 +5453,7 @@ void TraverseSchema::processComplexContent(const DOMElement* const ctElem, } // Check for derivation valid (extension) - 1.4.2.2 - if (baseContentType != SchemaElementDecl::Empty + if (baseContentType != SchemaElementDecl::Empty && baseContentType != SchemaElementDecl::Simple) { if ((isMixed && baseContentType == SchemaElementDecl::Children) || (!isMixed && baseContentType != SchemaElementDecl::Children)) { @@ -6090,9 +6085,8 @@ InputSource* TraverseSchema::resolveSchemaLocation(const XMLCh* const loc) { // ------------------------------------------------------------------ InputSource* srcToFill = 0; - if (fEntityResolver){ - srcToFill = fEntityResolver->resolveEntity(XMLUni::fgZeroLenString, - loc); + if (fEntityHandler){ + srcToFill = fEntityHandler->resolveEntity(XMLUni::fgZeroLenString, loc); } // If they didn't create a source via the entity resolver, then we @@ -7218,15 +7212,13 @@ bool TraverseSchema::openRedefinedSchema(const DOMElement* const redefineElem) { // ------------------------------------------------------------------ // Parse input source // ------------------------------------------------------------------ - XMLInternalErrorHandler internalErrorHandler(fErrorHandler); - if (!fParser) fParser = new XSDDOMParser; fParser->setValidationScheme(XercesDOMParser::Val_Never); fParser->setDoNamespaces(true); - fParser->setErrorHandler((ErrorHandler*) &internalErrorHandler); - fParser->setEntityResolver(fEntityResolver); + fParser->setUserEntityHandler(fEntityHandler); + fParser->setUserErrorReporter(fErrorReporter); // Should just issue warning if the schema is not found const bool flag = srcToFill->getIssueFatalErrorIfNotFound(); @@ -7237,7 +7229,7 @@ bool TraverseSchema::openRedefinedSchema(const DOMElement* const redefineElem) { // Reset the InputSource srcToFill->setIssueFatalErrorIfNotFound(flag); - if (internalErrorHandler.getSawFatal() && fScanner->getExitOnFirstFatal()) + if (fParser->getSawFatal() && fScanner->getExitOnFirstFatal()) reportSchemaError(redefineElem, XMLUni::fgXMLErrDomain, XMLErrs::SchemaScanFatalError); // ------------------------------------------------------------------ @@ -7666,7 +7658,7 @@ void TraverseSchema::reportSchemaError(const XSDLocator* const aLocator, const XMLCh* const msgDomain, const int errorCode) { - fErrorReporter.emitError(errorCode, msgDomain, aLocator); + fXSDErrorReporter.emitError(errorCode, msgDomain, aLocator); } void TraverseSchema::reportSchemaError(const XSDLocator* const aLocator, @@ -7677,7 +7669,7 @@ void TraverseSchema::reportSchemaError(const XSDLocator* const aLocator, const XMLCh* const text3, const XMLCh* const text4) { - fErrorReporter.emitError(errorCode, msgDomain, aLocator, text1, text2, text3, text4); + fXSDErrorReporter.emitError(errorCode, msgDomain, aLocator, text1, text2, text3, text4); } void TraverseSchema::reportSchemaError(const DOMElement* const elem, @@ -7688,7 +7680,7 @@ void TraverseSchema::reportSchemaError(const DOMElement* const elem, ((XSDElementNSImpl*) elem)->getLineNo(), ((XSDElementNSImpl*) elem)->getColumnNo()); - fErrorReporter.emitError(errorCode, msgDomain, fLocator); + fXSDErrorReporter.emitError(errorCode, msgDomain, fLocator); } void TraverseSchema::reportSchemaError(const DOMElement* const elem, @@ -7703,7 +7695,7 @@ void TraverseSchema::reportSchemaError(const DOMElement* const elem, ((XSDElementNSImpl*) elem)->getLineNo(), ((XSDElementNSImpl*) elem)->getColumnNo()); - fErrorReporter.emitError(errorCode, msgDomain, fLocator, text1, text2, text3, text4); + fXSDErrorReporter.emitError(errorCode, msgDomain, fLocator, text1, text2, text3, text4); } // --------------------------------------------------------------------------- @@ -7711,12 +7703,12 @@ void TraverseSchema::reportSchemaError(const DOMElement* const elem, // --------------------------------------------------------------------------- void TraverseSchema::init() { - fErrorReporter.setErrorHandler(fErrorHandler); + fXSDErrorReporter.setErrorReporter(fErrorReporter); if (fScanner && fScanner->getValidationSchemaFullChecking()) { fFullConstraintChecking = true; - fErrorReporter.setExitOnFirstFatal(fScanner->getExitOnFirstFatal()); + fXSDErrorReporter.setExitOnFirstFatal(fScanner->getExitOnFirstFatal()); } fDatatypeRegistry = fGrammarResolver->getDatatypeRegistry(); diff --git a/src/xercesc/validators/schema/TraverseSchema.hpp b/src/xercesc/validators/schema/TraverseSchema.hpp index aa4f503925b5e383999507489734a5b68425a93a..e82ed8462b66a8cd9d2d8a214533baf6bd5d521c 100644 --- a/src/xercesc/validators/schema/TraverseSchema.hpp +++ b/src/xercesc/validators/schema/TraverseSchema.hpp @@ -87,7 +87,7 @@ // Forward Declarations // --------------------------------------------------------------------------- class GrammarResolver; -class EntityResolver; +class XMLEntityHandler; class XMLValidator; class XMLScanner; class DatatypeValidator; @@ -98,13 +98,12 @@ class XMLAttDef; class NamespaceScope; class SchemaAttDef; class InputSource; -class ErrorHandler; class XercesGroupInfo; class XercesAttGroupInfo; class IdentityConstraint; -class XercesDOMParser; class XSDLocator; class XSDDOMParser; +class XMLErrorReporter; class VALIDATORS_EXPORT TraverseSchema @@ -122,8 +121,8 @@ public: , XMLScanner* const xmlScanner , XMLValidator* const xmlValidator , const XMLCh* const schemaURL - , EntityResolver* const entityResolver - , ErrorHandler* const errorHandler + , XMLEntityHandler* const entityHandler + , XMLErrorReporter* const errorReporter ); ~TraverseSchema(); @@ -241,7 +240,7 @@ private: const int errorCode); void reportSchemaError(const XSDLocator* const aLocator, const XMLCh* const msgDomain, - const int errorCode, + const int errorCode, const XMLCh* const text1, const XMLCh* const text2 = 0, const XMLCh* const text3 = 0, @@ -251,7 +250,7 @@ private: const int errorCode); void reportSchemaError(const DOMElement* const elem, const XMLCh* const msgDomain, - const int errorCode, + const int errorCode, const XMLCh* const text1, const XMLCh* const text2 = 0, const XMLCh* const text3 = 0, @@ -280,13 +279,13 @@ private: * Parameters: * rootElem - top element for a given type declaration * contentElem - content must be annotation? or some other simple content - * isEmpty: - true if (annotation?, smth_else), false if (annotation?) + * isEmpty: - true if (annotation?, smth_else), false if (annotation?) * * Check for Annotation if it is present, traverse it. If a sibling is * found and it is not an annotation return it, otherwise return 0. * Used by traverseSimpleTypeDecl. */ - DOMElement* checkContent(const DOMElement* const rootElem, + DOMElement* checkContent(const DOMElement* const rootElem, DOMElement* const contentElem, const bool isEmpty); @@ -571,7 +570,7 @@ private: * Attribute wild card intersection. * * Note: - * The first parameter will be the result of the intersection, so + * The first parameter will be the result of the intersection, so * we need to make sure that first parameter is a copy of the * actual attribute definition we need to intersect with. * @@ -585,7 +584,7 @@ private: * Attribute wild card union. * * Note: - * The first parameter will be the result of the union, so + * The first parameter will be the result of the union, so * we need to make sure that first parameter is a copy of the * actual attribute definition we need to intersect with. * @@ -654,12 +653,12 @@ private: SchemaInfo* const redefiningSchemaInfo); /** - * This function looks among the children of 'redefineChildElem' for a + * This function looks among the children of 'redefineChildElem' for a * component of type 'redefineChildComponentName'. If it finds one, it * evaluates whether its ref attribute contains a reference to * 'refChildTypeName'. If it does, it returns 1 + the value returned by * calls to itself on all other children. In all other cases it returns - * 0 plus the sum of the values returned by calls to itself on + * 0 plus the sum of the values returned by calls to itself on * redefineChildElem's children. It also resets the value of ref so that * it will refer to the renamed type from the schema being redefined. */ @@ -740,8 +739,8 @@ private: DatatypeValidatorFactory* fDatatypeRegistry; GrammarResolver* fGrammarResolver; SchemaGrammar* fSchemaGrammar; - EntityResolver* fEntityResolver; - ErrorHandler* fErrorHandler; + XMLEntityHandler* fEntityHandler; + XMLErrorReporter* fErrorReporter; XMLStringPool* fURIStringPool; XMLStringPool* fStringPool; XMLBuffer fBuffer; @@ -773,7 +772,7 @@ private: RefHashTableOf<ValueVectorOf<unsigned int> >* fIC_NamespaceDepthNS; XSDDOMParser* fParser; RefHashTableOf<SchemaInfo>* fPreprocessedNodes; - XSDErrorReporter fErrorReporter; + XSDErrorReporter fXSDErrorReporter; XSDLocator* fLocator; friend class GeneralAttributeCheck; @@ -824,7 +823,7 @@ TraverseSchema::isValidRefDeclaration(const DOMElement* const elem) { || XMLString::stringLen(elem->getAttribute(SchemaSymbols::fgATT_BLOCK)) != 0 || XMLString::stringLen(elem->getAttribute(SchemaSymbols::fgATT_FINAL)) != 0 || XMLString::stringLen(elem->getAttribute(SchemaSymbols::fgATT_TYPE)) != 0 - || XMLString::stringLen(elem->getAttribute(SchemaSymbols::fgATT_DEFAULT)) != 0 + || XMLString::stringLen(elem->getAttribute(SchemaSymbols::fgATT_DEFAULT)) != 0 || XMLString::stringLen(elem->getAttribute(SchemaSymbols::fgATT_FIXED)) != 0 || XMLString::stringLen(elem->getAttribute(SchemaSymbols::fgATT_SUBSTITUTIONGROUP)) != 0); } @@ -858,7 +857,7 @@ const XMLCh* TraverseSchema::getElementAttValue(const DOMElement* const elem, return attValue; } -inline const XMLCh* +inline const XMLCh* TraverseSchema::getTargetNamespaceString(const DOMElement* const elem) { const XMLCh* targetNS = getElementAttValue(elem, SchemaSymbols::fgATT_TARGETNAMESPACE); @@ -875,7 +874,7 @@ inline bool TraverseSchema::isBaseFromAnotherSchema(const XMLCh* const baseURI) if (XMLString::compareString(baseURI,fTargetNSURIString) != 0 && XMLString::compareString(baseURI, SchemaSymbols::fgURI_SCHEMAFORSCHEMA) != 0 && XMLString::stringLen(baseURI) != 0) { - //REVISIT, !!!! a hack: for schema that has no + //REVISIT, !!!! a hack: for schema that has no //target namespace, e.g. personal-schema.xml return true; } @@ -918,7 +917,7 @@ inline int TraverseSchema::resetCurrentTypeNameStack(const int value) { return value; } -inline void +inline void TraverseSchema::copyWildCardData(const SchemaAttDef* const srcWildCard, SchemaAttDef* const destWildCard) { diff --git a/src/xercesc/validators/schema/XSDDOMParser.cpp b/src/xercesc/validators/schema/XSDDOMParser.cpp index fc942a456bd73d62c7972c427f5b6a8076f678ca..252bb9e254d2df5cfaf11a3dda50247ab48cc2b9 100644 --- a/src/xercesc/validators/schema/XSDDOMParser.cpp +++ b/src/xercesc/validators/schema/XSDDOMParser.cpp @@ -73,6 +73,8 @@ // --------------------------------------------------------------------------- XSDDOMParser::XSDDOMParser(XMLValidator* const valToAdopt) : XercesDOMParser(valToAdopt) + , fSawFatal(false) + , fUserErrorReporter(0) { } @@ -87,11 +89,56 @@ XSDDOMParser::~XSDDOMParser() // XSDDOMParser: Helper methods // --------------------------------------------------------------------------- DOMElement* XSDDOMParser::createElementNSNode(const XMLCh *namespaceURI, - const XMLCh *qualifiedName) + const XMLCh *qualifiedName) { ReaderMgr::LastExtEntityInfo lastInfo; - ((ReaderMgr*) fScanner->getLocator())->getLastExtEntityInfo(lastInfo); + ((ReaderMgr*) getScanner()->getLocator())->getLastExtEntityInfo(lastInfo); return getDocument()->createElementNS(namespaceURI, qualifiedName, lastInfo.lineNumber, lastInfo.colNumber); } + + +// --------------------------------------------------------------------------- +// XSDDOMParser: Setter methods +// --------------------------------------------------------------------------- +inline void XSDDOMParser::setUserErrorReporter(XMLErrorReporter* const errorReporter) +{ + fUserErrorReporter = errorReporter; + getScanner()->setErrorReporter(this); +} + +inline void XSDDOMParser::setUserEntityHandler(XMLEntityHandler* const entityHandler) +{ + fUserEntityHandler = entityHandler; + getScanner()->setEntityHandler(this); +} + +// --------------------------------------------------------------------------- +// XSDDOMParser: Implementation of the XMLErrorReporter interface +// --------------------------------------------------------------------------- +void XSDDOMParser::error(const unsigned int code + , const XMLCh* const msgDomain + , const XMLErrorReporter::ErrTypes errType + , const XMLCh* const errorText + , const XMLCh* const systemId + , const XMLCh* const publicId + , const unsigned int lineNum + , const unsigned int colNum) +{ + if (errType >= XMLErrorReporter::ErrType_Fatal) + fSawFatal = true; + + if (fUserErrorReporter) + fUserErrorReporter->error(code, msgDomain, errType, errorText, + systemId, publicId, lineNum, colNum); +} + +InputSource* XSDDOMParser::resolveEntity(const XMLCh* const publicId, + const XMLCh* const systemId) +{ + if (fUserEntityHandler) + return fUserEntityHandler->resolveEntity(publicId, systemId); + + return 0; +} \ No newline at end of file diff --git a/src/xercesc/validators/schema/XSDDOMParser.hpp b/src/xercesc/validators/schema/XSDDOMParser.hpp index 5aa385041139b685b2e443905602810eed771daa..12c927822683bd7b5efeff4985a5eebe398f6f0e 100644 --- a/src/xercesc/validators/schema/XSDDOMParser.hpp +++ b/src/xercesc/validators/schema/XSDDOMParser.hpp @@ -101,12 +101,62 @@ public : //@} + + // ----------------------------------------------------------------------- + // Get methods + // ----------------------------------------------------------------------- + bool getSawFatal() const; + + + // ----------------------------------------------------------------------- + // Set methods + // ----------------------------------------------------------------------- + void setUserErrorReporter(XMLErrorReporter* const errorReporter); + void setUserEntityHandler(XMLEntityHandler* const entityHandler); + + + // ----------------------------------------------------------------------- + // XMLErrorReporter interface + // ----------------------------------------------------------------------- + virtual void error + ( + const unsigned int errCode + , const XMLCh* const errDomain + , const ErrTypes type + , const XMLCh* const errorText + , const XMLCh* const systemId + , const XMLCh* const publicId + , const unsigned int lineNum + , const unsigned int colNum + ); + + // ----------------------------------------------------------------------- + // XMLEntityHandler interface + // ----------------------------------------------------------------------- + virtual InputSource* resolveEntity + ( + const XMLCh* const publicId + , const XMLCh* const systemId + ); + protected : // ----------------------------------------------------------------------- // Protected Helper methods // ----------------------------------------------------------------------- virtual DOMElement* createElementNSNode(const XMLCh *fNamespaceURI, - const XMLCh *qualifiedName); + const XMLCh *qualifiedName); + +private: + bool fSawFatal; + XMLErrorReporter* fUserErrorReporter; + XMLEntityHandler* fUserEntityHandler; }; + +inline bool XSDDOMParser::getSawFatal() const +{ + return fSawFatal; +} + + #endif diff --git a/src/xercesc/validators/schema/XSDErrorReporter.cpp b/src/xercesc/validators/schema/XSDErrorReporter.cpp index c9beaaf1fb39ba422ef7012fefb27dbf0dc44a12..4fe2da4be3f4a3b972ebe22562d0a22708698669 100644 --- a/src/xercesc/validators/schema/XSDErrorReporter.cpp +++ b/src/xercesc/validators/schema/XSDErrorReporter.cpp @@ -56,6 +56,13 @@ /** * $Log$ + * Revision 1.2 2002/05/22 20:54:14 knoaman + * Prepare for DOM L3 : + * - Make use of the XMLEntityHandler/XMLErrorReporter interfaces, instead of using + * EntityHandler/ErrorHandler directly. + * - Add 'AbstractDOMParser' class to provide common functionality for XercesDOMParser + * and DOMBuilder. + * * Revision 1.1 2002/03/21 15:34:40 knoaman * Add support for reporting line/column numbers of schema errors. * @@ -67,10 +74,10 @@ // --------------------------------------------------------------------------- #include <xercesc/util/Mutexes.hpp> #include <xercesc/util/PlatformUtils.hpp> -#include <xercesc/sax/SAXParseException.hpp> -#include <xercesc/sax/ErrorHandler.hpp> +#include <xercesc/util/XMLString.hpp> #include <xercesc/framework/XMLErrorCodes.hpp> #include <xercesc/framework/XMLValidityCodes.hpp> +#include <xercesc/framework/XMLErrorReporter.hpp> #include <xercesc/util/XMLRegisterCleanup.hpp> #include <xercesc/validators/schema/XSDErrorReporter.hpp> #include <xercesc/validators/schema/XSDLocator.hpp> @@ -137,9 +144,9 @@ static XMLMutex& gErrMsgMutex() // --------------------------------------------------------------------------- // XSDErrorReporter: Constructors and Destructor // --------------------------------------------------------------------------- -XSDErrorReporter::XSDErrorReporter(ErrorHandler* const handler) : +XSDErrorReporter::XSDErrorReporter(XMLErrorReporter* const errorReporter) : fExitOnFirstFatal(false) - , fErrorHandler(handler) + , fErrorReporter(errorReporter) { // @@ -170,47 +177,6 @@ XSDErrorReporter::XSDErrorReporter(ErrorHandler* const handler) : } -// --------------------------------------------------------------------------- -// XSDErrorReporter: Error Handler -// --------------------------------------------------------------------------- -void XSDErrorReporter::error(const unsigned int errCode, - const XMLCh* const errDomain, - const ErrTypes errType, - const XMLCh* const errorText, - const XMLCh* const systemId, - const XMLCh* const publicId, - const unsigned int lineNum, - const unsigned int colNum) -{ - SAXParseException toThrow = SAXParseException - ( - errorText - , publicId - , systemId - , lineNum - , colNum - ); - - // - // If there is an error handler registered, call it, otherwise ignore - // all but the fatal errors. - // - if (!fErrorHandler) - { - if (errType == XMLErrorReporter::ErrType_Fatal) - throw toThrow; - return; - } - - if (errType == XMLErrorReporter::ErrType_Warning) - fErrorHandler->warning(toThrow); - else if (errType >= XMLErrorReporter::ErrType_Fatal) - fErrorHandler->fatalError(toThrow); - else - fErrorHandler->error(toThrow); -} - - // --------------------------------------------------------------------------- // XSDErrorReporter: Error reporting // --------------------------------------------------------------------------- @@ -229,7 +195,7 @@ void XSDErrorReporter::emitError(const unsigned int toEmit, const unsigned int msgSize = 1023; XMLCh errText[msgSize + 1]; XMLMsgLoader* msgLoader = gErrMsgLoader; - ErrTypes errType = XMLErrs::errorType((XMLErrs::Codes) toEmit); + XMLErrorReporter::ErrTypes errType = XMLErrs::errorType((XMLErrs::Codes) toEmit); if (!XMLString::compareString(msgDomain, XMLUni::fgValidityDomain)) { @@ -247,9 +213,10 @@ void XSDErrorReporter::emitError(const unsigned int toEmit, } } - error(toEmit, msgDomain, errType, errText, aLocator->getSystemId(), - aLocator->getPublicId(), aLocator->getLineNumber(), - aLocator->getColumnNumber()); + if (fErrorReporter) + fErrorReporter->error(toEmit, msgDomain, errType, errText, aLocator->getSystemId(), + aLocator->getPublicId(), aLocator->getLineNumber(), + aLocator->getColumnNumber()); // Bail out if its fatal an we are to give up on the first fatal error if (errType == XMLErrorReporter::ErrType_Fatal && fExitOnFirstFatal) @@ -275,7 +242,7 @@ void XSDErrorReporter::emitError(const unsigned int toEmit, const unsigned int maxChars = 2047; XMLCh errText[maxChars + 1]; XMLMsgLoader* msgLoader = gErrMsgLoader; - ErrTypes errType = XMLErrs::errorType((XMLErrs::Codes) toEmit); + XMLErrorReporter::ErrTypes errType = XMLErrs::errorType((XMLErrs::Codes) toEmit); if (!XMLString::compareString(msgDomain, XMLUni::fgValidityDomain)) { @@ -293,9 +260,10 @@ void XSDErrorReporter::emitError(const unsigned int toEmit, } } - error(toEmit, msgDomain, errType, errText, aLocator->getSystemId(), - aLocator->getPublicId(), aLocator->getLineNumber(), - aLocator->getColumnNumber()); + if (fErrorReporter) + fErrorReporter->error(toEmit, msgDomain, errType, errText, aLocator->getSystemId(), + aLocator->getPublicId(), aLocator->getLineNumber(), + aLocator->getColumnNumber()); // Bail out if its fatal an we are to give up on the first fatal error if (errType == XMLErrorReporter::ErrType_Fatal && fExitOnFirstFatal) diff --git a/src/xercesc/validators/schema/XSDErrorReporter.hpp b/src/xercesc/validators/schema/XSDErrorReporter.hpp index 7eed6ec76e1f55d81c768c6e89deae13170f3727..16446a771b9ee2a00e2b9a4c7340758d048da91e 100644 --- a/src/xercesc/validators/schema/XSDErrorReporter.hpp +++ b/src/xercesc/validators/schema/XSDErrorReporter.hpp @@ -62,23 +62,21 @@ #if !defined(XSDERRORREPORTER_HPP) #define XSDERRORREPORTER_HPP -#include <xercesc/framework/XMLErrorReporter.hpp> - class Locator; -class ErrorHandler; +class XMLErrorReporter; /** * This class reports schema errors */ -class VALIDATORS_EXPORT XSDErrorReporter: public XMLErrorReporter +class VALIDATORS_EXPORT XSDErrorReporter { public: // ----------------------------------------------------------------------- // Constructors are hidden, only the virtual destructor is exposed // ----------------------------------------------------------------------- - XSDErrorReporter(ErrorHandler* const handler = 0); + XSDErrorReporter(XMLErrorReporter* const errorReporter = 0); virtual ~XSDErrorReporter() { @@ -92,26 +90,9 @@ public: // ----------------------------------------------------------------------- // Setter methods // ----------------------------------------------------------------------- - void setErrorHandler(ErrorHandler* const handler); + void setErrorReporter(XMLErrorReporter* const errorReporter); void setExitOnFirstFatal(const bool newValue); - // ----------------------------------------------------------------------- - // The error handler interface - // ----------------------------------------------------------------------- - virtual void error - ( - const unsigned int errCode - , const XMLCh* const errDomain - , const ErrTypes type - , const XMLCh* const errorText - , const XMLCh* const systemId - , const XMLCh* const publicId - , const unsigned int lineNum - , const unsigned int colNum - ); - - virtual void resetErrors(); - // ----------------------------------------------------------------------- // Notification that lazy data has been deleted // ----------------------------------------------------------------------- @@ -142,8 +123,8 @@ private: // ----------------------------------------------------------------------- // Private data members // ----------------------------------------------------------------------- - bool fExitOnFirstFatal; - ErrorHandler* fErrorHandler; + bool fExitOnFirstFatal; + XMLErrorReporter* fErrorReporter; }; @@ -163,16 +144,9 @@ inline void XSDErrorReporter::setExitOnFirstFatal(const bool newValue) fExitOnFirstFatal = newValue; } -inline void XSDErrorReporter::setErrorHandler(ErrorHandler* const handler) -{ - fErrorHandler = handler; -} - -// --------------------------------------------------------------------------- -// XSDErrorReporter: Error Handler -// --------------------------------------------------------------------------- -inline void XSDErrorReporter::resetErrors() +inline void XSDErrorReporter::setErrorReporter(XMLErrorReporter* const errorReporter) { + fErrorReporter = errorReporter; }