mrglavas 2004/11/04 13:14:54 Modified: java/src/org/apache/xerces/dom DOMNormalizer.java Log: DOM Level 3 specifies an attribute called strictErrorChecking [1] which when set to false allows an implementation to not test every possible error case. Reducing the amount of checking performed when strictErrorChecking is false. This patch is thanks to Naela Nissar. [1] http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Document3-strictErrorChecking Revision Changes Path 1.59 +40 -35 xml-xerces/java/src/org/apache/xerces/dom/DOMNormalizer.java Index: DOMNormalizer.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DOMNormalizer.java,v retrieving revision 1.58 retrieving revision 1.59 diff -u -r1.58 -r1.59 --- DOMNormalizer.java 5 Oct 2004 17:12:51 -0000 1.58 +++ DOMNormalizer.java 4 Nov 2004 21:14:54 -0000 1.59 @@ -263,21 +263,23 @@ //do the name check only when version of the document was changed & //application has set the value of well-formed features to true - if ( ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) && - fDocument.isXMLVersionChanged()){ - if(fNamespaceValidation){ - wellformed = CoreDocumentImpl.isValidQName(node.getPrefix() , node.getLocalName(), fDocument.isXML11Version()) ; - } - else{ - wellformed = CoreDocumentImpl.isXMLName(node.getNodeName() , fDocument.isXML11Version()); - } - if (!wellformed){ - String msg = DOMMessageFormatter.formatMessage( - DOMMessageFormatter.DOM_DOMAIN, - "wf-invalid-character-in-node-name", - new Object[]{"Element", node.getNodeName()}); + if (fDocument.errorChecking) { + if ( ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) && + fDocument.isXMLVersionChanged()){ + if (fNamespaceValidation){ + wellformed = CoreDocumentImpl.isValidQName(node.getPrefix() , node.getLocalName(), fDocument.isXML11Version()) ; + } + else { + wellformed = CoreDocumentImpl.isXMLName(node.getNodeName() , fDocument.isXML11Version()); + } + if (!wellformed){ + String msg = DOMMessageFormatter.formatMessage( + DOMMessageFormatter.DOM_DOMAIN, + "wf-invalid-character-in-node-name", + new Object[]{"Element", node.getNodeName()}); reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR, - "wf-invalid-character-in-node-name"); + "wf-invalid-character-in-node-name"); + } } } // push namespace context @@ -314,7 +316,7 @@ Attr attr = (Attr)attributes.item(i); //removeDefault(attr, attributes); attr.normalize(); - if ( ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0)){ + if (fDocument.errorChecking && ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0)){ isAttrValueWF(fErrorHandler, fError, fLocator, attributes, (AttrImpl)attr, attr.getValue(), fDocument.isXML11Version()); if (fDocument.isXMLVersionChanged()){ wellformed=CoreDocumentImpl.isXMLName(node.getNodeName() , fDocument.isXML11Version()); @@ -403,7 +405,7 @@ } }//if comment node need not be removed else { - if ( ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0)){ + if (fDocument.errorChecking && ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0)){ String commentdata = ((Comment)node).getData(); // check comments for invalid xml chracter as per the version // of the document @@ -433,7 +435,7 @@ } return next; } else { - if ( ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) && + if (fDocument.errorChecking && ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) && fDocument.isXMLVersionChanged()){ CoreDocumentImpl.isXMLName(node.getNodeName() , fDocument.isXML11Version()); } @@ -480,8 +482,9 @@ if ((fConfiguration.features & DOMConfigurationImpl.SPLITCDATA) != 0) { int index; Node parent = node.getParentNode(); - - isXMLCharWF(fErrorHandler, fError, fLocator, node.getNodeValue(), fDocument.isXML11Version()); + if (fDocument.errorChecking) { + isXMLCharWF(fErrorHandler, fError, fLocator, node.getNodeValue(), fDocument.isXML11Version()); + } while ( (index=value.indexOf("]]>")) >= 0 ) { node.setNodeValue(value.substring(0, index+2)); value = value.substring(index +2); @@ -501,8 +504,8 @@ } } - else { - // check well-formness + else if (fDocument.errorChecking) { + // check well-formedness isCDataWF(fErrorHandler, fError, fLocator, value, fDocument.isXML11Version()); } break; @@ -543,7 +546,7 @@ nextType == Node.COMMENT_NODE) || ((fConfiguration.features & DOMConfigurationImpl.CDATA) == 0) && nextType == Node.CDATA_SECTION_NODE)) { - if ( ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) ){ + if (fDocument.errorChecking && ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) ){ isXMLCharWF(fErrorHandler, fError, fLocator, node.getNodeValue(), fDocument.isXML11Version()); } if (fValidationHandler != null) { @@ -568,7 +571,7 @@ case Node.PROCESSING_INSTRUCTION_NODE: { //do the well-formed valid PI target name , data check when application has set the value of well-formed feature to true - if((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0 ){ + if (fDocument.errorChecking && (fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0 ) { ProcessingInstruction pinode = (ProcessingInstruction)node ; String target = pinode.getTarget(); @@ -633,13 +636,13 @@ if (attributes != null) { // Record all valid local declarations - for (int k=0; k < attributes.getLength(); k++) { + for (int k = 0; k < attributes.getLength(); ++k) { Attr attr = (Attr)attributes.getItem(k); //do the name check only when version of the document was changed & //application has set the value of well-formed features to true - if ( ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) && - fDocument.isXMLVersionChanged()){ + if (fDocument.errorChecking && ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) && + fDocument.isXMLVersionChanged()) { //checkQName does checking based on the version of the document fDocument.checkQName(attr.getPrefix() , attr.getLocalName()) ; } @@ -653,7 +656,7 @@ } // Check for invalid namespace declaration: - if (value.equals(NamespaceContext.XMLNS_URI)) { + if (fDocument.errorChecking && value.equals(NamespaceContext.XMLNS_URI)) { //A null value for locale is passed to formatMessage, //which means that the default locale will be used fLocator.fRelatedNode = attr; @@ -726,20 +729,22 @@ } } else { // Element has no namespace if (element.getLocalName() == null) { + // Error: DOM Level 1 node! if (fNamespaceValidation) { String msg = DOMMessageFormatter.formatMessage( - DOMMessageFormatter.DOM_DOMAIN, "NullLocalElementName", - new Object[]{element.getNodeName()}); + DOMMessageFormatter.DOM_DOMAIN, "NullLocalElementName", + new Object[]{element.getNodeName()}); reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_FATAL_ERROR, - "NullLocalElementName"); + "NullLocalElementName"); } else { String msg = DOMMessageFormatter.formatMessage( - DOMMessageFormatter.DOM_DOMAIN, "NullLocalElementName", - new Object[]{element.getNodeName()}); + DOMMessageFormatter.DOM_DOMAIN, "NullLocalElementName", + new Object[]{element.getNodeName()}); reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR, - "NullLocalElementName"); + "NullLocalElementName"); } + } else { // uri=null and no colon (DOM L2 node) uri = fNamespaceContext.getURI(XMLSymbols.EMPTY_STRING); if (uri !=null && uri.length() > 0) { @@ -795,7 +800,7 @@ //--------------------------------------- // check if value of the attribute is namespace well-formed //--------------------------------------- - if ( ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0)){ + if (fDocument.errorChecking && ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0)) { isAttrValueWF(fErrorHandler, fError, fLocator, attributes, (AttrImpl)attr, attr.getValue(), fDocument.isXML11Version()); if (fDocument.isXMLVersionChanged()){ boolean wellformed=CoreDocumentImpl.isXMLName(attr.getNodeName() , fDocument.isXML11Version());
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]