domnormalizer.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,354 行 · 第 1/5 页
JAVA
1,354 行
fDocument.isXMLVersionChanged()){ CoreDocumentImpl.isXMLName(node.getNodeName() , fDocument.isXML11Version()); } // REVISIT: traverse entity reference and send appropriate calls to the validator // (no normalization should be performed for the children). } break; } case Node.CDATA_SECTION_NODE: { if (DEBUG_ND) { System.out.println("==>normalizeNode:{cdata}"); } if ((fConfiguration.features & DOMConfigurationImpl.CDATA) == 0) { // convert CDATA to TEXT nodes Node prevSibling = node.getPreviousSibling(); if (prevSibling != null && prevSibling.getNodeType() == Node.TEXT_NODE){ ((Text)prevSibling).appendData(node.getNodeValue()); node.getParentNode().removeChild(node); return prevSibling; //don't advance } else { Text text = fDocument.createTextNode(node.getNodeValue()); Node parent = node.getParentNode(); node = parent.replaceChild(text, node); return text; //don't advance } } // send characters call for CDATA if (fValidationHandler != null) { // set error node in the dom error wrapper // so if error occurs we can report an error node fConfiguration.fErrorHandlerWrapper.fCurrentNode = node; fCurrentNode = node; fValidationHandler.startCDATA(null); fValidationHandler.characterData(node.getNodeValue(),null); fValidationHandler.endCDATA(null); } if(fDTDValidator != null){ fCurrentNode = node; fDTDValidator.startCDATA(null); String st = node.getNodeValue(); XMLString str = new XMLString(); if(st!=null) str.setValues(st.toCharArray(),0,st.length()); fDTDValidator.characters(str, null); fDTDValidator.endCDATA(null); } String value = node.getNodeValue(); if ((fConfiguration.features & DOMConfigurationImpl.SPLITCDATA) != 0) { int index; Node parent = node.getParentNode(); 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); Node firstSplitNode = node; Node newChild = fDocument.createCDATASection(value); parent.insertBefore(newChild, node.getNextSibling()); node = newChild; // issue warning fLocator.fRelatedNode = firstSplitNode; String msg = DOMMessageFormatter.formatMessage( DOMMessageFormatter.DOM_DOMAIN, "cdata-sections-splitted", null); reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_WARNING, "cdata-sections-splitted"); } } else { // check well-formness isCDataWF(fErrorHandler, fError, fLocator, value, fDocument.isXML11Version()); } break; } case Node.TEXT_NODE: { if (DEBUG_ND) { System.out.println("==>normalizeNode(text):{"+node.getNodeValue()+"}"); } // If node is a text node, we need to check for one of two // conditions: // 1) There is an adjacent text node // 2) There is no adjacent text node, but node is // an empty text node. Node next = node.getNextSibling(); // If an adjacent text node, merge it with this node if ( next!=null && next.getNodeType() == Node.TEXT_NODE ) { ((Text)node).appendData(next.getNodeValue()); node.getParentNode().removeChild( next ); // We don't need to check well-formness here since we are not yet // done with this node. return node; // Don't advance; } else if (node.getNodeValue().length()==0) { // If kid is empty, remove it node.getParentNode().removeChild( node ); } else { // validator.characters() call and well-formness // Don't send characters or check well-formness in the following cases: // 1. entities is false, next child is entity reference: expand tree first // 2. comments is false, and next child is comment // 3. cdata is false, and next child is cdata short nextType = (next != null)?next.getNodeType():-1; if (nextType == -1 || !(((fConfiguration.features & DOMConfigurationImpl.ENTITIES) == 0 && nextType == Node.ENTITY_NODE) || ((fConfiguration.features & DOMConfigurationImpl.COMMENTS) == 0 && nextType == Node.COMMENT_NODE) || ((fConfiguration.features & DOMConfigurationImpl.CDATA) == 0) && nextType == Node.CDATA_SECTION_NODE)) { if ( ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) ){ isXMLCharWF(fErrorHandler, fError, fLocator, node.getNodeValue(), fDocument.isXML11Version()); } if (fValidationHandler != null) { fConfiguration.fErrorHandlerWrapper.fCurrentNode = node; fCurrentNode = node; fValidationHandler.characterData(node.getNodeValue(), null); if (DEBUG_ND) { System.out.println("=====>characterData(),"+nextType); } } if(fDTDValidator != null){ fCurrentNode = node; String st = node.getNodeValue(); XMLString str = new XMLString(); if(st!=null) str.setValues(st.toCharArray(),0,st.length()); fDTDValidator.characters(str, null); if(isWhitespace) ((TextImpl)node).setIgnorableWhitespace(true); } } else { if (DEBUG_ND) { System.out.println("=====>don't send characters(),"+nextType); } } } break; } 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 ){ ProcessingInstruction pinode = (ProcessingInstruction)node ; String target = pinode.getTarget(); //1.check PI target name if(fDocument.isXML11Version()){ wellformed = XML11Char.isXML11ValidName(target); } else{ wellformed = XMLChar.isValidName(target); } 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"); } //2. check PI data //processing isntruction data may have certain characters //which may not be valid XML character isXMLCharWF(fErrorHandler, fError, fLocator, pinode.getData(), fDocument.isXML11Version()); } }//end case Node.PROCESSING_INSTRUCTION_NODE }//end of switch return null; }//normalizeNode protected final void expandEntityRef(Node parent, Node reference){ Node kid, next; for (kid = reference.getFirstChild(); kid != null; kid = next) { next = kid.getNextSibling(); parent.insertBefore(kid, reference); } } // fix namespaces // normalize attribute values // remove default attributes // check attribute names if the version of the document changed. protected final void namespaceFixUp(ElementImpl element, AttributeMap attributes){ if (DEBUG) { System.out.println("[ns-fixup] element:" +element.getNodeName()+ " uri: "+element.getNamespaceURI()); } // ------------------------------------ // pick up local namespace declarations // <xsl:stylesheet xmlns:xsl="http://xslt"> // <!-- add the following via DOM // body is bound to http://xslt // --> // <xsl:body xmlns:xsl="http://bound"/> // // ------------------------------------ String value, name, uri, prefix; if (attributes != null) { // Record all valid local declarations 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()){ //checkQName does checking based on the version of the document fDocument.checkQName(attr.getPrefix() , attr.getLocalName()) ; } uri = attr.getNamespaceURI(); if (uri != null && uri.equals(NamespaceContext.XMLNS_URI)) { // namespace attribute value = attr.getNodeValue(); if (value == null) { value=XMLSymbols.EMPTY_STRING; } // Check for invalid namespace declaration: if (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; String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN,"CantBindXMLNS",null ); reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR, "CantBindXMLNS"); } else { // XML 1.0 Attribute value normalization // value = normalizeAttributeValue(value, attr); prefix = attr.getPrefix(); prefix = (prefix == null || prefix.length() == 0) ? XMLSymbols.EMPTY_STRING :fSymbolTable.addSymbol(prefix); String localpart = fSymbolTable.addSymbol( attr.getLocalName()); if (prefix == XMLSymbols.PREFIX_XMLNS) { //xmlns:prefix value = fSymbolTable.addSymbol(value); if (value.length() != 0) { fNamespaceContext.declarePrefix(localpart, value); } else { // REVISIT: issue error on invalid declarations // xmlns:foo = "" } //removeDefault (attr, attributes); continue; } else { // (localpart == fXmlnsSymbol && prefix == fEmptySymbol) -- xmlns // empty prefix is always bound ("" or some string) value = fSymbolTable.addSymbol(value);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?