elementnsimpl.java
来自「JAVA 所有包」· Java 代码 · 共 486 行 · 第 1/2 页
JAVA
486 行
{ if (needsSyncData()) { synchronizeData(); } return namespaceURI; } /** * Introduced in DOM Level 2. <p> * * The namespace prefix of this node, or null if it is unspecified. <p> * * For nodes created with a DOM Level 1 method, such as createElement * from the Document interface, this is null. <p> * * @since WD-DOM-Level-2-19990923 */ public String getPrefix() { if (needsSyncData()) { synchronizeData(); } int index = name.indexOf(':'); return index < 0 ? null : name.substring(0, index); } /** * Introduced in DOM Level 2. <p> * * Note that setting this attribute changes the nodeName attribute, which holds the * qualified name, as well as the tagName and name attributes of the Element * and Attr interfaces, when applicable.<p> * * @param prefix The namespace prefix of this node, or null(empty string) if it is unspecified. * * @exception INVALID_CHARACTER_ERR * Raised if the specified * prefix contains an invalid character. * @exception DOMException * @since WD-DOM-Level-2-19990923 */ public void setPrefix(String prefix) throws DOMException { if (needsSyncData()) { synchronizeData(); } if (ownerDocument.errorChecking) { if (isReadOnly()) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); throw new DOMException( DOMException.NO_MODIFICATION_ALLOWED_ERR, msg); } if (prefix != null && prefix.length() != 0) { if (!CoreDocumentImpl.isXMLName(prefix,ownerDocument.isXML11Version())) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null); throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg); } if (namespaceURI == null || prefix.indexOf(':') >=0) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null); throw new DOMException(DOMException.NAMESPACE_ERR, msg); } else if (prefix.equals("xml")) { if (!namespaceURI.equals(xmlURI)) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null); throw new DOMException(DOMException.NAMESPACE_ERR, msg); } } } } // update node name with new qualifiedName if (prefix !=null && prefix.length() != 0) { name = prefix + ":" + localName; } else { name = localName; } } /** * Introduced in DOM Level 2. <p> * * Returns the local part of the qualified name of this node. * @since WD-DOM-Level-2-19990923 */ public String getLocalName() { if (needsSyncData()) { synchronizeData(); } return localName; } /** * DOM Level 3 WD - Experimental. * Retrieve baseURI */ public String getBaseURI() { if (needsSyncData()) { synchronizeData(); } // Absolute base URI is computed according to XML Base (http://www.w3.org/TR/xmlbase/#granularity) // 1. the base URI specified by an xml:base attribute on the element, if one exists if (attributes != null) { Attr attrNode = (Attr)attributes.getNamedItemNS("http://www.w3.org/XML/1998/namespace", "base"); if (attrNode != null) { String uri = attrNode.getNodeValue(); if (uri.length() != 0 ) {// attribute value is always empty string try { uri = new URI(uri).toString(); } catch (com.sun.org.apache.xerces.internal.util.URI.MalformedURIException e) { // This may be a relative URI. // Start from the base URI of the parent, or if this node has no parent, the owner node. NodeImpl parentOrOwner = (parentNode() != null) ? parentNode() : ownerNode; // Make any parentURI into a URI object to use with the URI(URI, String) constructor. String parentBaseURI = (parentOrOwner != null) ? parentOrOwner.getBaseURI() : null; if (parentBaseURI != null) { try { uri = new URI(new URI(parentBaseURI), uri).toString(); } catch (com.sun.org.apache.xerces.internal.util.URI.MalformedURIException ex){ // This should never happen: parent should have checked the URI and returned null if invalid. return null; } return uri; } // REVISIT: what should happen in this case? return null; } return uri; } } } //2.the base URI of the element's parent element within the document or external entity, //if one exists String parentElementBaseURI = (this.parentNode() != null) ? this.parentNode().getBaseURI() : null ; //base URI of parent element is not null if(parentElementBaseURI != null){ try { //return valid absolute base URI return new URI(parentElementBaseURI).toString(); } catch (com.sun.org.apache.xerces.internal.util.URI.MalformedURIException e){ // REVISIT: what should happen in this case? return null; } } //3. the base URI of the document entity or external entity containing the element String baseURI = (this.ownerNode != null) ? this.ownerNode.getBaseURI() : null ; if(baseURI != null){ try { //return valid absolute base URI return new URI(baseURI).toString(); } catch (com.sun.org.apache.xerces.internal.util.URI.MalformedURIException e){ // REVISIT: what should happen in this case? return null; } } return null; } /** * @see org.w3c.dom.TypeInfo#getTypeName() */ public String getTypeName() { if (type !=null){ if (type instanceof XSSimpleTypeDefinition) { return ((XSSimpleTypeDecl) type).getTypeName(); } else { return ((XSComplexTypeDecl) type).getTypeName(); } } return null; } /** * @see org.w3c.dom.TypeInfo#getTypeNamespace() */ public String getTypeNamespace() { if (type !=null){ return type.getNamespace(); } return null; } /** * Introduced in DOM Level 2. <p> * Checks if a type is derived from another by restriction. See: * http://www.w3.org/TR/DOM-Level-3-Core/core.html#TypeInfo-isDerivedFrom * * @param ancestorNS * The namspace of the ancestor type declaration * @param ancestorName * The name of the ancestor type declaration * @param type * The reference type definition * * @return boolean True if the type is derived by restriciton for the * reference type */ public boolean isDerivedFrom(String typeNamespaceArg, String typeNameArg, int derivationMethod) { if(needsSyncData()) { synchronizeData(); } if (type != null) { if (type instanceof XSSimpleTypeDefinition) { return ((XSSimpleTypeDecl) type).isDOMDerivedFrom( typeNamespaceArg, typeNameArg, derivationMethod); } else { return ((XSComplexTypeDecl) type).isDOMDerivedFrom( typeNamespaceArg, typeNameArg, derivationMethod); } } return false; } /** * NON-DOM: setting type used by the DOM parser * @see NodeImpl#setReadOnly */ public void setType(XSTypeDefinition type) { this.type = type; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?