Java Code Examples for org.w3c.dom.Node#DOCUMENT_TYPE_NODE
The following examples show how to use
org.w3c.dom.Node#DOCUMENT_TYPE_NODE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CoreDocumentImpl.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Since insertBefore caches the docElement (and, currently, docType), * removeChild has to know how to undo the cache * * REVISIT: According to the spec it is not allowed to alter neither the * document element nor the document type in any way */ public Node removeChild(Node oldChild) throws DOMException { super.removeChild(oldChild); // If remove succeeded, un-cache the kid appropriately int type = oldChild.getNodeType(); if(type == Node.ELEMENT_NODE) { docElement = null; } else if (type == Node.DOCUMENT_TYPE_NODE) { docType = null; } return oldChild; }
Example 2
Source File: XMLEventStreamReaderTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void readCorrect() throws Exception { Transformer transformer = TransformerFactory.newInstance().newTransformer(); StAXSource source = new StAXSource(streamReader); StringWriter writer = new StringWriter(); transformer.transform(source, new StreamResult(writer)); Predicate<Node> nodeFilter = n -> n.getNodeType() != Node.DOCUMENT_TYPE_NODE && n.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE; assertThat(writer.toString(), isSimilarTo(XML).withNodeFilter(nodeFilter)); }
Example 3
Source File: DTMNodeProxy.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** This is a bit of a problem in DTM, since a DTM may be a Document * Fragment and hence not have a clear-cut Document Element. We can * make it work in the well-formed cases but would that be confusing for others? * * * @see org.w3c.dom.Document */ @Override public final Element getDocumentElement() { int dochandle=dtm.getDocument(); int elementhandle=DTM.NULL; for(int kidhandle=dtm.getFirstChild(dochandle); kidhandle!=DTM.NULL; kidhandle=dtm.getNextSibling(kidhandle)) { switch(dtm.getNodeType(kidhandle)) { case Node.ELEMENT_NODE: if(elementhandle!=DTM.NULL) { elementhandle=DTM.NULL; // More than one; ill-formed. kidhandle=dtm.getLastChild(dochandle); // End loop } else elementhandle=kidhandle; break; // These are harmless; document is still wellformed case Node.COMMENT_NODE: case Node.PROCESSING_INSTRUCTION_NODE: case Node.DOCUMENT_TYPE_NODE: break; default: elementhandle=DTM.NULL; // ill-formed kidhandle=dtm.getLastChild(dochandle); // End loop break; } } if(elementhandle==DTM.NULL) throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); else return (Element)(dtm.getNode(elementhandle)); }
Example 4
Source File: AbstractNodeTester.java From xmlunit with Apache License 2.0 | 5 votes |
/** * Validate a single Node by delegating to node type specific methods. * @see #testAttribute(Attr) * @see #testCDATASection(CDATASection) * @see #testComment(Comment) * @see #testDocumentType(DocumentType) * @see #testElement(Element) * @see #testEntity(Entity) * @see #testEntityReference(EntityReference) * @see #testNotation(Notation) * @see #testProcessingInstruction(ProcessingInstruction) * @see #testText(Text) */ public void testNode(Node aNode, NodeTest forTest) throws NodeTestException { switch (aNode.getNodeType()) { case Node.ATTRIBUTE_NODE: // should not happen as attributes are not exposed by DOM traversal testAttribute((Attr)aNode); break; case Node.CDATA_SECTION_NODE: testCDATASection((CDATASection)aNode); break; case Node.COMMENT_NODE: testComment((Comment)aNode); break; case Node.DOCUMENT_TYPE_NODE: testDocumentType((DocumentType)aNode); break; case Node.ELEMENT_NODE: testElement((Element)aNode); break; case Node.ENTITY_NODE: testEntity((Entity)aNode); break; case Node.ENTITY_REFERENCE_NODE: testEntityReference((EntityReference)aNode); break; case Node.NOTATION_NODE: testNotation((Notation)aNode); break; case Node.PROCESSING_INSTRUCTION_NODE: testProcessingInstruction( (ProcessingInstruction) aNode); break; case Node.TEXT_NODE: testText((Text)aNode); break; default: throw new NodeTestException("No delegate method for Node type", aNode); } }
Example 5
Source File: JTidyHTMLParser.java From lams with GNU General Public License v2.0 | 5 votes |
public void parse( URL pageURL, String pageText, DocumentAdapter adapter ) throws IOException, SAXException { try { Document jtidyDocument = getParser( pageURL ).parseDOM( new ByteArrayInputStream( pageText.getBytes( UTF_ENCODING ) ), null ); HTMLDocument htmlDocument = new HTMLDocumentImpl(); NodeList nl = jtidyDocument.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node importedNode = nl.item(i); if (importedNode.getNodeType() != Node.DOCUMENT_TYPE_NODE) htmlDocument.appendChild( htmlDocument.importNode( importedNode, true ) ); } adapter.setDocument( htmlDocument ); } catch (UnsupportedEncodingException e) { throw new RuntimeException( "UTF-8 encoding failed" ); } }
Example 6
Source File: CoreDocumentImpl.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Since a Document may contain at most one top-level Element child, * and at most one DocumentType declaraction, we need to subclass our * add-children methods to implement this constraint. * Since appendChild() is implemented as insertBefore(,null), * altering the latter fixes both. * <p> * While I'm doing so, I've taken advantage of the opportunity to * cache documentElement and docType so we don't have to * search for them. * * REVISIT: According to the spec it is not allowed to alter neither the * document element nor the document type in any way */ public Node insertBefore(Node newChild, Node refChild) throws DOMException { // Only one such child permitted int type = newChild.getNodeType(); if (errorChecking) { if((type == Node.ELEMENT_NODE && docElement != null) || (type == Node.DOCUMENT_TYPE_NODE && docType != null)) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null); throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, msg); } } // Adopt orphan doctypes if (newChild.getOwnerDocument() == null && newChild instanceof DocumentTypeImpl) { ((DocumentTypeImpl) newChild).ownerDocument = this; } super.insertBefore(newChild,refChild); // If insert succeeded, cache the kid appropriately if (type == Node.ELEMENT_NODE) { docElement = (ElementImpl)newChild; } else if (type == Node.DOCUMENT_TYPE_NODE) { docType = (DocumentTypeImpl)newChild; } return newChild; }
Example 7
Source File: CoreDocumentImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Since we cache the docElement (and, currently, docType), * replaceChild has to update the cache * * REVISIT: According to the spec it is not allowed to alter neither the * document element nor the document type in any way */ public Node replaceChild(Node newChild, Node oldChild) throws DOMException { // Adopt orphan doctypes if (newChild.getOwnerDocument() == null && newChild instanceof DocumentTypeImpl) { ((DocumentTypeImpl) newChild).ownerDocument = this; } if (errorChecking &&((docType != null && oldChild.getNodeType() != Node.DOCUMENT_TYPE_NODE && newChild.getNodeType() == Node.DOCUMENT_TYPE_NODE) || (docElement != null && oldChild.getNodeType() != Node.ELEMENT_NODE && newChild.getNodeType() == Node.ELEMENT_NODE))) { throw new DOMException( DOMException.HIERARCHY_REQUEST_ERR, DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null)); } super.replaceChild(newChild, oldChild); int type = oldChild.getNodeType(); if(type == Node.ELEMENT_NODE) { docElement = (ElementImpl)newChild; } else if (type == Node.DOCUMENT_TYPE_NODE) { docType = (DocumentTypeImpl)newChild; } return oldChild; }
Example 8
Source File: DOM2DTMdefaultNamespaceDeclarationNode.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
/** * DOM Level 3 - Experimental: * Look up the namespace URI associated to the given prefix, starting from this node. * Use lookupNamespaceURI(null) to lookup the default namespace * * @param namespaceURI * @return th URI for the namespace * @since DOM Level 3 */ public String lookupNamespaceURI(String specifiedPrefix) { short type = this.getNodeType(); switch (type) { case Node.ELEMENT_NODE : { String namespace = this.getNamespaceURI(); String prefix = this.getPrefix(); if (namespace !=null) { // REVISIT: is it possible that prefix is empty string? if (specifiedPrefix== null && prefix==specifiedPrefix) { // looking for default namespace return namespace; } else if (prefix != null && prefix.equals(specifiedPrefix)) { // non default namespace return namespace; } } if (this.hasAttributes()) { NamedNodeMap map = this.getAttributes(); int length = map.getLength(); for (int i=0;i<length;i++) { Node attr = map.item(i); String attrPrefix = attr.getPrefix(); String value = attr.getNodeValue(); namespace = attr.getNamespaceURI(); if (namespace !=null && namespace.equals("http://www.w3.org/2000/xmlns/")) { // at this point we are dealing with DOM Level 2 nodes only if (specifiedPrefix == null && attr.getNodeName().equals("xmlns")) { // default namespace return value; } else if (attrPrefix !=null && attrPrefix.equals("xmlns") && attr.getLocalName().equals(specifiedPrefix)) { // non default namespace return value; } } } } /* NodeImpl ancestor = (NodeImpl)getElementAncestor(this); if (ancestor != null) { return ancestor.lookupNamespaceURI(specifiedPrefix); } */ return null; } /* case Node.DOCUMENT_NODE : { return((NodeImpl)((Document)this).getDocumentElement()).lookupNamespaceURI(specifiedPrefix) ; } */ case Node.ENTITY_NODE : case Node.NOTATION_NODE: case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_TYPE_NODE: // type is unknown return null; case Node.ATTRIBUTE_NODE:{ if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) { return getOwnerElement().lookupNamespaceURI(specifiedPrefix); } return null; } default:{ /* NodeImpl ancestor = (NodeImpl)getElementAncestor(this); if (ancestor != null) { return ancestor.lookupNamespaceURI(specifiedPrefix); } */ return null; } } }
Example 9
Source File: DTMNodeProxy.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * DOM Level 3 * Look up the namespace URI associated to the given prefix, starting from this node. * Use lookupNamespaceURI(null) to lookup the default namespace * * @param namespaceURI * @return th URI for the namespace * @since DOM Level 3 */ @Override public String lookupNamespaceURI(String specifiedPrefix) { short type = this.getNodeType(); switch (type) { case Node.ELEMENT_NODE : { String namespace = this.getNamespaceURI(); String prefix = this.getPrefix(); if (namespace !=null) { // REVISIT: is it possible that prefix is empty string? if (specifiedPrefix== null && prefix==specifiedPrefix) { // looking for default namespace return namespace; } else if (prefix != null && prefix.equals(specifiedPrefix)) { // non default namespace return namespace; } } if (this.hasAttributes()) { NamedNodeMap map = this.getAttributes(); int length = map.getLength(); for (int i=0;i<length;i++) { Node attr = map.item(i); String attrPrefix = attr.getPrefix(); String value = attr.getNodeValue(); namespace = attr.getNamespaceURI(); if (namespace !=null && namespace.equals("http://www.w3.org/2000/xmlns/")) { // at this point we are dealing with DOM Level 2 nodes only if (specifiedPrefix == null && attr.getNodeName().equals("xmlns")) { // default namespace return value; } else if (attrPrefix !=null && attrPrefix.equals("xmlns") && attr.getLocalName().equals(specifiedPrefix)) { // non default namespace return value; } } } } /* NodeImpl ancestor = (NodeImpl)getElementAncestor(this); if (ancestor != null) { return ancestor.lookupNamespaceURI(specifiedPrefix); } */ return null; } /* case Node.DOCUMENT_NODE : { return((NodeImpl)((Document)this).getDocumentElement()).lookupNamespaceURI(specifiedPrefix) ; } */ case Node.ENTITY_NODE : case Node.NOTATION_NODE: case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_TYPE_NODE: // type is unknown return null; case Node.ATTRIBUTE_NODE:{ if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) { return getOwnerElement().lookupNamespaceURI(specifiedPrefix); } return null; } default:{ /* NodeImpl ancestor = (NodeImpl)getElementAncestor(this); if (ancestor != null) { return ancestor.lookupNamespaceURI(specifiedPrefix); } */ return null; } } }
Example 10
Source File: XMLUtils.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
@SuppressWarnings("fallthrough") private static void getSetRec(final Node rootNode, final Set<Node> result, final Node exclude, final boolean com) { if (rootNode == exclude) { return; } switch (rootNode.getNodeType()) { case Node.ELEMENT_NODE: result.add(rootNode); Element el = (Element)rootNode; if (el.hasAttributes()) { NamedNodeMap nl = el.getAttributes(); for (int i = 0;i < nl.getLength(); i++) { result.add(nl.item(i)); } } //no return keep working case Node.DOCUMENT_NODE: for (Node r = rootNode.getFirstChild(); r != null; r = r.getNextSibling()) { if (r.getNodeType() == Node.TEXT_NODE) { result.add(r); while ((r != null) && (r.getNodeType() == Node.TEXT_NODE)) { r = r.getNextSibling(); } if (r == null) { return; } } getSetRec(r, result, exclude, com); } return; case Node.COMMENT_NODE: if (com) { result.add(rootNode); } return; case Node.DOCUMENT_TYPE_NODE: return; default: result.add(rootNode); } }
Example 11
Source File: DTMNodeProxy.java From j2objc with Apache License 2.0 | 4 votes |
/** * DOM Level 3: * Look up the namespace URI associated to the given prefix, starting from this node. * Use lookupNamespaceURI(null) to lookup the default namespace * * @param namespaceURI * @return th URI for the namespace * @since DOM Level 3 */ public String lookupNamespaceURI(String specifiedPrefix) { short type = this.getNodeType(); switch (type) { case Node.ELEMENT_NODE : { String namespace = this.getNamespaceURI(); String prefix = this.getPrefix(); if (namespace !=null) { // REVISIT: is it possible that prefix is empty string? if (specifiedPrefix== null && prefix==specifiedPrefix) { // looking for default namespace return namespace; } else if (prefix != null && prefix.equals(specifiedPrefix)) { // non default namespace return namespace; } } if (this.hasAttributes()) { NamedNodeMap map = this.getAttributes(); int length = map.getLength(); for (int i=0;i<length;i++) { Node attr = map.item(i); String attrPrefix = attr.getPrefix(); String value = attr.getNodeValue(); namespace = attr.getNamespaceURI(); if (namespace !=null && namespace.equals("http://www.w3.org/2000/xmlns/")) { // at this point we are dealing with DOM Level 2 nodes only if (specifiedPrefix == null && attr.getNodeName().equals("xmlns")) { // default namespace return value; } else if (attrPrefix !=null && attrPrefix.equals("xmlns") && attr.getLocalName().equals(specifiedPrefix)) { // non default namespace return value; } } } } /* NodeImpl ancestor = (NodeImpl)getElementAncestor(this); if (ancestor != null) { return ancestor.lookupNamespaceURI(specifiedPrefix); } */ return null; } /* case Node.DOCUMENT_NODE : { return((NodeImpl)((Document)this).getDocumentElement()).lookupNamespaceURI(specifiedPrefix) ; } */ case Node.ENTITY_NODE : case Node.NOTATION_NODE: case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_TYPE_NODE: // type is unknown return null; case Node.ATTRIBUTE_NODE:{ if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) { return getOwnerElement().lookupNamespaceURI(specifiedPrefix); } return null; } default:{ /* NodeImpl ancestor = (NodeImpl)getElementAncestor(this); if (ancestor != null) { return ancestor.lookupNamespaceURI(specifiedPrefix); } */ return null; } } }
Example 12
Source File: DOMValidatorHelper.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** Do processing for the start of a node. */ private void beginNode(Node node) { switch (node.getNodeType()) { case Node.ELEMENT_NODE: fCurrentElement = node; // push namespace context fNamespaceContext.pushContext(); // start element fillQName(fElementQName, node); processAttributes(node.getAttributes()); fSchemaValidator.startElement(fElementQName, fAttributes, null); break; case Node.TEXT_NODE: if (fDOMValidatorHandler != null) { fDOMValidatorHandler.setIgnoringCharacters(true); sendCharactersToValidator(node.getNodeValue()); fDOMValidatorHandler.setIgnoringCharacters(false); fDOMValidatorHandler.characters((Text) node); } else { sendCharactersToValidator(node.getNodeValue()); } break; case Node.CDATA_SECTION_NODE: if (fDOMValidatorHandler != null) { fDOMValidatorHandler.setIgnoringCharacters(true); fSchemaValidator.startCDATA(null); sendCharactersToValidator(node.getNodeValue()); fSchemaValidator.endCDATA(null); fDOMValidatorHandler.setIgnoringCharacters(false); fDOMValidatorHandler.cdata((CDATASection) node); } else { fSchemaValidator.startCDATA(null); sendCharactersToValidator(node.getNodeValue()); fSchemaValidator.endCDATA(null); } break; case Node.PROCESSING_INSTRUCTION_NODE: /** * The validator does nothing with processing instructions so bypass it. * Send the ProcessingInstruction node directly to the result builder. */ if (fDOMValidatorHandler != null) { fDOMValidatorHandler.processingInstruction((ProcessingInstruction) node); } break; case Node.COMMENT_NODE: /** * The validator does nothing with comments so bypass it. * Send the Comment node directly to the result builder. */ if (fDOMValidatorHandler != null) { fDOMValidatorHandler.comment((Comment) node); } break; case Node.DOCUMENT_TYPE_NODE: /** * Send the DocumentType node directly to the result builder. */ if (fDOMValidatorHandler != null) { fDOMValidatorHandler.doctypeDecl((DocumentType) node); } break; default: // Ignore other node types. break; } }
Example 13
Source File: RangeImpl.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
/** * Utility method for traversing a single node when * we know a-priori that the node if fully * selected. * * @param n The node to be traversed. * * @param how Specifies what type of traversal is being * requested (extract, clone, or delete). * Legal values for this argument are: * * <ol> * <li><code>EXTRACT_CONTENTS</code> - will simply * return the original node. * * <li><code>CLONE_CONTENTS</code> - will leave the * context tree of the range undisturbed, but will * return a cloned node. * * <li><code>DELETE_CONTENTS</code> - will delete the * node from it's parent, but will return null. * </ol> * * @return Returns a node that is the result of visiting the node. * If the traversal operation is * <code>DELETE_CONTENTS</code> the return value is null. */ private Node traverseFullySelected( Node n, int how ) { switch( how ) { case CLONE_CONTENTS: return n.cloneNode( true ); case EXTRACT_CONTENTS: if ( n.getNodeType()==Node.DOCUMENT_TYPE_NODE ) { // TBD: This should be a HIERARCHY_REQUEST_ERR throw new DOMException( DOMException.HIERARCHY_REQUEST_ERR, DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null)); } return n; case DELETE_CONTENTS: n.getParentNode().removeChild(n); return null; } return null; }
Example 14
Source File: DOMWriter.java From exificient with MIT License | 4 votes |
protected void encodeChildNodes(NodeList children) throws EXIException, IOException { for (int i = 0; i < children.getLength(); i++) { Node n = children.item(i); switch (n.getNodeType()) { case Node.ELEMENT_NODE: encodeNode(n); break; case Node.ATTRIBUTE_NODE: break; case Node.TEXT_NODE: exiBody.encodeCharacters(new StringValue(n.getNodeValue())); break; case Node.COMMENT_NODE: if (preserveComments) { String c = n.getNodeValue(); exiBody.encodeComment(c.toCharArray(), 0, c.length()); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType dt = (DocumentType) n; String publicID = dt.getPublicId() == null ? "" : dt .getPublicId(); String systemID = dt.getSystemId() == null ? "" : dt .getSystemId(); String text = dt.getInternalSubset() == null ? "" : dt .getInternalSubset(); exiBody.encodeDocType(dt.getName(), publicID, systemID, text); break; case Node.ENTITY_REFERENCE_NODE: // checkPendingChars(); // TODO ER break; case Node.CDATA_SECTION_NODE: // String cdata = n.getNodeValue(); // exiBody.encodeCharacters(new // StringValue(Constants.CDATA_START // + cdata + Constants.CDATA_END)); exiBody.encodeCharacters(new StringValue(n.getNodeValue())); break; case Node.PROCESSING_INSTRUCTION_NODE: if (preservePIs) { ProcessingInstruction pi = (ProcessingInstruction) n; exiBody.encodeProcessingInstruction(pi.getTarget(), pi.getData()); } break; default: System.err.println("[WARNING] Unhandled DOM NodeType: " + n.getNodeType()); // throw new EXIException("Unknown NodeType? " + // n.getNodeType()); } } }
Example 15
Source File: DeferredDocumentImpl.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * Synchronizes the node's children with the internal structure. * Fluffing the children at once solves a lot of work to keep * the two structures in sync. The problem gets worse when * editing the tree -- this makes it a lot easier. */ protected void synchronizeChildren() { if (needsSyncData()) { synchronizeData(); /* * when we have elements with IDs this method is being recursively * called from synchronizeData, in which case we've already gone * through the following and we can now simply stop here. */ if (!needsSyncChildren()) { return; } } // we don't want to generate any event for this so turn them off boolean orig = mutationEvents; mutationEvents = false; // no need to sync in the future needsSyncChildren(false); getNodeType(0); // create children and link them as siblings ChildNode first = null; ChildNode last = null; for (int index = getLastChild(0); index != -1; index = getPrevSibling(index)) { ChildNode node = (ChildNode)getNodeObject(index); if (last == null) { last = node; } else { first.previousSibling = node; } node.ownerNode = this; node.isOwned(true); node.nextSibling = first; first = node; // save doctype and document type int type = node.getNodeType(); if (type == Node.ELEMENT_NODE) { docElement = (ElementImpl)node; } else if (type == Node.DOCUMENT_TYPE_NODE) { docType = (DocumentTypeImpl)node; } } if (first != null) { firstChild = first; first.isFirstChild(true); lastChild(last); } // set mutation events flag back to its original value mutationEvents = orig; }
Example 16
Source File: DeferredDocumentImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Synchronizes the node's children with the internal structure. * Fluffing the children at once solves a lot of work to keep * the two structures in sync. The problem gets worse when * editing the tree -- this makes it a lot easier. */ protected void synchronizeChildren() { if (needsSyncData()) { synchronizeData(); /* * when we have elements with IDs this method is being recursively * called from synchronizeData, in which case we've already gone * through the following and we can now simply stop here. */ if (!needsSyncChildren()) { return; } } // we don't want to generate any event for this so turn them off boolean orig = mutationEvents; mutationEvents = false; // no need to sync in the future needsSyncChildren(false); getNodeType(0); // create children and link them as siblings ChildNode first = null; ChildNode last = null; for (int index = getLastChild(0); index != -1; index = getPrevSibling(index)) { ChildNode node = (ChildNode)getNodeObject(index); if (last == null) { last = node; } else { first.previousSibling = node; } node.ownerNode = this; node.isOwned(true); node.nextSibling = first; first = node; // save doctype and document type int type = node.getNodeType(); if (type == Node.ELEMENT_NODE) { docElement = (ElementImpl)node; } else if (type == Node.DOCUMENT_TYPE_NODE) { docType = (DocumentTypeImpl)node; } } if (first != null) { firstChild = first; first.isFirstChild(true); lastChild(last); } // set mutation events flag back to its original value mutationEvents = orig; }
Example 17
Source File: DOM2DTMdefaultNamespaceDeclarationNode.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * DOM Level 3 - Experimental: * Look up the namespace URI associated to the given prefix, starting from this node. * Use lookupNamespaceURI(null) to lookup the default namespace * * @param namespaceURI * @return th URI for the namespace * @since DOM Level 3 */ public String lookupNamespaceURI(String specifiedPrefix) { short type = this.getNodeType(); switch (type) { case Node.ELEMENT_NODE : { String namespace = this.getNamespaceURI(); String prefix = this.getPrefix(); if (namespace !=null) { // REVISIT: is it possible that prefix is empty string? if (specifiedPrefix== null && prefix==specifiedPrefix) { // looking for default namespace return namespace; } else if (prefix != null && prefix.equals(specifiedPrefix)) { // non default namespace return namespace; } } if (this.hasAttributes()) { NamedNodeMap map = this.getAttributes(); int length = map.getLength(); for (int i=0;i<length;i++) { Node attr = map.item(i); String attrPrefix = attr.getPrefix(); String value = attr.getNodeValue(); namespace = attr.getNamespaceURI(); if (namespace !=null && namespace.equals("http://www.w3.org/2000/xmlns/")) { // at this point we are dealing with DOM Level 2 nodes only if (specifiedPrefix == null && attr.getNodeName().equals("xmlns")) { // default namespace return value; } else if (attrPrefix !=null && attrPrefix.equals("xmlns") && attr.getLocalName().equals(specifiedPrefix)) { // non default namespace return value; } } } } /* NodeImpl ancestor = (NodeImpl)getElementAncestor(this); if (ancestor != null) { return ancestor.lookupNamespaceURI(specifiedPrefix); } */ return null; } /* case Node.DOCUMENT_NODE : { return((NodeImpl)((Document)this).getDocumentElement()).lookupNamespaceURI(specifiedPrefix) ; } */ case Node.ENTITY_NODE : case Node.NOTATION_NODE: case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_TYPE_NODE: // type is unknown return null; case Node.ATTRIBUTE_NODE:{ if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) { return getOwnerElement().lookupNamespaceURI(specifiedPrefix); } return null; } default:{ /* NodeImpl ancestor = (NodeImpl)getElementAncestor(this); if (ancestor != null) { return ancestor.lookupNamespaceURI(specifiedPrefix); } */ return null; } } }
Example 18
Source File: UnImplNode.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * * DOM Level 3 - Experimental: * Look up the prefix associated to the given namespace URI, starting from this node. * * @param namespaceURI * @return the prefix for the namespace */ public String lookupPrefix(String namespaceURI){ // REVISIT: When Namespaces 1.1 comes out this may not be true // Prefix can't be bound to null namespace if (namespaceURI == null) { return null; } short type = this.getNodeType(); switch (type) { /* case Node.ELEMENT_NODE: { String namespace = this.getNamespaceURI(); // to flip out children return lookupNamespacePrefix(namespaceURI, (ElementImpl)this); } case Node.DOCUMENT_NODE:{ return((NodeImpl)((Document)this).getDocumentElement()).lookupPrefix(namespaceURI); } */ case Node.ENTITY_NODE : case Node.NOTATION_NODE: case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_TYPE_NODE: // type is unknown return null; case Node.ATTRIBUTE_NODE:{ if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) { return getOwnerElement().lookupPrefix(namespaceURI); } return null; } default:{ /* NodeImpl ancestor = (NodeImpl)getElementAncestor(this); if (ancestor != null) { return ancestor.lookupPrefix(namespaceURI); } */ return null; } } }
Example 19
Source File: DTMNodeProxy.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * * DOM Level 3 * Look up the prefix associated to the given namespace URI, starting from this node. * * @param namespaceURI * @return the prefix for the namespace */ @Override public String lookupPrefix(String namespaceURI){ // REVISIT: When Namespaces 1.1 comes out this may not be true // Prefix can't be bound to null namespace if (namespaceURI == null) { return null; } short type = this.getNodeType(); switch (type) { /* case Node.ELEMENT_NODE: { String namespace = this.getNamespaceURI(); // to flip out children return lookupNamespacePrefix(namespaceURI, (ElementImpl)this); } case Node.DOCUMENT_NODE:{ return((NodeImpl)((Document)this).getDocumentElement()).lookupPrefix(namespaceURI); } */ case Node.ENTITY_NODE : case Node.NOTATION_NODE: case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_TYPE_NODE: // type is unknown return null; case Node.ATTRIBUTE_NODE:{ if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) { return getOwnerElement().lookupPrefix(namespaceURI); } return null; } default:{ /* NodeImpl ancestor = (NodeImpl)getElementAncestor(this); if (ancestor != null) { return ancestor.lookupPrefix(namespaceURI); } */ return null; } } }
Example 20
Source File: DocumentTypeImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 2 votes |
/** * A short integer indicating what type of node this is. The named * constants for this value are defined in the org.w3c.dom.Node interface. */ public short getNodeType() { return Node.DOCUMENT_TYPE_NODE; }