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 2007/03/02 09:55:53 UTC
svn commit: r513661 [4/4] - in /xerces/c/trunk: samples/src/XInclude/
src/xercesc/NLS/EN_US/ src/xercesc/dom/impl/ src/xercesc/framework/
src/xercesc/parsers/ src/xercesc/util/
src/xercesc/util/MsgLoaders/ICU/resources/
src/xercesc/util/MsgLoaders/InMe...
Modified: xerces/c/trunk/src/xercesc/util/XMLUni.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/XMLUni.cpp?view=diff&rev=513661&r1=513660&r2=513661
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLUni.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLUni.cpp Fri Mar 2 00:55:51 2007
@@ -900,6 +900,14 @@
, chLatin_p, chLatin_t, chLatin_i, chLatin_o, chLatin_n, chNull
};
+const XMLCh XMLUni::fgXMLXIncludeException_Name[] =
+{
+ chLatin_X, chLatin_M, chLatin_L, chLatin_X, chLatin_I, chLatin_n
+ , chLatin_c, chLatin_l, chLatin_u, chLatin_d, chLatin_e, chLatin_E
+ , chLatin_x, chLatin_c, chLatin_e, chLatin_p, chLatin_t, chLatin_i
+ , chLatin_o, chLatin_n, chNull
+};
+
const XMLCh XMLUni::fgNegINFString[] =
{
chDash, chLatin_I, chLatin_N, chLatin_F, chNull
@@ -1657,6 +1665,13 @@
chLatin_e, chLatin_I, chLatin_m, chLatin_p, chLatin_l, chNull
};
+const XMLCh XMLUni::fgXercescInterfaceDOMDocumentImpl[] =
+{
+ chLatin_D, chLatin_O, chLatin_M, chLatin_D, chLatin_o, chLatin_c, chLatin_u,
+ chLatin_m, chLatin_e, chLatin_n, chLatin_t, chLatin_I, chLatin_m, chLatin_p,
+ chLatin_l, chNull
+};
+
const XMLCh XMLUni::fgXercescInterfaceDOMMemoryManager[] =
{
chLatin_D, chLatin_O, chLatin_M, chLatin_M, chLatin_e, chLatin_m, chLatin_o,
@@ -1797,7 +1812,14 @@
{ chDigit_1, chNull }
};
+const XMLCh XMLUni::fgXercesDoXInclude[] =
+{
+ /* temp value */
+ chLatin_D, chLatin_o, chLatin_X, chLatin_I, chNull
+};
+
const unsigned int XMLUni::fgBooleanValueSpaceArraySize = sizeof XMLUni::fgBooleanValueSpace / sizeof (XMLUni::fgBooleanValueSpace[0]);
XERCES_CPP_NAMESPACE_END
+
Modified: xerces/c/trunk/src/xercesc/util/XMLUni.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/XMLUni.hpp?view=diff&rev=513661&r1=513660&r2=513661
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLUni.hpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLUni.hpp Fri Mar 2 00:55:51 2007
@@ -195,6 +195,7 @@
static const XMLCh fgSchemaDateTimeException_Name[];
static const XMLCh fgXPathException_Name[];
static const XMLCh fgXSerializationException_Name[];
+ static const XMLCh fgXMLXIncludeException_Name[];
// Numerical String
static const XMLCh fgNegINFString[];
@@ -233,6 +234,7 @@
static const XMLCh fgXercesSkipDTDValidation[];
static const XMLCh fgXercesEntityResolver[];
+ static const XMLCh fgXercesDoXInclude[];
// SAX2 features/properties names
static const XMLCh fgSAX2CoreValidation[];
static const XMLCh fgSAX2CoreNameSpaces[];
@@ -284,6 +286,7 @@
// Private interface names
static const XMLCh fgXercescInterfacePSVITypeInfo[];
static const XMLCh fgXercescInterfaceDOMDocumentTypeImpl[];
+ static const XMLCh fgXercescInterfaceDOMDocumentImpl[];
static const XMLCh fgXercescInterfaceDOMMemoryManager[];
// Locale
Modified: xerces/c/trunk/src/xercesc/util/XercesDefs.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/XercesDefs.hpp?view=diff&rev=513661&r1=513660&r2=513661
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XercesDefs.hpp (original)
+++ xerces/c/trunk/src/xercesc/util/XercesDefs.hpp Fri Mar 2 00:55:51 2007
@@ -144,6 +144,7 @@
#define CDOM_EXPORT XERCES_PLATFORM_EXPORT
#define PARSERS_EXPORT XERCES_PLATFORM_EXPORT
#define VALIDATORS_EXPORT XERCES_PLATFORM_EXPORT
+ #define XINCLUDE_EXPORT XERCES_PLATFORM_EXPORT
#else
#define XMLUTIL_EXPORT XERCES_PLATFORM_IMPORT
#define XMLPARSER_EXPORT XERCES_PLATFORM_IMPORT
@@ -152,6 +153,7 @@
#define CDOM_EXPORT XERCES_PLATFORM_IMPORT
#define PARSERS_EXPORT XERCES_PLATFORM_IMPORT
#define VALIDATORS_EXPORT XERCES_PLATFORM_IMPORT
+ #define XINCLUDE_EXPORT XERCES_PLATFORM_IMPORT
#endif
#if defined(XERCES_BUILDING_DEPRECATED_LIBRARY)
#define DEPRECATED_DOM_EXPORT XERCES_PLATFORM_EXPORT
@@ -167,6 +169,7 @@
#define DEPRECATED_DOM_EXPORT
#define PARSERS_EXPORT
#define VALIDATORS_EXPORT
+ #define XINCLUDE_EXPORT
#endif
#endif
Added: xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.cpp?view=auto&rev=513661
==============================================================================
--- xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.cpp (added)
+++ xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.cpp Fri Mar 2 00:55:51 2007
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * $Id$
+ */
+
+
+// ---------------------------------------------------------------------------
+// Includes
+// ---------------------------------------------------------------------------
+#include <xercesc/xinclude/XIncludeDOMDocumentProcessor.hpp>
+#include <xercesc/xinclude/XIncludeUtils.hpp>
+#include <xercesc/dom/DOM.hpp>
+#include <xercesc/util/XMLUniDefs.hpp>
+#include <xercesc/framework/XMLErrorReporter.hpp>
+
+XERCES_CPP_NAMESPACE_BEGIN
+
+DOMDocument *
+XIncludeDOMDocumentProcessor::doXIncludeDOMProcess(const DOMDocument * const source, XMLErrorReporter *errorHandler){
+ XIncludeUtils xiu(errorHandler);
+
+ 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);
+
+ xincludedDocument->normalizeDocument();
+ }
+ catch(const XMLErrs::Codes)
+ {
+ xincludedDocument->release();
+ return NULL;
+ }
+ catch(...)
+ {
+ xincludedDocument->release();
+ throw;
+ }
+
+ return xincludedDocument;
+}
+
+XERCES_CPP_NAMESPACE_END
Propchange: xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.hpp?view=auto&rev=513661
==============================================================================
--- xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.hpp (added)
+++ xerces/c/trunk/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.hpp Fri Mar 2 00:55:51 2007
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * $Id: $
+ */
+
+#if !defined(XINCLUDEDOMDOCUMENTPROCESSOR_HPP)
+#define XINCLUDEDOMDOCUMENTPROCESSOR_HPP
+
+#include <xercesc/util/XercesDefs.hpp>
+#include <xercesc/dom/DOM.hpp>
+#include <xercesc/framework/XMLErrorReporter.hpp>
+
+XERCES_CPP_NAMESPACE_BEGIN
+
+/**
+ * Class for representing and manipulating the XMLCh * href's used
+ * by an xi:include element.
+ *
+ * This class is designed primarily for internal use. This class implements
+ * the functionality required to calculate relative hrefs and the base URI
+ * fixups required for performing XInclude functionality.
+ */
+class XINCLUDE_EXPORT XIncludeDOMDocumentProcessor
+{
+public:
+ /** 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.
+ */
+ DOMDocument *doXIncludeDOMProcess(const DOMDocument * const source, XMLErrorReporter *errorHandler);
+};
+
+XERCES_CPP_NAMESPACE_END
+
+#endif /* XINCLUDEDOMDOCUMENTPROCESSOR_HPP */
+
Added: xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.cpp?view=auto&rev=513661
==============================================================================
--- xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.cpp (added)
+++ xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.cpp Fri Mar 2 00:55:51 2007
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * $Id$
+ */
+
+
+// ---------------------------------------------------------------------------
+// Includes
+// ---------------------------------------------------------------------------
+#include <xercesc/xinclude/XIncludeLocation.hpp>
+#include <xercesc/dom/DOM.hpp>
+#include <xercesc/util/XMLUniDefs.hpp>
+
+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);
+
+ return allocated;
+}
+
+void deallocate(void *ptr){
+ if (ptr)
+ XMLPlatformUtils::fgMemoryManager->deallocate((void *)ptr);
+}
+
+// ---------------------------------------------------------------------------
+// Destructor and Constructor
+// ---------------------------------------------------------------------------
+XIncludeLocation::XIncludeLocation(const XMLCh *href){
+ size_t length = XMLString::stringLen(href);
+ fHref = allocate(href);
+}
+
+XIncludeLocation::~XIncludeLocation(){
+ deallocate((void *)fHref);
+}
+
+const XMLCh *
+XIncludeLocation::prependPath(const XMLCh *baseToAdd){
+ XMLCh *relativeHref = NULL;
+ if (fHref == NULL){
+ return NULL;
+ }
+ int fileLength = XMLString::stringLen(fHref);
+
+ if (baseToAdd == NULL){
+ return fHref;
+ }
+
+ XMLPlatformUtils::removeDotDotSlash((XMLCh *const)baseToAdd);
+ int 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;
+}
+
+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;
+}
+
+XERCES_CPP_NAMESPACE_END
Propchange: xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.hpp?view=auto&rev=513661
==============================================================================
--- xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.hpp (added)
+++ xerces/c/trunk/src/xercesc/xinclude/XIncludeLocation.hpp Fri Mar 2 00:55:51 2007
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * $Id: $
+ */
+
+#if !defined(XINCLUDELOCATION_HPP)
+#define XINCLUDELOCATION_HPP
+
+#include <xercesc/util/XercesDefs.hpp>
+#include <xercesc/dom/DOM.hpp>
+
+XERCES_CPP_NAMESPACE_BEGIN
+
+
+/**
+ * Class for representing and manipulating the XMLCh * href's used
+ * by an xi:include element.
+ *
+ * This class is designed primarily for internal use. This class implements
+ * the functionality required to calculate relative hrefs and the base URI
+ * fixups required for performing XInclude functionality.
+ */
+class XINCLUDE_EXPORT XIncludeLocation
+{
+public:
+ /** Create an XIncludeLocation, primed with the supplied href
+ *
+ * @param href the initial URI value
+ *
+ * @return nothing
+ */
+ XIncludeLocation(const XMLCh *href);
+
+ /** Destructor
+ *
+ * @return nothing
+ */
+ ~XIncludeLocation();
+
+ /** 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);
+
+ /** Get the current XIncludeLocation's compound URI location
+ *
+ * @return the current URI
+ */
+ const XMLCh *getLocation(){
+ return fHref;
+ };
+
+ /** 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.
+ */
+ static const XMLCh *findEndOfProtocol(const XMLCh *URI);
+
+private:
+ const XMLCh *fHref;
+};
+
+XERCES_CPP_NAMESPACE_END
+
+#endif /* XINCLUDELOCATION_HPP */
+
Added: xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.cpp?view=auto&rev=513661
==============================================================================
--- xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.cpp (added)
+++ xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.cpp Fri Mar 2 00:55:51 2007
@@ -0,0 +1,756 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * $Id$
+ */
+
+#include <xercesc/xinclude/XIncludeUtils.hpp>
+#include <xercesc/xinclude/XIncludeLocation.hpp>
+#include <xercesc/dom/DOM.hpp>
+#include <xercesc/util/TransService.hpp>
+#include <xercesc/util/XMLUri.hpp>
+#include <xercesc/util/XMLMsgLoader.hpp>
+
+XERCES_CPP_NAMESPACE_BEGIN
+
+XIncludeUtils::XIncludeUtils(XMLErrorReporter *errorReporter){
+ fErrorReporter = errorReporter;
+ fIncludeHistoryHead = NULL;
+}
+
+XIncludeUtils::~XIncludeUtils(){
+ freeInclusionHistory();
+}
+
+// ---------------------------------------------------------------------------
+// Generic function to parse a dom node performing any Xinclude's it ecounters,
+// storing its results in parsedDocument, which is expected to be a real
+// document. sourceNode is the current location in parsedDocument, and
+// all xinclude manipulation is done in place (i.e. source is manipulated).
+// ---------------------------------------------------------------------------
+bool
+XIncludeUtils::parseDOMNodeDoingXInclude(DOMNode *sourceNode, DOMDocument *parsedDocument){
+ 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);
+
+ //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);
+ }
+ }
+ return (included)?true:false;
+}
+
+// ---------------------------------------------------------------------------
+// utility func to extract a DOMNodes Base attr value if present
+// ---------------------------------------------------------------------------
+static const XMLCh *
+getBaseAttrValue(DOMNode *node){
+ if (node->getNodeType() == DOMNode::ELEMENT_NODE){
+ DOMElement *elem = (DOMElement *)node;
+ if(elem->hasAttributes()) {
+ /* get all the attributes of the node */
+ DOMNamedNodeMap *pAttributes = elem->getAttributes();
+ int nSize = pAttributes->getLength();
+ for(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){
+
+ }*/
+ return pAttributeNode->getValue();
+ }
+ }
+ }
+ }
+ return NULL;
+}
+
+// ---------------------------------------------------------------------------
+// This method assumes that currentNode is an xinclude element and parses
+// it accordingly, acting on what it finds.
+// ---------------------------------------------------------------------------
+bool
+XIncludeUtils::doDOMNodeXInclude(DOMNode *xincludeNode, DOMDocument *parsedDocument){
+ bool modifiedNode = false;
+ /* the relevant attributes to look for */
+ DOMNode *fallback = NULL;
+ 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();
+ int nSize = pAttributes->getLength();
+ for(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 */
+ }
+ }
+ }
+ }
+
+ 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 = new XIncludeLocation(href);
+ XIncludeLocation *relativeLocation = new XIncludeLocation(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);
+ } else if (XMLString::equals(parse, XIncludeUtils::fgXIIncludeParseAttrTextValue)){
+ /* including a text value */
+ includedText = doXIncludeTEXTFileDOM(hrefLoc->getLocation(), relativeLocation->getLocation(), encoding, parsedDocument);
+ } else {
+ //delete hrefLoc;
+ //delete relativeLocation;
+ /* 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());
+ DOMNode *child;
+ for (child = xincludeNode->getFirstChild(); child != 0; child=child->getNextSibling()){
+ 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 = child;
+ }
+ }
+
+ if (includeParent == NULL){
+ includeParent = parsedDocument;
+ }
+
+ if (fallback){
+ 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);
+ DOMNode *newChild = includeParent->insertBefore(newNode, xincludeNode);
+ parseDOMNodeDoingXInclude(newChild, parsedDocument);
+ }
+ 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 {
+ if (includedDoc){
+ /* record the successful include while we process the children */
+ addDocumentURIToCurrentInclusionHistoryStack(hrefLoc->getLocation());
+
+ /* need to import the document prolog here */
+ DOMNode *child = includedDoc->getFirstChild();
+ for (; child != NULL; child = child->getNextSibling()){
+ if (child->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE){
+ continue;
+ }
+ DOMNode *newNode = parsedDocument->importNode(child, true);
+ DOMNode *newChild = includeParent->insertBefore(newNode, xincludeNode);
+ parseDOMNodeDoingXInclude(newChild, parsedDocument);
+ }
+ includeParent->removeChild(xincludeNode);
+ popFromCurrentInclusionHistoryStack(NULL);
+ modifiedNode = true;
+ } else if (includedText){
+ includeParent->replaceChild(includedText, xincludeNode);
+ modifiedNode = true;
+ }
+ }
+
+ if (includedDoc)
+ includedDoc->release();
+
+ //delete hrefLoc;
+ //delete relativeLocation;
+
+ return modifiedNode;
+}
+
+DOMDocument *
+XIncludeUtils::doXIncludeXMLFileDOM(const XMLCh *href, const XMLCh *relativeHref, DOMNode *includeNode, DOMDocument *parsedDocument){
+ DOMDocument *includedNode = NULL;
+ XIDOMErrorHandler xierrhandler;
+
+ if (XIncludeUtils::isInCurrentInclusionHistoryStack(href)){
+ /* including something back up the current history */
+ XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeCircularInclusionLoop,
+ href, href);
+ return NULL;
+ }
+
+ if (XMLString::equals(href, parsedDocument->getBaseURI())){
+ /* trying to include itself */
+ XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeCircularInclusionDocIncludesSelf,
+ href, href);
+ return NULL;
+ }
+
+ /* Instantiate the DOM parser. */
+ static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
+ DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(gLS);
+ DOMLSParser *parser = ((DOMImplementationLS*)impl)->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
+ DOMConfiguration *config = parser->getDomConfig();
+
+ config->setParameter(XMLUni::fgDOMNamespaces, true);
+
+ /* set our error handler which will be used as a pass through */
+ config->setParameter(XMLUni::fgDOMErrorHandler, &xierrhandler);
+ config->setParameter(XMLUni::fgDOMDisallowDoctype, false);
+
+ /* need to be able to release the parser but keep the document */
+ config->setParameter(XMLUni::fgXercesUserAdoptsDOMDocument, true);
+
+ /* don't want to recurse the xi processing here */
+ config->setParameter(XMLUni::fgXercesDoXInclude, false);
+
+ try {
+ includedNode = parser->parseURI(href);
+ }
+ catch (const XMLException& /*toCatch*/)
+ {
+ XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeResourceErrorWarning,
+ href, href);
+ includedNode = NULL;
+ }
+ catch (const DOMException& /*toCatch*/)
+ {
+ XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeResourceErrorWarning,
+ href, href);
+ includedNode = NULL;
+ }
+ catch (...)
+ {
+ XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeResourceErrorWarning,
+ href, href);
+ includedNode = NULL;
+ }
+
+ //addDocumentURIToCurrentInclusionHistoryStack(href);
+
+ if (includedNode != NULL){
+ /* baseURI fixups - see http://www.w3.org/TR/xinclude/#base for details. */
+ DOMNode *topLevelElement = includedNode->getDocumentElement();
+ if (topLevelElement && topLevelElement->getNodeType() == DOMNode::ELEMENT_NODE ){
+ XMLUri *parentURI = new XMLUri(includeNode->getBaseURI());
+ XMLUri *includedURI = new XMLUri(includedNode->getBaseURI());
+
+ /* if the paths differ we need to add a base attribute */
+ if (!XMLString::equals(parentURI->getPath(), includedURI->getPath())){
+ if (getBaseAttrValue(topLevelElement) == NULL){
+ /* need to calculate the proper path difference to get the relativePath */
+ ((DOMElement *)topLevelElement)->setAttribute(fgXIBaseAttrName, relativeHref);
+ } else {
+ /* the included node has base of its own which takes precedence */
+ XIncludeLocation *xil = new XIncludeLocation(getBaseAttrValue(topLevelElement));
+ if (getBaseAttrValue(includeNode) != NULL){
+ /* prepend any specific base modification of the xinclude node */
+ xil->prependPath(getBaseAttrValue(includeNode));
+ }
+ ((DOMElement *)topLevelElement)->setAttribute(fgXIBaseAttrName, xil->getLocation());
+ delete xil;
+ }
+ }
+ delete parentURI;
+ delete includedURI;
+ }
+ }
+ parser->release();
+ return includedNode;
+}
+
+DOMText *
+XIncludeUtils::doXIncludeTEXTFileDOM(const XMLCh *href, const XMLCh *relativeHref, const XMLCh *encoding, DOMDocument *parsedDocument){
+ DOMText *ret = NULL;
+ bool xIncludeSuceeded;
+
+ //addDocumentURIToCurrentInclusionHistoryStack(href);
+
+ int pathLen = XMLString::stringLen(href);
+ /*(XMLString::stringLen(baseURI) + 9)*sizeof(XMLCh)
+ I am guessing 9 == "file:///" + 1 (nullTerm?) */
+ XMLCh *fixedFullTargetPath = (XMLCh *)XMLPlatformUtils::fgMemoryManager->allocate((pathLen + 9) * sizeof(XMLCh));
+ if (fixedFullTargetPath == NULL){
+ return NULL;
+ }
+ XMLString::fixURI(href, fixedFullTargetPath);
+
+ /* openFile doesn't like the protocol prefix, probably a better way of doing this. */
+ const XMLCh *fileRefMinusProtocol = XIncludeLocation::findEndOfProtocol(fixedFullTargetPath);
+ FileHandle fh = XMLPlatformUtils::openFile(fileRefMinusProtocol);
+ if (fh == NULL){
+ XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeCannotOpenFile,
+ href, href);
+ return NULL;
+ } else {
+ /* TODO - is this really the easiest way to read in the file and pass it out to DocHandler? */
+ XMLFilePos fileLen = XMLPlatformUtils::fileSize(fh);
+ XMLByte *buffer = (XMLByte *) XMLPlatformUtils::fgMemoryManager->allocate(fileLen * sizeof(XMLByte));
+ XMLCh *xmlChars = (XMLCh *) XMLPlatformUtils::fgMemoryManager->allocate((fileLen + 1) * sizeof(XMLCh));
+ unsigned char *charSizes = (unsigned char *)XMLPlatformUtils::fgMemoryManager->allocate(fileLen * sizeof(unsigned char));
+ if (buffer != NULL && xmlChars != NULL && charSizes != NULL){
+ XMLSize_t sizeRead = XMLPlatformUtils::readFileBuffer(fh, fileLen, buffer);
+ 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);
+ if (failReason){
+ xIncludeSuceeded = false;
+ XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeCannotOpenFile, href, href);
+ return NULL;
+ } else {
+ unsigned int processedFromSource = 0;
+ int charsInBuffer = transcoder->transcodeFrom(buffer, sizeRead, xmlChars , fileLen, processedFromSource, charSizes);
+ xmlChars[fileLen] = chNull;
+ /* TODO check for and consume / act on byte order mark if present -
+ possibly done under the covers actually */
+ xIncludeSuceeded = true;
+ }
+
+ /* report or record the xmlChars */
+ ret = parsedDocument->createTextNode(xmlChars);
+
+ delete transcoder;
+ XMLPlatformUtils::fgMemoryManager->deallocate(buffer);
+ XMLPlatformUtils::fgMemoryManager->deallocate(fixedFullTargetPath);
+ XMLPlatformUtils::fgMemoryManager->deallocate(xmlChars);
+ XMLPlatformUtils::fgMemoryManager->deallocate(charSizes);
+ XMLPlatformUtils::closeFile(fh);
+ } else {
+ /* memory manager should have thrown an exception */
+ return NULL;
+ }
+ }
+ return ret;
+}
+
+bool
+XIncludeUtils::isXIIncludeDOMNode(DOMNode *node){
+ const XMLCh *nodeName = node->getLocalName();
+ const XMLCh *namespaceURI = node->getNamespaceURI();
+
+ return isXIIncludeElement(nodeName, namespaceURI);
+}
+
+bool
+XIncludeUtils::isXIFallbackDOMNode(DOMNode *node){
+ const XMLCh *nodeName = node->getLocalName();
+ const XMLCh *namespaceURI = node->getNamespaceURI();
+
+ return isXIFallbackElement(nodeName, namespaceURI);
+}
+
+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;
+}
+
+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;
+}
+
+/* 4.1.1 */
+const XMLCh *
+XIncludeUtils::getEscapedHRefAttrValue(const XMLCh *hrefAttrValue, bool &needsDeallocating){
+ XMLCh *escapedAttr = NULL;
+ return escapedAttr;
+}
+
+/* 4.1.2 */
+bool
+XIncludeUtils::setContentNegotiation(const XMLCh *acceptAttrValue, const XMLCh *acceptLangAttrValue){
+ return false;
+}
+
+bool
+XIncludeUtils::checkTextIsValidForInclude(XMLCh *includeChars){
+ return false;
+}
+
+// ========================================================
+// the stack utilities are slightly convoluted debug versions, they
+// will be pared down for the release code
+// ========================================================
+static XIncludeHistoryNode *
+getTopOfCurrentInclusionHistoryStack(XIncludeHistoryNode *head){
+ 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;
+}
+
+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 *
+XIncludeUtils::popFromCurrentInclusionHistoryStack(const XMLCh *toPop){
+ 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;
+ }
+
+ // 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;
+}
+
+XIDOMErrorHandler::XIDOMErrorHandler()
+{
+}
+
+XIDOMErrorHandler::~XIDOMErrorHandler()
+{
+}
+
+// -----------------------------------------------------------------------
+// Getter methods
+// -----------------------------------------------------------------------
+bool
+XIDOMErrorHandler::getSawErrors() const{
+ return fSawErrors;
+}
+
+// ---------------------------------------------------------------------------
+// XIDOMErrorHandler: Overrides of the DOM ErrorHandler interface
+// ---------------------------------------------------------------------------
+bool
+XIDOMErrorHandler::handleError(const DOMError& domError)
+{
+ bool continueParsing = true;
+
+ fSawErrors = true;
+
+ if (domError.getSeverity() == DOMError::DOM_SEVERITY_WARNING) {
+ //XERCES_STD_QUALIFIER cerr << "\nXIInt Warning at file " << XMLString::transcode(domError.getLocation()->getURI())
+ // << " " << XMLString::transcode(domError.getMessage()) << " " << XERCES_STD_QUALIFIER endl;
+ } else if (domError.getSeverity() == DOMError::DOM_SEVERITY_ERROR) {
+ //XERCES_STD_QUALIFIER cerr << "\nXIInt Error at file " << XMLString::transcode(domError.getLocation()->getURI())
+ // << " " << XMLString::transcode(domError.getMessage()) << " " << XERCES_STD_QUALIFIER endl;
+ } else {
+ //XERCES_STD_QUALIFIER cerr << "\nXIInt Fatal Error at file " << XMLString::transcode(domError.getLocation()->getURI())
+ // << " " << XMLString::transcode(domError.getMessage()) << " " << XERCES_STD_QUALIFIER endl;
+ continueParsing = false;
+ }
+ /* the failure to parse the include target will be flagged as an XInclude Resource Error and dealt with above */
+ return continueParsing;
+}
+
+bool
+XIncludeUtils::reportError(const DOMNode* const errorNode
+ , XMLErrs::Codes errorType
+ , const XMLCh* const errorMsg
+ , const XMLCh * const href)
+{
+ bool toContinueProcess = true; /* default value for no error handler */
+
+ const XMLCh* const systemId = href;
+ const XMLCh* const publicId = href;
+ /* TODO - look these up somehow? */
+ const XMLSSize_t lineNum = -1;
+ const XMLSSize_t colNum = -1;
+
+ if (fErrorReporter)
+ {
+ // Load the message into a local for display
+ const unsigned int 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
+ }
+ }
+
+ fErrorReporter->error(errorType
+ , XMLUni::fgXMLErrDomain //fgXMLErrDomain
+ , XMLErrs::errorType(errorType)
+ , errText
+ , systemId
+ , publicId
+ , lineNum
+ , colNum);
+ }
+
+ if (XMLErrs::isFatal(errorType))
+ fErrorCount++;
+
+ return toContinueProcess;
+}
+
+/* TODO - declared in this file for convenience, prob ought to be moved out to
+ util/XMLUni.cpp before releasing */
+const XMLCh XIncludeUtils::fgXIIncludeQName[] =
+{
+ 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
+};
+const XMLCh XIncludeUtils::fgXIIncludeHREFAttrName[] =
+{
+ chLatin_h, chLatin_r, chLatin_e, chLatin_f, chNull
+};
+const XMLCh XIncludeUtils::fgXIIncludeParseAttrName[] =
+{
+ 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
+};
+const XMLCh XIncludeUtils::fgXIIncludeEncodingAttrName[] =
+{
+ 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
+};
+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
+};
+const XMLCh XIncludeUtils::fgXIIncludeParseAttrXMLValue[] =
+{
+ chLatin_x, chLatin_m, chLatin_l, chNull
+};
+const XMLCh XIncludeUtils::fgXIIncludeParseAttrTextValue[] =
+{
+ 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
+ , 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
+};
+const XMLCh XIncludeUtils::fgXIBaseAttrName[] =
+{
+ chLatin_x, chLatin_m, chLatin_l, chColon, chLatin_b, chLatin_a, chLatin_s, chLatin_e, chNull
+};
+
+XERCES_CPP_NAMESPACE_END
+
Propchange: xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.hpp?view=auto&rev=513661
==============================================================================
--- xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.hpp (added)
+++ xerces/c/trunk/src/xercesc/xinclude/XIncludeUtils.hpp Fri Mar 2 00:55:51 2007
@@ -0,0 +1,307 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * $Id: $
+ */
+
+#if !defined(XINCLUDEUTILS_HPP)
+#define XINCLUDEUTILS_HPP
+
+#include <xercesc/util/XercesDefs.hpp>
+#include <xercesc/util/XMLException.hpp>
+#include <xercesc/dom/DOMNode.hpp>
+#include <xercesc/dom/DOMDocument.hpp>
+#include <xercesc/dom/DOMErrorHandler.hpp>
+#include <xercesc/framework/XMLElementDecl.hpp>
+#include <xercesc/xinclude/XIncludeLocation.hpp>
+#include <xercesc/framework/XMLErrorCodes.hpp>
+
+XERCES_CPP_NAMESPACE_BEGIN
+
+typedef struct XIncludeHistoryNode{
+ XMLCh *URI;
+ struct XIncludeHistoryNode *next;
+}XIncludeHistoryNode;
+
+// ---------------------------------------------------------------------------
+// Simple error handler deriviative to install on parser
+// ---------------------------------------------------------------------------
+class XINCLUDE_EXPORT XIDOMErrorHandler : public DOMErrorHandler
+{
+public:
+ // -----------------------------------------------------------------------
+ // Constructors and Destructor
+ // -----------------------------------------------------------------------
+ XIDOMErrorHandler();
+ ~XIDOMErrorHandler();
+
+
+ // -----------------------------------------------------------------------
+ // Getter methods
+ // -----------------------------------------------------------------------
+ bool getSawErrors() const;
+
+
+ // -----------------------------------------------------------------------
+ // Implementation of the DOM ErrorHandler interface
+ // -----------------------------------------------------------------------
+ bool handleError(const DOMError& domError);
+ void resetErrors();
+
+
+private :
+ // -----------------------------------------------------------------------
+ // Unimplemented constructors and operators
+ // -----------------------------------------------------------------------
+ XIDOMErrorHandler(const XIDOMErrorHandler&);
+ void operator=(const XIDOMErrorHandler&);
+
+
+ // -----------------------------------------------------------------------
+ // Private data members
+ //
+ // fSawErrors
+ // This is set if we get any errors, and is queryable via a getter
+ // method. Its used by the main code to suppress output if there are
+ // errors.
+ // -----------------------------------------------------------------------
+ bool fSawErrors;
+};
+
+
+/**
+ * Class implementing all the utility functions required by an XInclude parser.
+ *
+ * This class is designed primarily for internal use. This class implements
+ * utility methods to be called by an XInclude parser. It is intended to encapsulate
+ * the actual processing and recognition of XInclude components.
+ */
+class XINCLUDE_EXPORT XIncludeUtils
+{
+private:
+
+ /** Constructor
+ *
+ */
+ XIncludeUtils(XMLErrorReporter *errorReporter);
+
+ /** Destructor
+ *
+ */
+ ~XIncludeUtils();
+
+ /** 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
+ *
+ * @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.
+ */
+ bool doDOMNodeXInclude(DOMNode *xincludeNode, DOMDocument *parsedDocument);
+
+ /** Parse an XInclude xml file into a DOMDocument node.
+ *
+ * @param href the location of the document to include
+ * @param relativeHref
+ * @param parsedDocument
+ *
+ * @return a newly created DOMDocument containing the parsed and actioned
+ * href, or NULL if the document could not be loaded.
+ */
+ DOMDocument *doXIncludeXMLFileDOM(const XMLCh *href,
+ const XMLCh *relativeHref,
+ DOMNode *xincludeNode,
+ DOMDocument *parsedDocument);
+
+ /** Parse an XInclude text file into a DOMText node.
+ *
+ * @param href the location of the document to include
+ * @param relativeHref
+ * @param encoding
+ * @param parsedDocument
+ *
+ * @return a newly created DOMText containing the parsed and actioned
+ * href, or NULL if the document could not be loaded.
+ */
+ DOMText *doXIncludeTEXTFileDOM(const XMLCh *href,
+ const XMLCh *relativeHref,
+ const XMLCh *encoding,
+ DOMDocument *parsedDocument);
+
+ /** Detect whether the supplied details are correct for an xi:include element
+ *
+ * @param name the element name
+ * @param namespaceURI the element namespace
+ *
+ * @return true if details are valid for an xi:include element, false
+ * if not.
+ */
+ bool isXIIncludeElement(const XMLCh *name, const XMLCh *namespaceURI);
+
+ /** Detect whether the supplied details are correct for an xi:fallback element
+ *
+ * @param name the element name
+ * @param namespaceURI the element namespace
+ *
+ * @return true if details are valid for an xi:fallback element, false
+ * if not.
+ */
+ bool isXIFallbackElement(const XMLCh *name, const XMLCh *namespaceURI);
+
+ /** 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.
+ */
+ bool isXIIncludeDOMNode(DOMNode *node);
+
+ /** 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.
+ */
+ bool isXIFallbackDOMNode(DOMNode *node);
+
+ /** 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.
+ *
+ * @return true if XInclude behaviour was successfully performed on source, false if not.
+ */
+ bool parseDOMNodeDoingXInclude(DOMNode *source, DOMDocument *parsedDocument);
+
+ /** 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.
+ *
+ * @return an escaped version of hrefAttrValue or hrefAttrValue itself if
+ * 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.
+ *
+ * @param acceptAttrValue
+ * @param acceptLangAttrValue
+ *
+ * @return true if the values were successfully added to the HTTP request, false
+ * if not.
+ */
+ /* 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
+ *
+ * @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.
+ */
+ bool checkTextIsValidForInclude(XMLCh *includeChars);
+
+ /** 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.
+ */
+ 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.
+ *
+ * @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.
+ */
+ bool isInCurrentInclusionHistoryStack(const XMLCh *toFind);
+
+ /** 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.
+ *
+ * @return the element at the top of the stack
+ */
+ XIncludeHistoryNode * popFromCurrentInclusionHistoryStack(const XMLCh *toPop);
+
+ /** Free the internal inclusion history list.
+ *
+ * @return nothing
+ */
+ void freeInclusionHistory();
+
+ /** 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.
+ *
+ * @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.
+ */
+ bool reportError(const DOMNode* const errorNode
+ , XMLErrs::Codes errorType
+ , const XMLCh* const errorMsg
+ , const XMLCh* const href);
+
+public:
+ /* 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[];
+
+ friend class XIncludeDOMDocumentProcessor;
+};
+
+XERCES_CPP_NAMESPACE_END
+
+#endif
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org