Example usage for org.w3c.dom Node getNamespaceURI

List of usage examples for org.w3c.dom Node getNamespaceURI

Introduction

In this page you can find the example usage for org.w3c.dom Node getNamespaceURI.

Prototype

public String getNamespaceURI();

Source Link

Document

The namespace URI of this node, or null if it is unspecified (see ).

Usage

From source file:org.eclipse.lyo.testsuite.oslcv2.ServiceProviderXmlTests.java

@Test
public void serviceProviderHasAtMostOneTitle() throws XPathException {
    //Verify that the ServiceProvider has at most one dc:title child element
    NodeList providerChildren = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_v2:ServiceProvider/*", doc,
            XPathConstants.NODESET);

    int numTitles = 0;
    for (int i = 0; i < providerChildren.getLength(); i++) {
        Node child = providerChildren.item(i);
        if (child.getLocalName() != null && child.getLocalName().equals("title")
                && child.getNamespaceURI().equals(OSLCConstants.DC)) {
            numTitles++;//from ww  w.  j a  v  a  2 s.  c o m
        }
    }
    assertTrue("Expected number of dcterms:titles to be <=1 but was:" + numTitles, numTitles <= 1);
}

From source file:de.betterform.xml.xforms.XFormsElement.java

/**
 * returns the list of all attributes that are not in 'known' namespaces and do not have the null (default?) namespace
 *
 * //from ww  w  . ja  v a 2 s . c  o m
 * @return the key-value-pair of the attributes
 */
public Map<String, String> getCustomMIPAttributes() {

    HashMap<String, String> customMIPAttributes = new HashMap<String, String>();
    NamedNodeMap nnm = element.getAttributes();
    for (int i = 0; i < nnm.getLength(); i++) {
        Node attribute = nnm.item(i);
        if (attribute.getNamespaceURI() != null
                && !NamespaceConstants.BETTERFORM_NS.equals(attribute.getNamespaceURI())
                && !NamespaceConstants.XFORMS_NS.equals(attribute.getNamespaceURI())
                && !NamespaceConstants.XHTML_NS.equals(attribute.getNamespaceURI())
                && !NamespaceConstants.XMLNS_NS.equals(attribute.getNamespaceURI())
                && !NamespaceConstants.XMLSCHEMA_INSTANCE_NS.equals(attribute.getNamespaceURI())
                && !NamespaceConstants.XMLEVENTS_NS.equals(attribute.getNamespaceURI())) {
            customMIPAttributes.put(attribute.getPrefix() + WordUtils.capitalize(attribute.getLocalName()),
                    attribute.getTextContent());
        }
    }
    return customMIPAttributes;

}

From source file:org.eclipse.lyo.testsuite.oslcv2.ServiceProviderCatalogXmlTests.java

@Test
public void publisherElementsAreValid() throws XPathExpressionException {
    // Get all Publisher xml blocks
    NodeList publishers = (NodeList) OSLCUtils.getXPath().evaluate("//dc:publisher/*", doc,
            XPathConstants.NODESET);

    // Verify that each block contains a title and identifier, and at most
    // one icon and label
    for (int i = 0; i < publishers.getLength(); i++) {
        NodeList publisherElements = publishers.item(i).getChildNodes();
        int titleCount = 0;
        int identifierCount = 0;
        int iconCount = 0;
        int labelCount = 0;
        for (int j = 0; j < publisherElements.getLength(); j++) {
            Node ele = publisherElements.item(j);
            if (ele.getLocalName() == null) {
                continue;
            }// w  w w. j  a va2 s . c  om
            if (ele.getNamespaceURI().equals(OSLCConstants.DC) && ele.getLocalName().equals("title")) {
                titleCount++;
            }
            if (ele.getNamespaceURI().equals(OSLCConstants.DC) && ele.getLocalName().equals("identifier")) {
                identifierCount++;
            }
            if (ele.getNamespaceURI().equals(OSLCConstants.OSLC_V2) && ele.getLocalName().equals("label")) {
                labelCount++;
            }
            if (ele.getNamespaceURI().equals(OSLCConstants.OSLC_V2) && ele.getLocalName().equals("icon")) {
                iconCount++;
            }
        }
        assertTrue(titleCount == 1);
        assertTrue(identifierCount == 1);
        assertTrue(iconCount <= 1);
        assertTrue(labelCount <= 1);
    }
}

From source file:org.eclipse.lyo.testsuite.oslcv2.ServiceProviderXmlTests.java

@Test
public void publisherElementsAreValid() throws XPathExpressionException {
    //Get all Publisher xml blocks
    NodeList publishers = (NodeList) OSLCUtils.getXPath().evaluate("//dc:publisher/*", doc,
            XPathConstants.NODESET);

    //Verify that each block contains a title and identifier, and at most one icon and label
    for (int i = 0; i < publishers.getLength(); i++) {
        NodeList publisherElements = publishers.item(i).getChildNodes();
        int titleCount = 0;
        int identifierCount = 0;
        int iconCount = 0;
        int labelCount = 0;
        for (int j = 0; j < publisherElements.getLength(); j++) {
            Node ele = publisherElements.item(j);
            if (ele.getLocalName() == null) {
                continue;
            }//ww w .j  a v  a2  s  . c  o m
            if (ele.getNamespaceURI().equals(OSLCConstants.DC) && ele.getLocalName().equals("title")) {
                titleCount++;
            }
            if (ele.getNamespaceURI().equals(OSLCConstants.DC) && ele.getLocalName().equals("identifier")) {
                identifierCount++;
            }
            if (ele.getNamespaceURI().equals(OSLCConstants.OSLC_V2) && ele.getLocalName().equals("label")) {
                labelCount++;
            }
            if (ele.getNamespaceURI().equals(OSLCConstants.OSLC_V2) && ele.getLocalName().equals("icon")) {
                iconCount++;
            }
        }
        assertTrue(titleCount == 1);
        assertTrue(identifierCount == 1);
        assertTrue(iconCount <= 1);
        assertTrue(labelCount <= 1);
    }
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

public static QName getQName(Node node) {
    if (node.getLocalName() == null) {
        if (node.getNodeName() == null) {
            return null;
        } else {// w  w w.  j a va 2  s. c  o m
            return new QName(null, node.getNodeName());
        }
    }
    if (node.getPrefix() == null) {
        return new QName(node.getNamespaceURI(), node.getLocalName());
    }
    return new QName(node.getNamespaceURI(), node.getLocalName(), node.getPrefix());
}

From source file:de.fau.cs.osr.hddiff.perfsuite.RunXyDiff.java

private Edit evaluateUpdate(Node node) {
    int ins = 0;//from  w  w  w  .j a v a  2s  .c o  m
    int del = 0;

    NodeList children = node.getChildNodes();
    int len = children.getLength();
    for (int i = 0; i < len; ++i) {
        Node child = children.item(i);

        String localName = child.getLocalName();
        if (localName == null) {
            String str = ((Text) child).getNodeValue();
            // Ignore whitespace in between tags
            if (!str.trim().isEmpty())
                xyDiffConfusesMe();
        } else {
            String namespaceURI = child.getNamespaceURI();
            if (!"urn:schemas-xydiff:xydelta".equals(namespaceURI))
                xyDiffConfusesMe();

            if ("td".equals(localName)) {
                Node namedItem = child.getAttributes().getNamedItem("len");
                if (namedItem == null)
                    xyDiffConfusesMe();
                del += Integer.valueOf(namedItem.getNodeValue());
            } else if ("ti".equals(localName)) {
                ins += child.getTextContent().length();
            } else if ("tr".equals(localName)) {
                Node namedItem = child.getAttributes().getNamedItem("len");
                if (namedItem == null)
                    xyDiffConfusesMe();
                del += Integer.valueOf(namedItem.getNodeValue());
                ins += child.getTextContent().length();
            } else
                xyDiffConfusesMe();
        }
    }

    return new Edit(GenericEditOp.UPD, ins, del);
}

From source file:com.centeractive.ws.builder.soap.XmlUtils.java

public static NodeList getChildElementsByTagNameNS(Element elm, String namespaceUri, String localName) {
    List<Element> list = new ArrayList<Element>();

    NodeList nl = elm.getChildNodes();
    for (int c = 0; c < nl.getLength(); c++) {
        Node item = nl.item(c);
        if (item.getParentNode() == elm && item.getNodeType() == Node.ELEMENT_NODE
                && localName.equals(item.getLocalName()) && namespaceUri.equals(item.getNamespaceURI()))
            list.add((Element) item);
    }/*from  ww w . j  a  v  a 2  s .  c  o  m*/

    return new ElementNodeList(list);
}

From source file:org.eclipse.lyo.testsuite.oslcv2.ServiceProviderXmlTests.java

@Test
public void creationFactoriesAreValid() throws XPathExpressionException {
    //Get all creation factories
    NodeList factories = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_v2:CreationFactory", doc,
            XPathConstants.NODESET);
    for (int i = 0; i < factories.getLength(); i++) {
        NodeList factoryChildren = factories.item(i).getChildNodes();
        int numTitles = 0;
        int numLabels = 0;
        int numCreation = 0;
        //Check children of current creation factory
        for (int j = 0; j < factoryChildren.getLength(); j++) {
            Node fChild = factoryChildren.item(j);
            if (fChild.getLocalName() == null) {
                continue;
            }//ww  w . ja va2 s  .  c o m
            if (fChild.getLocalName().equals("title") && fChild.getNamespaceURI().equals(OSLCConstants.DC)) {
                numTitles++;
            }
            if (fChild.getLocalName().equals("creation")
                    && fChild.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) {
                numCreation++;
            }
            if (fChild.getLocalName().equals("label")
                    && fChild.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) {
                numLabels++;
            }
        }
        //Make sure the factory has a title, a creation element, and at most 1 label
        assertTrue(numTitles == 1);
        assertTrue(numCreation == 1);
        assertTrue(numLabels <= 1);
    }
}

From source file:org.eclipse.lyo.testsuite.oslcv2.ServiceProviderXmlTests.java

@Test
public void queryCapabilityBlocksAreValid() throws XPathExpressionException {
    //Get all query blocks
    NodeList queryBlocks = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_v2:QueryCapability", doc,
            XPathConstants.NODESET);

    for (int i = 0; i < queryBlocks.getLength(); i++) {
        NodeList queryChildren = queryBlocks.item(i).getChildNodes();
        int numTitles = 0;
        int numLabels = 0;
        int numQueryBase = 0;
        int numResourceShape = 0;
        //Check children of each block
        for (int j = 0; j < queryChildren.getLength(); j++) {
            Node qChild = queryChildren.item(j);
            if (qChild.getLocalName() == null) {
                continue;
            }/*from w  w w . j  a  v  a 2 s.  co  m*/
            if (qChild.getLocalName().equals("title") && qChild.getNamespaceURI().equals(OSLCConstants.DC)) {
                numTitles++;
            }
            if (qChild.getLocalName().equals("queryBase")
                    && qChild.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) {
                numQueryBase++;
            }
            if (qChild.getLocalName().equals("label")
                    && qChild.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) {
                numLabels++;
            }
            if (qChild.getLocalName().equals("resourceShape")
                    && qChild.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) {
                numResourceShape++;
            }
        }
        //Make sure we have a title, a queryBase, and at most one label/resourceShape
        assertTrue(numTitles == 1);
        assertTrue(numQueryBase == 1);
        assertTrue(numLabels <= 1);
        assertTrue(numResourceShape <= 1);
    }
}