abstractdomparser.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,652 行 · 第 1/5 页
JAVA
1,652 行
fRejectedElement.setValues(element); return; } case LSParserFilter.FILTER_SKIP : { fSkippedElemStack.push(new QName(element)); return; } default : {} } } } fCurrentNode.appendChild (el); fCurrentNode = el; } else { int el = fDeferredDocumentImpl.createDeferredElement(fNamespaceAware ? element.uri : null, element.rawname, getElementTypeInfoFromAugs(augs)); int attrCount = attributes.getLength(); for (int i = 0; i < attrCount; i++) { // set type information Augmentations aaugs = attributes.getAugmentations(i); // create attribute fDeferredDocumentImpl.setDeferredAttribute( el, attributes.getQName(i), attributes.getURI(i), attributes.getValue(i), attributes.isSpecified(i), isIdAttribute(attributes,aaugs,i), getAttributeType(attributes,aaugs,i)); } fDeferredDocumentImpl.appendChild (fCurrentNodeIndex, el); fCurrentNodeIndex = el; } } // startElement(QName,XMLAttributes) /** * Returns true if the given attribute is marked as ID. */ private boolean isIdAttribute(XMLAttributes attributes,Augmentations augs, int index) { // look for augmentation first. Object o = augs.getItem(Constants.ID_ATTRIBUTE); if( o instanceof Boolean ) return ((Boolean)o).booleanValue(); // otherwise fall back to the DTD mode. return "ID".equals(attributes.getType(index)); } /** * Returns {@link TypeInfo} for the given attribute. */ private TypeInfo getAttributeType(XMLAttributes attributes,Augmentations augs, int index) { // look for augmentation TypeInfo type = (TypeInfo)augs.getItem(Constants.TYPEINFO); if(type!=null) return type; boolean isDeclared = Boolean.TRUE.equals (attributes.getAugmentations (index).getItem (Constants.ATTRIBUTE_DECLARED)); // otherwise fall back to the DTD mode. if (isDeclared ) return TypeInfoImpl.getDTDTypeInfo(attributes.getType(index)); else return new TypeInfoImpl(); } /** * Looks for {@link TypeInfo} object for the element in the augmentation. * * @return null if not found. */ private TypeInfo getElementTypeInfoFromAugs( Augmentations augs ) { //simple fix to handle dtd case. if (augs == null) return new TypeInfoImpl(); // if an external validator is used via JAXP, this would be set. TypeInfo ti = (TypeInfo)augs.getItem(Constants.TYPEINFO); if(ti!=null) return ti; // Xerces native validator would set this. ElementPSVI elementPSVI = (ElementPSVI)augs.getItem(Constants.ELEMENT_PSVI); if (elementPSVI == null) return null; XSTypeDefinition type = elementPSVI.getMemberTypeDefinition(); if( type!=null ) return type; return elementPSVI.getTypeDefinition(); } // /**// * Looks for {@link TypeInfo} object for the attribute in the augmentation.// */// private TypeInfo getAttribtueTypeInfoFromAugs( XMLAttributes atts, int idx ) {// Augmentations augs = atts.getAugmentations(idx);// // // if an external validator is used via JAXP, this would be set.// TypeInfo type = (TypeInfo)augs.getItem(Constants.TYPEINFO);// if(type!=null) return type;//// // look for PSVI// AttributePSVI attrPSVI =(AttributePSVI) augs.getItem(Constants.ATTRIBUTE_PSVI);// if (attrPSVI != null) {// type = attrPSVI.getMemberTypeDefinition();// if (type == null)// type = attrPSVI.getTypeDefinition();// // return type;// }// // // if everything else fails, fall back to the DTD type.// String typeName = atts.getType(idx);// return new TypeInfoImpl(null, typeName);// } /** * 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 (fStorePSVI && augs != null) { ElementPSVI elementPSVI = (ElementPSVI)augs.getItem(Constants.ELEMENT_PSVI); if (elementPSVI != null) { ((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;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?