List of usage examples for org.w3c.dom Element getNamespaceURI
public String getNamespaceURI();
null
if it is unspecified (see ). From source file:org.terracotta.config.TCConfigurationParser.java
@SuppressWarnings("unchecked") private static TcConfiguration parseStream(InputStream in, ErrorHandler eh, String source, ClassLoader loader) throws IOException, SAXException { Collection<Source> schemaSources = new ArrayList<>(); for (ServiceConfigParser parser : loadConfigurationParserClasses(loader)) { schemaSources.add(parser.getXmlSchema()); serviceParsers.put(parser.getNamespace(), parser); }/* w w w . j ava 2s . co m*/ schemaSources.add(new StreamSource(TERRACOTTA_XML_SCHEMA.openStream())); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); factory.setSchema(XSD_SCHEMA_FACTORY.newSchema(schemaSources.toArray(new Source[schemaSources.size()]))); final DocumentBuilder domBuilder; try { domBuilder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new AssertionError(e); } domBuilder.setErrorHandler(eh); final Element config = domBuilder.parse(in).getDocumentElement(); try { JAXBContext jc = JAXBContext.newInstance("org.terracotta.config", TCConfigurationParser.class.getClassLoader()); Unmarshaller u = jc.createUnmarshaller(); TcConfig tcConfig = u.unmarshal(config, TcConfig.class).getValue(); if (tcConfig.getServers() == null) { Servers servers = new Servers(); tcConfig.setServers(servers); } if (tcConfig.getServers().getServer().isEmpty()) { tcConfig.getServers().getServer().add(new Server()); } DefaultSubstitutor.applyDefaults(tcConfig); applyPlatformDefaults(tcConfig, source); Map<String, Map<String, ServiceOverride>> serviceOverrides = new HashMap<>(); for (Server server : tcConfig.getServers().getServer()) { if (server.getServiceOverrides() != null && server.getServiceOverrides().getServiceOverride() != null) { for (ServiceOverride serviceOverride : server.getServiceOverrides().getServiceOverride()) { String id = ((Service) serviceOverride.getOverrides()).getId(); if (serviceOverrides.get(id) == null) { serviceOverrides.put(id, new HashMap<>()); } serviceOverrides.get(id).put(server.getName(), serviceOverride); } } } Map<String, List<ServiceProviderConfiguration>> serviceConfigurations = new HashMap<>(); if (tcConfig.getServices() != null && tcConfig.getServices().getService() != null) { //now parse the service configuration. for (Service service : tcConfig.getServices().getService()) { Element element = service.getAny(); if (element != null) { URI namespace = URI.create(element.getNamespaceURI()); ServiceConfigParser parser = serviceParsers.get(namespace); if (parser == null) { throw new TCConfigurationSetupException("Can't find parser for service " + namespace); } ServiceProviderConfiguration serviceProviderConfiguration = parser.parse(element, source); for (Server server : tcConfig.getServers().getServer()) { if (serviceConfigurations.get(server.getName()) == null) { serviceConfigurations.put(server.getName(), new ArrayList<>()); } if (serviceOverrides.get(service.getId()) != null && serviceOverrides.get(service.getId()).containsKey(server.getName())) { Element overrideElement = serviceOverrides.get(service.getId()) .get(server.getName()).getAny(); if (overrideElement != null) { serviceConfigurations.get(server.getName()) .add(parser.parse(overrideElement, source)); } } else { serviceConfigurations.get(server.getName()).add(serviceProviderConfiguration); } } } } } return new TcConfiguration(tcConfig, source, serviceConfigurations); } catch (JAXBException e) { throw new TCConfigurationSetupException(e); } }
From source file:org.unitedinternet.cosmo.util.DomWriter.java
private static void writeElement(Element e, XMLStreamWriter writer) throws XMLStreamException { //if (log.isDebugEnabled()) //log.debug("Writing element " + e.getNodeName()); String local = e.getLocalName(); if (local == null) { local = e.getNodeName();/*from w ww.j av a 2s .com*/ } String ns = e.getNamespaceURI(); if (ns != null) { String prefix = e.getPrefix(); if (prefix != null) { writer.writeStartElement(prefix, local, ns); writer.writeNamespace(prefix, ns); } else { writer.setDefaultNamespace(ns); writer.writeStartElement(ns, local); writer.writeDefaultNamespace(ns); } } else { writer.writeStartElement(local); } NamedNodeMap attributes = e.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { writeAttribute((Attr) attributes.item(i), writer); } NodeList children = e.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { writeNode(children.item(i), writer); } writer.writeEndElement(); }
From source file:org.warlock.itk.distributionenvelope.Payload.java
/** * Handle signed content after decryption. The content is signed and encrypted * separately, and when a payload is decrypted it may or may not be signed. This * method checks if the payload has been signed: if not it is returned unchanged. * If the content has been signed, the signature is verified before the content * that was signed, is returned./* w w w .j a v a2 s. co m*/ * @param decrypted Decrypted * @return * @throws Exception If the signature verification fails. */ private byte[] checkSignature(byte[] decrypted) throws Exception { String tryXml = null; try { tryXml = new String(decrypted); } catch (Exception e) { return decrypted; } DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document doc = dbf.newDocumentBuilder().parse(new InputSource(new StringReader(tryXml))); Element rootElement = doc.getDocumentElement(); String rname = rootElement.getLocalName(); if ((rname == null) || !rname.contentEquals("Signature")) { return decrypted; } String rns = rootElement.getNamespaceURI(); if ((rns == null) || !rns.contentEquals(CfHNamespaceContext.DSNAMESPACE)) { return decrypted; } // We have a signed payload... Verify as an enveloping signature and return // the Object if the signature verifies OK. // verifySignature(rootElement); return getSignatureObject(rootElement); }
From source file:org.wso2.carbon.bpel.b4p.extension.PeopleActivity.java
private void init(ExtensionContext extensionContext, Element element) throws FaultException { if (!element.getLocalName().equals(BPEL4PeopleConstants.PEOPLE_ACTIVITY) || !element.getNamespaceURI().equals(BPEL4PeopleConstants.B4P_NAMESPACE)) { throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "No " + BPEL4PeopleConstants.PEOPLE_ACTIVITY + " activity found"); }/* ww w . j a v a2s .c o m*/ name = element.getAttribute(BPEL4PeopleConstants.PEOPLE_ACTIVITY_NAME); inputVarName = element.getAttribute(BPEL4PeopleConstants.PEOPLE_ACTIVITY_INPUT_VARIABLE); outputVarName = element.getAttribute(BPEL4PeopleConstants.PEOPLE_ACTIVITY_OUTPUT_VARIABLE); isSkipable = "yes".equalsIgnoreCase(element.getAttribute(BPEL4PeopleConstants.PEOPLE_ACTIVITY_IS_SKIPABLE)); processStandardElement(element); processAttachmentPropagationElement(element); String duDir = extensionContext.getDUDir().toString(); String duVersion = duDir.substring(duDir.lastIndexOf('-') + 1); if (duVersion.endsWith("/")) { duVersion = duVersion.substring(0, duVersion.lastIndexOf("/")); } else if (duVersion.endsWith("\\")) { duVersion = duVersion.substring(0, duVersion.lastIndexOf("\\")); } // //Commenting this logic to fix memory issues. // DeploymentUnitDir du = new DeploymentUnitDir(new File(extensionContext.getDUDir())); // processId = new QName(extensionContext.getProcessModel().getQName().getNamespaceURI(), // extensionContext.getProcessModel().getQName().getLocalPart() + "-" + // du.getStaticVersion()); processId = new QName(extensionContext.getProcessModel().getQName().getNamespaceURI(), extensionContext.getProcessModel().getQName().getLocalPart() + "-" + duVersion); Integer tenantId = B4PServiceComponent.getBPELServer().getMultiTenantProcessStore().getTenantId(processId); DeploymentUnitDir du = B4PServiceComponent.getBPELServer().getMultiTenantProcessStore() .getTenantsProcessStore(tenantId).getDeploymentUnitDir(processId); isTwoWay = activityType.equals(InteractionType.TASK); deriveServiceEPR(du, extensionContext); }
From source file:org.wso2.carbon.bpel.core.ode.integration.BPELProcessProxy.java
/** * Create-and-copy a service-ref element. * * @param elmt Service Reference element * @return wrapped element/*from w ww .j a v a 2 s.c o m*/ */ public static MutableEndpoint createServiceRef(final Element elmt) { Document doc = DOMUtils.newDocument(); QName elQName = new QName(elmt.getNamespaceURI(), elmt.getLocalName()); // If we get a service-ref, just copy it, otherwise make a service-ref // wrapper if (!EndpointReference.SERVICE_REF_QNAME.equals(elQName)) { Element serviceref = doc.createElementNS(EndpointReference.SERVICE_REF_QNAME.getNamespaceURI(), EndpointReference.SERVICE_REF_QNAME.getLocalPart()); serviceref.appendChild(doc.importNode(elmt, true)); doc.appendChild(serviceref); } else { doc.appendChild(doc.importNode(elmt, true)); } return EndpointFactory.createEndpoint(doc.getDocumentElement()); }
From source file:org.wso2.carbon.humantask.core.api.rendering.HTRenderingApiImpl.java
/** * Function to create response message template * * @param SrcWsdl source wsld : wsdl file path or url * @param portType callback port type/* w ww . j av a 2 s.com*/ * @param operation callback operation name * @param binding callback binding * @return DOM element of response message template * @throws IOException If error occurred while parsing string xml to Dom element * @throws SAXException If error occurred while parsing string xml to Dom element */ private static Element createSoapTemplate(String SrcWsdl, String portType, String operation, String binding) throws IOException, SAXException { WSDLParser parser = new WSDLParser(); //BPS-677 int fileLocationPrefixIndex = SrcWsdl.indexOf(HumanTaskConstants.FILE_LOCATION_FILE_PREFIX); if (SrcWsdl.indexOf(HumanTaskConstants.FILE_LOCATION_FILE_PREFIX) != -1) { SrcWsdl = SrcWsdl .substring(fileLocationPrefixIndex + HumanTaskConstants.FILE_LOCATION_FILE_PREFIX.length()); } Definitions wsdl = parser.parse(SrcWsdl); StringWriter writer = new StringWriter(); //SOAPRequestCreator constructor: SOARequestCreator(Definitions, Creator, MarkupBuilder) SOARequestCreator creator = new SOARequestCreator(wsdl, new RequestTemplateCreator(), new MarkupBuilder(writer)); //creator.createRequest(PortType name, Operation name, Binding name); creator.createRequest(portType, operation, binding); Element outGenMessageDom = DOMUtils.stringToDOM(writer.toString()); Element outMsgElement = null; NodeList nodes = outGenMessageDom.getElementsByTagNameNS(outGenMessageDom.getNamespaceURI(), "Body").item(0) .getChildNodes(); if (nodes != null) { for (int i = 0; i < nodes.getLength(); i++) { if (nodes.item(i).getNodeType() == Node.ELEMENT_NODE) { outMsgElement = (Element) nodes.item(i); break; } } } if (outMsgElement != null) { //convert element to string and back to element to remove Owner Document return DOMUtils.stringToDOM(DOMUtils.domToString(outMsgElement)); } return null; }
From source file:org.wso2.carbon.humantask.core.dao.TaskCreationContext.java
/** * Extract the header content related to attachment-ids and create a list from of those attachment-ids * * @return list of attachment-ids//from ww w . ja v a2 s . co m */ public List<String> getAttachmentIDs() { List<String> attachmentIDs = new ArrayList<String>(); final String NAMESPACE = Constants.ATTACHMENT_ID_NAMESPACE; final String NAMESPACE_PREFIX = Constants.ATTACHMENT_ID_NAMESPACE_PREFIX; final String PARENT_ELEMENT_NAME = Constants.ATTACHMENT_ID_PARENT_ELEMENT_NAME; final String CHILD_ELEMENT_NAME = Constants.ATTACHMENT_ID_CHILD_ELEMENT_NAME; Element attachmentElement = this.messageHeaderParts.get(PARENT_ELEMENT_NAME); if (attachmentElement != null && NAMESPACE.equals(attachmentElement.getNamespaceURI())) { NodeList childElementList = attachmentElement.getElementsByTagNameNS(NAMESPACE, CHILD_ELEMENT_NAME); int size = childElementList.getLength(); for (int i = 0; i < size; i++) { Element child = (Element) childElementList.item(i); attachmentIDs.add(child.getTextContent()); } } else { if (log.isDebugEnabled()) { log.debug("No header elements found with :" + PARENT_ELEMENT_NAME); } } return attachmentIDs; }
From source file:org.wso2.carbon.identity.entitlement.EntitlementUtil.java
public static String getPolicyVersion(String policy) { try {//from w w w . j a va2 s .c o m //build XML document DocumentBuilder documentBuilder = getSecuredDocumentBuilder(false); InputStream stream = new ByteArrayInputStream(policy.getBytes()); Document doc = documentBuilder.parse(stream); //get policy version Element policyElement = doc.getDocumentElement(); return policyElement.getNamespaceURI(); } catch (Exception e) { log.debug(e); // ignore exception as default value is used log.warn("Policy version can not be identified. Default XACML 3.0 version is used"); return XACMLConstants.XACML_3_0_IDENTIFIER; } }
From source file:org.wso2.carbon.identity.relyingparty.saml.SAMLTokenVerifier.java
/** * This method performs two actions 1) Decrypt the token 2) Verify the token * //from w w w. j av a 2s. c om * @param decryptedElem SAML token element * @return true if verification is successful and false if unsuccessful. * @throws SAMLException */ public boolean verifyDecryptedToken(Element decryptedElem, RelyingPartyData rpData) throws RelyingPartyException { if (log.isDebugEnabled()) { log.debug("verifyingDecryptedToken"); } if (log.isDebugEnabled()) { try { String val = DOM2Writer.nodeToString(decryptedElem); log.debug(val); FileWriter writer = new FileWriter(new File("last_msg.xml")); writer.write(val.toCharArray()); writer.flush(); writer.close(); } catch (IOException e) { log.error(e.getMessage(), e); } } try { String version = decryptedElem.getNamespaceURI(); TokenHolder holder = null; if (version.equals(IdentityConstants.SAML10_URL) || version.equals(IdentityConstants.SAML11_URL)) { holder = new SAML1TokenHolder(decryptedElem); } else if (version.equals(IdentityConstants.SAML20_URL)) { holder = new SAML2TokenHolder(decryptedElem); } else { throw new RelyingPartyException("invalidTokenType"); } issuerName = holder.getIssuerName(); if (issuerName == null) { throw new RelyingPartyException("issuerIsNull"); } Signature sig = holder.getSAMLSignature(); X509CredentialImpl credential = null; if (issuerName.equals(IdentityConstants.SELF_ISSUED_ISSUER)) { credential = (X509CredentialImpl) X509CredentialUtil.loadCredentialFromSignature(sig); this.keyInfoElement = sig.getKeyInfo().getDOM(); } else { String validationPolicy = rpData.getValidatePolicy(); String alias = null; URI uri = new URI(issuerName); alias = uri.getHost(); KeyStore trustStore = rpData.getTrustStore(); KeyStore systemStore = rpData.getSystemStore(); if (trustStore != null && alias != null) { credential = (X509CredentialImpl) X509CredentialUtil.loadCredentialFromTrustStore(alias, trustStore); } boolean isLoadedFromMessage = false; if (credential == null) { credential = (X509CredentialImpl) X509CredentialUtil.loadCredentialFromSignature(sig); if (credential == null) throw new RelyingPartyException("credentialIsNull"); isLoadedFromMessage = true; } if (!validationPolicy.equals(TokenVerifierConstants.PROMISCUOUS)) { this.signingCert = credential.getSigningCert(); if (signingCert == null) throw new RelyingPartyException("signingCertNull"); /* * do certificate validation for blacklist, whitelist and cert-validity */ signingCert.checkValidity(); if (isLoadedFromMessage) { if (!IssuerCertificateUtil.checkSystemStore(signingCert, systemStore) && !IssuerCertificateUtil.checkSystemStore(signingCert, trustStore)) { return false; } } if (validationPolicy.equals(TokenVerifierConstants.BLACK_LIST)) { if (IssuerCertificateUtil.isBlackListed(rpData.getBlackList(), signingCert)) { return false; } } else if (validationPolicy.equals(TokenVerifierConstants.WHITE_LIST)) { if (!IssuerCertificateUtil.isWhiteListed(rpData.getWhiteList(), signingCert)) { return false; } } } } SignatureValidator validator = new SignatureValidator(credential); validator.validate(sig); holder.populateAttributeTable(this.attributeTable); } catch (Exception e) { log.debug(e); throw new RelyingPartyException("errorInTokenVerification", e); } if (log.isDebugEnabled()) { log.debug("verifyingDecryptedTokenDone"); } // everything is fine :D return true; }
From source file:org.wso2.developerstudio.eclipse.esb.impl.ModelObjectImpl.java
/** * {@inheritDoc}/*from www. j a va2 s. c o m*/ */ public void load(Element self) throws Exception { // Extract additional namespaces. Map<String, String> extractedNamespaceEntries = extractNamespaces(self); // Load default namespace info. if (!StringUtils.isBlank(self.getNamespaceURI())) { Namespace defaultNs = getEsbFactory().createNamespace(); defaultNs.setUri(self.getNamespaceURI()); if (!StringUtils.isBlank(self.getPrefix())) { defaultNs.setPrefix(self.getPrefix()); // Additional namespaces should not contain the namespace // corresponding to current element itself. extractedNamespaceEntries.remove(self.getPrefix()); } setDefaultNamespace(defaultNs); } // Store extracted namespaces as additional namespaces. for (Entry<String, String> namespaceEntry : extractedNamespaceEntries.entrySet()) { Namespace extractedNs = getEsbFactory().createNamespace(); extractedNs.setPrefix(namespaceEntry.getKey()); extractedNs.setUri(namespaceEntry.getValue()); getAdditionalNamespaces().add(extractedNs); } doLoad(self); }