You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by kn...@apache.org on 2003/10/30 22:37:32 UTC
cvs commit: xml-xerces/c/src/xercesc/validators/schema TraverseSchema.cpp TraverseSchema.hpp
knoaman 2003/10/30 13:37:32
Modified: c/src/xercesc/dom/deprecated DOMParser.cpp DOMParser.hpp
c/src/xercesc/framework XMLEntityHandler.hpp
c/src/xercesc/internal DGXMLScanner.cpp IGXMLScanner2.cpp
ReaderMgr.cpp SGXMLScanner.cpp XMLScanner.cpp
c/src/xercesc/parsers DOMBuilderImpl.cpp DOMBuilderImpl.hpp
SAX2XMLReaderImpl.cpp SAX2XMLReaderImpl.hpp
SAXParser.cpp SAXParser.hpp XercesDOMParser.cpp
XercesDOMParser.hpp
c/src/xercesc/util Makefile.in
c/src/xercesc/validators/schema TraverseSchema.cpp
TraverseSchema.hpp
Added: c/src/xercesc/util XMLEntityResolver.hpp
XMLResourceIdentifier.hpp
Log:
Enhanced Entity Resolver Support. Thanks to David Cargill.
Revision Changes Path
1.27 +29 -2 xml-xerces/c/src/xercesc/dom/deprecated/DOMParser.cpp
Index: DOMParser.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/deprecated/DOMParser.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- DOMParser.cpp 1 Oct 2003 16:32:37 -0000 1.26
+++ DOMParser.cpp 30 Oct 2003 21:37:31 -0000 1.27
@@ -97,6 +97,7 @@
#include <xercesc/validators/common/ContentSpecNode.hpp>
#include <xercesc/validators/DTD/DTDAttDefList.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
+#include <xercesc/util/XMLEntityResolver.hpp>
XERCES_CPP_NAMESPACE_BEGIN
@@ -114,6 +115,7 @@
, fParseInProgress(false)
, fWithinElement(false)
, fEntityResolver(0)
+ , fXMLEntityResolver(0)
, fErrorHandler(0)
, fNodeStack(0)
, fScanner(0)
@@ -322,6 +324,19 @@
fEntityResolver = handler;
if (fEntityResolver) {
fScanner->setEntityHandler(this);
+ fXMLEntityResolver = 0;
+ }
+ else {
+ fScanner->setEntityHandler(0);
+ }
+}
+
+void DOMParser::setXMLEntityResolver(XMLEntityResolver* const handler)
+{
+ fXMLEntityResolver = handler;
+ if (fXMLEntityResolver) {
+ fEntityResolver = 0;
+ fScanner->setEntityHandler(this);
}
else {
fScanner->setEntityHandler(0);
@@ -611,7 +626,19 @@
return 0;
}
-
+InputSource* DOMParser::resolveEntity(XMLResourceIdentifier* resourceIdentifier)
+{
+ //
+ // Just map it to the SAX entity resolver. If there is not one installed,
+ // return a null pointer to cause the default resolution.
+ //
+ if (fEntityResolver)
+ return fEntityResolver->resolveEntity(resourceIdentifier->getPublicId(),
+ resourceIdentifier->getSystemId());
+ if (fXMLEntityResolver)
+ return fXMLEntityResolver->resolveEntity(resourceIdentifier);
+ return 0;
+}
// ---------------------------------------------------------------------------
// DOMParser: Implementation of XMLDocumentHandler interface
1.20 +75 -4 xml-xerces/c/src/xercesc/dom/deprecated/DOMParser.hpp
Index: DOMParser.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/deprecated/DOMParser.hpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- DOMParser.hpp 20 Jun 2003 18:48:37 -0000 1.19
+++ DOMParser.hpp 30 Oct 2003 21:37:31 -0000 1.20
@@ -66,7 +66,6 @@
#include <xercesc/framework/XMLErrorReporter.hpp>
#include <xercesc/framework/XMLEntityHandler.hpp>
#include <xercesc/util/ValueStackOf.hpp>
-
#include <xercesc/validators/DTD/DocTypeHandler.hpp>
#include <xercesc/validators/DTD/DTDElementDecl.hpp>
#include "DOM_Document.hpp"
@@ -83,6 +82,7 @@
class Grammar;
class GrammarResolver;
class XMLGrammarPool;
+class XMLEntityResolver;
/**
* This class implements the Document Object Model (DOM) interface.
@@ -205,6 +205,24 @@
*/
const EntityResolver* getEntityResolver() const;
+ /** Get a pointer to the entity resolver
+ *
+ * This method returns the installed entity resolver. If no resolver
+ * has been installed, then it will be a zero pointer.
+ *
+ * @return The pointer to the installed entity resolver object.
+ */
+ XMLEntityResolver* getXMLEntityResolver();
+
+ /** Get a const pointer to the entity resolver
+ *
+ * This method returns the installed entity resolver. If no resolver
+ * has been installed, then it will be a zero pointer.
+ *
+ * @return A const pointer to the installed entity resolver object.
+ */
+ const XMLEntityResolver* getXMLEntityResolver() const;
+
/** Get a const reference to the underlying scanner
*
* This method returns a reference to the underlying scanner object.
@@ -494,8 +512,9 @@
* can trap and potentially redirect references to external
* entities.
*
- * <i>Any previously set resolver is merely dropped, since the parser
- * does not own them.</i>
+ * <i>Any previously set entity resolver is merely dropped, since the parser
+ * does not own them. If both setEntityResolver and setXMLEntityResolver
+ * are called, then the last one is used.</i>
*
* @param handler A const pointer to the user supplied entity
* resolver.
@@ -504,6 +523,24 @@
*/
void setEntityResolver(EntityResolver* const handler);
+ /** Set the entity resolver
+ *
+ * This method allows applications to install their own entity
+ * resolver. By installing an entity resolver, the applications
+ * can trap and potentially redirect references to external
+ * entities.
+ *
+ * <i>Any previously set entity resolver is merely dropped, since the parser
+ * does not own them. If both setEntityResolver and setXMLEntityResolver
+ * are called, then the last one is used.</i>
+ *
+ * @param handler A const pointer to the user supplied entity
+ * resolver.
+ *
+ * @see #getXMLEntityResolver
+ */
+ void setXMLEntityResolver(XMLEntityResolver* const handler);
+
/** Set the 'do namespaces' flag
*
* This method allows users to enable or disable the parser's
@@ -1230,6 +1267,8 @@
* implement 'redirection' via this callback. This method is also
* borrowed from the SAX specification.
*
+ * @deprecated This method is no longer called (the other resolveEntity one is).
+ *
* @param publicId A const pointer to a Unicode string representing the
* public id of the entity just parsed.
* @param systemId A const pointer to a Unicode string representing the
@@ -1251,6 +1290,27 @@
, const XMLCh* const baseURI = 0
);
+ /** Resolve a public/system id
+ *
+ * This method allows a user installed entity handler to further
+ * process any pointers to external entities. The applications can
+ * implement 'redirection' via this callback.
+ *
+ * @param resourceIdentifier An object containing the type of
+ * resource to be resolved and the associated data members
+ * corresponding to this type.
+ * @return The value returned by the user installed resolveEntity
+ * method or NULL otherwise to indicate no processing was done.
+ * The returned InputSource is owned by the parser which is
+ * responsible to clean up the memory.
+ * @see XMLEntityHandler
+ * @see XMLEntityResolver
+ */
+ virtual InputSource* resolveEntity
+ (
+ XMLResourceIdentifier* resourceIdentifier
+ );
+
/** Handle a 'start input source' event
*
* This method is used to indicate the start of parsing an external
@@ -1753,6 +1813,7 @@
DOM_Node fCurrentNode;
DOM_Document fDocument;
EntityResolver* fEntityResolver;
+ XMLEntityResolver* fXMLEntityResolver;
ErrorHandler* fErrorHandler;
ValueStackOf<DOM_Node>* fNodeStack;
XMLScanner* fScanner;
@@ -1811,6 +1872,16 @@
inline EntityResolver* DOMParser::getEntityResolver()
{
return fEntityResolver;
+}
+
+inline XMLEntityResolver* DOMParser::getXMLEntityResolver()
+{
+ return fXMLEntityResolver;
+}
+
+inline const XMLEntityResolver* DOMParser::getXMLEntityResolver() const
+{
+ return fXMLEntityResolver;
}
inline const EntityResolver* DOMParser::getEntityResolver() const
1.7 +27 -1 xml-xerces/c/src/xercesc/framework/XMLEntityHandler.hpp
Index: XMLEntityHandler.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/framework/XMLEntityHandler.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XMLEntityHandler.hpp 7 Mar 2003 18:08:10 -0000 1.6
+++ XMLEntityHandler.hpp 30 Oct 2003 21:37:31 -0000 1.7
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.7 2003/10/30 21:37:31 knoaman
+ * Enhanced Entity Resolver Support. Thanks to David Cargill.
+ *
* Revision 1.6 2003/03/07 18:08:10 tng
* Return a reference instead of void for operator=
*
@@ -113,7 +116,7 @@
class InputSource;
class XMLBuffer;
-
+class XMLResourceIdentifier;
/**
* This abstract class is a callback mechanism for the scanner. By creating
@@ -187,6 +190,9 @@
* application specific entity resolution. This method is defined
* by SAX 1.0 API.
*
+ * <i>Only one resolveEntity method will be used. If both setEntityResolver and
+ * setXMLEntityResolver are called, then the last one is used.</i>
+ *
* @param publicId A const pointer to a Unicode string representing the
* public id of the entity just parsed.
* @param systemId A const pointer to a Unicode string representing the
@@ -204,6 +210,26 @@
const XMLCh* const publicId
, const XMLCh* const systemId
, const XMLCh* const baseURI = 0
+ ) = 0;
+
+ /**
+ * This method allows the entity handler to provide customized
+ * application specific entity resolution.
+ *
+ * <i>Only one resolveEntity method will be used. If both setEntityResolver and
+ * setXMLEntityResolver are called, then the last one is used.</i>
+ *
+ * @param resourceIdentifier An object containing the type of
+ * resource to be resolved and the associated data members
+ * corresponding to this type.
+ * @return The value returned by the resolveEntity method or
+ * NULL otherwise to indicate no processing was done.
+ * The returned InputSource is owned by the parser which is
+ * responsible to clean up the memory.
+ */
+ virtual InputSource* resolveEntity
+ (
+ XMLResourceIdentifier* resourceIdentifier
) = 0;
/**
1.26 +5 -3 xml-xerces/c/src/xercesc/internal/DGXMLScanner.cpp
Index: DGXMLScanner.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/DGXMLScanner.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- DGXMLScanner.cpp 22 Oct 2003 20:22:30 -0000 1.25
+++ DGXMLScanner.cpp 30 Oct 2003 21:37:31 -0000 1.26
@@ -79,6 +79,7 @@
#include <xercesc/validators/DTD/DTDScanner.hpp>
#include <xercesc/validators/DTD/DTDValidator.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
+#include <xercesc/util/XMLResourceIdentifier.hpp>
XERCES_CPP_NAMESPACE_BEGIN
@@ -2380,8 +2381,9 @@
if (!fEntityHandler->expandSystemId(sysId, expSysId))
expSysId.set(sysId);
- srcToFill = fEntityHandler->resolveEntity( XMLUni::fgZeroLenString
- , expSysId.getRawBuffer());
+ XMLResourceIdentifier resourceIdentifier(XMLResourceIdentifier::ExternalEntity,
+ expSysId.getRawBuffer());
+ srcToFill = fEntityHandler->resolveEntity(&resourceIdentifier);
}
else
{
1.36 +8 -5 xml-xerces/c/src/xercesc/internal/IGXMLScanner2.cpp
Index: IGXMLScanner2.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner2.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- IGXMLScanner2.cpp 9 Oct 2003 19:11:37 -0000 1.35
+++ IGXMLScanner2.cpp 30 Oct 2003 21:37:31 -0000 1.36
@@ -91,6 +91,7 @@
#include <xercesc/validators/schema/identity/XPathMatcherStack.hpp>
#include <xercesc/validators/schema/XSDDOMParser.hpp>
#include <xercesc/validators/schema/identity/ValueStoreCache.hpp>
+#include <xercesc/util/XMLResourceIdentifier.hpp>
XERCES_CPP_NAMESPACE_BEGIN
@@ -1391,8 +1392,9 @@
if (!fEntityHandler->expandSystemId(normalizedURI, expSysId))
expSysId.set(normalizedURI);
- srcToFill = fEntityHandler->resolveEntity( XMLUni::fgZeroLenString
- , expSysId.getRawBuffer());
+ XMLResourceIdentifier resourceIdentifier(XMLResourceIdentifier::SchemaGrammar,
+ expSysId.getRawBuffer(), uri);
+ srcToFill = fEntityHandler->resolveEntity(&resourceIdentifier);
}
else
{
@@ -1566,8 +1568,9 @@
if (!fEntityHandler->expandSystemId(sysId, expSysId))
expSysId.set(sysId);
- srcToFill = fEntityHandler->resolveEntity( XMLUni::fgZeroLenString
- , expSysId.getRawBuffer());
+ XMLResourceIdentifier resourceIdentifier(XMLResourceIdentifier::ExternalEntity,
+ expSysId.getRawBuffer());
+ srcToFill = fEntityHandler->resolveEntity(&resourceIdentifier);
}
else
{
1.18 +8 -11 xml-xerces/c/src/xercesc/internal/ReaderMgr.cpp
Index: ReaderMgr.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/ReaderMgr.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ReaderMgr.cpp 1 Oct 2003 16:32:38 -0000 1.17
+++ ReaderMgr.cpp 30 Oct 2003 21:37:31 -0000 1.18
@@ -79,6 +79,7 @@
#include <xercesc/internal/EndOfEntityException.hpp>
#include <xercesc/internal/ReaderMgr.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
+#include <xercesc/util/XMLResourceIdentifier.hpp>
XERCES_CPP_NAMESPACE_BEGIN
@@ -527,11 +528,9 @@
srcToFill = 0;
if (fEntityHandler)
{
- srcToFill = fEntityHandler->resolveEntity
- (
- pubId
- , expSysId.getRawBuffer()
- );
+ XMLResourceIdentifier resourceIdentifier(XMLResourceIdentifier::ExternalEntity,
+ expSysId.getRawBuffer(), XMLUni::fgZeroLenString, pubId);
+ srcToFill = fEntityHandler->resolveEntity(&resourceIdentifier);
}
//
@@ -637,11 +636,9 @@
srcToFill = 0;
if (fEntityHandler)
{
- srcToFill = fEntityHandler->resolveEntity
- (
- pubId
- , expSysId.getRawBuffer()
- );
+ XMLResourceIdentifier resourceIdentifier(XMLResourceIdentifier::ExternalEntity,
+ expSysId.getRawBuffer(), XMLUni::fgZeroLenString, pubId, baseURI);
+ srcToFill = fEntityHandler->resolveEntity(&resourceIdentifier);
}
//
1.43 +8 -5 xml-xerces/c/src/xercesc/internal/SGXMLScanner.cpp
Index: SGXMLScanner.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/SGXMLScanner.cpp,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- SGXMLScanner.cpp 22 Oct 2003 20:22:30 -0000 1.42
+++ SGXMLScanner.cpp 30 Oct 2003 21:37:31 -0000 1.43
@@ -85,6 +85,7 @@
#include <xercesc/validators/schema/identity/IC_Selector.hpp>
#include <xercesc/validators/schema/identity/ValueStore.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
+#include <xercesc/util/XMLResourceIdentifier.hpp>
XERCES_CPP_NAMESPACE_BEGIN
@@ -3191,8 +3192,9 @@
if (!fEntityHandler->expandSystemId(normalizedURI, expSysId))
expSysId.set(normalizedURI);
- srcToFill = fEntityHandler->resolveEntity( XMLUni::fgZeroLenString
- , expSysId.getRawBuffer());
+ XMLResourceIdentifier resourceIdentifier(XMLResourceIdentifier::SchemaGrammar,
+ expSysId.getRawBuffer(), uri);
+ srcToFill = fEntityHandler->resolveEntity(&resourceIdentifier);
}
else
{
@@ -3343,8 +3345,9 @@
if (!fEntityHandler->expandSystemId(sysId, expSysId))
expSysId.set(sysId);
- srcToFill = fEntityHandler->resolveEntity( XMLUni::fgZeroLenString
- , expSysId.getRawBuffer());
+ XMLResourceIdentifier resourceIdentifier(XMLResourceIdentifier::ExternalEntity,
+ expSysId.getRawBuffer());
+ srcToFill = fEntityHandler->resolveEntity(&resourceIdentifier);
}
else
{
1.50 +5 -2 xml-xerces/c/src/xercesc/internal/XMLScanner.cpp
Index: XMLScanner.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XMLScanner.cpp,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- XMLScanner.cpp 22 Oct 2003 20:22:30 -0000 1.49
+++ XMLScanner.cpp 30 Oct 2003 21:37:31 -0000 1.50
@@ -79,6 +79,7 @@
#include <xercesc/validators/DTD/DocTypeHandler.hpp>
#include <xercesc/validators/common/GrammarResolver.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
+#include <xercesc/util/XMLResourceIdentifier.hpp>
XERCES_CPP_NAMESPACE_BEGIN
@@ -1585,7 +1586,9 @@
InputSource* srcToUse = 0;
if (fEntityHandler){
- srcToUse = fEntityHandler->resolveEntity(XMLUni::fgZeroLenString, systemId);
+ XMLResourceIdentifier resourceIdentifier(XMLResourceIdentifier::ExternalEntity,
+ systemId);
+ srcToUse = fEntityHandler->resolveEntity(&resourceIdentifier);
}
// First we try to parse it as a URL. If that fails, we assume its
1.31 +37 -1 xml-xerces/c/src/xercesc/parsers/DOMBuilderImpl.cpp
Index: DOMBuilderImpl.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/parsers/DOMBuilderImpl.cpp,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- DOMBuilderImpl.cpp 1 Oct 2003 16:32:38 -0000 1.30
+++ DOMBuilderImpl.cpp 30 Oct 2003 21:37:31 -0000 1.31
@@ -83,6 +83,7 @@
#include <xercesc/util/Janitor.hpp>
#include <xercesc/validators/common/GrammarResolver.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
+#include <xercesc/util/XMLEntityResolver.hpp>
XERCES_CPP_NAMESPACE_BEGIN
@@ -100,6 +101,7 @@
, fValidation(false)
, fErrorHandler(0)
, fEntityResolver(0)
+, fXMLEntityResolver(0)
, fFilter(0)
, fCharsetOverridesXMLEncoding(true)
, fUserAdoptsDocument(false)
@@ -133,6 +135,19 @@
fEntityResolver = handler;
if (fEntityResolver) {
getScanner()->setEntityHandler(this);
+ fXMLEntityResolver = 0;
+ }
+ else {
+ getScanner()->setEntityHandler(0);
+ }
+}
+
+void DOMBuilderImpl::setXMLEntityResolver(XMLEntityResolver* const handler)
+{
+ fXMLEntityResolver = handler;
+ if (fXMLEntityResolver) {
+ getScanner()->setEntityHandler(this);
+ fEntityResolver = 0;
}
else {
getScanner()->setEntityHandler(0);
@@ -533,6 +548,27 @@
return new Wrapper4DOMInputSource(is, true, getMemoryManager());
}
+ return 0;
+}
+
+InputSource*
+DOMBuilderImpl::resolveEntity( XMLResourceIdentifier* resourceIdentifier )
+{
+ //
+ // Just map it to the SAX entity resolver. If there is not one installed,
+ // return a null pointer to cause the default resolution.
+ //
+ if (fEntityResolver) {
+ DOMInputSource* is = fEntityResolver->resolveEntity(resourceIdentifier->getPublicId(),
+ resourceIdentifier->getSystemId(),
+ resourceIdentifier->getBaseURI());
+ if (is)
+ return new Wrapper4DOMInputSource(is, true, getMemoryManager());
+ }
+ if (fXMLEntityResolver) {
+ return(fXMLEntityResolver->resolveEntity(resourceIdentifier));
+ }
+
return 0;
}
1.15 +80 -3 xml-xerces/c/src/xercesc/parsers/DOMBuilderImpl.hpp
Index: DOMBuilderImpl.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/parsers/DOMBuilderImpl.hpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- DOMBuilderImpl.hpp 20 Jun 2003 18:55:54 -0000 1.14
+++ DOMBuilderImpl.hpp 30 Oct 2003 21:37:31 -0000 1.15
@@ -70,6 +70,9 @@
XERCES_CPP_NAMESPACE_BEGIN
+class XMLEntityResolver;
+class XMLResourceIdentifier;
+
/**
* Introduced in DOM Level 3
*
@@ -161,6 +164,26 @@
DOMEntityResolver* getEntityResolver();
/**
+ * Get a pointer to the entity resolver
+ *
+ * This method returns the installed entity resolver. If no resolver
+ * has been installed, then it will be a zero pointer.
+ *
+ * @return The pointer to the installed entity resolver object.
+ */
+ XMLEntityResolver* getXMLEntityResolver();
+
+ /**
+ * Get a const pointer to the entity resolver
+ *
+ * This method returns the installed entity resolver. If no resolver
+ * has been installed, then it will be a zero pointer.
+ *
+ * @return A const pointer to the installed entity resolver object.
+ */
+ const XMLEntityResolver* getXMLEntityResolver() const;
+
+ /**
* <p><b>"Experimental - subject to change"</b></p>
*
* Get a const pointer to the entity resolver
@@ -234,8 +257,9 @@
* can trap and potentially redirect references to external
* entities.
*
- * <i>Any previously set resolver is merely dropped, since the parser
- * does not own them.</i>
+ * <i>Any previously set entity resolver is merely dropped, since the parser
+ * does not own them. If both setEntityResolver and setXMLEntityResolver
+ * are called, then the last one is used.</i>
*
* @param handler A const pointer to the user supplied entity
* resolver.
@@ -245,6 +269,25 @@
void setEntityResolver(DOMEntityResolver* const handler);
/**
+ * Set the entity resolver
+ *
+ * This method allows applications to install their own entity
+ * resolver. By installing an entity resolver, the applications
+ * can trap and potentially redirect references to external
+ * entities.
+ *
+ * <i>Any previously set entity resolver is merely dropped, since the parser
+ * does not own them. If both setEntityResolver and setXMLEntityResolver
+ * are called, then the last one is used.</i>
+ *
+ * @param handler A const pointer to the user supplied entity
+ * resolver.
+ *
+ * @see #getXMLEntityResolver
+ */
+ void setXMLEntityResolver(XMLEntityResolver* const handler);
+
+ /**
* <p><b>"Experimental - subject to change"</b></p>
*
* Set the application filter
@@ -770,6 +813,8 @@
* implement 'redirection' via this callback. This method is also
* borrowed from the SAX specification.
*
+ * @deprecated This method is no longer called (the other resolveEntity one is).
+ *
* @param publicId A const pointer to a Unicode string representing the
* public id of the entity just parsed.
* @param systemId A const pointer to a Unicode string representing the
@@ -791,6 +836,27 @@
, const XMLCh* const baseURI = 0
);
+ /** Resolve a public/system id
+ *
+ * This method allows a user installed entity handler to further
+ * process any pointers to external entities. The applications can
+ * implement 'redirection' via this callback.
+ *
+ * @param resourceIdentifier An object containing the type of
+ * resource to be resolved and the associated data members
+ * corresponding to this type.
+ * @return The value returned by the user installed resolveEntity
+ * method or NULL otherwise to indicate no processing was done.
+ * The returned InputSource is owned by the parser which is
+ * responsible to clean up the memory.
+ * @see XMLEntityHandler
+ * @see XMLEntityResolver
+ */
+ virtual InputSource* resolveEntity
+ (
+ XMLResourceIdentifier* resourceIdentifier
+ );
+
/** Handle a 'start input source' event
*
* This method is used to indicate the start of parsing an external
@@ -832,6 +898,7 @@
bool fAutoValidation;
bool fValidation;
DOMEntityResolver* fEntityResolver;
+ XMLEntityResolver* fXMLEntityResolver;
DOMErrorHandler* fErrorHandler;
DOMBuilderFilter* fFilter;
bool fCharsetOverridesXMLEncoding;
@@ -886,6 +953,16 @@
inline const DOMEntityResolver* DOMBuilderImpl::getEntityResolver() const
{
return fEntityResolver;
+}
+
+inline XMLEntityResolver* DOMBuilderImpl::getXMLEntityResolver()
+{
+ return fXMLEntityResolver;
+}
+
+inline const XMLEntityResolver* DOMBuilderImpl::getXMLEntityResolver() const
+{
+ return fXMLEntityResolver;
}
inline DOMBuilderFilter* DOMBuilderImpl::getFilter()
1.29 +32 -0 xml-xerces/c/src/xercesc/parsers/SAX2XMLReaderImpl.cpp
Index: SAX2XMLReaderImpl.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/parsers/SAX2XMLReaderImpl.cpp,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- SAX2XMLReaderImpl.cpp 1 Oct 2003 16:32:38 -0000 1.28
+++ SAX2XMLReaderImpl.cpp 30 Oct 2003 21:37:31 -0000 1.29
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.29 2003/10/30 21:37:31 knoaman
+ * Enhanced Entity Resolver Support. Thanks to David Cargill.
+ *
* Revision 1.28 2003/10/01 16:32:38 neilg
* improve handling of out of memory conditions, bug #23415. Thanks to David Cargill.
*
@@ -306,6 +309,7 @@
#include <xercesc/framework/XMLGrammarPool.hpp>
#include <xercesc/framework/XMLSchemaDescription.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
+#include <xercesc/util/XMLEntityResolver.hpp>
#include <string.h>
XERCES_CPP_NAMESPACE_BEGIN
@@ -333,6 +337,7 @@
, fPrefixCounts(0)
, fDTDHandler(0)
, fEntityResolver(0)
+ , fXMLEntityResolver(0)
, fErrorHandler(0)
, fLexicalHandler(0)
, fDeclHandler(0)
@@ -599,6 +604,19 @@
fEntityResolver = resolver;
if (fEntityResolver) {
fScanner->setEntityHandler(this);
+ fXMLEntityResolver = 0;
+ }
+ else {
+ fScanner->setEntityHandler(0);
+ }
+}
+
+void SAX2XMLReaderImpl::setXMLEntityResolver(XMLEntityResolver* const resolver)
+{
+ fXMLEntityResolver = resolver;
+ if (fXMLEntityResolver) {
+ fScanner->setEntityHandler(this);
+ fEntityResolver = 0;
}
else {
fScanner->setEntityHandler(0);
@@ -1395,7 +1413,21 @@
return 0;
}
+InputSource* SAX2XMLReaderImpl::resolveEntity(XMLResourceIdentifier* resourceIdentifier)
+{
+ //
+ // Just map it to the SAX entity resolver. If there is not one installed,
+ // return a null pointer to cause the default resolution.
+ //
+ if (fEntityResolver)
+ return fEntityResolver->resolveEntity(resourceIdentifier->getPublicId(),
+ resourceIdentifier->getSystemId());
+ if (fXMLEntityResolver)
+ return fXMLEntityResolver->resolveEntity(resourceIdentifier);
+ return 0;
+}
+
void SAX2XMLReaderImpl::startInputSource(const InputSource&)
{
// Nothing to do for this one
1.23 +65 -3 xml-xerces/c/src/xercesc/parsers/SAX2XMLReaderImpl.hpp
Index: SAX2XMLReaderImpl.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/parsers/SAX2XMLReaderImpl.hpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- SAX2XMLReaderImpl.hpp 20 Jun 2003 18:55:54 -0000 1.22
+++ SAX2XMLReaderImpl.hpp 30 Oct 2003 21:37:31 -0000 1.23
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.23 2003/10/30 21:37:31 knoaman
+ * Enhanced Entity Resolver Support. Thanks to David Cargill.
+ *
* Revision 1.22 2003/06/20 18:55:54 peiyongz
* Stateless Grammar Pool :: Part I
*
@@ -246,6 +249,7 @@
class DeclHandler;
class GrammarResolver;
class XMLGrammarPool;
+class XMLResourceIdentifier;
/**
* This class implements the SAX2 'XMLReader' interface and should be
@@ -317,6 +321,13 @@
virtual EntityResolver* getEntityResolver() const ;
/**
+ * This method returns the installed entity resolver.
+ *
+ * @return A pointer to the installed entity resolver object.
+ */
+ virtual XMLEntityResolver* getXMLEntityResolver() const ;
+
+ /**
* This method returns the installed error handler.
*
* @return A pointer to the installed error handler object.
@@ -400,11 +411,33 @@
* in the middle of a parse, and the SAX parser must begin using
* the new resolver immediately.
*
+ * <i>Any previously set entity resolver is merely dropped, since the parser
+ * does not own them. If both setEntityResolver and setXMLEntityResolver
+ * are called, then the last one is used.</i>
+ *
* @param resolver The object for resolving entities.
* @see EntityResolver#EntityResolver
* @see DefaultHandler#DefaultHandler
*/
virtual void setEntityResolver(EntityResolver* const resolver) ;
+
+ /** Set the entity resolver
+ *
+ * This method allows applications to install their own entity
+ * resolver. By installing an entity resolver, the applications
+ * can trap and potentially redirect references to external
+ * entities.
+ *
+ * <i>Any previously set entity resolver is merely dropped, since the parser
+ * does not own them. If both setEntityResolver and setXMLEntityResolver
+ * are called, then the last one is used.</i>
+ *
+ * @param resolver A const pointer to the user supplied entity
+ * resolver.
+ *
+ * @see #getXMLEntityResolver
+ */
+ virtual void setXMLEntityResolver(XMLEntityResolver* const resolver) ;
/**
* Allow an application to register an error event handler.
@@ -1409,6 +1442,8 @@
* can implement 'redirection' via this callback. The driver
* should call the SAX EntityHandler 'resolveEntity' method.
*
+ * @deprecated This method is no longer called (the other resolveEntity one is).
+ *
* @param publicId A const pointer to a Unicode string representing the
* public id of the entity just parsed.
* @param systemId A const pointer to a Unicode string representing the
@@ -1430,6 +1465,27 @@
, const XMLCh* const baseURI = 0
);
+ /** Resolve a public/system id
+ *
+ * This method allows a user installed entity handler to further
+ * process any pointers to external entities. The applications can
+ * implement 'redirection' via this callback.
+ *
+ * @param resourceIdentifier An object containing the type of
+ * resource to be resolved and the associated data members
+ * corresponding to this type.
+ * @return The value returned by the user installed resolveEntity
+ * method or NULL otherwise to indicate no processing was done.
+ * The returned InputSource is owned by the parser which is
+ * responsible to clean up the memory.
+ * @see XMLEntityHandler
+ * @see XMLEntityResolver
+ */
+ virtual InputSource* resolveEntity
+ (
+ XMLResourceIdentifier* resourceIdentifier
+ );
+
/**
* This method is used to indicate the start of parsing an
* external entity file.
@@ -1798,13 +1854,14 @@
unsigned int fElemDepth;
unsigned int fAdvDHCount;
unsigned int fAdvDHListSize;
- VecAttributesImpl fAttrList ;
- ContentHandler* fDocHandler ;
+ VecAttributesImpl fAttrList ;
+ ContentHandler* fDocHandler ;
RefVectorOf<XMLAttr>* fTempAttrVec ;
RefStackOf<XMLBuffer> * fPrefixes ;
ValueStackOf<unsigned int>* fPrefixCounts ;
DTDHandler* fDTDHandler;
EntityResolver* fEntityResolver;
+ XMLEntityResolver* fXMLEntityResolver;
ErrorHandler* fErrorHandler;
LexicalHandler* fLexicalHandler;
DeclHandler* fDeclHandler;
@@ -1815,7 +1872,7 @@
XMLValidator* fValidator;
MemoryManager* fMemoryManager;
XMLGrammarPool* fGrammarPool;
- XMLBufferMgr fStringBuffers;
+ XMLBufferMgr fStringBuffers;
// -----------------------------------------------------------------------
// internal function used to set the state of the parser
@@ -1844,6 +1901,11 @@
inline EntityResolver* SAX2XMLReaderImpl::getEntityResolver() const
{
return fEntityResolver;
+}
+
+inline XMLEntityResolver* SAX2XMLReaderImpl::getXMLEntityResolver() const
+{
+ return fXMLEntityResolver;
}
inline ErrorHandler* SAX2XMLReaderImpl::getErrorHandler() const
1.27 +30 -1 xml-xerces/c/src/xercesc/parsers/SAXParser.cpp
Index: SAXParser.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/parsers/SAXParser.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- SAXParser.cpp 1 Oct 2003 16:32:38 -0000 1.26
+++ SAXParser.cpp 30 Oct 2003 21:37:31 -0000 1.27
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.27 2003/10/30 21:37:31 knoaman
+ * Enhanced Entity Resolver Support. Thanks to David Cargill.
+ *
* Revision 1.26 2003/10/01 16:32:38 neilg
* improve handling of out of memory conditions, bug #23415. Thanks to David Cargill.
*
@@ -268,6 +271,7 @@
#include <xercesc/framework/XMLSchemaDescription.hpp>
#include <xercesc/util/Janitor.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
+#include <xercesc/util/XMLEntityResolver.hpp>
#include <string.h>
XERCES_CPP_NAMESPACE_BEGIN
@@ -287,6 +291,7 @@
, fDocHandler(0)
, fDTDHandler(0)
, fEntityResolver(0)
+ , fXMLEntityResolver(0)
, fErrorHandler(0)
, fAdvDHList(0)
, fScanner(0)
@@ -804,13 +809,24 @@
fEntityResolver = resolver;
if (fEntityResolver) {
fScanner->setEntityHandler(this);
+ fXMLEntityResolver = 0;
}
else {
fScanner->setEntityHandler(0);
}
}
-
+void SAXParser::setXMLEntityResolver(XMLEntityResolver* const resolver)
+{
+ fXMLEntityResolver = resolver;
+ if (fXMLEntityResolver) {
+ fScanner->setEntityHandler(this);
+ fEntityResolver = 0;
+ }
+ else {
+ fScanner->setEntityHandler(0);
+ }
+}
// ---------------------------------------------------------------------------
// SAXParser: Progressive parse methods
@@ -1348,6 +1364,19 @@
// Just map to the SAX entity resolver handler
if (fEntityResolver)
return fEntityResolver->resolveEntity(publicId, systemId);
+ return 0;
+}
+
+
+InputSource*
+SAXParser::resolveEntity( XMLResourceIdentifier* resourceIdentifier )
+{
+ // Just map to the SAX entity resolver handler
+ if (fEntityResolver)
+ return fEntityResolver->resolveEntity(resourceIdentifier->getPublicId(),
+ resourceIdentifier->getSystemId());
+ if (fXMLEntityResolver)
+ return fXMLEntityResolver->resolveEntity(resourceIdentifier);
return 0;
}
1.26 +77 -0 xml-xerces/c/src/xercesc/parsers/SAXParser.hpp
Index: SAXParser.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/parsers/SAXParser.hpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- SAXParser.hpp 20 Oct 2003 13:41:10 -0000 1.25
+++ SAXParser.hpp 30 Oct 2003 21:37:31 -0000 1.26
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.26 2003/10/30 21:37:31 knoaman
+ * Enhanced Entity Resolver Support. Thanks to David Cargill.
+ *
* Revision 1.25 2003/10/20 13:41:10 amassari
* Added getGrammarResolver API
*
@@ -256,6 +259,8 @@
class Grammar;
class GrammarResolver;
class XMLGrammarPool;
+class XMLEntityResolver;
+class XMLResourceIdentifier;
/**
* This class implements the SAX 'Parser' interface and should be
@@ -358,6 +363,22 @@
const EntityResolver* getEntityResolver() const;
/**
+ * This method returns the installed entity resolver. Suitable
+ * for 'lvalue' usages.
+ *
+ * @return The pointer to the installed entity resolver object.
+ */
+ XMLEntityResolver* getXMLEntityResolver();
+
+ /**
+ * This method returns the installed entity resolver. Suitable
+ * for 'rvalue' usages.
+ *
+ * @return A const pointer to the installed entity resolver object.
+ */
+ const XMLEntityResolver* getXMLEntityResolver() const;
+
+ /**
* This method returns the installed error handler. Suitable
* for 'lvalue' usages.
*
@@ -1266,6 +1287,10 @@
* parser. It allows applications to trap and redirect calls to
* external entities.
*
+ * <i>Any previously set entity resolver is merely dropped, since the parser
+ * does not own them. If both setEntityResolver and setXMLEntityResolver
+ * are called, then the last one is used.</i>
+ *
* @param resolver A pointer to the entity resolver to be called
* when the parser comes across references to
* entities in the XML file.
@@ -1273,6 +1298,24 @@
* @see Parser#setEntityResolver
*/
virtual void setEntityResolver(EntityResolver* const resolver);
+
+ /**
+ * This method installs the user specified entity resolver on the
+ * parser. It allows applications to trap and redirect calls to
+ * external entities.
+ *
+ * <i>Any previously set entity resolver is merely dropped, since the parser
+ * does not own them. If both setEntityResolver and setXMLEntityResolver
+ * are called, then the last one is used.</i>
+ *
+ * @param resolver A pointer to the entity resolver to be called
+ * when the parser comes across references to
+ * entities in the XML file.
+ *
+ * @see Parser#setXMLEntityResolver
+ */
+ virtual void setXMLEntityResolver(XMLEntityResolver* const resolver);
+
//@}
@@ -1627,6 +1670,8 @@
* can implement 'redirection' via this callback. The driver
* should call the SAX EntityHandler 'resolveEntity' method.
*
+ * @deprecated This method is no longer called (the other resolveEntity one is).
+ *
* @param publicId A const pointer to a Unicode string representing the
* public id of the entity just parsed.
* @param systemId A const pointer to a Unicode string representing the
@@ -1648,6 +1693,27 @@
, const XMLCh* const baseURI = 0
);
+ /** Resolve a public/system id
+ *
+ * This method allows a user installed entity handler to further
+ * process any pointers to external entities. The applications can
+ * implement 'redirection' via this callback.
+ *
+ * @param resourceIdentifier An object containing the type of
+ * resource to be resolved and the associated data members
+ * corresponding to this type.
+ * @return The value returned by the user installed resolveEntity
+ * method or NULL otherwise to indicate no processing was done.
+ * The returned InputSource is owned by the parser which is
+ * responsible to clean up the memory.
+ * @see XMLEntityHandler
+ * @see XMLEntityResolver
+ */
+ virtual InputSource* resolveEntity
+ (
+ XMLResourceIdentifier* resourceIdentifier
+ );
+
/**
* This method is used to indicate the start of parsing an
* external entity file.
@@ -2036,6 +2102,7 @@
DocumentHandler* fDocHandler;
DTDHandler* fDTDHandler;
EntityResolver* fEntityResolver;
+ XMLEntityResolver* fXMLEntityResolver;
ErrorHandler* fErrorHandler;
XMLDocumentHandler** fAdvDHList;
XMLScanner* fScanner;
@@ -2064,6 +2131,16 @@
inline EntityResolver* SAXParser::getEntityResolver()
{
return fEntityResolver;
+}
+
+inline XMLEntityResolver* SAXParser::getXMLEntityResolver()
+{
+ return fXMLEntityResolver;
+}
+
+inline const XMLEntityResolver* SAXParser::getXMLEntityResolver() const
+{
+ return fXMLEntityResolver;
}
inline const EntityResolver* SAXParser::getEntityResolver() const
1.19 +32 -1 xml-xerces/c/src/xercesc/parsers/XercesDOMParser.cpp
Index: XercesDOMParser.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/parsers/XercesDOMParser.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- XercesDOMParser.cpp 1 Oct 2003 16:32:38 -0000 1.18
+++ XercesDOMParser.cpp 30 Oct 2003 21:37:31 -0000 1.19
@@ -79,6 +79,7 @@
#include <xercesc/framework/XMLSchemaDescription.hpp>
#include <xercesc/util/Janitor.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
+#include <xercesc/util/XMLEntityResolver.hpp>
XERCES_CPP_NAMESPACE_BEGIN
@@ -94,6 +95,7 @@
AbstractDOMParser(valToAdopt, manager, gramPool)
, fErrorHandler(0)
, fEntityResolver(0)
+, fXMLEntityResolver(0)
{
}
@@ -158,6 +160,19 @@
fEntityResolver = handler;
if (fEntityResolver) {
getScanner()->setEntityHandler(this);
+ fXMLEntityResolver = 0;
+ }
+ else {
+ getScanner()->setEntityHandler(0);
+ }
+}
+
+void XercesDOMParser::setXMLEntityResolver(XMLEntityResolver* const handler)
+{
+ fXMLEntityResolver = handler;
+ if (fXMLEntityResolver) {
+ getScanner()->setEntityHandler(this);
+ fEntityResolver = 0;
}
else {
getScanner()->setEntityHandler(0);
@@ -248,6 +263,22 @@
//
if (fEntityResolver)
return fEntityResolver->resolveEntity(publicId, systemId);
+ return 0;
+}
+
+InputSource*
+XercesDOMParser::resolveEntity(XMLResourceIdentifier* resourceIdentifier)
+{
+ //
+ // Just map it to the SAX entity resolver. If there is not one installed,
+ // return a null pointer to cause the default resolution.
+ //
+ if (fEntityResolver)
+ return fEntityResolver->resolveEntity(resourceIdentifier->getPublicId(),
+ resourceIdentifier->getSystemId());
+ if (fXMLEntityResolver)
+ return fXMLEntityResolver->resolveEntity(resourceIdentifier);
+
return 0;
}
1.16 +78 -4 xml-xerces/c/src/xercesc/parsers/XercesDOMParser.hpp
Index: XercesDOMParser.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/parsers/XercesDOMParser.hpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- XercesDOMParser.hpp 20 Jun 2003 18:55:55 -0000 1.15
+++ XercesDOMParser.hpp 30 Oct 2003 21:37:31 -0000 1.16
@@ -71,7 +71,8 @@
class EntityResolver;
class ErrorHandler;
class Grammar;
-
+class XMLEntityResolver;
+class XMLResourceIdentifier;
/**
* This class implements the Document Object Model (DOM) interface.
@@ -163,6 +164,26 @@
*/
const EntityResolver* getEntityResolver() const;
+ /**
+ * Get a pointer to the entity resolver
+ *
+ * This method returns the installed entity resolver. If no resolver
+ * has been installed, then it will be a zero pointer.
+ *
+ * @return The pointer to the installed entity resolver object.
+ */
+ XMLEntityResolver* getXMLEntityResolver();
+
+ /**
+ * Get a const pointer to the entity resolver
+ *
+ * This method returns the installed entity resolver. If no resolver
+ * has been installed, then it will be a zero pointer.
+ *
+ * @return A const pointer to the installed entity resolver object.
+ */
+ const XMLEntityResolver* getXMLEntityResolver() const;
+
/** Get the 'Grammar caching' flag
*
* This method returns the state of the parser's grammar caching when
@@ -249,8 +270,9 @@
* can trap and potentially redirect references to external
* entities.
*
- * <i>Any previously set resolver is merely dropped, since the parser
- * does not own them.</i>
+ * <i>Any previously set entity resolver is merely dropped, since the parser
+ * does not own them. If both setEntityResolver and setXMLEntityResolver
+ * are called, then the last one is used.</i>
*
* @param handler A const pointer to the user supplied entity
* resolver.
@@ -259,6 +281,25 @@
*/
void setEntityResolver(EntityResolver* const handler);
+ /**
+ * Set the entity resolver
+ *
+ * This method allows applications to install their own entity
+ * resolver. By installing an entity resolver, the applications
+ * can trap and potentially redirect references to external
+ * entities.
+ *
+ * <i>Any previously set entity resolver is merely dropped, since the parser
+ * does not own them. If both setEntityResolver and setXMLEntityResolver
+ * are called, then the last one set is used.</i>
+ *
+ * @param handler A const pointer to the user supplied entity
+ * resolver.
+ *
+ * @see #getXMLEntityResolver
+ */
+ void setXMLEntityResolver(XMLEntityResolver* const handler);
+
/** Set the 'Grammar caching' flag
*
* This method allows users to enable or disable caching of grammar when
@@ -447,6 +488,8 @@
* implement 'redirection' via this callback. This method is also
* borrowed from the SAX specification.
*
+ * @deprecated This method is no longer called (the other resolveEntity one is).
+ *
* @param publicId A const pointer to a Unicode string representing the
* public id of the entity just parsed.
* @param systemId A const pointer to a Unicode string representing the
@@ -468,6 +511,27 @@
, const XMLCh* const baseURI = 0
);
+ /** Resolve a public/system id
+ *
+ * This method allows a user installed entity handler to further
+ * process any pointers to external entities. The applications can
+ * implement 'redirection' via this callback.
+ *
+ * @param resourceIdentifier An object containing the type of
+ * resource to be resolved and the associated data members
+ * corresponding to this type.
+ * @return The value returned by the user installed resolveEntity
+ * method or NULL otherwise to indicate no processing was done.
+ * The returned InputSource is owned by the parser which is
+ * responsible to clean up the memory.
+ * @see XMLEntityHandler
+ * @see XMLEntityResolver
+ */
+ virtual InputSource* resolveEntity
+ (
+ XMLResourceIdentifier* resourceIdentifier
+ );
+
/** Handle a 'start input source' event
*
* This method is used to indicate the start of parsing an external
@@ -597,6 +661,7 @@
// The installed SAX error handler, if any. Null if none.
//-----------------------------------------------------------------------
EntityResolver* fEntityResolver;
+ XMLEntityResolver* fXMLEntityResolver;
ErrorHandler* fErrorHandler;
};
@@ -650,6 +715,15 @@
return fEntityResolver;
}
+inline XMLEntityResolver* XercesDOMParser::getXMLEntityResolver()
+{
+ return fXMLEntityResolver;
+}
+
+inline const XMLEntityResolver* XercesDOMParser::getXMLEntityResolver() const
+{
+ return fXMLEntityResolver;
+}
XERCES_CPP_NAMESPACE_END
1.39 +6 -1 xml-xerces/c/src/xercesc/util/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/Makefile.in,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- Makefile.in 9 Oct 2003 13:52:17 -0000 1.38
+++ Makefile.in 30 Oct 2003 21:37:32 -0000 1.39
@@ -55,6 +55,9 @@
#
#
# $Log$
+# Revision 1.39 2003/10/30 21:37:32 knoaman
+# Enhanced Entity Resolver Support. Thanks to David Cargill.
+#
# Revision 1.38 2003/10/09 13:52:17 neilg
# build SynchronizedStringPool
#
@@ -504,7 +507,7 @@
NoSuchElementException.hpp \
NullPointerException.hpp \
NumberFormatException.hpp \
- OutOfMemoryException.hpp \
+ OutOfMemoryException.hpp \
PanicHandler.hpp \
ParseException.hpp \
PlatformUtils.hpp \
@@ -545,6 +548,7 @@
XMLDOMMsg.hpp \
XMLDouble.hpp \
XMLEBCDICTranscoder.hpp \
+ XMLEntityResolver.hpp \
XMLEnumerator.hpp \
XMLException.hpp \
XMLExceptMsgs.hpp \
@@ -555,6 +559,7 @@
XMLNetAccessor.hpp \
XMLNumber.hpp \
XMLRegisterCleanup.hpp \
+ XMLResourceIdentifier.hpp \
XMLString.hpp \
XMLStringTokenizer.hpp \
XMLUCS4Transcoder.hpp \
1.1 xml-xerces/c/src/xercesc/util/XMLEntityResolver.hpp
Index: XMLEntityResolver.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2000 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) 1999, International
* Business Machines, Inc., http://www.ibm.com . For more information
* on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* $Log: XMLEntityResolver.hpp,v $
* Revision 1.1 2003/10/30 21:37:32 knoaman
* Enhanced Entity Resolver Support. Thanks to David Cargill.
*
*
* Revision 1.1 1999/11/09 01:07:44 twl
* Initial checkin
*
*/
#ifndef XMLENTITYRESOLVER_HPP
#define XMLENTITYRESOLVER_HPP
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/util/XMemory.hpp>
#include <xercesc/util/XMLResourceIdentifier.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class InputSource;
/**
* Revised interface for resolving entities.
*
* <p>If an application needs to implement customized handling
* for external entities, it can implement this interface and
* register an instance with the parser using the parser's
* setXMLEntityResolver method or it can use the basic SAX interface
* (EntityResolver). The difference between the two interfaces is
* the arguments to the resolveEntity() method. With the SAX
* EntityResolve the arguments are systemId and publicId. With this
* interface the argument is a XMLResourceIdentifier object. <i>Only
* one EntityResolver can be set using setEntityResolver() or
* setXMLEntityResolver, if both are set the last one set is
* used.</i></p>
*
* <p>The parser will then allow the application to intercept any
* external entities (including the external DTD subset and external
* parameter entities, if any) before including them.</p>
*
* <p>Many applications will not need to implement this interface,
* but it will be especially useful for applications that build
* XML documents from databases or other specialised input sources,
* or for applications that use URI types other than URLs.</p>
*
* <p>The following resolver would provide the application
* with a special character stream for the entity with the system
* identifier "http://www.myhost.com/today":</p>
*
*<pre>
* #include <xercesc/util/XMLEntityResolver.hpp>
* #include <xercesc/sax/InputSource.hpp>
*
* class MyResolver : public XMLEntityResolver {
* public:
* InputSource resolveEntity (XMLResourceIdentifier* xmlri);
* ...
* };
*
* MyResolver::resolveEntity(XMLResourceIdentifier* xmlri) {
* switch(xmlri->getResourceIdentifierType()) {
* case XMLResourceIdentifier::SystemId:
* if (XMLString::compareString(xmlri->getSystemId(), "http://www.myhost.com/today")) {
* MyReader* reader = new MyReader();
* return new InputSource(reader);
* } else {
* return null;
* }
* break;
* default:
* return null;
* }
* }</pre>
*
* <p>The application can also use this interface to redirect system
* identifiers to local URIs or to look up replacements in a catalog
* (possibly by using the public identifier).</p>
*
* <p>The HandlerBase class implements the default behaviour for
* this interface, which is simply always to return null (to request
* that the parser use the default system identifier).</p>
*
* @see XMLResourceIdentifier
* @see Parser#setXMLEntityResolver
* @see InputSource#InputSource
* @see HandlerBase#HandlerBase
*/
class XMLUTIL_EXPORT XMLEntityResolver
{
public:
/** @name Constructors and Destructor */
//@{
/** Destructor */
virtual ~XMLEntityResolver()
{
}
//@}
/** @name The XMLEntityResolver interface */
//@{
/**
* Allow the application to resolve external entities.
*
* <p>The Parser will call this method before opening any external
* entity except the top-level document entity (including the
* external DTD subset, external entities referenced within the
* DTD, and external entities referenced within the document
* element): the application may request that the parser resolve
* the entity itself, that it use an alternative URI, or that it
* use an entirely different input source.</p>
*
* <p>Application writers can use this method to redirect external
* system identifiers to secure and/or local URIs, to look up
* public identifiers in a catalogue, or to read an entity from a
* database or other input source (including, for example, a dialog
* box).</p>
*
* <p>If the system identifier is a URL, the SAX parser must
* resolve it fully before reporting it to the application.</p>
*
* @param resourceIdentifier An object containing the type of
* resource to be resolved and the associated data members
* corresponding to this type.
* @return An InputSource object describing the new input source,
* or null to request that the parser open a regular
* URI connection to the system identifier.
* The returned InputSource is owned by the parser which is
* responsible to clean up the memory.
* @exception SAXException Any SAX exception, possibly
* wrapping another exception.
* @exception IOException An IO exception,
* possibly the result of creating a new InputStream
* or Reader for the InputSource.
*
* @see InputSource#InputSource
* @see XMLResourceIdentifier
*/
virtual InputSource* resolveEntity
(
XMLResourceIdentifier* resourceIdentifier
) = 0;
//@}
protected:
/** Default Constructor */
XMLEntityResolver()
{
}
private :
/* Unimplemented constructors and operators */
/* Copy constructor */
XMLEntityResolver(const XMLEntityResolver&);
/* Assignment operator */
XMLEntityResolver& operator=(const XMLEntityResolver&);
};
XERCES_CPP_NAMESPACE_END
#endif
1.1 xml-xerces/c/src/xercesc/util/XMLResourceIdentifier.hpp
Index: XMLResourceIdentifier.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2000 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) 1999, International
* Business Machines, Inc., http://www.ibm.com . For more information
* on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* $Log: XMLResourceIdentifier.hpp,v $
* Revision 1.1 2003/10/30 21:37:32 knoaman
* Enhanced Entity Resolver Support. Thanks to David Cargill.
*
*
* Revision 1.1 1999/11/09 01:07:44 twl
* Initial checkin
*
*/
#ifndef XMLRESOURCEIDENTIFIER_HPP
#define XMLRESOURCEIDENTIFIER_HPP
XERCES_CPP_NAMESPACE_BEGIN
/**
* <p>This class is used along with XMLEntityResolver to resolve entities.
* Instead of passing publicId and systemId on the resolveEntity call,
* as is done with the SAX entity resolver, an object of type XMLResourceIdentifier
* is passed. By calling the getResourceIdentifierType() method the user can
* determine which data members are available for inspection:</p>
*
* <table border='1'>
* <tr>
* <td>ResourceIdentifierType</td>
* <td>Available Data Members</td>
* </tr>
* <tr>
* <td>SchemaGrammar</td>
* <td>schemaLocation & nameSpace</td>
* </tr>
* <tr>
* <td>SchemaImport</td>
* <td>schemaLocation & nameSpace</td>
* </tr>
* <tr>
* <td>SchemaInclude</td>
* <td>schemaLocation</td>
* </tr>
* <tr>
* <td>SchemaRedefine</td>
* <td>schemaLocation</td>
* </tr>
* <tr>
* <td>ExternalEntity</td>
* <td>systemId, publicId & baseURI (some items may be NULL)</td>
* </tr>
* </table>
*
* <p>The following resolver would provide the application
* with a special character stream for the entity with the system
* identifier "http://www.myhost.com/today":</p>
*
*<pre>
* #include <xercesc/util/XMLEntityResolver.hpp>
* #include <xercesc/sax/InputSource.hpp>
*
* class MyResolver : public XMLEntityResolver {
* public:
* InputSource resolveEntity (XMLResourceIdentifier* xmlri);
* ...
* };
*
* MyResolver::resolveEntity(XMLResourceIdentifier* xmlri) {
* switch(xmlri->getResourceIdentifierType()) {
* case XMLResourceIdentifier::SystemId:
* if (XMLString::compareString(xmlri->getSystemId(), "http://www.myhost.com/today")) {
* MyReader* reader = new MyReader();
* return new InputSource(reader);
* } else {
* return null;
* }
* break;
* default:
* return null;
* }
* }</pre>
*
* @see SAXParser#setXMLEntityResolver
* @see InputSource#InputSource
*/
class XMLUTIL_EXPORT XMLResourceIdentifier
{
public:
enum ResourceIdentifierType {
SchemaGrammar = 0,
SchemaImport,
SchemaInclude,
SchemaRedefine ,
ExternalEntity,
UnKnown = 255
//@{
};
/** @name Constructors and Destructor */
/** Constructor */
XMLResourceIdentifier(const ResourceIdentifierType resourceIdentitiferType
, const XMLCh* const systemId
, const XMLCh* const nameSpace = 0
, const XMLCh* const publicId = 0
, const XMLCh* const baseURI = 0);
/** Destructor */
virtual ~XMLResourceIdentifier()
{
}
//@}
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
const ResourceIdentifierType getResourceIdentifierType() const;
const XMLCh* getPublicId() const;
const XMLCh* getSystemId() const;
const XMLCh* getSchemaLocation() const;
const XMLCh* getBaseURI() const;
const XMLCh* getNameSpace() const;
private :
const ResourceIdentifierType fResourceIdentifierType;
const XMLCh* fPublicId;
const XMLCh* fSystemId;
const XMLCh* fBaseURI;
const XMLCh* fNameSpace;
/* Unimplemented constructors and operators */
/* Copy constructor */
XMLResourceIdentifier(const XMLResourceIdentifier&);
/* Assignment operator */
XMLResourceIdentifier& operator=(const XMLResourceIdentifier&);
};
inline const XMLResourceIdentifier::ResourceIdentifierType XMLResourceIdentifier::getResourceIdentifierType() const
{
return fResourceIdentifierType;
}
inline const XMLCh* XMLResourceIdentifier::getPublicId() const
{
return fPublicId;
}
inline const XMLCh* XMLResourceIdentifier::getSystemId() const
{
return fSystemId;
}
inline const XMLCh* XMLResourceIdentifier::getSchemaLocation() const
{
return fSystemId;
}
inline const XMLCh* XMLResourceIdentifier::getBaseURI() const
{
return fBaseURI;
}
inline const XMLCh* XMLResourceIdentifier::getNameSpace() const
{
return fNameSpace;
}
inline XMLResourceIdentifier::XMLResourceIdentifier(const ResourceIdentifierType resourceIdentifierType
, const XMLCh* const systemId
, const XMLCh* const nameSpace
, const XMLCh* const publicId
, const XMLCh* const baseURI ) :
fResourceIdentifierType(resourceIdentifierType),
fSystemId(systemId),
fNameSpace(nameSpace),
fPublicId(publicId),
fBaseURI(baseURI)
{
}
XERCES_CPP_NAMESPACE_END
#endif
1.89 +28 -14 xml-xerces/c/src/xercesc/validators/schema/TraverseSchema.cpp
Index: TraverseSchema.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/TraverseSchema.cpp,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -r1.88 -r1.89
--- TraverseSchema.cpp 21 Oct 2003 10:46:23 -0000 1.88
+++ TraverseSchema.cpp 30 Oct 2003 21:37:32 -0000 1.89
@@ -92,6 +92,7 @@
#include <xercesc/dom/DOMNamedNodeMap.hpp>
#include <xercesc/dom/impl/XSDElementNSImpl.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
+#include <xercesc/util/XMLEntityResolver.hpp>
XERCES_CPP_NAMESPACE_BEGIN
@@ -510,7 +511,8 @@
// ------------------------------------------------------------------
// Resolve schema location
// ------------------------------------------------------------------
- InputSource* srcToFill = resolveSchemaLocation(schemaLocation);
+ InputSource* srcToFill = resolveSchemaLocation(schemaLocation,
+ XMLResourceIdentifier::SchemaInclude);
Janitor<InputSource> janSrc(srcToFill);
// Nothing to do
@@ -683,21 +685,23 @@
// ------------------------------------------------------------------
const XMLCh* schemaLocation = getElementAttValue(elem, SchemaSymbols::fgATT_SCHEMALOCATION);
- if (!schemaLocation || !*schemaLocation) {
- return;
- }
+ //if (!schemaLocation || !*schemaLocation) {
+ // return;
+ //}
+ // With new XMLEntityResolver, it may resolve the nameSpace so call resolveSchemaLocation...
// ------------------------------------------------------------------
// Resolve schema location
// ------------------------------------------------------------------
- InputSource* srcToFill = resolveSchemaLocation(schemaLocation);
- Janitor<InputSource> janSrc(srcToFill);
+ InputSource* srcToFill = resolveSchemaLocation(schemaLocation,
+ XMLResourceIdentifier::SchemaImport, nameSpace);
// Nothing to do
if (!srcToFill) {
return;
}
+ Janitor<InputSource> janSrc(srcToFill);
const XMLCh* importURL = srcToFill->getSystemId();
SchemaInfo* importSchemaInfo = 0;
@@ -6409,22 +6413,31 @@
}
-InputSource* TraverseSchema::resolveSchemaLocation(const XMLCh* const loc) {
+InputSource* TraverseSchema::resolveSchemaLocation(const XMLCh* const loc,
+ const XMLResourceIdentifier::ResourceIdentifierType resourceIdentitiferType,
+ const XMLCh* const nameSpace) {
// ------------------------------------------------------------------
// Create an input source
// ------------------------------------------------------------------
InputSource* srcToFill = 0;
- normalizeURI(loc, fBuffer);
+ XMLCh* normalizedURI = 0;
+ if (loc) {
+ normalizeURI(loc, fBuffer);
+ normalizedURI = fBuffer.getRawBuffer();
+ }
- const XMLCh* normalizedURI = fBuffer.getRawBuffer();
if (fEntityHandler){
- srcToFill = fEntityHandler->resolveEntity(XMLUni::fgZeroLenString, normalizedURI);
+ XMLResourceIdentifier resourceIdentifier(resourceIdentitiferType,
+ normalizedURI, nameSpace);
+ srcToFill = fEntityHandler->resolveEntity(&resourceIdentifier);
}
// If they didn't create a source via the entity resolver, then we
- // have to create one on our own.
- if (!srcToFill) {
+ // have to create one on our own if we have the schemaLocation (with
+ // the update resolveEntity accepting nameSpace, a schemImport could
+ // pass a null schemaLocation)
+ if (!srcToFill && loc) {
try {
@@ -7595,7 +7608,8 @@
// ------------------------------------------------------------------
// Resolve schema location
// ------------------------------------------------------------------
- InputSource* srcToFill = resolveSchemaLocation(schemaLocation);
+ InputSource* srcToFill = resolveSchemaLocation(schemaLocation,
+ XMLResourceIdentifier::SchemaRedefine);
Janitor<InputSource> janSrc(srcToFill);
// Nothing to do
1.27 +8 -2 xml-xerces/c/src/xercesc/validators/schema/TraverseSchema.hpp
Index: TraverseSchema.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/TraverseSchema.hpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- TraverseSchema.hpp 10 Jul 2003 19:58:57 -0000 1.26
+++ TraverseSchema.hpp 30 Oct 2003 21:37:32 -0000 1.27
@@ -82,6 +82,7 @@
#include <xercesc/validators/schema/SchemaInfo.hpp>
#include <xercesc/validators/schema/GeneralAttributeCheck.hpp>
#include <xercesc/validators/schema/XSDErrorReporter.hpp>
+#include <xercesc/util/XMLResourceIdentifier.hpp>
XERCES_CPP_NAMESPACE_BEGIN
@@ -525,7 +526,12 @@
* Resolve a schema location attribute value to an input source.
* Caller to delete the returned object.
*/
- InputSource* resolveSchemaLocation(const XMLCh* const loc);
+ InputSource* resolveSchemaLocation
+ (
+ const XMLCh* const loc
+ , const XMLResourceIdentifier::ResourceIdentifierType resourceIdentitiferType
+ , const XMLCh* const nameSpace=0
+ );
void restoreSchemaInfo(SchemaInfo* const toRestore,
SchemaInfo::ListType const aListType = SchemaInfo::INCLUDE,
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org