Java Code Examples for org.w3c.dom.NamedNodeMap#setNamedItemNS()

The following examples show how to use org.w3c.dom.NamedNodeMap#setNamedItemNS() . 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: NamedNodeMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSetNamedItemNS() throws Exception {
    final String nsURI = "urn:BooksAreUs.org:BookInfo";
    Document document = createDOMWithNS("NamedNodeMap01.xml");
    NodeList nodeList = document.getElementsByTagName("body");
    nodeList = nodeList.item(0).getChildNodes();
    Node n = nodeList.item(3);

    NamedNodeMap namedNodeMap = n.getAttributes();

    // creating an Attribute using createAttributeNS
    // method having the same namespaceURI
    // and the same qualified name as the existing one in the xml file
    Attr attr = document.createAttributeNS(nsURI, "b:style");
    // setting to a new Value
    attr.setValue("newValue");
    Node replacedAttr = namedNodeMap.setNamedItemNS(attr); // return the replaced attr
    assertEquals(replacedAttr.getNodeValue(), "font-family");
    Node updatedAttr = namedNodeMap.getNamedItemNS(nsURI, "style");
    assertEquals(updatedAttr.getNodeValue(), "newValue");


    // creating a non existing attribute node
    attr = document.createAttributeNS(nsURI, "b:newNode");
    attr.setValue("newValue");

    assertNull(namedNodeMap.setNamedItemNS(attr)); // return null

    // checking if the node could be accessed
    // using the getNamedItemNS method
    Node newAttr = namedNodeMap.getNamedItemNS(nsURI, "newNode");
    assertEquals(newAttr.getNodeValue(), "newValue");
}
 
Example 2
Source File: DeferredElementNSImpl.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/** Synchronizes the data (name and value) for fast nodes. */
protected final void synchronizeData() {

    // no need to sync in the future
    needsSyncData(false);

    // fluff data
    DeferredDocumentImpl ownerDocument =
        (DeferredDocumentImpl) this.ownerDocument;

    // we don't want to generate any event for this so turn them off
    boolean orig = ownerDocument.mutationEvents;
    ownerDocument.mutationEvents = false;

    name = ownerDocument.getNodeName(fNodeIndex);

    // extract local part from QName
    int index = name.indexOf(':');
    if (index < 0) {
        localName = name;
    }
    else {
        localName = name.substring(index + 1);
    }

        namespaceURI = ownerDocument.getNodeURI(fNodeIndex);
    type = (XSTypeDefinition)ownerDocument.getTypeInfo(fNodeIndex);

    // attributes
    setupDefaultAttributes();
    int attrIndex = ownerDocument.getNodeExtra(fNodeIndex);
    if (attrIndex != -1) {
        NamedNodeMap attrs = getAttributes();
        boolean seenSchemaDefault = false;
        do {
            AttrImpl attr = (AttrImpl) ownerDocument.getNodeObject(attrIndex);
            // Take special care of schema defaulted attributes. Calling the
            // non-namespace aware setAttributeNode() method could overwrite
            // another attribute with the same local name.
            if (!attr.getSpecified() && (seenSchemaDefault ||
                (attr.getNamespaceURI() != null &&
                attr.getNamespaceURI() != NamespaceContext.XMLNS_URI &&
                attr.getName().indexOf(':') < 0))) {
                seenSchemaDefault = true;
                attrs.setNamedItemNS(attr);
            }
            else {
                attrs.setNamedItem(attr);
            }
            attrIndex = ownerDocument.getPrevSibling(attrIndex);
        } while (attrIndex != -1);
    }

    // set mutation events flag back to its original value
    ownerDocument.mutationEvents = orig;

}
 
Example 3
Source File: DeferredElementNSImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/** Synchronizes the data (name and value) for fast nodes. */
protected final void synchronizeData() {

    // no need to sync in the future
    needsSyncData(false);

    // fluff data
    DeferredDocumentImpl ownerDocument =
        (DeferredDocumentImpl) this.ownerDocument;

    // we don't want to generate any event for this so turn them off
    boolean orig = ownerDocument.mutationEvents;
    ownerDocument.mutationEvents = false;

    name = ownerDocument.getNodeName(fNodeIndex);

    // extract local part from QName
    int index = name.indexOf(':');
    if (index < 0) {
        localName = name;
    }
    else {
        localName = name.substring(index + 1);
    }

        namespaceURI = ownerDocument.getNodeURI(fNodeIndex);
    type = (XSTypeDefinition)ownerDocument.getTypeInfo(fNodeIndex);

    // attributes
    setupDefaultAttributes();
    int attrIndex = ownerDocument.getNodeExtra(fNodeIndex);
    if (attrIndex != -1) {
        NamedNodeMap attrs = getAttributes();
        boolean seenSchemaDefault = false;
        do {
            AttrImpl attr = (AttrImpl) ownerDocument.getNodeObject(attrIndex);
            // Take special care of schema defaulted attributes. Calling the
            // non-namespace aware setAttributeNode() method could overwrite
            // another attribute with the same local name.
            if (!attr.getSpecified() && (seenSchemaDefault ||
                (attr.getNamespaceURI() != null &&
                attr.getNamespaceURI() != NamespaceContext.XMLNS_URI &&
                attr.getName().indexOf(':') < 0))) {
                seenSchemaDefault = true;
                attrs.setNamedItemNS(attr);
            }
            else {
                attrs.setNamedItem(attr);
            }
            attrIndex = ownerDocument.getPrevSibling(attrIndex);
        } while (attrIndex != -1);
    }

    // set mutation events flag back to its original value
    ownerDocument.mutationEvents = orig;

}
 
Example 4
Source File: DeferredElementNSImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/** Synchronizes the data (name and value) for fast nodes. */
protected final void synchronizeData() {

    // no need to sync in the future
    needsSyncData(false);

    // fluff data
    DeferredDocumentImpl ownerDocument =
        (DeferredDocumentImpl) this.ownerDocument;

    // we don't want to generate any event for this so turn them off
    boolean orig = ownerDocument.mutationEvents;
    ownerDocument.mutationEvents = false;

    name = ownerDocument.getNodeName(fNodeIndex);

    // extract local part from QName
    int index = name.indexOf(':');
    if (index < 0) {
        localName = name;
    }
    else {
        localName = name.substring(index + 1);
    }

        namespaceURI = ownerDocument.getNodeURI(fNodeIndex);
    type = (XSTypeDefinition)ownerDocument.getTypeInfo(fNodeIndex);

    // attributes
    setupDefaultAttributes();
    int attrIndex = ownerDocument.getNodeExtra(fNodeIndex);
    if (attrIndex != -1) {
        NamedNodeMap attrs = getAttributes();
        boolean seenSchemaDefault = false;
        do {
            AttrImpl attr = (AttrImpl) ownerDocument.getNodeObject(attrIndex);
            // Take special care of schema defaulted attributes. Calling the
            // non-namespace aware setAttributeNode() method could overwrite
            // another attribute with the same local name.
            if (!attr.getSpecified() && (seenSchemaDefault ||
                (attr.getNamespaceURI() != null &&
                attr.getNamespaceURI() != NamespaceContext.XMLNS_URI &&
                attr.getName().indexOf(':') < 0))) {
                seenSchemaDefault = true;
                attrs.setNamedItemNS(attr);
            }
            else {
                attrs.setNamedItem(attr);
            }
            attrIndex = ownerDocument.getPrevSibling(attrIndex);
        } while (attrIndex != -1);
    }

    // set mutation events flag back to its original value
    ownerDocument.mutationEvents = orig;

}
 
Example 5
Source File: DeferredElementNSImpl.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/** Synchronizes the data (name and value) for fast nodes. */
protected final void synchronizeData() {

    // no need to sync in the future
    needsSyncData(false);

    // fluff data
    DeferredDocumentImpl ownerDocument =
        (DeferredDocumentImpl) this.ownerDocument;

    // we don't want to generate any event for this so turn them off
    boolean orig = ownerDocument.mutationEvents;
    ownerDocument.mutationEvents = false;

    name = ownerDocument.getNodeName(fNodeIndex);

    // extract local part from QName
    int index = name.indexOf(':');
    if (index < 0) {
        localName = name;
    }
    else {
        localName = name.substring(index + 1);
    }

        namespaceURI = ownerDocument.getNodeURI(fNodeIndex);
    type = (XSTypeDefinition)ownerDocument.getTypeInfo(fNodeIndex);

    // attributes
    setupDefaultAttributes();
    int attrIndex = ownerDocument.getNodeExtra(fNodeIndex);
    if (attrIndex != -1) {
        NamedNodeMap attrs = getAttributes();
        boolean seenSchemaDefault = false;
        do {
            AttrImpl attr = (AttrImpl) ownerDocument.getNodeObject(attrIndex);
            // Take special care of schema defaulted attributes. Calling the
            // non-namespace aware setAttributeNode() method could overwrite
            // another attribute with the same local name.
            if (!attr.getSpecified() && (seenSchemaDefault ||
                (attr.getNamespaceURI() != null &&
                attr.getNamespaceURI() != NamespaceContext.XMLNS_URI &&
                attr.getName().indexOf(':') < 0))) {
                seenSchemaDefault = true;
                attrs.setNamedItemNS(attr);
            }
            else {
                attrs.setNamedItem(attr);
            }
            attrIndex = ownerDocument.getPrevSibling(attrIndex);
        } while (attrIndex != -1);
    }

    // set mutation events flag back to its original value
    ownerDocument.mutationEvents = orig;

}
 
Example 6
Source File: DeferredElementNSImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/** Synchronizes the data (name and value) for fast nodes. */
protected final void synchronizeData() {

    // no need to sync in the future
    needsSyncData(false);

    // fluff data
    DeferredDocumentImpl ownerDocument =
        (DeferredDocumentImpl) this.ownerDocument;

    // we don't want to generate any event for this so turn them off
    boolean orig = ownerDocument.mutationEvents;
    ownerDocument.mutationEvents = false;

    name = ownerDocument.getNodeName(fNodeIndex);

    // extract local part from QName
    int index = name.indexOf(':');
    if (index < 0) {
        localName = name;
    }
    else {
        localName = name.substring(index + 1);
    }

        namespaceURI = ownerDocument.getNodeURI(fNodeIndex);
    type = (XSTypeDefinition)ownerDocument.getTypeInfo(fNodeIndex);

    // attributes
    setupDefaultAttributes();
    int attrIndex = ownerDocument.getNodeExtra(fNodeIndex);
    if (attrIndex != -1) {
        NamedNodeMap attrs = getAttributes();
        boolean seenSchemaDefault = false;
        do {
            AttrImpl attr = (AttrImpl) ownerDocument.getNodeObject(attrIndex);
            // Take special care of schema defaulted attributes. Calling the
            // non-namespace aware setAttributeNode() method could overwrite
            // another attribute with the same local name.
            if (!attr.getSpecified() && (seenSchemaDefault ||
                (attr.getNamespaceURI() != null &&
                attr.getNamespaceURI() != NamespaceContext.XMLNS_URI &&
                attr.getName().indexOf(':') < 0))) {
                seenSchemaDefault = true;
                attrs.setNamedItemNS(attr);
            }
            else {
                attrs.setNamedItem(attr);
            }
            attrIndex = ownerDocument.getPrevSibling(attrIndex);
        } while (attrIndex != -1);
    }

    // set mutation events flag back to its original value
    ownerDocument.mutationEvents = orig;

}
 
Example 7
Source File: DeferredElementNSImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/** Synchronizes the data (name and value) for fast nodes. */
protected final void synchronizeData() {

    // no need to sync in the future
    needsSyncData(false);

    // fluff data
    DeferredDocumentImpl ownerDocument =
        (DeferredDocumentImpl) this.ownerDocument;

    // we don't want to generate any event for this so turn them off
    boolean orig = ownerDocument.mutationEvents;
    ownerDocument.mutationEvents = false;

    name = ownerDocument.getNodeName(fNodeIndex);

    // extract local part from QName
    int index = name.indexOf(':');
    if (index < 0) {
        localName = name;
    }
    else {
        localName = name.substring(index + 1);
    }

        namespaceURI = ownerDocument.getNodeURI(fNodeIndex);
    type = (XSTypeDefinition)ownerDocument.getTypeInfo(fNodeIndex);

    // attributes
    setupDefaultAttributes();
    int attrIndex = ownerDocument.getNodeExtra(fNodeIndex);
    if (attrIndex != -1) {
        NamedNodeMap attrs = getAttributes();
        boolean seenSchemaDefault = false;
        do {
            AttrImpl attr = (AttrImpl) ownerDocument.getNodeObject(attrIndex);
            // Take special care of schema defaulted attributes. Calling the
            // non-namespace aware setAttributeNode() method could overwrite
            // another attribute with the same local name.
            if (!attr.getSpecified() && (seenSchemaDefault ||
                (attr.getNamespaceURI() != null &&
                attr.getNamespaceURI() != NamespaceContext.XMLNS_URI &&
                attr.getName().indexOf(':') < 0))) {
                seenSchemaDefault = true;
                attrs.setNamedItemNS(attr);
            }
            else {
                attrs.setNamedItem(attr);
            }
            attrIndex = ownerDocument.getPrevSibling(attrIndex);
        } while (attrIndex != -1);
    }

    // set mutation events flag back to its original value
    ownerDocument.mutationEvents = orig;

}
 
Example 8
Source File: DeferredElementNSImpl.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/** Synchronizes the data (name and value) for fast nodes. */
protected final void synchronizeData() {

    // no need to sync in the future
    needsSyncData(false);

    // fluff data
    DeferredDocumentImpl ownerDocument =
        (DeferredDocumentImpl) this.ownerDocument;

    // we don't want to generate any event for this so turn them off
    boolean orig = ownerDocument.mutationEvents;
    ownerDocument.mutationEvents = false;

    name = ownerDocument.getNodeName(fNodeIndex);

    // extract local part from QName
    int index = name.indexOf(':');
    if (index < 0) {
        localName = name;
    }
    else {
        localName = name.substring(index + 1);
    }

        namespaceURI = ownerDocument.getNodeURI(fNodeIndex);
    type = (XSTypeDefinition)ownerDocument.getTypeInfo(fNodeIndex);

    // attributes
    setupDefaultAttributes();
    int attrIndex = ownerDocument.getNodeExtra(fNodeIndex);
    if (attrIndex != -1) {
        NamedNodeMap attrs = getAttributes();
        boolean seenSchemaDefault = false;
        do {
            AttrImpl attr = (AttrImpl) ownerDocument.getNodeObject(attrIndex);
            // Take special care of schema defaulted attributes. Calling the
            // non-namespace aware setAttributeNode() method could overwrite
            // another attribute with the same local name.
            if (!attr.getSpecified() && (seenSchemaDefault ||
                (attr.getNamespaceURI() != null &&
                attr.getNamespaceURI() != NamespaceContext.XMLNS_URI &&
                attr.getName().indexOf(':') < 0))) {
                seenSchemaDefault = true;
                attrs.setNamedItemNS(attr);
            }
            else {
                attrs.setNamedItem(attr);
            }
            attrIndex = ownerDocument.getPrevSibling(attrIndex);
        } while (attrIndex != -1);
    }

    // set mutation events flag back to its original value
    ownerDocument.mutationEvents = orig;

}
 
Example 9
Source File: DeferredElementNSImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/** Synchronizes the data (name and value) for fast nodes. */
protected final void synchronizeData() {

    // no need to sync in the future
    needsSyncData(false);

    // fluff data
    DeferredDocumentImpl ownerDocument =
        (DeferredDocumentImpl) this.ownerDocument;

    // we don't want to generate any event for this so turn them off
    boolean orig = ownerDocument.mutationEvents;
    ownerDocument.mutationEvents = false;

    name = ownerDocument.getNodeName(fNodeIndex);

    // extract local part from QName
    int index = name.indexOf(':');
    if (index < 0) {
        localName = name;
    }
    else {
        localName = name.substring(index + 1);
    }

        namespaceURI = ownerDocument.getNodeURI(fNodeIndex);
    type = (XSTypeDefinition)ownerDocument.getTypeInfo(fNodeIndex);

    // attributes
    setupDefaultAttributes();
    int attrIndex = ownerDocument.getNodeExtra(fNodeIndex);
    if (attrIndex != -1) {
        NamedNodeMap attrs = getAttributes();
        boolean seenSchemaDefault = false;
        do {
            AttrImpl attr = (AttrImpl) ownerDocument.getNodeObject(attrIndex);
            // Take special care of schema defaulted attributes. Calling the
            // non-namespace aware setAttributeNode() method could overwrite
            // another attribute with the same local name.
            if (!attr.getSpecified() && (seenSchemaDefault ||
                (attr.getNamespaceURI() != null &&
                attr.getNamespaceURI() != NamespaceContext.XMLNS_URI &&
                attr.getName().indexOf(':') < 0))) {
                seenSchemaDefault = true;
                attrs.setNamedItemNS(attr);
            }
            else {
                attrs.setNamedItem(attr);
            }
            attrIndex = ownerDocument.getPrevSibling(attrIndex);
        } while (attrIndex != -1);
    }

    // set mutation events flag back to its original value
    ownerDocument.mutationEvents = orig;

}
 
Example 10
Source File: DeferredElementNSImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/** Synchronizes the data (name and value) for fast nodes. */
protected final void synchronizeData() {

    // no need to sync in the future
    needsSyncData(false);

    // fluff data
    DeferredDocumentImpl ownerDocument =
        (DeferredDocumentImpl) this.ownerDocument;

    // we don't want to generate any event for this so turn them off
    boolean orig = ownerDocument.mutationEvents;
    ownerDocument.mutationEvents = false;

    name = ownerDocument.getNodeName(fNodeIndex);

    // extract local part from QName
    int index = name.indexOf(':');
    if (index < 0) {
        localName = name;
    }
    else {
        localName = name.substring(index + 1);
    }

        namespaceURI = ownerDocument.getNodeURI(fNodeIndex);
    type = (XSTypeDefinition)ownerDocument.getTypeInfo(fNodeIndex);

    // attributes
    setupDefaultAttributes();
    int attrIndex = ownerDocument.getNodeExtra(fNodeIndex);
    if (attrIndex != -1) {
        NamedNodeMap attrs = getAttributes();
        boolean seenSchemaDefault = false;
        do {
            AttrImpl attr = (AttrImpl) ownerDocument.getNodeObject(attrIndex);
            // Take special care of schema defaulted attributes. Calling the
            // non-namespace aware setAttributeNode() method could overwrite
            // another attribute with the same local name.
            if (!attr.getSpecified() && (seenSchemaDefault ||
                (attr.getNamespaceURI() != null &&
                attr.getNamespaceURI() != NamespaceContext.XMLNS_URI &&
                attr.getName().indexOf(':') < 0))) {
                seenSchemaDefault = true;
                attrs.setNamedItemNS(attr);
            }
            else {
                attrs.setNamedItem(attr);
            }
            attrIndex = ownerDocument.getPrevSibling(attrIndex);
        } while (attrIndex != -1);
    }

    // set mutation events flag back to its original value
    ownerDocument.mutationEvents = orig;

}
 
Example 11
Source File: DeferredElementNSImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/** Synchronizes the data (name and value) for fast nodes. */
protected final void synchronizeData() {

    // no need to sync in the future
    needsSyncData(false);

    // fluff data
    DeferredDocumentImpl ownerDocument =
        (DeferredDocumentImpl) this.ownerDocument;

    // we don't want to generate any event for this so turn them off
    boolean orig = ownerDocument.mutationEvents;
    ownerDocument.mutationEvents = false;

    name = ownerDocument.getNodeName(fNodeIndex);

    // extract local part from QName
    int index = name.indexOf(':');
    if (index < 0) {
        localName = name;
    }
    else {
        localName = name.substring(index + 1);
    }

        namespaceURI = ownerDocument.getNodeURI(fNodeIndex);
    type = (XSTypeDefinition)ownerDocument.getTypeInfo(fNodeIndex);

    // attributes
    setupDefaultAttributes();
    int attrIndex = ownerDocument.getNodeExtra(fNodeIndex);
    if (attrIndex != -1) {
        NamedNodeMap attrs = getAttributes();
        boolean seenSchemaDefault = false;
        do {
            AttrImpl attr = (AttrImpl) ownerDocument.getNodeObject(attrIndex);
            // Take special care of schema defaulted attributes. Calling the
            // non-namespace aware setAttributeNode() method could overwrite
            // another attribute with the same local name.
            if (!attr.getSpecified() && (seenSchemaDefault ||
                (attr.getNamespaceURI() != null &&
                attr.getNamespaceURI() != NamespaceContext.XMLNS_URI &&
                attr.getName().indexOf(':') < 0))) {
                seenSchemaDefault = true;
                attrs.setNamedItemNS(attr);
            }
            else {
                attrs.setNamedItem(attr);
            }
            attrIndex = ownerDocument.getPrevSibling(attrIndex);
        } while (attrIndex != -1);
    }

    // set mutation events flag back to its original value
    ownerDocument.mutationEvents = orig;

}
 
Example 12
Source File: DeferredElementNSImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/** Synchronizes the data (name and value) for fast nodes. */
protected final void synchronizeData() {

    // no need to sync in the future
    needsSyncData(false);

    // fluff data
    DeferredDocumentImpl ownerDocument =
        (DeferredDocumentImpl) this.ownerDocument;

    // we don't want to generate any event for this so turn them off
    boolean orig = ownerDocument.mutationEvents;
    ownerDocument.mutationEvents = false;

    name = ownerDocument.getNodeName(fNodeIndex);

    // extract local part from QName
    int index = name.indexOf(':');
    if (index < 0) {
        localName = name;
    }
    else {
        localName = name.substring(index + 1);
    }

        namespaceURI = ownerDocument.getNodeURI(fNodeIndex);
    type = (XSTypeDefinition)ownerDocument.getTypeInfo(fNodeIndex);

    // attributes
    setupDefaultAttributes();
    int attrIndex = ownerDocument.getNodeExtra(fNodeIndex);
    if (attrIndex != -1) {
        NamedNodeMap attrs = getAttributes();
        boolean seenSchemaDefault = false;
        do {
            AttrImpl attr = (AttrImpl) ownerDocument.getNodeObject(attrIndex);
            // Take special care of schema defaulted attributes. Calling the
            // non-namespace aware setAttributeNode() method could overwrite
            // another attribute with the same local name.
            if (!attr.getSpecified() && (seenSchemaDefault ||
                (attr.getNamespaceURI() != null &&
                attr.getNamespaceURI() != NamespaceContext.XMLNS_URI &&
                attr.getName().indexOf(':') < 0))) {
                seenSchemaDefault = true;
                attrs.setNamedItemNS(attr);
            }
            else {
                attrs.setNamedItem(attr);
            }
            attrIndex = ownerDocument.getPrevSibling(attrIndex);
        } while (attrIndex != -1);
    }

    // set mutation events flag back to its original value
    ownerDocument.mutationEvents = orig;

}