List of usage examples for org.w3c.dom NamedNodeMap getNamedItemNS
public Node getNamedItemNS(String namespaceURI, String localName) throws DOMException;
From source file:Main.java
/** * Allows to retrieve the UUID of the node. * @param node node to be modified.// ww w . j a v a2s .co m * @return the UUID of the node. */ public static String getNodeId(Node node) { String nodeId = null; NamedNodeMap nnm = node.getAttributes(); if (nnm != null) { Attr a = (Attr) nnm.getNamedItemNS(CEFX_NAMESPACE, CEFXUID); if (a == null) { String name = CEFXUID; a = (Attr) nnm.getNamedItem(name); } if (a != null) { nodeId = a.getNodeValue(); } } return nodeId; }
From source file:Main.java
/** * Gets attribute value of a node.//from ww w . j av a 2s. co m * * @param node * a node * @param namespaceURI * attribute namespace URI * @param attrName * attribute name * @return attribute value */ public static String getNodeAttributeValueNS(Node node, String namespaceURI, String attrName) { NamedNodeMap attrs = node.getAttributes(); if (attrs == null) { return null; } Node value = attrs.getNamedItemNS(namespaceURI, attrName); if (value == null) { return null; } return value.getNodeValue(); }
From source file:Main.java
public static Node getNamedItemNS(final NamedNodeMap nodeMap, final String namespaceURI, final String localName) { return nodeMap == null ? null : nodeMap.getNamedItemNS(namespaceURI, localName); }
From source file:Main.java
static boolean canBeMerged(Node node1, Node node2, String requiredTagName) { if (node1.getNodeType() != Node.ELEMENT_NODE || node2.getNodeType() != Node.ELEMENT_NODE) return false; Element element1 = (Element) node1; Element element2 = (Element) node2; if (!equals(requiredTagName, element1.getTagName()) || !equals(requiredTagName, element2.getTagName())) return false; NamedNodeMap attributes1 = element1.getAttributes(); NamedNodeMap attributes2 = element2.getAttributes(); if (attributes1.getLength() != attributes2.getLength()) return false; for (int i = 0; i < attributes1.getLength(); i++) { final Attr attr1 = (Attr) attributes1.item(i); final Attr attr2; if (isNotEmpty(attr1.getNamespaceURI())) attr2 = (Attr) attributes2.getNamedItemNS(attr1.getNamespaceURI(), attr1.getLocalName()); else/* www . j ava 2 s . com*/ attr2 = (Attr) attributes2.getNamedItem(attr1.getName()); if (attr2 == null || !equals(attr1.getTextContent(), attr2.getTextContent())) return false; } return true; }
From source file:org.eclipse.lyo.testsuite.oslcv2.OAuthTests.java
public static Collection<Object[]> getReferencedUrls(ArrayList<Node> capabilityDOMNodesUsingXML, String base) throws IOException, XPathException, ParserConfigurationException, SAXException { //ArrayList to contain the urls from all SPCs Collection<Object[]> data = new ArrayList<Object[]>(); String requestTokenUri = ""; String authorizationUri = ""; String accessTokenUri = ""; for (Node node : capabilityDOMNodesUsingXML) { NodeList oAuthChildren = node.getChildNodes(); requestTokenUri = null;/* w ww . ja va2 s . co m*/ authorizationUri = null; accessTokenUri = null; for (int j = 0; j < oAuthChildren.getLength(); j++) { Node oAuthNode = oAuthChildren.item(j); if (oAuthNode.getLocalName() == null) continue; NamedNodeMap attribs = oAuthNode.getAttributes(); if (oAuthNode.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) { if (oAuthNode.getLocalName().equals("oauthRequestTokenURI")) { requestTokenUri = attribs.getNamedItemNS(OSLCConstants.RDF, "resource").getNodeValue(); } else if (oAuthNode.getLocalName().equals("authorizationURI")) { authorizationUri = attribs.getNamedItemNS(OSLCConstants.RDF, "resource").getNodeValue(); } else if (oAuthNode.getLocalName().equals("oauthAccessTokenURI")) { accessTokenUri = attribs.getNamedItemNS(OSLCConstants.RDF, "resource").getNodeValue(); } } } if (requestTokenUri != null && authorizationUri != null && accessTokenUri != null) data.add(new Object[] { base, requestTokenUri, authorizationUri, accessTokenUri }); } // If service provider didn't provide OAuth parameters, see if they // were provided in test configuration parameters. if (data.isEmpty()) { requestTokenUri = setupProps.getProperty("OAuthRequestTokenUrl"); authorizationUri = setupProps.getProperty("OAuthAuthorizationUrl"); accessTokenUri = setupProps.getProperty("OAuthAccessTokenUrl"); if (requestTokenUri != null && authorizationUri != null && accessTokenUri != null) data.add(new Object[] { base, requestTokenUri, authorizationUri, accessTokenUri }); } return data; }
From source file:DOMUtils.java
public static void compareNodes(Node expected, Node actual) throws Exception { if (expected.getNodeType() != actual.getNodeType()) { throw new Exception("Different types of nodes: " + expected + " " + actual); }// w ww. j a va 2 s. com if (expected instanceof Document) { Document expectedDoc = (Document) expected; Document actualDoc = (Document) actual; compareNodes(expectedDoc.getDocumentElement(), actualDoc.getDocumentElement()); } else if (expected instanceof Element) { Element expectedElement = (Element) expected; Element actualElement = (Element) actual; // compare element names if (!expectedElement.getLocalName().equals(actualElement.getLocalName())) { throw new Exception("Element names do not match: " + expectedElement.getLocalName() + " " + actualElement.getLocalName()); } // compare element ns String expectedNS = expectedElement.getNamespaceURI(); String actualNS = actualElement.getNamespaceURI(); if ((expectedNS == null && actualNS != null) || (expectedNS != null && !expectedNS.equals(actualNS))) { throw new Exception("Element namespaces names do not match: " + expectedNS + " " + actualNS); } String elementName = "{" + expectedElement.getNamespaceURI() + "}" + actualElement.getLocalName(); // compare attributes NamedNodeMap expectedAttrs = expectedElement.getAttributes(); NamedNodeMap actualAttrs = actualElement.getAttributes(); if (countNonNamespaceAttribures(expectedAttrs) != countNonNamespaceAttribures(actualAttrs)) { throw new Exception(elementName + ": Number of attributes do not match up: " + countNonNamespaceAttribures(expectedAttrs) + " " + countNonNamespaceAttribures(actualAttrs)); } for (int i = 0; i < expectedAttrs.getLength(); i++) { Attr expectedAttr = (Attr) expectedAttrs.item(i); if (expectedAttr.getName().startsWith("xmlns")) { continue; } Attr actualAttr = null; if (expectedAttr.getNamespaceURI() == null) { actualAttr = (Attr) actualAttrs.getNamedItem(expectedAttr.getName()); } else { actualAttr = (Attr) actualAttrs.getNamedItemNS(expectedAttr.getNamespaceURI(), expectedAttr.getLocalName()); } if (actualAttr == null) { throw new Exception(elementName + ": No attribute found:" + expectedAttr); } if (!expectedAttr.getValue().equals(actualAttr.getValue())) { throw new Exception(elementName + ": Attribute values do not match: " + expectedAttr.getValue() + " " + actualAttr.getValue()); } } // compare children NodeList expectedChildren = expectedElement.getChildNodes(); NodeList actualChildren = actualElement.getChildNodes(); if (expectedChildren.getLength() != actualChildren.getLength()) { throw new Exception(elementName + ": Number of children do not match up: " + expectedChildren.getLength() + " " + actualChildren.getLength()); } for (int i = 0; i < expectedChildren.getLength(); i++) { Node expectedChild = expectedChildren.item(i); Node actualChild = actualChildren.item(i); compareNodes(expectedChild, actualChild); } } else if (expected instanceof Text) { String expectedData = ((Text) expected).getData().trim(); String actualData = ((Text) actual).getData().trim(); if (!expectedData.equals(actualData)) { throw new Exception("Text does not match: " + expectedData + " " + actualData); } } }
From source file:org.apache.sling.launchpad.SmokeIT.java
@Test public void ensureRepositoryIsStarted() throws Exception { try (CloseableHttpClient client = newClient()) { HttpGet get = new HttpGet("http://localhost:" + LAUNCHPAD_PORT + "/server/default/jcr:root"); try (CloseableHttpResponse response = client.execute(get)) { if (response.getStatusLine().getStatusCode() != 200) { fail("Unexpected status line " + response.getStatusLine()); }// w ww. ja v a 2 s. c o m Header contentType = response.getFirstHeader("Content-Type"); assertThat("Content-Type header", contentType.getValue(), equalTo("text/xml")); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse(response.getEntity().getContent()); Element docElement = document.getDocumentElement(); NamedNodeMap attrs = docElement.getAttributes(); Node nameAttr = attrs.getNamedItemNS("http://www.jcp.org/jcr/sv/1.0", "name"); assertThat("no 'name' attribute found", nameAttr, notNullValue()); assertThat("Invalid name attribute value", nameAttr.getNodeValue(), equalTo("jcr:root")); } } }
From source file:com.amalto.core.history.accessor.AttributeAccessor.java
private Node getAttribute() { Node parentNode = parent.getNode(); if (parentNode == null) { throw new IllegalStateException( "Could not find a parent node in document (check if document has a root element)."); //$NON-NLS-1$ }/* w ww . ja v a 2 s. c o m*/ NamedNodeMap attributes = parentNode.getAttributes(); if (attributes == null) { throw new IllegalStateException("Could not find attributes on parent node."); //$NON-NLS-1$ } QName qName = getQName(document.asDOM()); Node attribute = attributes.getNamedItemNS(qName.getNamespaceURI(), qName.getLocalPart()); if (attribute == null) { // Look up with namespace didn't work, falls back to standard getNamedItem attribute = attributes.getNamedItem(qName.getLocalPart()); } return attribute; }
From source file:com.marklogic.client.test.SPARQLManagerTest.java
@Test public void testDescribe() { // verify base has expected effect String relativeConstruct = "DESCRIBE <http://example.org/s1>"; SPARQLQueryDefinition qdef = smgr.newQueryDefinition(relativeConstruct); Document rdf = smgr.executeConstruct(qdef, new DOMHandle()).get(); Node description = rdf.getFirstChild().getFirstChild(); assertNotNull(description.getAttributes()); assertEquals("subject", "http://example.org/s1", description.getAttributes().item(0).getTextContent()); assertNotNull(description.getFirstChild()); assertEquals("predicate", "p1", description.getFirstChild().getNodeName()); assertEquals("predicate namespace", "http://example.org/", description.getFirstChild().getNamespaceURI()); NamedNodeMap attrs = description.getFirstChild().getAttributes(); assertNotNull(attrs);/*from w w w. j a va 2 s . c o m*/ assertNotNull(attrs.getNamedItemNS("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "resource")); assertEquals("object", "http://example.org/o1", attrs.getNamedItemNS("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "resource").getTextContent()); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test//from www.j a va 2s . c om public void testRemoveAttributeByName() throws Exception { SOAPEnvelope envelope = saajUtil.createSOAP11Envelope(); SOAPBody body = envelope.addBody(); SOAPElement element = body.addChildElement(new QName("urn:test", "test")); element.setAttributeNS("urn:ns1", "ns1:attr1", "value"); element.setAttributeNS("urn:ns1", "ns1:attr2", "value"); assertTrue(element.removeAttribute(envelope.createName("attr2", "p", "urn:ns1"))); NamedNodeMap attributes = element.getAttributes(); assertNull(attributes.getNamedItemNS("urn:ns1", "attr2")); }