List of usage examples for org.w3c.dom Element getElementsByTagNameNS
public NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException;
NodeList
of all the descendant Elements
with a given local name and namespace URI in document order. From source file:edu.harvard.i2b2.eclipse.plugins.query.utils.XmlUtil.java
public static String getName(XmlValueType xml) { String name = null;//from ww w . j a v a 2 s .com Element rootElement = xml.getAny().get(0); NodeList nameElements = rootElement.getElementsByTagName("name"); // Group templates dont have tag 'name' if (nameElements.getLength() == 0) { nameElements = rootElement.getElementsByTagNameNS("*", "panel"); if (nameElements.getLength() == 0) { nameElements = rootElement.getElementsByTagName("query_name"); if (nameElements.getLength() == 0) { // if we get to here and no name has been found then its a PDO. // return generically -- change to obs or event etc one level up. return "PDO"; } else { name = nameElements.item(0).getTextContent(); } } else { name = nameElements.item(0).getAttributes().getNamedItem("name").getNodeValue(); } if (name != null) return name; // Default to ABC if we cant find a name at all. else return "ABC";//+MessageUtil.getInstance().getTimestamp(); } // append result_instance_id to PATIENT_COUNT_XML <name> to create unique name else if ((nameElements.item(0).getTextContent().equals("PATIENT_COUNT_XML"))) { NodeList resultElements = rootElement.getElementsByTagName("result_instance_id"); if (resultElements.getLength() > 0) { String resultInstanceId = resultElements.item(0).getTextContent(); return nameElements.item(0).getTextContent() + "_" + resultInstanceId; } } else if ((nameElements.item(0).getTextContent().equals("PATIENTSET")) || (nameElements.item(0).getTextContent().equals("PATIENT_ENCOUNTER_SET")) || (nameElements.item(0).getTextContent().equals("PATIENT_GENDER_COUNT_XML")) || (nameElements.item(0).getTextContent().equals("PATIENT_AGE_COUNT_XML")) || (nameElements.item(0).getTextContent().equals("PATIENT_VITALSTATUS_COUNT_XML")) || (nameElements.item(0).getTextContent().equals("PATIENT_RACE_COUNT_XML"))) { NodeList resultElements = rootElement.getElementsByTagName("description"); if (resultElements.getLength() > 0) { return resultElements.item(0).getTextContent(); } } return nameElements.item(0).getTextContent(); }
From source file:gov.nist.healthcare.ttt.parsing.Parsing.java
private static boolean isSoapValidDirectAddressBlock(String soap) { Envelope env = (Envelope) JAXB.unmarshal(new StringReader(soap), Envelope.class); List<Object> headers = env.getHeader().getAny(); if (headers == null) { return false; }//from w w w .j ava 2 s. c om Iterator it = headers.iterator(); boolean foundDirectAddressBlock = false; while (it.hasNext()) { Element header = (Element) it.next(); if (header.getLocalName().equals(ELEMENT_NAME_DIRECT_ADDRESS_BLOCK) && header.getNamespaceURI().equals(NAMESPACE_DIRECT)) { foundDirectAddressBlock = true; NodeList directFrom = header.getElementsByTagNameNS(NAMESPACE_DIRECT, ELEMENT_NAME_DIRECT_FROM); NodeList directTo = header.getElementsByTagNameNS(NAMESPACE_DIRECT, ELEMENT_NAME_DIRECT_TO); if (directFrom.getLength() > 0 && directTo.getLength() > 0) { return true; } else { return false; } } } return false; }
From source file:gov.nist.healthcare.ttt.parsing.Parsing.java
public static DirectAddressing getDirectAddressing(String mtom) throws MessagingException, IOException { SOAPWithAttachment swa = Parsing.parseMtom(mtom); DirectAddressing directAddressing = new DirectAddressing(); Envelope env = (Envelope) JAXB.unmarshal(new StringReader(swa.getSoap()), Envelope.class); List<Object> headers = env.getHeader().getAny(); if (headers == null) { return directAddressing; }/*from w w w . j a v a 2 s . com*/ Iterator it = headers.iterator(); boolean foundDirectAddressBlock = false; while (it.hasNext()) { Element header = (Element) it.next(); if (header.getLocalName().equals(ELEMENT_NAME_DIRECT_ADDRESS_BLOCK) && header.getNamespaceURI().equals(NAMESPACE_DIRECT)) { foundDirectAddressBlock = true; NodeList directFrom = header.getElementsByTagNameNS(NAMESPACE_DIRECT, ELEMENT_NAME_DIRECT_FROM); NodeList directTo = header.getElementsByTagNameNS(NAMESPACE_DIRECT, ELEMENT_NAME_DIRECT_TO); directAddressing.setDirectFrom(directFrom.item(0).getFirstChild().getNodeValue()); directAddressing.setDirectTo(directTo.item(0).getFirstChild().getNodeValue()); } else if (header.getLocalName().equals(ELEMENT_NAME_WSA_MESSAGEID) && header.getNamespaceURI().equals(NAMESPACE_WSA)) { directAddressing.setMessageID(header.getFirstChild().getNodeValue()); } } return directAddressing; }
From source file:be.fedict.eid.dss.spi.utils.XAdESUtils.java
/** * Finds a XAdES named unsigned signature property as DOM element. * <p/>/*w w w .j ava2 s.c o m*/ * Working DOM based is required if you want to be able to find the next * sibling at the DOM level. JAXB does not expose this properly. * * @param qualifyingPropertiesElement * the XAdES qualifying properties DOM element. * @param localName * @return * @throws XAdESValidationException */ public static Element findUnsignedSignaturePropertyElement(Element qualifyingPropertiesElement, String localName) throws XAdESValidationException { NodeList unsignedSignaturePropertiesNodeList = qualifyingPropertiesElement .getElementsByTagNameNS(XAdESUtils.XADES_132_NS_URI, "UnsignedSignatureProperties"); if (unsignedSignaturePropertiesNodeList.getLength() == 0) { throw new XAdESValidationException("UnsignedSignatureProperties node not present"); } Node unsignedSignaturePropertiesNode = unsignedSignaturePropertiesNodeList.item(0); NodeList childNodes = unsignedSignaturePropertiesNode.getChildNodes(); int childNodesCount = childNodes.getLength(); for (int idx = 0; idx < childNodesCount; idx++) { Node childNode = childNodes.item(idx); if (Node.ELEMENT_NODE != childNode.getNodeType()) { continue; } Element childElement = (Element) childNode; if (!XAdESUtils.XADES_132_NS_URI.equals(childNode.getNamespaceURI())) { continue; } String actualLocalName = childNode.getLocalName(); if (localName.equals(actualLocalName)) { return childElement; } } return null; }
From source file:edu.indiana.lib.twinpeaks.util.DomUtils.java
/** * Return a list of specified namespace:Elements * @param namespace Namespace URI/* w ww.j a v a 2 s .co m*/ * @param element the containing Element * @param name the tag name * @return NodeList of matching elements */ public static NodeList getElementListNS(String namespace, Element element, String name) { return element.getElementsByTagNameNS(namespace, name); }
From source file:eu.elf.license.LicenseParser.java
/** * Parses a list of active licenses from GetLicenseReferences response string * /*from w w w .j av a2 s . c o m*/ * @param xml - xml response * @return - ArrayList of license identifiers that are active * @throws Exception */ public static ArrayList<String> parseActiveLicensesFromGetLicenseReferencesResponse(String xml) throws Exception { ArrayList<String> activeLicenses = new ArrayList<String>(); try { Document xmlDoc = createXMLDocumentFromString(xml); NodeList licenseReferenceList = xmlDoc.getElementsByTagNameNS("http://www.52north.org/license/0.3.2", "LicenseReference"); for (int i = 0; i < licenseReferenceList.getLength(); i++) { Element licenseReferenceElement = (Element) licenseReferenceList.item(i); NodeList attributeElementList = licenseReferenceElement .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Attribute"); for (int j = 0; j < attributeElementList.getLength(); j++) { Element attributeElement = (Element) attributeElementList.item(j); Element attributeValueElement = (Element) attributeElement .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "AttributeValue") .item(0); NamedNodeMap attributeMap = attributeElement.getAttributes(); for (int k = 0; k < attributeMap.getLength(); k++) { Attr attrs = (Attr) attributeMap.item(k); if (attrs.getNodeName().equals("Name")) { if (attrs.getNodeValue().equals("urn:opengeospatial:ows4:geodrm:LicenseID")) { activeLicenses.add(attributeValueElement.getTextContent()); } } } } } } catch (Exception e) { throw e; } return activeLicenses; }
From source file:eu.elf.license.LicenseParser.java
/** * Creates LicenseConcludeResponseObject from the concludeLicense operation's response string * //from w ww.java2 s . c o m * @param response * @return * @throws Exception */ public static LicenseConcludeResponseObject parseConcludeLicenseResponse(String response) throws Exception { LicenseConcludeResponseObject lcro = new LicenseConcludeResponseObject(); try { Document xmlDoc = LicenseParser.createXMLDocumentFromString(response); NodeList LicenseReferenceNL = xmlDoc.getElementsByTagNameNS("http://www.52north.org/license/0.3.2", "LicenseReference"); for (int i = 0; i < LicenseReferenceNL.getLength(); i++) { Element attributeStatementElement = (Element) LicenseReferenceNL.item(i); NodeList attributeElementList = attributeStatementElement .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Attribute"); for (int j = 0; j < attributeElementList.getLength(); j++) { Element attributeElement = (Element) attributeElementList.item(j); Element AttributeValueElement = (Element) attributeElement .getElementsByTagName("AttributeValue").item(0); NamedNodeMap licenseReferenceElementAttributeMap = attributeElement.getAttributes(); for (int k = 0; k < licenseReferenceElementAttributeMap.getLength(); k++) { Attr attrs = (Attr) licenseReferenceElementAttributeMap.item(k); if (attrs.getNodeName().equals("Name")) { if (attrs.getNodeValue().equals("urn:opengeospatial:ows4:geodrm:NotOnOrAfter")) { lcro.setValidTo(AttributeValueElement.getTextContent()); } if (attrs.getNodeValue().equals("urn:opengeospatial:ows4:geodrm:ProductID")) { lcro.setProductId(AttributeValueElement.getTextContent()); } if (attrs.getNodeValue().equals("urn:opengeospatial:ows4:geodrm:LicenseID")) { lcro.setLicenseId(AttributeValueElement.getTextContent()); } } } } } } catch (Exception e) { throw e; } return lcro; }
From source file:org.brekka.stillingar.spring.config.ConfigurationServiceBeanDefinitionParser.java
protected static List<Element> selectChildElements(Element element, String tagName) { NodeList children = element.getElementsByTagNameNS("*", tagName); List<Element> elementList = new ArrayList<Element>(children.getLength()); for (int i = 0; i < children.getLength(); i++) { Node item = children.item(i); if (item instanceof Element) { elementList.add((Element) item); } else {//from w w w . j a va 2 s.co m throw new IllegalArgumentException(String.format( "The child node '%s' of element '%s' at index %d is not an instance of Element, " + "it is instead '%s'", tagName, element.getTagName(), i, item.getClass().getName())); } } return elementList; }
From source file:be.fedict.eid.dss.spi.utils.XAdESSigAndRefsTimeStampValidation.java
public static List<TimeStampToken> verify(XAdESTimeStampType sigAndRefsTimeStamp, Element signatureElement) throws XAdESValidationException { LOG.debug("validate SigAndRefsTimeStamp..."); List<TimeStampToken> timeStampTokens = XAdESUtils.getTimeStampTokens(sigAndRefsTimeStamp); if (timeStampTokens.isEmpty()) { LOG.error("No timestamp tokens present in SigAndRefsTimeStamp"); throw new XAdESValidationException("No timestamp tokens present in SigAndRefsTimeStamp"); }/* w ww .j a va 2 s .c o m*/ TimeStampDigestInput digestInput = new TimeStampDigestInput( sigAndRefsTimeStamp.getCanonicalizationMethod().getAlgorithm()); /* * 2. check ds:SignatureValue present 3. take ds:SignatureValue, * cannonicalize and concatenate bytes. */ NodeList signatureValueNodeList = signatureElement.getElementsByTagNameNS(XMLSignature.XMLNS, "SignatureValue"); if (0 == signatureValueNodeList.getLength()) { LOG.error("no XML signature valuefound"); throw new XAdESValidationException("no XML signature valuefound"); } digestInput.addNode(signatureValueNodeList.item(0)); /* * 4. check SignatureTimeStamp(s), CompleteCertificateRefs, * CompleteRevocationRefs, AttributeCertificateRefs, * AttributeRevocationRefs 5. canonicalize these and concatenate to * bytestream from step 3 These nodes should be added in their order of * appearance. */ NodeList unsignedSignaturePropertiesNodeList = signatureElement .getElementsByTagNameNS(XAdESUtils.XADES_132_NS_URI, "UnsignedSignatureProperties"); if (unsignedSignaturePropertiesNodeList.getLength() == 0) { throw new XAdESValidationException("UnsignedSignatureProperties node not present"); } Node unsignedSignaturePropertiesNode = unsignedSignaturePropertiesNodeList.item(0); NodeList childNodes = unsignedSignaturePropertiesNode.getChildNodes(); int childNodesCount = childNodes.getLength(); for (int idx = 0; idx < childNodesCount; idx++) { Node childNode = childNodes.item(idx); if (Node.ELEMENT_NODE != childNode.getNodeType()) { continue; } if (!XAdESUtils.XADES_132_NS_URI.equals(childNode.getNamespaceURI())) { continue; } String localName = childNode.getLocalName(); if ("SignatureTimeStamp".equals(localName)) { digestInput.addNode(childNode); continue; } if ("CompleteCertificateRefs".equals(localName)) { digestInput.addNode(childNode); continue; } if ("CompleteRevocationRefs".equals(localName)) { digestInput.addNode(childNode); continue; } if ("AttributeCertificateRefs".equals(localName)) { digestInput.addNode(childNode); continue; } if ("AttributeRevocationRefs".equals(localName)) { digestInput.addNode(childNode); continue; } } for (TimeStampToken timeStampToken : timeStampTokens) { // 1. verify signature in timestamp token XAdESUtils.verifyTimeStampTokenSignature(timeStampToken); // 6. compute digest and compare with token XAdESUtils.verifyTimeStampTokenDigest(timeStampToken, digestInput); } return timeStampTokens; }
From source file:edu.indiana.lib.twinpeaks.util.DomUtils.java
/** * Return a list of named Elements with a specific attribute * value (namespace aware)//from w ww . j a v a2 s .co m * * @param namespace Namespace URI * @param element the containing Element * @param name the tag name * @param attribute Attribute name * @param value Attribute value * @param returnFirst Return only the first matching value? * @return List of matching elements */ public static List selectElementsByAttributeValueNS(String namespace, Element element, String name, String attribute, String value, boolean returnFirst) { NodeList elementList = element.getElementsByTagNameNS(namespace, name); List resultList = new ArrayList(); for (int i = 0; i < elementList.getLength(); i++) { if (getAttribute((Element) elementList.item(i), attribute).equals(value)) { resultList.add(elementList.item(i)); if (returnFirst) { break; } } } return resultList; }