You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by am...@apache.org on 2008/05/13 03:08:39 UTC
svn commit: r655706 - in /xerces/c/trunk/src/xercesc/xinclude:
XIncludeDOMDocumentProcessor.cpp XIncludeDOMDocumentProcessor.hpp
XIncludeLocation.cpp XIncludeLocation.hpp XIncludeUtils.cpp XIncludeUtils.hpp
Author: amassari
Date: Mon May 12 18:08:39 2008
New Revision: 655706
URL: http://svn.apache.org/viewvc?rev=655706&view=rev
Log:
When importing nodes, use a temp DOMDocumentFragment, or the insertBefore will fail if happening at the root element
Modified:
xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.cpp
xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.hpp
xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.cpp
xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.hpp
xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.cpp
xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.hpp
Modified: xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.cpp?rev=655706&r1=655705&r2=655706&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.cpp (original)
+++ xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.cpp Mon May 12 18:08:39 2008
@@ -33,35 +33,35 @@
DOMDocument *
XIncludeDOMDocumentProcessor::doXIncludeDOMProcess(const DOMDocument * const source, XMLErrorReporter *errorHandler, XMLEntityHandler* entityResolver /*=NULL*/){
- XIncludeUtils xiu(errorHandler);
+ XIncludeUtils xiu(errorHandler);
- DOMImplementation* impl = source->getImplementation();
- DOMDocument *xincludedDocument = impl->createDocument();
-
+ DOMImplementation* impl = source->getImplementation();
+ DOMDocument *xincludedDocument = impl->createDocument();
+
try
{
- /* set up the declaration etc of the output document to match the source */
- xincludedDocument->setDocumentURI( source->getDocumentURI());
- xincludedDocument->setXmlStandalone( source->getXmlStandalone());
- xincludedDocument->setXmlVersion( source->getXmlVersion());
-
- /* copy entire source document into the xincluded document. Xincluded document can
- then be modified in place */
- DOMNode *child = source->getFirstChild();
- for (; child != NULL; child = child->getNextSibling()){
- if (child->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE){
- /* I am simply ignoring these at the moment */
- continue;
- }
- DOMNode *newNode = xincludedDocument->importNode(child, true);
- xincludedDocument->appendChild(newNode);
- }
-
- DOMNode *docNode = xincludedDocument->getDocumentElement();
- /* parse and include the document node */
- xiu.parseDOMNodeDoingXInclude(docNode, xincludedDocument, entityResolver);
+ /* set up the declaration etc of the output document to match the source */
+ xincludedDocument->setDocumentURI( source->getDocumentURI());
+ xincludedDocument->setXmlStandalone( source->getXmlStandalone());
+ xincludedDocument->setXmlVersion( source->getXmlVersion());
+
+ /* copy entire source document into the xincluded document. Xincluded document can
+ then be modified in place */
+ DOMNode *child = source->getFirstChild();
+ for (; child != NULL; child = child->getNextSibling()){
+ if (child->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE){
+ /* I am simply ignoring these at the moment */
+ continue;
+ }
+ DOMNode *newNode = xincludedDocument->importNode(child, true);
+ xincludedDocument->appendChild(newNode);
+ }
+
+ DOMNode *docNode = xincludedDocument->getDocumentElement();
+ /* parse and include the document node */
+ xiu.parseDOMNodeDoingXInclude(docNode, xincludedDocument, entityResolver);
- xincludedDocument->normalizeDocument();
+ xincludedDocument->normalizeDocument();
}
catch(const XMLErrs::Codes)
{
@@ -74,7 +74,7 @@
throw;
}
- return xincludedDocument;
+ return xincludedDocument;
}
XERCES_CPP_NAMESPACE_END
Modified: xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.hpp?rev=655706&r1=655705&r2=655706&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.hpp (original)
+++ xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.hpp Mon May 12 18:08:39 2008
@@ -41,15 +41,15 @@
class XINCLUDE_EXPORT XIncludeDOMDocumentProcessor
{
public:
- /** Walk the supplied DOMDocument performing all XInclude's as encountered.
- *
+ /** Walk the supplied DOMDocument performing all XInclude's as encountered.
+ *
* @param source A DOMDocument to parse, this document is not modified.
* @param errorHandled An errorHandler to call back in case of problems
- *
+ *
* @return a newly created DOMDocument containing the parsed and actioned
- * xinclude elements.
+ * xinclude elements.
*/
- DOMDocument *doXIncludeDOMProcess(const DOMDocument * const source, XMLErrorReporter *errorHandler, XMLEntityHandler* entityResolver=NULL);
+ DOMDocument *doXIncludeDOMProcess(const DOMDocument * const source, XMLErrorReporter *errorHandler, XMLEntityHandler* entityResolver=NULL);
};
XERCES_CPP_NAMESPACE_END
Modified: xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.cpp?rev=655706&r1=655705&r2=655706&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.cpp (original)
+++ xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.cpp Mon May 12 18:08:39 2008
@@ -30,25 +30,25 @@
XERCES_CPP_NAMESPACE_BEGIN
const XMLCh *allocate(const XMLCh *href){
- const XMLCh *allocated;
- size_t length = XMLString::stringLen(href);
- allocated = (const XMLCh *)XMLPlatformUtils::fgMemoryManager->allocate((length+1) * sizeof(XMLCh));
- XMLString::copyString((XMLCh *)allocated, href);
- XMLPlatformUtils::removeDotDotSlash((XMLCh *const)allocated);
+ const XMLCh *allocated;
+ size_t length = XMLString::stringLen(href);
+ allocated = (const XMLCh *)XMLPlatformUtils::fgMemoryManager->allocate((length+1) * sizeof(XMLCh));
+ XMLString::copyString((XMLCh *)allocated, href);
+ XMLPlatformUtils::removeDotDotSlash((XMLCh *const)allocated);
- return allocated;
+ return allocated;
}
void deallocate(void *ptr){
- if (ptr)
- XMLPlatformUtils::fgMemoryManager->deallocate((void *)ptr);
+ if (ptr)
+ XMLPlatformUtils::fgMemoryManager->deallocate((void *)ptr);
}
// ---------------------------------------------------------------------------
// Destructor and Constructor
// ---------------------------------------------------------------------------
XIncludeLocation::XIncludeLocation(const XMLCh *href){
- fHref = allocate(href);
+ fHref = allocate(href);
}
XIncludeLocation::~XIncludeLocation(){
@@ -57,84 +57,80 @@
const XMLCh *
XIncludeLocation::prependPath(const XMLCh *baseToAdd){
- XMLCh *relativeHref = NULL;
- if (fHref == NULL){
- return NULL;
- }
- XMLSize_t fileLength = XMLString::stringLen(fHref);
-
- if (baseToAdd == NULL){
- return fHref;
- }
-
- XMLPlatformUtils::removeDotDotSlash((XMLCh *const)baseToAdd);
- XMLSize_t baseLength = XMLString::stringLen(baseToAdd);
-
- int lastSlash = XMLString::lastIndexOf(baseToAdd, chForwardSlash);
- if (lastSlash == -1){
- /* not found, try another platform */
- lastSlash = XMLString::lastIndexOf(baseToAdd, chBackSlash);
- }
- if (lastSlash == -1){
- /* still no slash found */
- lastSlash = 0;
- }
-
- relativeHref = (XMLCh *)XMLPlatformUtils::fgMemoryManager->allocate((fileLength + baseLength + 2) * sizeof(XMLCh));
- if (relativeHref == NULL){
- return NULL;
- }
- XMLString::copyNString(relativeHref, baseToAdd, lastSlash + 1);
- relativeHref[lastSlash + 2] = chNull;
- XMLString::catString(relativeHref, fHref);
-
- /* free the old reference */
- deallocate((void *)fHref);
-
- fHref = relativeHref;
- return fHref;
+ XMLCh *relativeHref = NULL;
+ if (fHref == NULL){
+ return NULL;
+ }
+ XMLSize_t fileLength = XMLString::stringLen(fHref);
+
+ if (baseToAdd == NULL){
+ return fHref;
+ }
+
+ XMLPlatformUtils::removeDotDotSlash((XMLCh *const)baseToAdd);
+ XMLSize_t baseLength = XMLString::stringLen(baseToAdd);
+
+ int lastSlash = XMLString::lastIndexOf(baseToAdd, chForwardSlash);
+ if (lastSlash == -1){
+ /* not found, try another platform */
+ lastSlash = XMLString::lastIndexOf(baseToAdd, chBackSlash);
+ }
+
+ relativeHref = (XMLCh *)XMLPlatformUtils::fgMemoryManager->allocate((fileLength + baseLength + 2) * sizeof(XMLCh));
+ if (relativeHref == NULL){
+ return NULL;
+ }
+ XMLString::copyNString(relativeHref, baseToAdd, lastSlash + 1);
+ relativeHref[lastSlash + 1] = chNull;
+ XMLString::catString(relativeHref, fHref);
+
+ /* free the old reference */
+ deallocate((void *)fHref);
+
+ fHref = relativeHref;
+ return fHref;
}
const XMLCh *
XIncludeLocation::findEndOfProtocol(const XMLCh *URI){
- if ( URI[0] == chLatin_f &&
- URI[1] == chLatin_i &&
- URI[2] == chLatin_l &&
- URI[3] == chLatin_e &&
- URI[4] == chColon &&
- URI[5] == chForwardSlash &&
- URI[6] == chForwardSlash &&
- URI[7] == chForwardSlash )
- {
- return URI + 8;
- }
-
- if ( URI[0] == chLatin_f &&
- URI[1] == chLatin_t &&
- URI[2] == chLatin_p &&
- URI[3] == chColon &&
- URI[4] == chForwardSlash &&
- URI[5] == chForwardSlash &&
- URI[6] == chForwardSlash )
- {
- return URI + 7;
- }
-
- if ( URI[0] == chLatin_h &&
- URI[1] == chLatin_t &&
- URI[2] == chLatin_t &&
- URI[3] == chLatin_p &&
- URI[4] == chColon &&
- URI[5] == chForwardSlash &&
- URI[6] == chForwardSlash &&
- URI[7] == chForwardSlash )
- {
- return URI + 8;
- }
-
- /* if method fails, simply return the URI and let the problem be detected
- * and reported down the line (it may not have a protocol of course) */
- return URI;
+ if ( URI[0] == chLatin_f &&
+ URI[1] == chLatin_i &&
+ URI[2] == chLatin_l &&
+ URI[3] == chLatin_e &&
+ URI[4] == chColon &&
+ URI[5] == chForwardSlash &&
+ URI[6] == chForwardSlash &&
+ URI[7] == chForwardSlash )
+ {
+ return URI + 8;
+ }
+
+ if ( URI[0] == chLatin_f &&
+ URI[1] == chLatin_t &&
+ URI[2] == chLatin_p &&
+ URI[3] == chColon &&
+ URI[4] == chForwardSlash &&
+ URI[5] == chForwardSlash &&
+ URI[6] == chForwardSlash )
+ {
+ return URI + 7;
+ }
+
+ if ( URI[0] == chLatin_h &&
+ URI[1] == chLatin_t &&
+ URI[2] == chLatin_t &&
+ URI[3] == chLatin_p &&
+ URI[4] == chColon &&
+ URI[5] == chForwardSlash &&
+ URI[6] == chForwardSlash &&
+ URI[7] == chForwardSlash )
+ {
+ return URI + 8;
+ }
+
+ /* if method fails, simply return the URI and let the problem be detected
+ * and reported down the line (it may not have a protocol of course) */
+ return URI;
}
XERCES_CPP_NAMESPACE_END
Modified: xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.hpp?rev=655706&r1=655705&r2=655706&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.hpp (original)
+++ xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.hpp Mon May 12 18:08:39 2008
@@ -39,48 +39,48 @@
class XINCLUDE_EXPORT XIncludeLocation
{
public:
- /** Create an XIncludeLocation, primed with the supplied href
- *
+ /** Create an XIncludeLocation, primed with the supplied href
+ *
* @param href the initial URI value
- *
+ *
* @return nothing
*/
- XIncludeLocation(const XMLCh *href);
+ XIncludeLocation(const XMLCh *href);
- /** Destructor
- *
+ /** Destructor
+ *
* @return nothing
*/
- ~XIncludeLocation();
+ ~XIncludeLocation();
- /** Prepend the supplied href to the current location and modify the current XIncludeLocation's
- * internal href field
- *
+ /** Prepend the supplied href to the current location and modify the current XIncludeLocation's
+ * internal href field
+ *
* @param toPrepend the path to prepend
- *
+ *
* @return the resultant compound URI
*/
- const XMLCh *prependPath(const XMLCh *toPrepend);
+ const XMLCh *prependPath(const XMLCh *toPrepend);
- /** Get the current XIncludeLocation's compound URI location
- *
+ /** Get the current XIncludeLocation's compound URI location
+ *
* @return the current URI
*/
- const XMLCh *getLocation(){
- return fHref;
- };
+ const XMLCh *getLocation(){
+ return fHref;
+ };
- /** Get a pointer to the end of the protocol section of a URI
- *
+ /** Get a pointer to the end of the protocol section of a URI
+ *
* @param URI a URI to strip the protocol from
- *
+ *
* @return a pointer into the supplied URI immediately after the last character of the protocol section
- * the pointer points to the first character after the protocol.
+ * the pointer points to the first character after the protocol.
*/
- static const XMLCh *findEndOfProtocol(const XMLCh *URI);
+ static const XMLCh *findEndOfProtocol(const XMLCh *URI);
private:
- const XMLCh *fHref;
+ const XMLCh *fHref;
};
XERCES_CPP_NAMESPACE_END
Modified: xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.cpp?rev=655706&r1=655705&r2=655706&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.cpp (original)
+++ xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.cpp Mon May 12 18:08:39 2008
@@ -36,12 +36,12 @@
XERCES_CPP_NAMESPACE_BEGIN
XIncludeUtils::XIncludeUtils(XMLErrorReporter *errorReporter){
- fErrorReporter = errorReporter;
- fIncludeHistoryHead = NULL;
+ fErrorReporter = errorReporter;
+ fIncludeHistoryHead = NULL;
}
XIncludeUtils::~XIncludeUtils(){
- freeInclusionHistory();
+ freeInclusionHistory();
}
// ---------------------------------------------------------------------------
@@ -52,41 +52,41 @@
// ---------------------------------------------------------------------------
bool
XIncludeUtils::parseDOMNodeDoingXInclude(DOMNode *sourceNode, DOMDocument *parsedDocument, XMLEntityHandler* entityResolver){
- int included = 0;
+ int included = 0;
if (sourceNode) {
- /* create the list of child elements here, since it gets changed during the parse */
- RefVectorOf<DOMNode> children(10, false);
- for (DOMNode *child = sourceNode->getFirstChild(); child != NULL; child = child->getNextSibling()){
- children.addElement(child);
- }
-
- if (sourceNode->getNodeType() == DOMNode::ELEMENT_NODE){
- if (isXIIncludeDOMNode(sourceNode)){
- /* once we do an include on the source element, it is unsafe to do the include
- on the children, since they will have been changed by the top level include */
- bool success = doDOMNodeXInclude(sourceNode, parsedDocument, entityResolver);
-
- //popFromCurrentInclusionHistoryStack(NULL);
- /* return here as we do not want to fall through to the parsing of the children below
- - they should have been replaced by the XInclude */
- return success;
- } else if (isXIFallbackDOMNode(sourceNode)){
- /* This must be a fallback element that is not a child of an include element.
- This is defined as a fatal error */
- XIncludeUtils::reportError(sourceNode, XMLErrs::XIncludeOrphanFallback,
- NULL, parsedDocument->getDocumentURI());
- return false;
- }
- }
-
- /* to have got here, we must not have found an xinclude element in the current element, so
- need to walk the entire child list parsing for each. An xinclude in a
- node does not affect a peer, so we can simply parse each child in turn */
- for (unsigned int i = 0; i < children.size(); i++){
- parseDOMNodeDoingXInclude(children.elementAt(i), parsedDocument, entityResolver);
- }
- }
- return (included)?true:false;
+ /* create the list of child elements here, since it gets changed during the parse */
+ RefVectorOf<DOMNode> children(10, false);
+ for (DOMNode *child = sourceNode->getFirstChild(); child != NULL; child = child->getNextSibling()){
+ children.addElement(child);
+ }
+
+ if (sourceNode->getNodeType() == DOMNode::ELEMENT_NODE){
+ if (isXIIncludeDOMNode(sourceNode)){
+ /* once we do an include on the source element, it is unsafe to do the include
+ on the children, since they will have been changed by the top level include */
+ bool success = doDOMNodeXInclude(sourceNode, parsedDocument, entityResolver);
+
+ //popFromCurrentInclusionHistoryStack(NULL);
+ /* return here as we do not want to fall through to the parsing of the children below
+ - they should have been replaced by the XInclude */
+ return success;
+ } else if (isXIFallbackDOMNode(sourceNode)){
+ /* This must be a fallback element that is not a child of an include element.
+ This is defined as a fatal error */
+ XIncludeUtils::reportError(sourceNode, XMLErrs::XIncludeOrphanFallback,
+ NULL, parsedDocument->getDocumentURI());
+ return false;
+ }
+ }
+
+ /* to have got here, we must not have found an xinclude element in the current element, so
+ need to walk the entire child list parsing for each. An xinclude in a
+ node does not affect a peer, so we can simply parse each child in turn */
+ for (unsigned int i = 0; i < children.size(); i++){
+ parseDOMNodeDoingXInclude(children.elementAt(i), parsedDocument, entityResolver);
+ }
+ }
+ return (included)?true:false;
}
// ---------------------------------------------------------------------------
@@ -94,25 +94,25 @@
// ---------------------------------------------------------------------------
static const XMLCh *
getBaseAttrValue(DOMNode *node){
- if (node->getNodeType() == DOMNode::ELEMENT_NODE){
- DOMElement *elem = (DOMElement *)node;
- if(elem->hasAttributes()) {
+ if (node->getNodeType() == DOMNode::ELEMENT_NODE){
+ DOMElement *elem = (DOMElement *)node;
+ if(elem->hasAttributes()) {
/* get all the attributes of the node */
DOMNamedNodeMap *pAttributes = elem->getAttributes();
unsigned int nSize = pAttributes->getLength();
for(unsigned int i=0;i<nSize;++i) {
DOMAttr *pAttributeNode = (DOMAttr*) pAttributes->item(i);
/* get attribute name */
- if (XMLString::equals(pAttributeNode->getName(), XIncludeUtils::fgXIBaseAttrName)){
- /*if (namespace == XMLUni::fgXMLString){
+ if (XMLString::equals(pAttributeNode->getName(), XIncludeUtils::fgXIBaseAttrName)){
+ /*if (namespace == XMLUni::fgXMLString){
- }*/
- return pAttributeNode->getValue();
- }
+ }*/
+ return pAttributeNode->getValue();
+ }
}
}
- }
- return NULL;
+ }
+ return NULL;
}
// ---------------------------------------------------------------------------
@@ -121,156 +121,159 @@
// ---------------------------------------------------------------------------
bool
XIncludeUtils::doDOMNodeXInclude(DOMNode *xincludeNode, DOMDocument *parsedDocument, XMLEntityHandler* entityResolver){
- bool modifiedNode = false;
- /* the relevant attributes to look for */
- const XMLCh *href = NULL;
- const XMLCh *parse = NULL;
- const XMLCh *xpointer = NULL;
- const XMLCh *encoding = NULL;
- const XMLCh *accept = NULL;
- const XMLCh *acceptlanguage = NULL;
- DOMNode *includeParent = xincludeNode->getParentNode();
-
-
- if(xincludeNode->hasAttributes()) {
- /* get all the attributes of the node */
- DOMNamedNodeMap *pAttributes = xincludeNode->getAttributes();
- unsigned int nSize = pAttributes->getLength();
- for(unsigned int i=0;i<nSize;++i) {
- DOMAttr *pAttributeNode = (DOMAttr*) pAttributes->item(i);
- const XMLCh *attrName = pAttributeNode->getName();
- /* check each attribute against the potential useful names */
- if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeHREFAttrName)){
- href = pAttributeNode->getValue();
- } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeParseAttrName)){
- parse = pAttributeNode->getValue();
- } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeXPointerAttrName)){
- xpointer = pAttributeNode->getValue();
- } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeEncodingAttrName)){
- encoding = pAttributeNode->getValue();
- } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeAcceptAttrName)){
- accept = pAttributeNode->getValue();
- } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeAcceptLanguageAttrName)){
- acceptlanguage = pAttributeNode->getValue();
- } else {
- /* if any other attribute is in the xi namespace, it's an error */
- const XMLCh *attrNamespaceURI = pAttributeNode->getNamespaceURI();
- if (attrNamespaceURI && XMLString::equals(attrNamespaceURI, XIncludeUtils::fgXIIIncludeNamespaceURI)){
- } else {
- /* ignore - any other attribute is allowed according to spec,
- and must be ignored */
- }
- }
- }
- }
+ bool modifiedNode = false;
+ /* the relevant attributes to look for */
+ const XMLCh *href = NULL;
+ const XMLCh *parse = NULL;
+ const XMLCh *xpointer = NULL;
+ const XMLCh *encoding = NULL;
+ const XMLCh *accept = NULL;
+ const XMLCh *acceptlanguage = NULL;
+ DOMNode *includeParent = xincludeNode->getParentNode();
+
+
+ if(xincludeNode->hasAttributes()) {
+ /* get all the attributes of the node */
+ DOMNamedNodeMap *pAttributes = xincludeNode->getAttributes();
+ unsigned int nSize = pAttributes->getLength();
+ for(unsigned int i=0;i<nSize;++i) {
+ DOMAttr *pAttributeNode = (DOMAttr*) pAttributes->item(i);
+ const XMLCh *attrName = pAttributeNode->getName();
+ /* check each attribute against the potential useful names */
+ if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeHREFAttrName)){
+ href = pAttributeNode->getValue();
+ } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeParseAttrName)){
+ parse = pAttributeNode->getValue();
+ } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeXPointerAttrName)){
+ xpointer = pAttributeNode->getValue();
+ } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeEncodingAttrName)){
+ encoding = pAttributeNode->getValue();
+ } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeAcceptAttrName)){
+ accept = pAttributeNode->getValue();
+ } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeAcceptLanguageAttrName)){
+ acceptlanguage = pAttributeNode->getValue();
+ } else {
+ /* if any other attribute is in the xi namespace, it's an error */
+ const XMLCh *attrNamespaceURI = pAttributeNode->getNamespaceURI();
+ if (attrNamespaceURI && XMLString::equals(attrNamespaceURI, XIncludeUtils::fgXIIIncludeNamespaceURI)){
+ } else {
+ /* ignore - any other attribute is allowed according to spec,
+ and must be ignored */
+ }
+ }
+ }
+ }
// 3.1 xi:include Element
// The children property of the xi:include element may include a single xi:fallback element;
// the appearance of more than one xi:fallback element, an xi:include element,
// or any other element from the XInclude namespace is a fatal error.
- DOMNode *child;
+ DOMNode *child;
DOMElement *fallback = NULL;
- for (child = xincludeNode->getFirstChild(); child != 0; child=child->getNextSibling()){
+ for (child = xincludeNode->getFirstChild(); child != 0; child=child->getNextSibling()){
if(child->getNodeType()!=DOMNode::ELEMENT_NODE)
continue;
- if ( isXIFallbackDOMNode(child) ){
- if (fallback != NULL){
- /* fatal error - there are more than one fallback children */
- XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeMultipleFallbackElems,
- parsedDocument->getDocumentURI(), parsedDocument->getDocumentURI());
- return false;
- }
- fallback = (DOMElement*)child;
- }
+ if ( isXIFallbackDOMNode(child) ){
+ if (fallback != NULL){
+ /* fatal error - there are more than one fallback children */
+ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeMultipleFallbackElems,
+ parsedDocument->getDocumentURI(), parsedDocument->getDocumentURI());
+ return false;
+ }
+ fallback = (DOMElement*)child;
+ }
else if(isXIIncludeDOMNode(child) || XMLString::equals(child->getNamespaceURI(), XIncludeUtils::fgXIIIncludeNamespaceURI)) {
- /* fatal error - an xi element different from xi:fallback is a child of xi:include */
- XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeDisallowedChild,
- child->getNodeName(), parsedDocument->getDocumentURI());
- return false;
- }
- }
-
- if (href == NULL){
- /* this is an unrecoverable error until we have xpointer support -
- if there is an xpointer, the current document is assumed
- however, there is no xpointer support yet */
- XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeNoHref,
- NULL, parsedDocument->getDocumentURI());
- return false;
- }
-
- /* set up the accept and accept-language values */
- if (accept != NULL){
-
- }
-
- if (parse == NULL){
- /* use the default, as specified */
- parse = XIncludeUtils::fgXIIncludeParseAttrXMLValue;
- }
-
- if (xpointer != NULL){
- /* not supported yet */
- /* Note that finding an xpointer attr along with parse="text" is a Fatal Error
- * - http://www.w3.org/TR/xinclude/#include-location */
- XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeXPointerNotSupported,
- NULL, href);
- return false;
- }
-
- /* set up the href according to what has gone before */
- XIncludeLocation hrefLoc(href);
- XIncludeLocation relativeLocation(href);
- const XMLCh *includeBase = xincludeNode->getBaseURI();
- if (includeBase != NULL){
- hrefLoc.prependPath(includeBase);
- }
-
- if (getBaseAttrValue(xincludeNode) != NULL){
- relativeLocation.prependPath(getBaseAttrValue(xincludeNode));
- }
-
- /* Take the relevant action - we need to retrieve the target as a whole before
- we can know if it was successful or not, therefore the do* methods do
- not modify the parsedDocument. Swapping the results in is left to the
- caller (i.e. here) */
- DOMText *includedText = NULL;
- DOMDocument *includedDoc = NULL;
- if (XMLString::equals(parse, XIncludeUtils::fgXIIncludeParseAttrXMLValue)){
- /* including a XML element */
- includedDoc = doXIncludeXMLFileDOM(hrefLoc.getLocation(), relativeLocation.getLocation(), xincludeNode, parsedDocument, entityResolver);
- } else if (XMLString::equals(parse, XIncludeUtils::fgXIIncludeParseAttrTextValue)){
- /* including a text value */
- includedText = doXIncludeTEXTFileDOM(hrefLoc.getLocation(), relativeLocation.getLocation(), encoding, xincludeNode, parsedDocument, entityResolver);
- } else {
- /* invalid parse attribute value - fatal error according to the specification */
- XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeInvalidParseVal,
- parse, parsedDocument->getDocumentURI());
- return false;
- }
-
- if (includedDoc == NULL && includedText == NULL){
- /* there was an error - this is now a resource error
- let's see if there is a fallback */
- XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeIncludeFailedResourceError,
- hrefLoc.getLocation(), parsedDocument->getDocumentURI());
+ /* fatal error - an xi element different from xi:fallback is a child of xi:include */
+ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeDisallowedChild,
+ child->getNodeName(), parsedDocument->getDocumentURI());
+ return false;
+ }
+ }
+
+ if (href == NULL){
+ /* this is an unrecoverable error until we have xpointer support -
+ if there is an xpointer, the current document is assumed
+ however, there is no xpointer support yet */
+ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeNoHref,
+ NULL, parsedDocument->getDocumentURI());
+ return false;
+ }
+
+ /* set up the accept and accept-language values */
+ if (accept != NULL){
+
+ }
+
+ if (parse == NULL){
+ /* use the default, as specified */
+ parse = XIncludeUtils::fgXIIncludeParseAttrXMLValue;
+ }
+
+ if (xpointer != NULL){
+ /* not supported yet */
+ /* Note that finding an xpointer attr along with parse="text" is a Fatal Error
+ * - http://www.w3.org/TR/xinclude/#include-location */
+ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeXPointerNotSupported,
+ NULL, href);
+ return false;
+ }
+
+ /* set up the href according to what has gone before */
+ XIncludeLocation hrefLoc(href);
+ XIncludeLocation relativeLocation(href);
+ const XMLCh *includeBase = xincludeNode->getBaseURI();
+ if (includeBase != NULL){
+ hrefLoc.prependPath(includeBase);
+ }
+
+ if (getBaseAttrValue(xincludeNode) != NULL){
+ relativeLocation.prependPath(getBaseAttrValue(xincludeNode));
+ }
+
+ /* Take the relevant action - we need to retrieve the target as a whole before
+ we can know if it was successful or not, therefore the do* methods do
+ not modify the parsedDocument. Swapping the results in is left to the
+ caller (i.e. here) */
+ DOMText *includedText = NULL;
+ DOMDocument *includedDoc = NULL;
+ if (XMLString::equals(parse, XIncludeUtils::fgXIIncludeParseAttrXMLValue)){
+ /* including a XML element */
+ includedDoc = doXIncludeXMLFileDOM(hrefLoc.getLocation(), relativeLocation.getLocation(), xincludeNode, parsedDocument, entityResolver);
+ } else if (XMLString::equals(parse, XIncludeUtils::fgXIIncludeParseAttrTextValue)){
+ /* including a text value */
+ includedText = doXIncludeTEXTFileDOM(hrefLoc.getLocation(), relativeLocation.getLocation(), encoding, xincludeNode, parsedDocument, entityResolver);
+ } else {
+ /* invalid parse attribute value - fatal error according to the specification */
+ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeInvalidParseVal,
+ parse, parsedDocument->getDocumentURI());
+ return false;
+ }
+
+ if (includedDoc == NULL && includedText == NULL){
+ /* there was an error - this is now a resource error
+ let's see if there is a fallback */
+ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeIncludeFailedResourceError,
+ hrefLoc.getLocation(), parsedDocument->getDocumentURI());
if (includeParent == NULL){
- includeParent = parsedDocument;
- }
+ includeParent = parsedDocument;
+ }
- if (fallback){
+ // we could be getting errors trying to insert elements at the root of the document, so we should use replaceChild;
+ // in order to handle multiple nodes, add them to a document fragment and use that to replace the original node
+ if (fallback){
/* baseURI fixups - see http://www.w3.org/TR/xinclude/#base for details. */
XMLUri parentURI(includeParent->getBaseURI());
XMLUri includedURI(fallback->getBaseURI());
- if (fallback->hasChildNodes()){
- DOMNode *child = fallback->getFirstChild();
- /* add the content of the fallback element, and remove the fallback elem itself */
- for ( ; child != NULL ; child=child->getNextSibling()){
- if (child->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE){
- continue;
- }
- DOMNode *newNode = parsedDocument->importNode(child, true);
+ if (fallback->hasChildNodes()){
+ DOMDocumentFragment* frag = parsedDocument->createDocumentFragment();
+ DOMNode *child = fallback->getFirstChild();
+ /* add the content of the fallback element, and remove the fallback elem itself */
+ for ( ; child != NULL ; child=child->getNextSibling()){
+ if (child->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE){
+ continue;
+ }
+ DOMNode *newNode = parsedDocument->importNode(child, true);
/* if the paths differ we need to add a base attribute */
if (newNode->getNodeType()==DOMNode::ELEMENT_NODE && !XMLString::equals(parentURI.getPath(), includedURI.getPath())){
if (getBaseAttrValue(newNode) == NULL){
@@ -286,26 +289,28 @@
((DOMElement*)newNode)->setAttribute(fgXIBaseAttrName, xil.getLocation());
}
}
- DOMNode *newChild = includeParent->insertBefore(newNode, xincludeNode);
- parseDOMNodeDoingXInclude(newChild, parsedDocument, entityResolver);
- }
- includeParent->removeChild(xincludeNode);
- modifiedNode = true;
- } else {
- /* empty fallback element - simply remove it! */
- includeParent->removeChild(xincludeNode);
- modifiedNode = true;
- }
- } else {
- XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeIncludeFailedNoFallback,
- parsedDocument->getDocumentURI(), parsedDocument->getDocumentURI());
- return false;
- }
- } else {
+ DOMNode *newChild = frag->appendChild(newNode);
+ parseDOMNodeDoingXInclude(newChild, parsedDocument, entityResolver);
+ }
+ includeParent->replaceChild(frag, xincludeNode);
+ frag->release();
+ modifiedNode = true;
+ } else {
+ /* empty fallback element - simply remove it! */
+ includeParent->removeChild(xincludeNode);
+ modifiedNode = true;
+ }
+ } else {
+ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeIncludeFailedNoFallback,
+ parsedDocument->getDocumentURI(), parsedDocument->getDocumentURI());
+ return false;
+ }
+ } else {
if (includedDoc){
/* record the successful include while we process the children */
addDocumentURIToCurrentInclusionHistoryStack(hrefLoc.getLocation());
+ DOMDocumentFragment* frag = parsedDocument->createDocumentFragment();
/* need to import the document prolog here */
DOMNode *child = includedDoc->getFirstChild();
for (; child != NULL; child = child->getNextSibling()) {
@@ -313,10 +318,10 @@
continue;
// check for NOTATION or ENTITY clash
if(child->getNodeType()==DOMNode::ELEMENT_NODE && includedDoc->getDoctype()!=NULL) {
- DOMNamedNodeMap *pAttributes = child->getAttributes();
- unsigned int nSize = pAttributes->getLength();
- for(unsigned int i=0;i<nSize;++i) {
- DOMAttr *pAttributeNode = (DOMAttr*) pAttributes->item(i);
+ DOMNamedNodeMap *pAttributes = child->getAttributes();
+ unsigned int nSize = pAttributes->getLength();
+ for(unsigned int i=0;i<nSize;++i) {
+ DOMAttr *pAttributeNode = (DOMAttr*) pAttributes->item(i);
const DOMTypeInfo * typeInfo=pAttributeNode->getSchemaTypeInfo();
if(typeInfo && XMLString::equals(typeInfo->getTypeNamespace(), XMLUni::fgInfosetURIName)) {
if(XMLString::equals(typeInfo->getTypeName(), XMLUni::fgNotationString)) {
@@ -340,8 +345,8 @@
else
{
// it's a conflict, report it
- XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeConflictingNotation,
- notationName, parsedDocument->getDocumentURI());
+ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeConflictingNotation,
+ notationName, parsedDocument->getDocumentURI());
}
}
else if(XMLString::equals(typeInfo->getTypeName(), XMLUni::fgEntityString)) {
@@ -365,30 +370,31 @@
else
{
// it's a conflict, report it
- XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeConflictingEntity,
- entityName, parsedDocument->getDocumentURI());
+ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeConflictingEntity,
+ entityName, parsedDocument->getDocumentURI());
}
}
}
}
}
DOMNode *newNode = parsedDocument->importNode(child, true);
- DOMNode *newChild = includeParent->insertBefore(newNode, xincludeNode);
+ DOMNode *newChild = frag->appendChild(newNode);
parseDOMNodeDoingXInclude(newChild, parsedDocument, entityResolver);
}
- includeParent->removeChild(xincludeNode);
+ includeParent->replaceChild(frag, xincludeNode);
+ frag->release();
popFromCurrentInclusionHistoryStack(NULL);
modifiedNode = true;
} else if (includedText){
includeParent->replaceChild(includedText, xincludeNode);
modifiedNode = true;
}
- }
+ }
- if (includedDoc)
- includedDoc->release();
+ if (includedDoc)
+ includedDoc->release();
- return modifiedNode;
+ return modifiedNode;
}
DOMDocument *
@@ -491,22 +497,22 @@
XIncludeUtils::doXIncludeTEXTFileDOM(const XMLCh *href,
const XMLCh *relativeHref,
const XMLCh *encoding,
- DOMNode *includeNode,
+ DOMNode *includeNode,
DOMDocument *parsedDocument,
XMLEntityHandler* entityResolver){
- if (encoding == NULL)
- /* "UTF-8" is stipulated default by spec */
- encoding = XMLUni::fgUTF8EncodingString;
+ if (encoding == NULL)
+ /* "UTF-8" is stipulated default by spec */
+ encoding = XMLUni::fgUTF8EncodingString;
- XMLTransService::Codes failReason;
- XMLTranscoder* transcoder = XMLPlatformUtils::fgTransService->makeNewTranscoderFor(encoding, failReason, 16*1024);
+ XMLTransService::Codes failReason;
+ XMLTranscoder* transcoder = XMLPlatformUtils::fgTransService->makeNewTranscoderFor(encoding, failReason, 16*1024);
Janitor<XMLTranscoder> janTranscoder(transcoder);
- if (failReason){
- XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeCannotOpenFile, href, href);
- return NULL;
+ if (failReason){
+ XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeCannotOpenFile, href, href);
+ return NULL;
}
- //addDocumentURIToCurrentInclusionHistoryStack(href);
+ //addDocumentURIToCurrentInclusionHistoryStack(href);
InputSource* is=NULL;
Janitor<InputSource> janIS(is);
@@ -522,14 +528,14 @@
if(janIS.get()==NULL)
janIS.reset(new URLInputSource(href));
if(janIS.get()==NULL) {
- XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeCannotOpenFile,
- href, href);
+ XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeCannotOpenFile,
+ href, href);
return NULL;
}
BinInputStream* stream=janIS.get()->makeStream();
if(stream==NULL) {
- XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeCannotOpenFile,
- href, href);
+ XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeCannotOpenFile,
+ href, href);
return NULL;
}
Janitor<BinInputStream> janStream(stream);
@@ -551,7 +557,7 @@
XMLBuffer repository;
while((nRead=stream->readBytes(buffer+nOffset, maxToRead-nOffset))>0){
XMLSize_t bytesEaten=0;
- XMLSize_t nCount = transcoder->transcodeFrom(buffer, nRead, xmlChars, maxToRead*2, bytesEaten, charSizes);
+ XMLSize_t nCount = transcoder->transcodeFrom(buffer, nRead, xmlChars, maxToRead*2, bytesEaten, charSizes);
repository.append(xmlChars, nCount);
if(bytesEaten<nRead) {
nOffset=nRead-bytesEaten;
@@ -563,62 +569,62 @@
/*static*/ bool
XIncludeUtils::isXIIncludeDOMNode(DOMNode *node){
- const XMLCh *nodeName = node->getLocalName();
- const XMLCh *namespaceURI = node->getNamespaceURI();
+ const XMLCh *nodeName = node->getLocalName();
+ const XMLCh *namespaceURI = node->getNamespaceURI();
- return isXIIncludeElement(nodeName, namespaceURI);
+ return isXIIncludeElement(nodeName, namespaceURI);
}
/*static*/ bool
XIncludeUtils::isXIFallbackDOMNode(DOMNode *node){
- const XMLCh *nodeName = node->getLocalName();
- const XMLCh *namespaceURI = node->getNamespaceURI();
+ const XMLCh *nodeName = node->getLocalName();
+ const XMLCh *namespaceURI = node->getNamespaceURI();
- return isXIFallbackElement(nodeName, namespaceURI);
+ return isXIFallbackElement(nodeName, namespaceURI);
}
/*static*/ bool
XIncludeUtils::isXIIncludeElement(const XMLCh *name, const XMLCh *namespaceURI){
- if (namespaceURI == NULL || name == NULL){
- /* no namespaces not supported */
- return false;
- }
- if (XMLString::equals(name, fgXIIncludeQName)
- && XMLString::equals(namespaceURI, fgXIIIncludeNamespaceURI)){
- return true;
- }
- return false;
+ if (namespaceURI == NULL || name == NULL){
+ /* no namespaces not supported */
+ return false;
+ }
+ if (XMLString::equals(name, fgXIIncludeQName)
+ && XMLString::equals(namespaceURI, fgXIIIncludeNamespaceURI)){
+ return true;
+ }
+ return false;
}
-
+
/*static*/ bool
XIncludeUtils::isXIFallbackElement(const XMLCh *name, const XMLCh *namespaceURI){
- if (namespaceURI == NULL || name == NULL){
- /* no namespaces not supported */
- return false;
- }
- if (XMLString::equals(name, fgXIFallbackQName)
- && XMLString::equals(namespaceURI, fgXIIIncludeNamespaceURI)){
- return true;
- }
- return false;
+ if (namespaceURI == NULL || name == NULL){
+ /* no namespaces not supported */
+ return false;
+ }
+ if (XMLString::equals(name, fgXIFallbackQName)
+ && XMLString::equals(namespaceURI, fgXIIIncludeNamespaceURI)){
+ return true;
+ }
+ return false;
}
/* 4.1.1 */
const XMLCh *
XIncludeUtils::getEscapedHRefAttrValue(const XMLCh * /*hrefAttrValue*/, bool & /*needsDeallocating*/){
- XMLCh *escapedAttr = NULL;
- return escapedAttr;
+ XMLCh *escapedAttr = NULL;
+ return escapedAttr;
}
/* 4.1.2 */
bool
XIncludeUtils::setContentNegotiation(const XMLCh * /*acceptAttrValue*/, const XMLCh * /*acceptLangAttrValue*/){
- return false;
+ return false;
}
bool
XIncludeUtils::checkTextIsValidForInclude(XMLCh * /*includeChars*/){
- return false;
+ return false;
}
// ========================================================
@@ -627,128 +633,128 @@
// ========================================================
static XIncludeHistoryNode *
getTopOfCurrentInclusionHistoryStack(XIncludeHistoryNode *head){
- XIncludeHistoryNode *historyCursor = head;
- if (historyCursor == NULL){
- return NULL;
- }
- while (historyCursor->next != NULL){
- historyCursor = historyCursor->next;
- }
- return historyCursor;
+ XIncludeHistoryNode *historyCursor = head;
+ if (historyCursor == NULL){
+ return NULL;
+ }
+ while (historyCursor->next != NULL){
+ historyCursor = historyCursor->next;
+ }
+ return historyCursor;
}
bool
XIncludeUtils::addDocumentURIToCurrentInclusionHistoryStack(const XMLCh *URItoAdd){
- XIncludeHistoryNode *newNode = (XIncludeHistoryNode *)XMLPlatformUtils::fgMemoryManager->allocate(sizeof(XIncludeHistoryNode));
- if (newNode == NULL){
- return false;
- }
- newNode->URI = XMLString::replicate(URItoAdd);
- newNode->next = NULL;
-
- if (fIncludeHistoryHead == NULL){
- fIncludeHistoryHead = newNode;
- return true;
- }
- XIncludeHistoryNode *topNode = getTopOfCurrentInclusionHistoryStack(fIncludeHistoryHead);
- topNode->next = newNode;
- return true;
+ XIncludeHistoryNode *newNode = (XIncludeHistoryNode *)XMLPlatformUtils::fgMemoryManager->allocate(sizeof(XIncludeHistoryNode));
+ if (newNode == NULL){
+ return false;
+ }
+ newNode->URI = XMLString::replicate(URItoAdd);
+ newNode->next = NULL;
+
+ if (fIncludeHistoryHead == NULL){
+ fIncludeHistoryHead = newNode;
+ return true;
+ }
+ XIncludeHistoryNode *topNode = getTopOfCurrentInclusionHistoryStack(fIncludeHistoryHead);
+ topNode->next = newNode;
+ return true;
}
bool
XIncludeUtils::isInCurrentInclusionHistoryStack(const XMLCh *toFind){
- XIncludeHistoryNode *historyCursor = fIncludeHistoryHead;
- /* walk the list */
- while (historyCursor != NULL){
- if (XMLString::equals(toFind, historyCursor->URI)){
- return true;
- }
- historyCursor = historyCursor->next;
- }
- return false;
+ XIncludeHistoryNode *historyCursor = fIncludeHistoryHead;
+ /* walk the list */
+ while (historyCursor != NULL){
+ if (XMLString::equals(toFind, historyCursor->URI)){
+ return true;
+ }
+ historyCursor = historyCursor->next;
+ }
+ return false;
}
XIncludeHistoryNode *
XIncludeUtils::popFromCurrentInclusionHistoryStack(const XMLCh * /*toPop*/){
- XIncludeHistoryNode *historyCursor = fIncludeHistoryHead;
- XIncludeHistoryNode *penultimateCursor = historyCursor;
+ XIncludeHistoryNode *historyCursor = fIncludeHistoryHead;
+ XIncludeHistoryNode *penultimateCursor = historyCursor;
+
+ if (fIncludeHistoryHead == NULL){
+ return NULL;
+ }
+
+ while (historyCursor->next != NULL){
+ penultimateCursor = historyCursor;
+ historyCursor = historyCursor->next;
+ }
+
+ if (penultimateCursor == fIncludeHistoryHead){
+ historyCursor = fIncludeHistoryHead;
+ fIncludeHistoryHead = NULL;
+ } else {
+ penultimateCursor->next = NULL;
+ }
- if (fIncludeHistoryHead == NULL){
- return NULL;
- }
-
- while (historyCursor->next != NULL){
- penultimateCursor = historyCursor;
- historyCursor = historyCursor->next;
- }
-
- if (penultimateCursor == fIncludeHistoryHead){
- historyCursor = fIncludeHistoryHead;
- fIncludeHistoryHead = NULL;
- } else {
- penultimateCursor->next = NULL;
- }
-
- // XERCES_STD_QUALIFIER cerr << "poppinURIofStack " << XMLString::transcode(historyCursor->URI) << XERCES_STD_QUALIFIER endl;
- XMLString::release(&(historyCursor->URI));
- XMLPlatformUtils::fgMemoryManager->deallocate((void *)historyCursor);
- return NULL;
+ // XERCES_STD_QUALIFIER cerr << "poppinURIofStack " << XMLString::transcode(historyCursor->URI) << XERCES_STD_QUALIFIER endl;
+ XMLString::release(&(historyCursor->URI));
+ XMLPlatformUtils::fgMemoryManager->deallocate((void *)historyCursor);
+ return NULL;
}
void
XIncludeUtils::freeInclusionHistory(){
- XIncludeHistoryNode *historyCursor = XIncludeUtils::fIncludeHistoryHead;
- while (historyCursor != NULL){
- XIncludeHistoryNode *next = historyCursor->next;
- /* XMLString::release(&(historyCursor->URI));
- XMLPlatformUtils::fgMemoryManager->deallocate((void *)historyCursor); */
- historyCursor = next;
- }
- XIncludeUtils::fIncludeHistoryHead = NULL;
+ XIncludeHistoryNode *historyCursor = XIncludeUtils::fIncludeHistoryHead;
+ while (historyCursor != NULL){
+ XIncludeHistoryNode *next = historyCursor->next;
+ /* XMLString::release(&(historyCursor->URI));
+ XMLPlatformUtils::fgMemoryManager->deallocate((void *)historyCursor); */
+ historyCursor = next;
+ }
+ XIncludeUtils::fIncludeHistoryHead = NULL;
}
bool
XIncludeUtils::reportError(const DOMNode* const /*errorNode*/
, XMLErrs::Codes errorType
, const XMLCh* const errorMsg
- , const XMLCh * const href)
+ , const XMLCh * const href)
{
bool toContinueProcess = true; /* default value for no error handler */
- const XMLCh* const systemId = href;
- const XMLCh* const publicId = href;
+ const XMLCh* const systemId = href;
+ const XMLCh* const publicId = href;
/* TODO - look these up somehow? */
const unsigned long lineNum = 0;
const unsigned long colNum = 0;
if (fErrorReporter)
{
- // Load the message into a local for display
+ // Load the message into a local for display
const XMLSize_t msgSize = 1023;
XMLCh errText[msgSize + 1];
- /* TODO - investigate whether this is complete */
- XMLMsgLoader *errMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgXMLErrDomain);
- if (errorMsg == NULL){
- if (errMsgLoader->loadMsg(errorType, errText, msgSize))
- {
- // <TBD> Probably should load a default msg here
- }
- } else {
- if (errMsgLoader->loadMsg(errorType, errText, msgSize, errorMsg))
- {
- // <TBD> Probably should load a default msg here
- }
- }
-
+ /* TODO - investigate whether this is complete */
+ XMLMsgLoader *errMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgXMLErrDomain);
+ if (errorMsg == NULL){
+ if (errMsgLoader->loadMsg(errorType, errText, msgSize))
+ {
+ // <TBD> Probably should load a default msg here
+ }
+ } else {
+ if (errMsgLoader->loadMsg(errorType, errText, msgSize, errorMsg))
+ {
+ // <TBD> Probably should load a default msg here
+ }
+ }
+
fErrorReporter->error(errorType
- , XMLUni::fgXMLErrDomain //fgXMLErrDomain
- , XMLErrs::errorType(errorType)
- , errText
- , systemId
- , publicId
- , lineNum
- , colNum);
+ , XMLUni::fgXMLErrDomain //fgXMLErrDomain
+ , XMLErrs::errorType(errorType)
+ , errText
+ , systemId
+ , publicId
+ , lineNum
+ , colNum);
}
if (XMLErrs::isFatal(errorType))
@@ -761,58 +767,58 @@
util/XMLUni.cpp before releasing */
const XMLCh XIncludeUtils::fgXIIncludeQName[] =
{
- chLatin_i, chLatin_n, chLatin_c, chLatin_l, chLatin_u, chLatin_d, chLatin_e, chNull
+ chLatin_i, chLatin_n, chLatin_c, chLatin_l, chLatin_u, chLatin_d, chLatin_e, chNull
};
const XMLCh XIncludeUtils::fgXIFallbackQName[] =
{
- chLatin_f, chLatin_a, chLatin_l, chLatin_l, chLatin_b, chLatin_a, chLatin_c, chLatin_k, chNull
+ chLatin_f, chLatin_a, chLatin_l, chLatin_l, chLatin_b, chLatin_a, chLatin_c, chLatin_k, chNull
};
const XMLCh XIncludeUtils::fgXIIncludeHREFAttrName[] =
{
- chLatin_h, chLatin_r, chLatin_e, chLatin_f, chNull
+ chLatin_h, chLatin_r, chLatin_e, chLatin_f, chNull
};
const XMLCh XIncludeUtils::fgXIIncludeParseAttrName[] =
{
- chLatin_p, chLatin_a, chLatin_r, chLatin_s, chLatin_e, chNull
+ chLatin_p, chLatin_a, chLatin_r, chLatin_s, chLatin_e, chNull
};
const XMLCh XIncludeUtils::fgXIIncludeXPointerAttrName[] =
{
- chLatin_x, chLatin_p, chLatin_o, chLatin_i, chLatin_n, chLatin_t, chLatin_e, chLatin_r, chNull
+ chLatin_x, chLatin_p, chLatin_o, chLatin_i, chLatin_n, chLatin_t, chLatin_e, chLatin_r, chNull
};
const XMLCh XIncludeUtils::fgXIIncludeEncodingAttrName[] =
{
- chLatin_e, chLatin_n, chLatin_c, chLatin_o, chLatin_d, chLatin_i, chLatin_n, chLatin_g, chNull
+ chLatin_e, chLatin_n, chLatin_c, chLatin_o, chLatin_d, chLatin_i, chLatin_n, chLatin_g, chNull
};
const XMLCh XIncludeUtils::fgXIIncludeAcceptAttrName[] =
{
- chLatin_a, chLatin_c, chLatin_c, chLatin_e, chLatin_p, chLatin_t, chNull
+ chLatin_a, chLatin_c, chLatin_c, chLatin_e, chLatin_p, chLatin_t, chNull
};
const XMLCh XIncludeUtils::fgXIIncludeAcceptLanguageAttrName[] =
{
- chLatin_a, chLatin_c, chLatin_c, chLatin_e, chLatin_p, chLatin_t, chDash, chLatin_l, chLatin_a,
- chLatin_n, chLatin_g, chLatin_u, chLatin_a, chLatin_g, chLatin_e, chNull
+ chLatin_a, chLatin_c, chLatin_c, chLatin_e, chLatin_p, chLatin_t, chDash, chLatin_l, chLatin_a,
+ chLatin_n, chLatin_g, chLatin_u, chLatin_a, chLatin_g, chLatin_e, chNull
};
const XMLCh XIncludeUtils::fgXIIncludeParseAttrXMLValue[] =
{
- chLatin_x, chLatin_m, chLatin_l, chNull
+ chLatin_x, chLatin_m, chLatin_l, chNull
};
const XMLCh XIncludeUtils::fgXIIncludeParseAttrTextValue[] =
{
- chLatin_t, chLatin_e, chLatin_x, chLatin_t, chNull
+ chLatin_t, chLatin_e, chLatin_x, chLatin_t, chNull
};
const XMLCh XIncludeUtils::fgXIIIncludeNamespaceURI[] =
{
- /* http://www.w3.org/2001/XInclude */
- chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash
+ /* http://www.w3.org/2001/XInclude */
+ chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash
, chForwardSlash, chLatin_w, chLatin_w, chLatin_w, chPeriod
, chLatin_w, chDigit_3, chPeriod, chLatin_o, chLatin_r, chLatin_g
, chForwardSlash, chDigit_2, chDigit_0, chDigit_0, chDigit_1
- , chForwardSlash, chLatin_X, chLatin_I, chLatin_n, chLatin_c, chLatin_l
- , chLatin_u, chLatin_d, chLatin_e, chNull
+ , chForwardSlash, chLatin_X, chLatin_I, chLatin_n, chLatin_c, chLatin_l
+ , chLatin_u, chLatin_d, chLatin_e, chNull
};
const XMLCh XIncludeUtils::fgXIBaseAttrName[] =
{
- chLatin_x, chLatin_m, chLatin_l, chColon, chLatin_b, chLatin_a, chLatin_s, chLatin_e, chNull
+ chLatin_x, chLatin_m, chLatin_l, chColon, chLatin_b, chLatin_a, chLatin_s, chLatin_e, chNull
};
XERCES_CPP_NAMESPACE_END
Modified: xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.hpp?rev=655706&r1=655705&r2=655706&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.hpp (original)
+++ xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.hpp Mon May 12 18:08:39 2008
@@ -36,8 +36,8 @@
class XMLEntityHandler;
typedef struct XIncludeHistoryNode{
- XMLCh *URI;
- struct XIncludeHistoryNode *next;
+ XMLCh *URI;
+ struct XIncludeHistoryNode *next;
}XIncludeHistoryNode;
/**
@@ -51,215 +51,215 @@
{
private:
- /** Constructor
- *
- */
- XIncludeUtils(XMLErrorReporter *errorReporter);
-
- /** Destructor
- *
- */
- ~XIncludeUtils();
+ /** Constructor
+ *
+ */
+ XIncludeUtils(XMLErrorReporter *errorReporter);
+
+ /** Destructor
+ *
+ */
+ ~XIncludeUtils();
- /** Parse the supplied XInclude element performing relevant XInclude functionality
- *
+ /** Parse the supplied XInclude element performing relevant XInclude functionality
+ *
* @param xincludeNode The XInclude node to parse and action
- * @param parsedDocument The DOMDocument to which the results of the XInclude are to be added
- *
+ * @param parsedDocument The DOMDocument to which the results of the XInclude are to be added
+ *
* @return true if the XInclude processing was successful, false if not. Note that an
- * XInclude that fails resulting in a successful fallback action would return true.
+ * XInclude that fails resulting in a successful fallback action would return true.
*/
- bool doDOMNodeXInclude(DOMNode *xincludeNode, DOMDocument *parsedDocument, XMLEntityHandler* entityResolver);
+ bool doDOMNodeXInclude(DOMNode *xincludeNode, DOMDocument *parsedDocument, XMLEntityHandler* entityResolver);
- /** Parse an XInclude xml file into a DOMDocument node.
- *
+ /** Parse an XInclude xml file into a DOMDocument node.
+ *
* @param href the location of the document to include
* @param relativeHref
- * @param parsedDocument
- *
+ * @param parsedDocument
+ *
* @return a newly created DOMDocument containing the parsed and actioned
- * href, or NULL if the document could not be loaded.
+ * href, or NULL if the document could not be loaded.
*/
- DOMDocument *doXIncludeXMLFileDOM(const XMLCh *href,
- const XMLCh *relativeHref,
- DOMNode *xincludeNode,
- DOMDocument *parsedDocument,
- XMLEntityHandler* entityResolver);
+ DOMDocument *doXIncludeXMLFileDOM(const XMLCh *href,
+ const XMLCh *relativeHref,
+ DOMNode *xincludeNode,
+ DOMDocument *parsedDocument,
+ XMLEntityHandler* entityResolver);
- /** Parse an XInclude text file into a DOMText node.
- *
+ /** Parse an XInclude text file into a DOMText node.
+ *
* @param href the location of the document to include
* @param relativeHref
- * @param encoding
- * @param parsedDocument
- *
+ * @param encoding
+ * @param parsedDocument
+ *
* @return a newly created DOMText containing the parsed and actioned
- * href, or NULL if the document could not be loaded.
+ * href, or NULL if the document could not be loaded.
*/
- DOMText *doXIncludeTEXTFileDOM(const XMLCh *href,
- const XMLCh *relativeHref,
- const XMLCh *encoding,
- DOMNode *xincludeNode,
- DOMDocument *parsedDocument,
- XMLEntityHandler* entityResolver);
+ DOMText *doXIncludeTEXTFileDOM(const XMLCh *href,
+ const XMLCh *relativeHref,
+ const XMLCh *encoding,
+ DOMNode *xincludeNode,
+ DOMDocument *parsedDocument,
+ XMLEntityHandler* entityResolver);
- /** Detect whether the supplied details are correct for an xi:include element
- *
+ /** Detect whether the supplied details are correct for an xi:include element
+ *
* @param name the element name
- * @param namespaceURI the element namespace
- *
+ * @param namespaceURI the element namespace
+ *
* @return true if details are valid for an xi:include element, false
- * if not.
+ * if not.
*/
- static bool isXIIncludeElement(const XMLCh *name, const XMLCh *namespaceURI);
+ static bool isXIIncludeElement(const XMLCh *name, const XMLCh *namespaceURI);
- /** Detect whether the supplied details are correct for an xi:fallback element
- *
+ /** Detect whether the supplied details are correct for an xi:fallback element
+ *
* @param name the element name
- * @param namespaceURI the element namespace
- *
+ * @param namespaceURI the element namespace
+ *
* @return true if details are valid for an xi:fallback element, false
- * if not.
+ * if not.
*/
- static bool isXIFallbackElement(const XMLCh *name, const XMLCh *namespaceURI);
+ static bool isXIFallbackElement(const XMLCh *name, const XMLCh *namespaceURI);
- /** Detect whether the supplied DOMNode is an xi:include element
- *
+ /** Detect whether the supplied DOMNode is an xi:include element
+ *
* @param node The node to check
- *
+ *
* @return true if node is an xi:include element, false
- * if not.
+ * if not.
*/
- static bool isXIIncludeDOMNode(DOMNode *node);
+ static bool isXIIncludeDOMNode(DOMNode *node);
- /** Detect whether the supplied DOMNode is an xi:fallback element
- *
+ /** Detect whether the supplied DOMNode is an xi:fallback element
+ *
* @param node The DOMNode to check
- *
+ *
* @return true if node is an xi:fallback element, false
- * if not.
+ * if not.
*/
- static bool isXIFallbackDOMNode(DOMNode *node);
+ static bool isXIFallbackDOMNode(DOMNode *node);
- /** Walk the content of the supplied source node, performing any xinclude actions
- * that are encountered.
- *
+ /** Walk the content of the supplied source node, performing any xinclude actions
+ * that are encountered.
+ *
* @param source A DOMNode to parse, this node may be modified by the method
- * @param parsedDocument the DOMDocument to which the parsed results are to be copied.
- *
+ * @param parsedDocument the DOMDocument to which the parsed results are to be copied.
+ *
* @return true if XInclude behaviour was successfully performed on source, false if not.
*/
- bool parseDOMNodeDoingXInclude(DOMNode *source, DOMDocument *parsedDocument, XMLEntityHandler* entityResolver);
+ bool parseDOMNodeDoingXInclude(DOMNode *source, DOMDocument *parsedDocument, XMLEntityHandler* entityResolver);
- /** Parse the supplied URI and escape all characters as specified by
- * the XINclusions specification.
- *
+ /** Parse the supplied URI and escape all characters as specified by
+ * the XINclusions specification.
+ *
* @param hrefAttrValue the href to parse and escape.
* @param needsDeallocating set to true if the return value needs deallocating
- * by the caller after use, false if the value returned is the same as the
- * hrefAttrValue passed in.
- *
+ * by the caller after use, false if the value returned is the same as the
+ * hrefAttrValue passed in.
+ *
* @return an escaped version of hrefAttrValue or hrefAttrValue itself if
- * hrefAttrValue contains only valid characters.
+ * hrefAttrValue contains only valid characters.
*/
- /* 4.1.1 */
- const XMLCh *getEscapedHRefAttrValue(const XMLCh *hrefAttrValue, bool &needsDeallocating);
-
- /** Set the accept and accept-lang parameters on HTTP requests generated while
- * XIncluding.
- *
+ /* 4.1.1 */
+ const XMLCh *getEscapedHRefAttrValue(const XMLCh *hrefAttrValue, bool &needsDeallocating);
+
+ /** Set the accept and accept-lang parameters on HTTP requests generated while
+ * XIncluding.
+ *
* @param acceptAttrValue
* @param acceptLangAttrValue
- *
+ *
* @return true if the values were successfully added to the HTTP request, false
- * if not.
+ * if not.
*/
- /* 4.1.2 */
- bool setContentNegotiation(const XMLCh *acceptAttrValue, const XMLCh *acceptLangAttrValue);
+ /* 4.1.2 */
+ bool setContentNegotiation(const XMLCh *acceptAttrValue, const XMLCh *acceptLangAttrValue);
- /** Check the characters passed in are all valid characters for XInclusion
- * as specified at http://www.w3.org/TR/xinclude/#text-included-items
- *
+ /** Check the characters passed in are all valid characters for XInclusion
+ * as specified at http://www.w3.org/TR/xinclude/#text-included-items
+ *
* @param includeChars the characters to parse for validity
- *
+ *
* @return true if the includeChars parameter contains only valid characters
- * for inclusion, false if there are invalid characters in includeChars.
+ * for inclusion, false if there are invalid characters in includeChars.
*/
- bool checkTextIsValidForInclude(XMLCh *includeChars);
+ bool checkTextIsValidForInclude(XMLCh *includeChars);
- /** Add the supplied parameter to the InclusionHistoryStack
- *
+ /** Add the supplied parameter to the InclusionHistoryStack
+ *
* @param URItoAdd the URI to add to the InclusionHistoryStack/
- *
+ *
* @return true if the URI was added, false if a problem prevented
- * the URI being added.
+ * the URI being added.
*/
- bool addDocumentURIToCurrentInclusionHistoryStack(const XMLCh *URItoAdd);
+ bool addDocumentURIToCurrentInclusionHistoryStack(const XMLCh *URItoAdd);
- /** Check the XInclude InclusionHistoryStack to see if the supplied URI
- * has already been included. This is used to ensure that circular inclusion
- * chains are detected and that the inclusion mechanism does not get stuck in
- * a loop.
- *
+ /** Check the XInclude InclusionHistoryStack to see if the supplied URI
+ * has already been included. This is used to ensure that circular inclusion
+ * chains are detected and that the inclusion mechanism does not get stuck in
+ * a loop.
+ *
* @param toFind the URI to look up.
- *
+ *
* @return true if the toFind parameter is found in the InclusionHistortStack,
- * false if the parameter is not in the stack or the stack is empty.
+ * false if the parameter is not in the stack or the stack is empty.
*/
- bool isInCurrentInclusionHistoryStack(const XMLCh *toFind);
+ bool isInCurrentInclusionHistoryStack(const XMLCh *toFind);
- /** Pop (i.e. remove and return) the top value from the InclusionHistoryStack
- *
+ /** Pop (i.e. remove and return) the top value from the InclusionHistoryStack
+ *
* @param toPop the value that is expected to be at the top of the stack, or
- * NULL if no checking is required.
- *
+ * NULL if no checking is required.
+ *
* @return the element at the top of the stack
*/
- XIncludeHistoryNode * popFromCurrentInclusionHistoryStack(const XMLCh *toPop);
+ XIncludeHistoryNode * popFromCurrentInclusionHistoryStack(const XMLCh *toPop);
- /** Free the internal inclusion history list.
- *
+ /** Free the internal inclusion history list.
+ *
* @return nothing
*/
- void freeInclusionHistory();
+ void freeInclusionHistory();
- /** Construct and pass on an error description
- *
+ /** Construct and pass on an error description
+ *
* @param errorNode The DOMNode that was being parsed when the error occurred
* @param errorType The severity of the error
- * @param errorMsg An optional message to include in the error report
- * @param href The URI of the document being parsed.
- *
+ * @param errorMsg An optional message to include in the error report
+ * @param href The URI of the document being parsed.
+ *
* @return true if the errorHandler requests continuation of parsing despite error
- * false if the errorHandler requests parsing end on encountering error, or it
- * there is no error handler.
+ * false if the errorHandler requests parsing end on encountering error, or it
+ * there is no error handler.
*/
- bool reportError(const DOMNode* const errorNode
+ bool reportError(const DOMNode* const errorNode
, XMLErrs::Codes errorType
, const XMLCh* const errorMsg
- , const XMLCh* const href);
+ , const XMLCh* const href);
public:
- /* temporarily public to facilitate helper func getBaseAttrValue */
- static const XMLCh fgXIBaseAttrName[];
+ /* temporarily public to facilitate helper func getBaseAttrValue */
+ static const XMLCh fgXIBaseAttrName[];
private:
- XIncludeHistoryNode *fIncludeHistoryHead;
- long fErrorCount;
- XMLErrorReporter *fErrorReporter;
- static const XMLCh fgXIIncludeQName[];
- static const XMLCh fgXIFallbackQName[];
- static const XMLCh fgXIIncludeHREFAttrName[];
- static const XMLCh fgXIIncludeParseAttrName[];
- static const XMLCh fgXIIncludeParseAttrXMLValue[];
- static const XMLCh fgXIIncludeParseAttrTextValue[];
- static const XMLCh fgXIIncludeXPointerAttrName[];
- static const XMLCh fgXIIncludeEncodingAttrName[];
- static const XMLCh fgXIIncludeAcceptAttrName[];
- static const XMLCh fgXIIncludeAcceptLanguageAttrName[];
- static const XMLCh fgXIIIncludeNamespaceURI[];
+ XIncludeHistoryNode *fIncludeHistoryHead;
+ long fErrorCount;
+ XMLErrorReporter *fErrorReporter;
+ static const XMLCh fgXIIncludeQName[];
+ static const XMLCh fgXIFallbackQName[];
+ static const XMLCh fgXIIncludeHREFAttrName[];
+ static const XMLCh fgXIIncludeParseAttrName[];
+ static const XMLCh fgXIIncludeParseAttrXMLValue[];
+ static const XMLCh fgXIIncludeParseAttrTextValue[];
+ static const XMLCh fgXIIncludeXPointerAttrName[];
+ static const XMLCh fgXIIncludeEncodingAttrName[];
+ static const XMLCh fgXIIncludeAcceptAttrName[];
+ static const XMLCh fgXIIncludeAcceptLanguageAttrName[];
+ static const XMLCh fgXIIIncludeNamespaceURI[];
- friend class XIncludeDOMDocumentProcessor;
- friend class AbstractDOMParser;
+ friend class XIncludeDOMDocumentProcessor;
+ friend class AbstractDOMParser;
};
XERCES_CPP_NAMESPACE_END
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org