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 dialogsAreValid() throws XPathExpressionException {
    //Get all dialogs
    NodeList dialogs = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_v2:Dialog", doc,
            XPathConstants.NODESET);

    for (int i = 0; i < dialogs.getLength(); i++) {
        NodeList dialogChildren = dialogs.item(i).getChildNodes();
        int numTitles = 0;
        int numLabels = 0;
        int numDialog = 0;
        int numHintWidth = 0;
        int numHintHeight = 0;
        //Check children of dialog
        for (int j = 0; j < dialogChildren.getLength(); j++) {
            Node dChild = dialogChildren.item(j);
            if (dChild.getLocalName() == null) {
                continue;
            }/*from  w w w .j  a  v a 2 s . c  o m*/
            if (dChild.getLocalName().equals("title") && dChild.getNamespaceURI().equals(OSLCConstants.DC)) {
                numTitles++;
            }
            if (dChild.getLocalName().equals("dialog")
                    && dChild.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) {
                numDialog++;
            }
            if (dChild.getLocalName().equals("label")
                    && dChild.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) {
                numLabels++;
            }
            if (dChild.getLocalName().equals("hintWidth")
                    && dChild.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) {
                numHintWidth++;
            }
            if (dChild.getLocalName().equals("hintHeight")
                    && dChild.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) {
                numHintHeight++;
            }
        }
        //Make sure we have a title, a dialog child element, at most one label/hintWidth/hintHeight
        assertTrue(numTitles == 1);
        assertTrue(numDialog == 1);
        assertTrue(numLabels <= 1);
        assertTrue(numHintWidth <= 1);
        assertTrue(numHintHeight <= 1);
    }
}

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

@Test
public void prefixDefinitionsAreValid() throws XPathExpressionException {
    //Get all the prefix definitions
    NodeList prefixes = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_v2:PrefixDefinition", doc,
            XPathConstants.NODESET);

    for (int i = 0; i < prefixes.getLength(); i++) {
        NodeList subNodes = (NodeList) OSLCUtils.getXPath().evaluate("./*", prefixes.item(i),
                XPathConstants.NODESET);
        int prefixCount = 0;
        int baseCount = 0;
        //Check all the children of this prefix definition
        for (int j = 0; j < subNodes.getLength(); j++) {
            Node pChild = subNodes.item(j);
            if (pChild.getLocalName() == null) {
                continue;
            }//from w  w w.jav a 2s.c  om
            if (pChild.getLocalName().equals("prefix")
                    && pChild.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) {
                prefixCount++;
            }
            if (pChild.getLocalName().equals("prefixBase")
                    && pChild.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) {
                baseCount++;
            }
        }
        //Make sure the prefix definition had 1 prefix and 1 prefixBase
        assertEquals(1, prefixCount);
        assertEquals(1, baseCount);
    }
}

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

@Test
public void eachServiceHasOneDomain() throws XPathExpressionException {
    //Get the services referenced
    NodeList services = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_v2:service/oslc_v2:Service", doc,
            XPathConstants.NODESET);

    for (int i = 0; i < services.getLength(); i++) {
        NodeList serviceChildren = services.item(i).getChildNodes();
        int numDomains = 0;
        //Check the service for domain child elements
        for (int j = 0; j < serviceChildren.getLength(); j++) {
            Node sChild = serviceChildren.item(j);
            if (sChild.getLocalName() == null) {
                continue;
            }//from   www  .  j  ava 2s  .c  o  m
            if (sChild.getLocalName().equals("domain")
                    && sChild.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) {
                numDomains++;
            }
        }
        //Make sure the service has exactly one domain element
        assertTrue(numDomains == 1);
    }
}

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

private boolean cmpTag(Node node, String ns, String tag) {
    if (node.getNodeType() != Node.ELEMENT_NODE)
        return false;
    String localName = node.getLocalName();
    if (localName == null)
        localName = node.getNodeName();//  ww w  .  jav a 2 s. c  o m
    return cmpStr(node.getNamespaceURI(), ns) && cmpStr(localName, tag);
}

From source file:edu.duke.cabig.c3pr.webservice.studyimportexport.impl.StudyImportExportImpl.java

/**
 * Gets the first child./*from w w w .j  a  v a  2  s . co m*/
 *
 * @param node the node
 * @param name the name
 * @param ns the ns
 * @return the first child
 */
private Node getFirstChild(Node node, String name, String ns) {
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (name.equals(child.getLocalName()) && ns.equals(child.getNamespaceURI())) {
            return child;
        }
    }
    return null;
}

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

@Test
public void oAuthElementsAreValid() throws XPathExpressionException {
    // Get all oauthAuthorization xml blocks
    NodeList oAuthElement = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_v2:oauthConfiguration/*", doc,
            XPathConstants.NODESET);

    // Verify the block contains the required expected elements
    for (int i = 0; i < oAuthElement.getLength(); i++) {
        NodeList oAuthChildren = oAuthElement.item(i).getChildNodes();
        int reqTokenCount = 0;
        int authCount = 0;
        int accessCount = 0;
        for (int j = 0; j < oAuthChildren.getLength(); j++) {
            Node oAuthNode = oAuthChildren.item(j);
            if (oAuthNode.getLocalName() == null) {
                continue;
            }//www  .  j a va 2  s.  co m
            if (oAuthNode.getLocalName().equals("oauthRequestTokenURI")
                    && oAuthNode.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) {
                reqTokenCount++;
            }
            if (oAuthNode.getLocalName().equals("authorizationURI")
                    && oAuthNode.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) {
                authCount++;
            }
            if (oAuthNode.getLocalName().equals("oauthAccessTokenURI")
                    && oAuthNode.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) {
                accessCount++;
            }
        }
        assertTrue(reqTokenCount == 1);
        assertTrue(authCount == 1);
        assertTrue(accessCount == 1);
    }
}

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

@Test
public void oAuthElementsAreValid() throws XPathExpressionException {
    //Get all oauthAuthorization xml blocks
    NodeList oAuthElement = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_v2:oauthConfiguration/*", doc,
            XPathConstants.NODESET);

    //Verify the block contains the required expected elements
    for (int i = 0; i < oAuthElement.getLength(); i++) {
        NodeList oAuthChildren = oAuthElement.item(i).getChildNodes();
        int reqTokenCount = 0;
        int authCount = 0;
        int accessCount = 0;
        for (int j = 0; j < oAuthChildren.getLength(); j++) {
            Node oAuthNode = oAuthChildren.item(j);
            if (oAuthNode.getLocalName() == null) {
                continue;
            }/* ww w.  j  ava 2  s.co  m*/
            if (oAuthNode.getLocalName().equals("oauthRequestTokenURI")
                    && oAuthNode.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) {
                reqTokenCount++;
            }
            if (oAuthNode.getLocalName().equals("authorizationURI")
                    && oAuthNode.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) {
                authCount++;
            }
            if (oAuthNode.getLocalName().equals("oauthAccessTokenURI")
                    && oAuthNode.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) {
                accessCount++;
            }
        }
        assertTrue(reqTokenCount == 1);
        assertTrue(authCount == 1);
        assertTrue(accessCount == 1);
    }
}

From source file:org.escidoc.browser.elabsmodul.service.ELabsService.java

private RigBean resolveRig(final ItemProxy itemProxy) throws EscidocBrowserException {
    Preconditions.checkNotNull(itemProxy, "Resource is null");

    final RigBean rigBean = new RigBean();
    final String URI_DC = "http://purl.org/dc/elements/1.1/";
    final String URI_EL = "http://escidoc.org/ontologies/bw-elabs/re#";
    final String URI_RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";

    final NodeList nodeList = itemProxy.getMetadataRecords().get("escidoc").getContent().getChildNodes();

    rigBean.setObjectId(itemProxy.getId());
    for (int i = 0; i < nodeList.getLength(); i++) {
        final Node node = nodeList.item(i);
        final String nodeName = node.getLocalName();
        final String nsUri = node.getNamespaceURI();

        if ("title".equals(nodeName) && URI_DC.equals(nsUri)) {
            rigBean.setName((node.getFirstChild() != null) ? node.getFirstChild().getNodeValue() : null);
        } else if ("description".equals(nodeName) && URI_DC.equals(nsUri)) {
            rigBean.setDescription((node.getFirstChild() != null) ? node.getFirstChild().getNodeValue() : null);
        } else if ("instrument".equals(nodeName) && URI_EL.equals(nsUri)) {
            if (node.getAttributes() != null
                    && node.getAttributes().getNamedItemNS(URI_RDF, "resource") != null) {
                final Node attributeNode = node.getAttributes().getNamedItemNS(URI_RDF, "resource");
                final String instrumentID = attributeNode.getNodeValue();

                try {
                    final ItemProxy instrumentProxy = (ItemProxy) repositories.item().findById(instrumentID);
                    rigBean.getContentList().add(resolveInstrument(instrumentProxy));
                } catch (final EscidocClientException e) {
                    LOG.error(e.getLocalizedMessage());
                }//w  w w  .ja v a  2s  .  com
            }
        }
    }
    return rigBean;
}

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

private void evaluateDiff(Node node, int depth, boolean parentIsTextContainer, GenericEditOp op) {
    String indent = null;/*from w ww.  j  av  a2s  .c o  m*/

    Edit e = null;
    GenericEditOp childOp = op;
    boolean isTextContainer = false;
    boolean descend = true;

    String localName = node.getLocalName();
    if (localName == null) {
        e = handleXmlText(node, op, parentIsTextContainer, indent);
    } else {
        String namespaceURI = node.getNamespaceURI();

        if (Wom3Node.WOM_NS_URI.equals(namespaceURI) || AstToWomConverter.MWW_NS_URI.equals(namespaceURI)) {
            if ((op == null) || (op == GenericEditOp.NONE))
                xyDiffConfusesMe();

            e = new Edit(op, localName, null);

            isTextContainer = ("text".equals(localName) || "rtd".equals(localName));
        } else if ("urn:schemas-xydiff:xydelta".equals(namespaceURI)) {
            if (op != null && op != GenericEditOp.NONE)
                xyDiffConfusesMe();

            if ("unit_delta".equals(localName) || "t".equals(localName)) {
                // Don't know what that means...
            } else if ("d".equals(localName)) {
                Node namedItem = node.getAttributes().getNamedItem("move");
                if (namedItem != null && "yes".equalsIgnoreCase(namedItem.getNodeValue())) {
                    // We only count moves on insert, not delete
                } else {
                    childOp = GenericEditOp.DEL;
                }
            } else if ("i".equals(localName)) {
                Node namedItem = node.getAttributes().getNamedItem("move");
                if (namedItem != null && "yes".equalsIgnoreCase(namedItem.getNodeValue())) {
                    childOp = GenericEditOp.MOV;
                    e = new Edit(GenericEditOp.MOV, "#move", null);
                } else {
                    childOp = GenericEditOp.INS;
                }
            } else if ("au".equals(localName) || "ai".equals(localName) || "ad".equals(localName)) {
                // We ignore attribute update/insert/delete
            } else if ("u".equals(localName)) {
                e = evaluateUpdate(node);
                descend = false;
            } else {
                xyDiffConfusesMe();
            }
        } else {
            xyDiffConfusesMe();
        }
    }

    // Insert/move/update top-down
    if ((e != null) && (e.op != GenericEditOp.DEL))
        editScriptAnalysis.add(e);

    if (descend) {
        NodeList children = node.getChildNodes();
        int len = children.getLength();
        for (int i = 0; i < len; ++i) {
            Node child = children.item(i);
            evaluateDiff(child, depth + 1, isTextContainer, childOp);
        }
    }

    // Delete bottom-up
    if ((e != null) && (e.op == GenericEditOp.DEL))
        editScriptAnalysis.add(e);
}

From source file:net.sf.jaceko.mock.model.webservice.WebserviceOperation.java

private void validateNameSpace() {
    Node rootElement;
    try {//  www  .  j  ava  2  s .c om
        rootElement = SOAPMessageParser.getRequestMessageNode(request);
    } catch (ClientFaultException e) {
        LOG.debug("Message was not SOAP message, won't validate.");
        return;
    }

    if (getNameSpaces() == null || getNameSpaces().length == 0) {
        LOG.debug("Nothing to validate...");
        return;
    }
    if (rootElement.getNamespaceURI() == null || rootElement.getNamespaceURI().isEmpty()) {
        throw new ClientFaultException(MISSING_NAMESPACE);
    }

    boolean match = false;
    for (String namespace : getNameSpaces()) {
        if (rootElement.getNamespaceURI().equals(namespace))
            match = true;
    }

    if (!match)
        throw new ClientFaultException(INVALID_NAMESPACE);
}