Java Code Examples for org.w3c.dom.Node.DOCUMENT_TYPE_NODE

The following are Jave code examples for showing how to use DOCUMENT_TYPE_NODE of the org.w3c.dom.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: openjdk-jdk10   File: DOM3TreeWalker.java   Source Code and License Vote up 6 votes
/**
 * End processing of given node
 *
 *
 * @param node Node we just finished processing
 *
 * @throws org.xml.sax.SAXException
 */
protected void endNode(Node node) throws org.xml.sax.SAXException {

    switch (node.getNodeType()) {
        case Node.DOCUMENT_NODE :
            break;
        case Node.DOCUMENT_TYPE_NODE :
            serializeDocType((DocumentType) node, false);
            break;
        case Node.ELEMENT_NODE :
            serializeElement((Element) node, false);
            break;
        case Node.CDATA_SECTION_NODE :
            break;
        case Node.ENTITY_REFERENCE_NODE :
            serializeEntityReference((EntityReference) node, false);
            break;
        default :
            }
}
 
Example 2
Project: openjdk-jdk10   File: CoreDocumentImpl.java   Source Code and License Vote up 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 3
Project: openjdk-jdk10   File: DOM2TO.java   Source Code and License Vote up 5 votes
private String getNodeTypeFromCode(short code) {
    String retval = null;
    switch (code) {
    case Node.ATTRIBUTE_NODE :
        retval = "ATTRIBUTE_NODE"; break;
    case Node.CDATA_SECTION_NODE :
        retval = "CDATA_SECTION_NODE"; break;
    case Node.COMMENT_NODE :
        retval = "COMMENT_NODE"; break;
    case Node.DOCUMENT_FRAGMENT_NODE :
        retval = "DOCUMENT_FRAGMENT_NODE"; break;
    case Node.DOCUMENT_NODE :
        retval = "DOCUMENT_NODE"; break;
    case Node.DOCUMENT_TYPE_NODE :
        retval = "DOCUMENT_TYPE_NODE"; break;
    case Node.ELEMENT_NODE :
        retval = "ELEMENT_NODE"; break;
    case Node.ENTITY_NODE :
        retval = "ENTITY_NODE"; break;
    case Node.ENTITY_REFERENCE_NODE :
        retval = "ENTITY_REFERENCE_NODE"; break;
    case Node.NOTATION_NODE :
        retval = "NOTATION_NODE"; break;
    case Node.PROCESSING_INSTRUCTION_NODE :
        retval = "PROCESSING_INSTRUCTION_NODE"; break;
    case Node.TEXT_NODE:
        retval = "TEXT_NODE"; break;
    }
    return retval;
}
 
Example 4
Project: openjdk-jdk10   File: CoreDocumentImpl.java   Source Code and License Vote up 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 5
Project: OpenJSharp   File: DTMNodeProxy.java   Source Code and License Vote up 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 6
Project: openjdk-jdk10   File: DTMNodeProxy.java   Source Code and License Vote up 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 7
Project: OpenJSharp   File: DOM2SAX.java   Source Code and License Vote up 5 votes
private String getNodeTypeFromCode(short code) {
    String retval = null;
    switch (code) {
    case Node.ATTRIBUTE_NODE :
        retval = "ATTRIBUTE_NODE"; break;
    case Node.CDATA_SECTION_NODE :
        retval = "CDATA_SECTION_NODE"; break;
    case Node.COMMENT_NODE :
        retval = "COMMENT_NODE"; break;
    case Node.DOCUMENT_FRAGMENT_NODE :
        retval = "DOCUMENT_FRAGMENT_NODE"; break;
    case Node.DOCUMENT_NODE :
        retval = "DOCUMENT_NODE"; break;
    case Node.DOCUMENT_TYPE_NODE :
        retval = "DOCUMENT_TYPE_NODE"; break;
    case Node.ELEMENT_NODE :
        retval = "ELEMENT_NODE"; break;
    case Node.ENTITY_NODE :
        retval = "ENTITY_NODE"; break;
    case Node.ENTITY_REFERENCE_NODE :
        retval = "ENTITY_REFERENCE_NODE"; break;
    case Node.NOTATION_NODE :
        retval = "NOTATION_NODE"; break;
    case Node.PROCESSING_INSTRUCTION_NODE :
        retval = "PROCESSING_INSTRUCTION_NODE"; break;
    case Node.TEXT_NODE:
        retval = "TEXT_NODE"; break;
    }
    return retval;
}
 
Example 8
Project: OpenJSharp   File: DOM2TO.java   Source Code and License Vote up 5 votes
private String getNodeTypeFromCode(short code) {
    String retval = null;
    switch (code) {
    case Node.ATTRIBUTE_NODE :
        retval = "ATTRIBUTE_NODE"; break;
    case Node.CDATA_SECTION_NODE :
        retval = "CDATA_SECTION_NODE"; break;
    case Node.COMMENT_NODE :
        retval = "COMMENT_NODE"; break;
    case Node.DOCUMENT_FRAGMENT_NODE :
        retval = "DOCUMENT_FRAGMENT_NODE"; break;
    case Node.DOCUMENT_NODE :
        retval = "DOCUMENT_NODE"; break;
    case Node.DOCUMENT_TYPE_NODE :
        retval = "DOCUMENT_TYPE_NODE"; break;
    case Node.ELEMENT_NODE :
        retval = "ELEMENT_NODE"; break;
    case Node.ENTITY_NODE :
        retval = "ENTITY_NODE"; break;
    case Node.ENTITY_REFERENCE_NODE :
        retval = "ENTITY_REFERENCE_NODE"; break;
    case Node.NOTATION_NODE :
        retval = "NOTATION_NODE"; break;
    case Node.PROCESSING_INSTRUCTION_NODE :
        retval = "PROCESSING_INSTRUCTION_NODE"; break;
    case Node.TEXT_NODE:
        retval = "TEXT_NODE"; break;
    }
    return retval;
}
 
Example 9
Project: OpenJSharp   File: CoreDocumentImpl.java   Source Code and License Vote up 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 10
Project: OpenJSharp   File: CoreDocumentImpl.java   Source Code and License Vote up 5 votes
/**
 * Uses the kidOK lookup table to check whether the proposed
 * tree structure is legal.
 */
protected boolean isKidOK(Node parent, Node child) {
    if (allowGrammarAccess &&
    parent.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
        return child.getNodeType() == Node.ELEMENT_NODE;
    }
    return 0 != (kidOK[parent.getNodeType()] & 1 << child.getNodeType());
}
 
Example 11
Project: openjdk-jdk10   File: DeferredDocumentImpl.java   Source Code and License Vote up 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 12
Project: openjdk-jdk10   File: UnImplNode.java   Source Code and License Vote up 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 13
Project: openjdk-jdk10   File: DOM2DTMdefaultNamespaceDeclarationNode.java   Source Code and License Vote up 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 14
Project: openjdk-jdk10   File: RangeImpl.java   Source Code and License Vote up 4 votes
public void surroundContents(Node newParent)
    throws DOMException, RangeException
{
    if (newParent==null) return;
    int type = newParent.getNodeType();

    if (fDocument.errorChecking) {
        if (fDetach) {
            throw new DOMException(
                    DOMException.INVALID_STATE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
        }
        if (type == Node.ATTRIBUTE_NODE
                || type == Node.ENTITY_NODE
                || type == Node.NOTATION_NODE
                || type == Node.DOCUMENT_TYPE_NODE
                || type == Node.DOCUMENT_NODE
                || type == Node.DOCUMENT_FRAGMENT_NODE)
        {
            throw new RangeExceptionImpl(
                    RangeException.INVALID_NODE_TYPE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null));
        }
    }

    Node realStart = fStartContainer;
    Node realEnd = fEndContainer;
    if (fStartContainer.getNodeType() == Node.TEXT_NODE) {
        realStart = fStartContainer.getParentNode();
    }
    if (fEndContainer.getNodeType() == Node.TEXT_NODE) {
        realEnd = fEndContainer.getParentNode();
    }

    if (realStart != realEnd) {
            throw new RangeExceptionImpl(
            RangeException.BAD_BOUNDARYPOINTS_ERR,
            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "BAD_BOUNDARYPOINTS_ERR", null));
    }

    DocumentFragment frag = extractContents();
    insertNode(newParent);
    newParent.appendChild(frag);
    selectNode(newParent);
}
 
Example 15
Project: server-utility   File: DomWriter.java   Source Code and License Vote up 4 votes
/**
 * Write any node.
 *
 * @param node
 *            the node
 * @throws ShellException
 *             the shell exception
 */
protected void writeAnyNode(Node node) throws ShellException {
    // is there anything to do?
    if (node == null) {
        return;
    }

    short type = node.getNodeType();
    switch (type) {
    case Node.DOCUMENT_NODE:
        write((Document) node);
        break;

    case Node.DOCUMENT_TYPE_NODE:
        write((DocumentType) node);
        break;

    case Node.ELEMENT_NODE:
        write((Element) node);
        break;

    case Node.ENTITY_REFERENCE_NODE:
        write((EntityReference) node);
        break;

    case Node.CDATA_SECTION_NODE:
        write((CDATASection) node);
        break;

    case Node.TEXT_NODE:
        write((Text) node);
        break;

    case Node.PROCESSING_INSTRUCTION_NODE:
        write((ProcessingInstruction) node);
        break;

    case Node.COMMENT_NODE:
        write((Comment) node);
        break;

    default:
        throw new ShellException(getString(
                "RuntimeError.18", Short.toString(type))); //$NON-NLS-1$
    }
}
 
Example 16
Project: OpenJSharp   File: DeferredDocumentImpl.java   Source Code and License Vote up 4 votes
/**
 * Returns the index of the element definition in the table
 * with the specified name index, or -1 if no such definition
 * exists.
 */
public int lookupElementDefinition(String elementName) {

    if (fNodeCount > 1) {

        // find doctype
        int docTypeIndex = -1;
        int nchunk = 0;
        int nindex = 0;
        for (int index = getChunkIndex(fNodeLastChild, nchunk, nindex);
             index != -1;
             index = getChunkIndex(fNodePrevSib, nchunk, nindex)) {

            nchunk = index >> CHUNK_SHIFT;
            nindex = index  & CHUNK_MASK;
            if (getChunkIndex(fNodeType, nchunk, nindex) == Node.DOCUMENT_TYPE_NODE) {
                docTypeIndex = index;
                break;
            }
        }

        // find element definition
        if (docTypeIndex == -1) {
            return -1;
        }
        nchunk = docTypeIndex >> CHUNK_SHIFT;
        nindex = docTypeIndex & CHUNK_MASK;
        for (int index = getChunkIndex(fNodeLastChild, nchunk, nindex);
             index != -1;
             index = getChunkIndex(fNodePrevSib, nchunk, nindex)) {

            nchunk = index >> CHUNK_SHIFT;
            nindex = index & CHUNK_MASK;
            if (getChunkIndex(fNodeType, nchunk, nindex) ==
                                       NodeImpl.ELEMENT_DEFINITION_NODE
             && getChunkValue(fNodeName, nchunk, nindex) == elementName) {
                return index;
            }
        }
    }

    return -1;

}
 
Example 17
Project: openjdk-jdk10   File: NodeImpl.java   Source Code and License Vote up 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.ownerNode.getNodeType() == Node.ELEMENT_NODE) {
                return ownerNode.lookupPrefix(namespaceURI);

            }
            return null;
        }
    default:{
            NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
            if (ancestor != null) {
                return ancestor.lookupPrefix(namespaceURI);
            }
            return null;
        }

    }
}
 
Example 18
Project: openjdk-jdk10   File: DeferredDocumentImpl.java   Source Code and License Vote up 4 votes
/**
 * Returns the index of the element definition in the table
 * with the specified name index, or -1 if no such definition
 * exists.
 */
public int lookupElementDefinition(String elementName) {

    if (fNodeCount > 1) {

        // find doctype
        int docTypeIndex = -1;
        int nchunk = 0;
        int nindex = 0;
        for (int index = getChunkIndex(fNodeLastChild, nchunk, nindex);
             index != -1;
             index = getChunkIndex(fNodePrevSib, nchunk, nindex)) {

            nchunk = index >> CHUNK_SHIFT;
            nindex = index  & CHUNK_MASK;
            if (getChunkIndex(fNodeType, nchunk, nindex) == Node.DOCUMENT_TYPE_NODE) {
                docTypeIndex = index;
                break;
            }
        }

        // find element definition
        if (docTypeIndex == -1) {
            return -1;
        }
        nchunk = docTypeIndex >> CHUNK_SHIFT;
        nindex = docTypeIndex & CHUNK_MASK;
        for (int index = getChunkIndex(fNodeLastChild, nchunk, nindex);
             index != -1;
             index = getChunkIndex(fNodePrevSib, nchunk, nindex)) {

            nchunk = index >> CHUNK_SHIFT;
            nindex = index & CHUNK_MASK;
            if (getChunkIndex(fNodeType, nchunk, nindex) ==
                                       NodeImpl.ELEMENT_DEFINITION_NODE
             && getChunkValue(fNodeName, nchunk, nindex) == elementName) {
                return index;
            }
        }
    }

    return -1;

}
 
Example 19
Project: OpenJSharp   File: UnImplNode.java   Source Code and License Vote up 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 20
Project: OpenJSharp   File: DocumentTypeImpl.java   Source Code and License Vote up 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;
}