List of usage examples for org.w3c.dom Element getNamespaceURI
public String getNamespaceURI();
null
if it is unspecified (see ). From source file:com.verisign.epp.codec.gen.EPPUtil.java
/** * Gets the first direct child element with a given tag name and XML * namespace.// w w w. ja v a2 s.c o m * * @param aNS * XML namespace of the elements. For example, for domain element * this is "urn:iana:xmlns:domain". * @param aTagName * Tag name to scan for. * @return Matching <code>Element</code> if found; <code>null</code> * otherwise. */ public static Element getElementByTagNameNS(Element aElement, String aNS, String aTagName) { Element retElm = null; aTagName = EPPUtil.getLocalName(aTagName); NodeList theNodes = aElement.getChildNodes(); // Found matching nodes? if (theNodes != null) { for (int i = 0; (i < theNodes.getLength()) && retElm == null; i++) { if (theNodes.item(i).getNodeType() == Node.ELEMENT_NODE) { Element currElm = (Element) theNodes.item(i); if (currElm.getNamespaceURI().equals(aNS) && currElm.getLocalName().equals(aTagName)) { retElm = currElm; } } } } return retElm; }
From source file:be.fedict.eid.dss.client.DigitalSignatureServiceClient.java
@SuppressWarnings("unchecked") private VerificationReportType findVerificationReport(ResponseBaseType responseBase) { AnyType optionalOutputs = responseBase.getOptionalOutputs(); if (null == optionalOutputs) { return null; }/* w w w. jav a 2 s .c om*/ List<Object> optionalOutputContent = optionalOutputs.getAny(); for (Object optionalOutput : optionalOutputContent) { if (optionalOutput instanceof Element) { Element optionalOutputElement = (Element) optionalOutput; if (DSSConstants.VR_NAMESPACE.equals(optionalOutputElement.getNamespaceURI()) && "VerificationReport".equals(optionalOutputElement.getLocalName())) { JAXBElement<VerificationReportType> verificationReportElement; try { verificationReportElement = (JAXBElement<VerificationReportType>) this.vrUnmarshaller .unmarshal(optionalOutputElement); } catch (JAXBException e) { throw new RuntimeException("JAXB error parsing verification report: " + e.getMessage(), e); } return verificationReportElement.getValue(); } } } return null; }
From source file:be.fedict.eid.dss.client.DigitalSignatureServiceClient.java
@SuppressWarnings("unchecked") private StorageInfo findStorageInfo(SignResponse signeResponse) { AnyType optionalOutputs = signeResponse.getOptionalOutputs(); if (null == optionalOutputs) { return null; }/*w w w . j a v a 2 s . co m*/ List<Object> optionalOutputContent = optionalOutputs.getAny(); for (Object optionalOutput : optionalOutputContent) { if (optionalOutput instanceof Element) { Element optionalOutputElement = (Element) optionalOutput; if (DSSConstants.ARTIFACT_NAMESPACE.equals(optionalOutputElement.getNamespaceURI()) && "StorageInfo".equals(optionalOutputElement.getLocalName())) { JAXBElement<StorageInfo> storageInfoElement; try { storageInfoElement = (JAXBElement<StorageInfo>) this.artifactUnmarshaller .unmarshal(optionalOutputElement); } catch (JAXBException e) { throw new RuntimeException("JAXB error parsing storage info: " + e.getMessage(), e); } return storageInfoElement.getValue(); } } } return null; }
From source file:com.mirth.connect.model.util.ImportConverter.java
public static Document convertCodeTemplates(String codeTemplatesXML) throws Exception { codeTemplatesXML = convertPackageNames(codeTemplatesXML); codeTemplatesXML = runStringConversions(codeTemplatesXML); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document document;/*w ww . java 2 s. c o m*/ DocumentBuilder builder; builder = factory.newDocumentBuilder(); document = builder.parse(new InputSource(new StringReader(codeTemplatesXML))); NodeList codeTemplates = getElements(document, "codeTemplate", "com.mirth.connect.model.CodeTemplate"); int length = codeTemplates.getLength(); for (int i = 0; i < length; i++) { Element codeTemplate = (Element) codeTemplates.item(i); codeTemplate.getOwnerDocument().renameNode(codeTemplate, codeTemplate.getNamespaceURI(), "codeTemplate"); NodeList versions = codeTemplate.getElementsByTagName("version"); // If there is no version, then this is a migration to 2.0 and the // scope should be incremented by 1 if its value is not currently 0 // (global map). Global Channel Map was added in position 1 for 2.0. if (versions.getLength() == 0) { Element scope = (Element) codeTemplate.getElementsByTagName("scope").item(0); int scopeValue = Integer.parseInt(scope.getTextContent()); if (scopeValue != 0) { scopeValue++; scope.setTextContent(Integer.toString(scopeValue)); } } } return document; }
From source file:org.springjutsu.validation.namespace.ValidationEntityDefinitionParser.java
/** * Do actual parsing.// w ww. j ava2s . c o m * Since rules may be nested, delegate to {@link #parseNestedRules(Element, Class)} * where necessary. */ public BeanDefinition parse(Element entityNode, ParserContext parserContext) { RootBeanDefinition entityDefinition = new RootBeanDefinition(ValidationEntity.class); String className = entityNode.getAttribute("class"); Class<?> modelClass; try { modelClass = Class.forName(className); } catch (ClassNotFoundException cnfe) { throw new ValidationParseException("Class " + className + " does not exist as a model class."); } List<String> excludePaths = new ArrayList<String>(); NodeList excludes = entityNode.getElementsByTagNameNS(entityNode.getNamespaceURI(), "recursion-exclude"); for (int excludeNbr = 0; excludeNbr < excludes.getLength(); excludeNbr++) { Element excludeNode = (Element) excludes.item(excludeNbr); String path = excludeNode.getAttribute("propertyName"); if (path.contains(".")) { throw new ValidationParseException("Invalid recursion-exclude property name \"" + path + "\" Exclude paths should not be nested fields."); } else { excludePaths.add(path); } } List<String> includePaths = new ArrayList<String>(); NodeList includes = entityNode.getElementsByTagNameNS(entityNode.getNamespaceURI(), "recursion-include"); for (int includeNbr = 0; includeNbr < includes.getLength(); includeNbr++) { Element includeNode = (Element) includes.item(includeNbr); String path = includeNode.getAttribute("propertyName"); if (path.contains(".")) { throw new ValidationParseException("Invalid recursion-include property name \"" + path + "\" Include paths should not be nested fields."); } else { includePaths.add(path); } } ValidationStructure validationStructure = parseNestedValidation(entityNode, modelClass); List<ValidationTemplate> templates = new ArrayList<ValidationTemplate>(); NodeList templateNodes = entityNode.getElementsByTagNameNS(entityNode.getNamespaceURI(), "template"); for (int templateNbr = 0; templateNbr < templateNodes.getLength(); templateNbr++) { Element templateNode = (Element) templateNodes.item(templateNbr); String templateName = templateNode.getAttribute("name"); ValidationStructure templateValidation = parseNestedValidation(templateNode, modelClass); ValidationTemplate template = new ValidationTemplate(templateName, modelClass); template.setRules(templateValidation.rules); template.setTemplateReferences(templateValidation.refs); template.setValidationContexts(templateValidation.contexts); templates.add(template); } entityDefinition.getPropertyValues().add("rules", validationStructure.rules); entityDefinition.getPropertyValues().add("templateReferences", validationStructure.refs); entityDefinition.getPropertyValues().add("validationContexts", validationStructure.contexts); entityDefinition.getPropertyValues().add("validationTemplates", templates); entityDefinition.getPropertyValues().add("validationClass", modelClass); entityDefinition.getPropertyValues().add("includedPaths", includePaths); entityDefinition.getPropertyValues().add("excludedPaths", excludePaths); String entityName = parserContext.getReaderContext().registerWithGeneratedName(entityDefinition); parserContext.registerComponent(new BeanComponentDefinition(entityDefinition, entityName)); return null; }
From source file:com.streamsets.pipeline.stage.processor.xmlflattener.XMLFlatteningProcessor.java
private void addAttrs(Record record, Element element, String elementPrefix) { if (!ignoreAttrs) { NamedNodeMap attrs = element.getAttributes(); for (int j = 0; j < attrs.getLength(); j++) { Node attr = attrs.item(j); String attrName = attr.getNodeName(); if (attrName.equals("xmlns")) { //handled separately. continue; }/*w w w. j a va 2 s. co m*/ record.set(getPathPrefix() + elementPrefix + attrDelimiter + attr.getNodeName(), Field.create(attr.getNodeValue())); } } if (!ignoreNamespace) { String namespaceURI = element.getNamespaceURI(); if (namespaceURI != null) { record.set(getPathPrefix() + elementPrefix + attrDelimiter + "xmlns", Field.create(namespaceURI)); } } }
From source file:eu.europa.esig.dss.xades.validation.XAdESSignatureScopeFinder.java
@Override public List<SignatureScope> findSignatureScope(final XAdESSignature xadesSignature) { final List<SignatureScope> result = new ArrayList<SignatureScope>(); final Set<Element> unsignedObjects = new HashSet<Element>(); unsignedObjects.addAll(xadesSignature.getSignatureObjects()); final Set<Element> signedObjects = new HashSet<Element>(); final List<Element> signatureReferences = xadesSignature.getSignatureReferences(); for (final Element signatureReference : signatureReferences) { final String type = DSSXMLUtils.getValue(signatureReference, "@Type"); if (xadesSignature.getXPathQueryHolder().XADES_SIGNED_PROPERTIES.equals(type)) { continue; }//from w w w . ja v a 2 s. c o m final String uri = DSSXMLUtils.getValue(signatureReference, "@URI"); final List<String> transformations = getTransformationNames(signatureReference); if (StringUtils.isBlank(uri)) { // self contained document result.add(new XmlRootSignatureScope(transformations)); } else if (uri.startsWith("#")) { // internal reference final boolean xPointerQuery = XPointerResourceResolver.isXPointerQuery(uri, true); if (xPointerQuery) { final String id = DSSXMLUtils.getIDIdentifier(signatureReference); final XPointerSignatureScope xPointerSignatureScope = new XPointerSignatureScope(id, uri); result.add(xPointerSignatureScope); continue; } final String xmlIdOfSignedElement = uri.substring(1); final String xPathString = XPathQueryHolder.XPATH_OBJECT + "[@Id='" + xmlIdOfSignedElement + "']"; Element signedElement = DSSXMLUtils.getElement(xadesSignature.getSignatureElement(), xPathString); if (signedElement != null) { if (unsignedObjects.remove(signedElement)) { signedObjects.add(signedElement); result.add(new XmlElementSignatureScope(xmlIdOfSignedElement, transformations)); } } else { signedElement = DSSXMLUtils.getElement( xadesSignature.getSignatureElement().getOwnerDocument().getDocumentElement(), "//*" + "[@Id='" + xmlIdOfSignedElement + "']"); if (signedElement != null) { final String namespaceURI = signedElement.getNamespaceURI(); if ((namespaceURI == null) || (!XAdESNamespaces.exists(namespaceURI) && !namespaceURI.equals(XMLSignature.XMLNS))) { signedObjects.add(signedElement); result.add(new XmlElementSignatureScope(xmlIdOfSignedElement, transformations)); } } } } else { // detached file result.add(new FullSignatureScope(uri)); } } return result; }
From source file:org.jmxtrans.embedded.spring.EmbeddedJmxTransBeanDefinitionParser.java
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { builder.setRole(BeanDefinition.ROLE_APPLICATION); builder.getRawBeanDefinition().setSource(parserContext.extractSource(element)); if (element.hasAttribute(IGNORE_CONFIGURATION_NOT_FOUND_ATTRIBUTE)) { builder.addPropertyValue("ignoreConfigurationNotFound", element.getAttribute(IGNORE_CONFIGURATION_NOT_FOUND_ATTRIBUTE)); }/*from w w w . j a va2 s. com*/ List<String> configurationUrls = new ArrayList<String>(); if (element.hasAttribute(CONFIGURATION_ATTRIBUTE)) { String configurationUrl = element.getAttribute(CONFIGURATION_ATTRIBUTE); logger.debug("Add configuration from attribute {}", configurationUrl); configurationUrls.add(configurationUrl); } NodeList configurationNodeList = element.getElementsByTagNameNS(element.getNamespaceURI(), CONFIGURATION_ATTRIBUTE); for (int i = 0; i < configurationNodeList.getLength(); i++) { Node node = configurationNodeList.item(i); if (node instanceof Element) { String configurationUrl = node.getTextContent(); logger.debug("Add configuration from attribute {}", configurationUrl); configurationUrls.add(configurationUrl); } else { throw new EmbeddedJmxTransException("Invalid configuration child element " + node); } } builder.addPropertyValue("configurationUrls", configurationUrls); }
From source file:io.hummer.util.ws.WebServiceClient.java
private SOAPMessage createSOAPMessage(Element request, List<Element> headers, String protocol) throws Exception { MessageFactory mf = MessageFactory.newInstance(protocol); SOAPMessage message = mf.createMessage(); SOAPBody body = message.getSOAPBody(); // check if we have a complete soap:Envelope as request.. String ns = request.getNamespaceURI(); if (request.getTagName().contains("Envelope")) { if (ns.equals("http://schemas.xmlsoap.org/soap/envelope/")) message = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL).createMessage( new MimeHeaders(), new ByteArrayInputStream(xmlUtil.toString(request).getBytes())); if (ns.equals("http://www.w3.org/2003/05/soap-envelope")) message = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage( new MimeHeaders(), new ByteArrayInputStream(xmlUtil.toString(request).getBytes())); } else {/* ww w .ja v a2 s . c o m*/ xmlUtil.appendChild(body, request); } for (Element h : headers) { xmlUtil.appendChild(message.getSOAPHeader(), h); } for (Element h : eprParamsAndProps) { xmlUtil.appendChild(message.getSOAPHeader(), h); } xmlUtil.appendChild(message.getSOAPHeader(), xmlUtil.toElement( "<wsa:To xmlns:wsa=\"" + EndpointReference.NS_WS_ADDRESSING + "\">" + endpointURL + "</wsa:To>")); message.saveChanges(); return message; }