abstractdomparser.java
来自「JAVA 所有包」· Java 代码 · 共 1,657 行 · 第 1/5 页
JAVA
1,657 行
throw abort; } case LSParserFilter.FILTER_REJECT : { fFilterReject = true; fRejectedElement.setValues(element); return; } case LSParserFilter.FILTER_SKIP : { fSkippedElemStack.push(element.clone()); return; } default : {} } } } fCurrentNode.appendChild (el); fCurrentNode = el; } else { Object type = null; if (augs != null) { ElementPSVI elementPSVI = (ElementPSVI)augs.getItem (Constants.ELEMENT_PSVI); if (elementPSVI != null) { type = elementPSVI.getMemberTypeDefinition (); if (type == null) { type = elementPSVI.getTypeDefinition (); } } } int el = fDeferredDocumentImpl.createDeferredElement (fNamespaceAware ? element.uri : null, element.rawname, type); int attrCount = attributes.getLength (); for (int i = 0; i < attrCount; i++) { // set type information AttributePSVI attrPSVI = (AttributePSVI)attributes.getAugmentations (i).getItem (Constants.ATTRIBUTE_PSVI); boolean id = false; // REVISIT: currently it is possible that someone turns off // namespaces and turns on xml schema validation // To avoid classcast exception in AttrImpl check for namespaces // however the correct solution should probably disallow setting // namespaces to false when schema processing is turned on. if (attrPSVI != null && fNamespaceAware) { // XML Schema type = attrPSVI.getMemberTypeDefinition (); if (type == null) { type = attrPSVI.getTypeDefinition (); if (type != null){ id = ((XSSimpleType) type).isIDType (); } } else { id = ((XSSimpleType) type).isIDType (); } } else { // DTD boolean isDeclared = Boolean.TRUE.equals (attributes.getAugmentations (i).getItem (Constants.ATTRIBUTE_DECLARED)); // For DOM Level 3 TypeInfo, the type name must // be null if this attribute has not been declared // in the DTD. if (isDeclared) { type = attributes.getType (i); id = "ID".equals (type); } } // create attribute fDeferredDocumentImpl.setDeferredAttribute ( el, attributes.getQName (i), attributes.getURI (i), attributes.getValue (i), attributes.isSpecified (i), id, type); } fDeferredDocumentImpl.appendChild (fCurrentNodeIndex, el); fCurrentNodeIndex = el; } } // startElement(QName,XMLAttributes) /** * An empty element. * * @param element The name of the element. * @param attributes The element attributes. * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ public void emptyElement (QName element, XMLAttributes attributes, Augmentations augs) throws XNIException { startElement (element, attributes, augs); endElement (element, augs); } // emptyElement(QName,XMLAttributes) /** * Character content. * * @param text The content. * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ public void characters (XMLString text, Augmentations augs) throws XNIException { if (DEBUG_EVENTS) { System.out.println ("==>characters(): "+text.toString ()); } if (!fDeferNodeExpansion) { if (fFilterReject) { return; } if (fInCDATASection && fCreateCDATANodes) { if (fCurrentCDATASection == null) { fCurrentCDATASection = fDocument.createCDATASection (text.toString ()); fCurrentNode.appendChild (fCurrentCDATASection); fCurrentNode = fCurrentCDATASection; } else { fCurrentCDATASection.appendData (text.toString ()); } } else if (!fInDTD) { // if type is union (XML Schema) it is possible that we receive // character call with empty data if (text.length == 0) { return; } String value = text.toString (); Node child = fCurrentNode.getLastChild (); if (child != null && child.getNodeType () == Node.TEXT_NODE) { // collect all the data into the string buffer. if (fFirstChunk) { if (fDocumentImpl != null) { fStringBuffer.append (((TextImpl)child).removeData ()); } else { fStringBuffer.append (((Text)child).getData ()); ((Text)child).setNodeValue (null); } fFirstChunk = false; } fStringBuffer.append (value); } else { fFirstChunk = true; Text textNode = fDocument.createTextNode (value); fCurrentNode.appendChild (textNode); } } } else { // The Text and CDATASection normalization is taken care of within // the DOM in the deferred case. if (fInCDATASection && fCreateCDATANodes) { if (fCurrentCDATASectionIndex == -1) { int cs = fDeferredDocumentImpl. createDeferredCDATASection (text.toString ()); fDeferredDocumentImpl.appendChild (fCurrentNodeIndex, cs); fCurrentCDATASectionIndex = cs; fCurrentNodeIndex = cs; } else { int txt = fDeferredDocumentImpl. createDeferredTextNode (text.toString (), false); fDeferredDocumentImpl.appendChild (fCurrentNodeIndex, txt); } } else if (!fInDTD) { // if type is union (XML Schema) it is possible that we receive // character call with empty data if (text.length == 0) { return; } String value = text.toString (); int txt = fDeferredDocumentImpl. createDeferredTextNode (value, false); fDeferredDocumentImpl.appendChild (fCurrentNodeIndex, txt); } } } // characters(XMLString) /** * Ignorable whitespace. For this method to be called, the document * source must have some way of determining that the text containing * only whitespace characters should be considered ignorable. For * example, the validator can determine if a length of whitespace * characters in the document are ignorable based on the element * content model. * * @param text The ignorable whitespace. * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ public void ignorableWhitespace (XMLString text, Augmentations augs) throws XNIException { if (!fIncludeIgnorableWhitespace || fFilterReject) { return; } if (!fDeferNodeExpansion) { Node child = fCurrentNode.getLastChild (); if (child != null && child.getNodeType () == Node.TEXT_NODE) { Text textNode = (Text)child; textNode.appendData (text.toString ()); } else { Text textNode = fDocument.createTextNode (text.toString ()); if (fDocumentImpl != null) { TextImpl textNodeImpl = (TextImpl)textNode; textNodeImpl.setIgnorableWhitespace (true); } fCurrentNode.appendChild (textNode); } } else { // The Text normalization is taken care of within the DOM in the // deferred case. int txt = fDeferredDocumentImpl. createDeferredTextNode (text.toString (), true); fDeferredDocumentImpl.appendChild (fCurrentNodeIndex, txt); } } // ignorableWhitespace(XMLString) /** * The end of an element. * * @param element The name of the element. * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ public void endElement (QName element, Augmentations augs) throws XNIException { if (DEBUG_EVENTS) { System.out.println ("==>endElement ("+element.rawname+")"); } if (!fDeferNodeExpansion) { // REVISIT: Should this happen after we call the filter? if (augs != null && fDocumentImpl != null && (fNamespaceAware || fStorePSVI)) { ElementPSVI elementPSVI = (ElementPSVI) augs.getItem(Constants.ELEMENT_PSVI); if (elementPSVI != null) { // Updating TypeInfo. If the declared type is a union the // [member type definition] will only be available at the // end of an element. if (fNamespaceAware) { XSTypeDefinition type = elementPSVI.getMemberTypeDefinition(); if (type == null) { type = elementPSVI.getTypeDefinition(); } ((ElementNSImpl)fCurrentNode).setType(type); } if (fStorePSVI) { ((PSVIElementNSImpl)fCurrentNode).setPSVI (elementPSVI); } } } if (fDOMFilter != null) { if (fFilterReject) { if (element.equals (fRejectedElement)) { fFilterReject = false; } return; } if (!fSkippedElemStack.isEmpty ()) { if (fSkippedElemStack.peek ().equals (element)) { fSkippedElemStack.pop (); return; } } setCharacterData (false); if (!fRoot.equals(element) && !fInEntityRef && (fDOMFilter.getWhatToShow () & NodeFilter.SHOW_ELEMENT)!=0) { short code = fDOMFilter.acceptNode (fCurrentNode); switch (code) { case LSParserFilter.FILTER_INTERRUPT:{ throw abort; } case LSParserFilter.FILTER_REJECT:{ Node parent = fCurrentNode.getParentNode (); parent.removeChild (fCurrentNode); fCurrentNode = parent; return; } case LSParserFilter.FILTER_SKIP: { // make sure that if any char data is available // the fFirstChunk is true, so that if the next event // is characters(), and the last node is text, we will copy // the value already in the text node to fStringBuffer // (not to loose it). fFirstChunk = true; // replace children Node parent = fCurrentNode.getParentNode (); NodeList ls = fCurrentNode.getChildNodes (); int length = ls.getLength (); for (int i=0;i<length;i++) { parent.appendChild (ls.item (0)); } parent.removeChild (fCurrentNode); fCurrentNode = parent; return; } default: { } } } fCurrentNode = fCurrentNode.getParentNode (); } // end-if DOMFilter else {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?