mrglavas 2005/05/11 09:42:27 Modified: java/src/org/apache/xerces/xinclude XIncludeHandler.java Log: The XInclude 1.0 REC [1] states that: "It is a fatal error to attempt to replace an xi:include element appearing as the document (top-level) element in the source infoset with something other than a list of zero or more comments, zero or more processing instructions, and one element." The processor was erroneously reporting a fatal error for a missing root element in some cases and in others failed to report a fatal error for multiple root elements. This should be fixed now as well as a few other problems. [1] http://www.w3.org/TR/2004/REC-xinclude-20041220/#creating-result Revision Changes Path 1.50 +39 -14 xml-xerces/java/src/org/apache/xerces/xinclude/XIncludeHandler.java Index: XIncludeHandler.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/xinclude/XIncludeHandler.java,v retrieving revision 1.49 retrieving revision 1.50 diff -u -r1.49 -r1.50 --- XIncludeHandler.java 11 May 2005 15:14:24 -0000 1.49 +++ XIncludeHandler.java 11 May 2005 16:42:27 -0000 1.50 @@ -364,7 +364,7 @@ throws XNIException { fNamespaceContext = null; fDepth = 0; - fResultDepth = 0; + fResultDepth = isRootDocument() ? 0 : fParentXIncludeHandler.getResultDepth(); fNotations.clear(); fUnparsedEntities.clear(); fParentRelativeURI = null; @@ -874,7 +874,7 @@ new Object[] { element.rawname }); } if (getState() == STATE_NORMAL_PROCESSING) { - if (fResultDepth++ == 0 && isRootDocument()) { + if (fResultDepth++ == 0) { checkMultipleRootElements(); } if (fDocumentHandler != null) { @@ -885,7 +885,7 @@ } } else if (getState() == STATE_NORMAL_PROCESSING) { - if (fResultDepth++ == 0 && isRootDocument()) { + if (fResultDepth++ == 0) { checkMultipleRootElements(); } if (fDocumentHandler != null) { @@ -944,7 +944,7 @@ new Object[] { element.rawname }); } if (getState() == STATE_NORMAL_PROCESSING) { - if (fResultDepth == 0 && isRootDocument()) { + if (fResultDepth == 0) { checkMultipleRootElements(); } if (fDocumentHandler != null) { @@ -955,7 +955,7 @@ } } else if (getState() == STATE_NORMAL_PROCESSING) { - if (fResultDepth == 0 && isRootDocument()) { + if (fResultDepth == 0) { checkMultipleRootElements(); } if (fDocumentHandler != null) { @@ -1027,7 +1027,7 @@ Augmentations augs) throws XNIException { if (getState() == STATE_NORMAL_PROCESSING) { - if (fResultDepth == 0 && isRootDocument()) { + if (fResultDepth == 0) { if (augs != null && Boolean.TRUE.equals(augs.getItem(Constants.ENTITY_SKIPPED))) { reportFatalError("UnexpandedEntityReferenceIllegal"); } @@ -1050,7 +1050,7 @@ throws XNIException { if (fDocumentHandler != null && getState() == STATE_NORMAL_PROCESSING - && (fResultDepth != 0 || !isRootDocument())) { + && fResultDepth != 0) { fDocumentHandler.endGeneralEntity(name, augs); } } @@ -1058,7 +1058,7 @@ public void characters(XMLString text, Augmentations augs) throws XNIException { if (getState() == STATE_NORMAL_PROCESSING) { - if (fResultDepth == 0 && isRootDocument()) { + if (fResultDepth == 0) { checkWhitespace(text); } else if (fDocumentHandler != null) { @@ -1075,7 +1075,7 @@ throws XNIException { if (fDocumentHandler != null && getState() == STATE_NORMAL_PROCESSING - && (fResultDepth != 0 || !isRootDocument())) { + && fResultDepth != 0) { fDocumentHandler.ignorableWhitespace(text, augs); } } @@ -1083,7 +1083,7 @@ public void startCDATA(Augmentations augs) throws XNIException { if (fDocumentHandler != null && getState() == STATE_NORMAL_PROCESSING - && (fResultDepth != 0 || !isRootDocument())) { + && fResultDepth != 0) { fDocumentHandler.startCDATA(augs); } } @@ -1091,7 +1091,7 @@ public void endCDATA(Augmentations augs) throws XNIException { if (fDocumentHandler != null && getState() == STATE_NORMAL_PROCESSING - && (fResultDepth != 0 || !isRootDocument())) { + && fResultDepth != 0) { fDocumentHandler.endCDATA(augs); } } @@ -2052,6 +2052,13 @@ // a fallback element return 0; } + + /** + * Returns the current element depth of the result infoset. + */ + private int getResultDepth() { + return fResultDepth; + } /** * Modify the augmentations. Add an [included] infoset item, if the current @@ -2382,10 +2389,28 @@ * Checks whether the root element has already been processed. */ private void checkMultipleRootElements() { - if (fSeenRootElement) { + if (getRootElementProcessed()) { reportFatalError("MultipleRootElements"); } - fSeenRootElement = true; + setRootElementProcessed(true); + } + + /** + * Sets whether the root element has been processed. + */ + private void setRootElementProcessed(boolean seenRoot) { + if (isRootDocument()) { + fSeenRootElement = seenRoot; + return; + } + fParentXIncludeHandler.setRootElementProcessed(seenRoot); + } + + /** + * Returns whether the root element has been processed. + */ + private boolean getRootElementProcessed() { + return isRootDocument() ? fSeenRootElement : fParentXIncludeHandler.getRootElementProcessed(); } // It would be nice if we didn't have to repeat code like this, but there's no interface that has
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
