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:org.kuali.coeus.s2sgen.impl.generate.support.RRSubAwardBudget5_30V1_2Generator.java
/** * //ww w. jav a2 s . c o m * This method is used to get RRBudget from BudgetSubAwards * * @param budgetSubAwards(BudgetSubAwards) budget sub awards entry. * @return RRBudget corresponding to the BudgetSubAwards object. */ private RRBudgetDocument getRRBudget(BudgetSubAwardsContract budgetSubAwards) { RRBudgetDocument rrBudget = RRBudgetDocument.Factory.newInstance(); String subAwdXML = budgetSubAwards.getSubAwardXmlFileData(); Document subAwdFormsDoc; try { subAwdFormsDoc = stringToDom(subAwdXML); } catch (S2SException e1) { return rrBudget; } Element subAwdFormsElement = subAwdFormsDoc.getDocumentElement(); NodeList subAwdNodeList = subAwdFormsElement.getElementsByTagNameNS(RR_BUDGET_11_NAMESPACE_URI, LOCAL_NAME); Node subAwdNode = null; if (subAwdNodeList != null) { if (subAwdNodeList.getLength() == 0) { return null; } subAwdNode = subAwdNodeList.item(0); } byte[] subAwdNodeBytes = null; try { subAwdNodeBytes = docToBytes(nodeToDom(subAwdNode)); InputStream bgtIS = new ByteArrayInputStream(subAwdNodeBytes); rrBudget = (RRBudgetDocument) XmlObject.Factory.parse(bgtIS); } catch (S2SException e) { return rrBudget; } catch (XmlException e) { return rrBudget; } catch (IOException e) { return rrBudget; } return rrBudget; }
From source file:org.kuali.coeus.s2sgen.impl.generate.support.RRSubAwardBudget30_1_3V1_3Generator.java
/** * /*w ww . j a v a2 s. c o m*/ * This method is used to get RRBudget13 from BudgetSubAwards * * @param budgetSubAwards(BudgetSubAwards) budget sub awards entry. * @return RRBudget13 corresponding to the BudgetSubAwards object. */ private RRBudget13Document getRRBudget(BudgetSubAwardsContract budgetSubAwards) { RRBudget13Document rrBudget = RRBudget13Document.Factory.newInstance(); String subAwdXML = budgetSubAwards.getSubAwardXmlFileData(); Document subAwdFormsDoc; try { subAwdFormsDoc = stringToDom(subAwdXML); } catch (S2SException e1) { return rrBudget; } Element subAwdFormsElement = subAwdFormsDoc.getDocumentElement(); NodeList subAwdNodeList = subAwdFormsElement.getElementsByTagNameNS(RR_BUDGET30_13_NAMESPACE_URI, RR_BUDGET30_13_LOCAL_NAME); Node subAwdNode = null; if (subAwdNodeList != null) { if (subAwdNodeList.getLength() == 0) { return null; } subAwdNode = subAwdNodeList.item(0); } byte[] subAwdNodeBytes = null; try { subAwdNodeBytes = docToBytes(nodeToDom(subAwdNode)); InputStream bgtIS = new ByteArrayInputStream(subAwdNodeBytes); rrBudget = (RRBudget13Document) XmlObject.Factory.parse(bgtIS); } catch (S2SException e) { return rrBudget; } catch (XmlException e) { return rrBudget; } catch (IOException e) { return rrBudget; } return rrBudget; }
From source file:org.kuali.coeus.s2sgen.impl.generate.support.RRFedNonFedSubAwardBudget10_30V1_2Generator.java
/** * //from ww w .j a va 2 s. co m * This method is used to get RRFedNonFedBudget from BudgetSubAwards * * @param budgetSubAwards(BudgetSubAwards) budget sub awards entry. * @return RRFedNonFedBudget corresponding to the BudgetSubAwards object. */ private RRFedNonFedBudget10Document getRRFedNonFedBudget(BudgetSubAwardsContract budgetSubAwards) { RRFedNonFedBudget10Document rrBudget = RRFedNonFedBudget10Document.Factory.newInstance(); String subAwdXML = budgetSubAwards.getSubAwardXmlFileData(); Document subAwdFormsDoc; try { subAwdFormsDoc = stringToDom(subAwdXML); } catch (S2SException e1) { return rrBudget; } Element subAwdFormsElement = subAwdFormsDoc.getDocumentElement(); NodeList subAwdNodeList = subAwdFormsElement .getElementsByTagNameNS(RR_FED_NON_FED_BUDGET1030_11_NAMESPACE_URI, LOCAL_FED_NON_FED_NAME); Node subAwdNode = null; if (subAwdNodeList != null) { if (subAwdNodeList.getLength() == 0) { return null; } subAwdNode = subAwdNodeList.item(0); } byte[] subAwdNodeBytes = null; try { subAwdNodeBytes = docToBytes(nodeToDom(subAwdNode)); InputStream bgtIS = new ByteArrayInputStream(subAwdNodeBytes); rrBudget = (RRFedNonFedBudget10Document) XmlObject.Factory.parse(bgtIS); } catch (S2SException e) { return rrBudget; } catch (XmlException e) { return rrBudget; } catch (IOException e) { return rrBudget; } return rrBudget; }
From source file:org.kuali.coeus.s2sgen.impl.generate.support.RRSubAwardBudget10_30_1_3V1_3Generator.java
/** * /*from w w w . j av a 2 s .com*/ * This method is used to get RRBudget from BudgetSubAwards * * @param budgetSubAwards(BudgetSubAwards) budget sub awards entry. * @return RRBudget corresponding to the BudgetSubAwards object. */ private RRBudget1013Document getRRBudget1013(BudgetSubAwardsContract budgetSubAwards) { RRBudget1013Document rrBudget = RRBudget1013Document.Factory.newInstance(); String subAwdXML = budgetSubAwards.getSubAwardXmlFileData(); Document subAwdFormsDoc; try { subAwdFormsDoc = stringToDom(subAwdXML); } catch (S2SException e1) { return rrBudget; } Element subAwdFormsElement = subAwdFormsDoc.getDocumentElement(); NodeList subAwdNodeList = subAwdFormsElement.getElementsByTagNameNS(RR_BUDGET10_13_NAMESPACE_URI, RR_BUDGET10_13_LOCAL_NAME); Node subAwdNode = null; if (subAwdNodeList != null) { if (subAwdNodeList.getLength() == 0) { return null; } subAwdNode = subAwdNodeList.item(0); } byte[] subAwdNodeBytes = null; try { subAwdNodeBytes = docToBytes(nodeToDom(subAwdNode)); InputStream bgtIS = new ByteArrayInputStream(subAwdNodeBytes); rrBudget = (RRBudget1013Document) XmlObject.Factory.parse(bgtIS); } catch (S2SException e) { return rrBudget; } catch (XmlException e) { return rrBudget; } catch (IOException e) { return rrBudget; } return rrBudget; }
From source file:org.kuali.coeus.s2sgen.impl.generate.support.RRFedNonFedSubAwardBudget5_30V1_2Generator.java
/** * /*from w w w . jav a2 s. co m*/ * This method is used to get RRFedNonFedBudget from BudgetSubAwards * * @param budgetSubAwards(BudgetSubAwards) budget sub awards entry. * @return RRFedNonFedBudget corresponding to the BudgetSubAwards object. */ private RRFedNonFedBudgetDocument getRRFedNonFedBudget(BudgetSubAwardsContract budgetSubAwards) { RRFedNonFedBudgetDocument rrBudget = RRFedNonFedBudgetDocument.Factory.newInstance(); String subAwdXML = budgetSubAwards.getSubAwardXmlFileData(); Document subAwdFormsDoc; try { subAwdFormsDoc = stringToDom(subAwdXML); } catch (S2SException e1) { return rrBudget; } Element subAwdFormsElement = subAwdFormsDoc.getDocumentElement(); NodeList subAwdNodeList = subAwdFormsElement .getElementsByTagNameNS(RR_FED_NON_FED_BUDGET30_11_NAMESPACE_URI, LOCAL_FED_NON_FED_NAME); Node subAwdNode = null; if (subAwdNodeList != null) { if (subAwdNodeList.getLength() == 0) { return null; } subAwdNode = subAwdNodeList.item(0); } byte[] subAwdNodeBytes = null; try { subAwdNodeBytes = docToBytes(nodeToDom(subAwdNode)); InputStream bgtIS = new ByteArrayInputStream(subAwdNodeBytes); rrBudget = (RRFedNonFedBudgetDocument) XmlObject.Factory.parse(bgtIS); } catch (S2SException e) { return rrBudget; } catch (XmlException e) { return rrBudget; } catch (IOException e) { return rrBudget; } return rrBudget; }
From source file:com.castlemock.web.mock.soap.model.project.service.CreateSoapPortsService.java
private String getInputMessageName(Element operationElement) { String inputMessageName = null; final NodeList inputNodeList = operationElement.getElementsByTagNameNS(WSDL_NAMESPACE, "input"); for (int inputIndex = 0; inputIndex < inputNodeList.getLength(); inputIndex++) { final Node inputNode = inputNodeList.item(inputIndex); if (inputNode.getNodeType() == Node.ELEMENT_NODE) { final Element inputElement = (Element) inputNode; inputMessageName = getAttribute(inputElement, "name"); }/* w w w . j a va 2 s . c o m*/ } return inputMessageName; }
From source file:eu.elf.license.LicenseParser.java
/** * Creates list of LicenseModel elements * * @param productElementList - NodeList of <ns:product> elements: * @return List of LicenseModel objects/*w w w .j a v a 2 s . c o m*/ */ private static List<LicenseModel> createLicenseModelList(NodeList productElementList) { List<LicenseModel> lmList = new ArrayList<LicenseModel>(); for (int i = 0; i < productElementList.getLength(); i++) { LicenseModel tempLM = new LicenseModel(); Boolean isRestricted = true; Element productElement = (Element) productElementList.item(i); NamedNodeMap productElementAttributeMap = productElement.getAttributes(); for (int j = 0; j < productElementAttributeMap.getLength(); j++) { Attr attrs = (Attr) productElementAttributeMap.item(j); if (attrs.getNodeName().equals("id")) { if (attrs.getNodeName() != null) { tempLM.setId(attrs.getNodeValue()); } } } Element titleElement = (Element) productElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0); if (titleElement != null) { tempLM.setName(titleElement.getTextContent()); } Element abstractElement = (Element) productElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "abstract").item(0); if (abstractElement != null) { tempLM.setDescription(abstractElement.getTextContent()); } Element calculationElement = (Element) productElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "calculation").item(0); Element declarationListElement = (Element) calculationElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "declarationList").item(0); Element predefinedParametersElement = (Element) declarationListElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "predefinedParameters").item(0); NodeList predefinedParametersParameterElementList = predefinedParametersElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "parameter"); for (int k = 0; k < predefinedParametersParameterElementList.getLength(); k++) { Element parameterElement = (Element) predefinedParametersParameterElementList.item(k); NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes(); for (int l = 0; l < parameterElementAttributeMap.getLength(); l++) { Attr attrs = (Attr) parameterElementAttributeMap.item(l); if (attrs.getNodeName().equals("name")) { if (attrs.getNodeName() != null) { if (attrs.getNodeValue().equals("ALL_ROLES")) { Element valueElement = (Element) parameterElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "value").item(0); if (valueElement.getTextContent().equals("true")) { isRestricted = false; } } } } if (attrs.getNodeName().equals("name")) { if (attrs.getNodeName() != null) { if (attrs.getNodeValue().equals("ALLOWED_ROLES")) { NodeList valueElementList = parameterElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "value"); for (int m = 0; m < valueElementList.getLength(); m++) { tempLM.addRole(valueElementList.item(m).getTextContent()); } } } } } } tempLM.setRestricted(isRestricted); tempLM.setParams(createLicenseModelParamList(declarationListElement)); lmList.add(tempLM); } return lmList; }
From source file:com.castlemock.web.mock.soap.model.project.service.CreateSoapPortsService.java
/** * THe method provides the functionality to parse a document and extract all the SOAP ports from the SOAP ports. * The method will also generate mocked responses if the {@code generateResponse} * @param document The document which will be parsed * @param generateResponse Boolean value determining if a response should be generated for each extracted * operation.// w w w . ja va 2s . co m * @return A list of SOAP ports */ private List<SoapPortDto> getSoapPorts(final Document document, final boolean generateResponse) { final List<SoapPortDto> soapPorts = new ArrayList<SoapPortDto>(); final NodeList serviceNodeList = document.getDocumentElement().getElementsByTagNameNS(WSDL_NAMESPACE, "service"); for (int serviceIndex = 0; serviceIndex < serviceNodeList.getLength(); serviceIndex++) { final Node serviceNode = serviceNodeList.item(serviceIndex); if (serviceNode.getNodeType() == Node.ELEMENT_NODE) { final Element serviceElement = (Element) serviceNode; final NodeList portNodeList = serviceElement.getElementsByTagNameNS(WSDL_NAMESPACE, "port"); for (int portIndex = 0; portIndex < portNodeList.getLength(); portIndex++) { Node portNode = portNodeList.item(portIndex); if (portNode.getNodeType() == Node.ELEMENT_NODE) { final Element portElement = (Element) portNode; String soapOperationAddress = extractSoapAddress(portElement, SOAP_11_NAMESPACE); SoapVersion soapOperationVersion = SoapVersion.SOAP11; if (soapOperationAddress == null) { soapOperationAddress = extractSoapAddress(portElement, SOAP_12_NAMESPACE); soapOperationVersion = SoapVersion.SOAP12; } if (soapOperationAddress == null) { // The port element is not a SOAP port continue; } final String portName = getAttribute(portElement, "name"); final String portBinding = getAttribute(portElement, "binding"); final List<SoapOperationDto> soapOperations = getSoapOperations(document, portBinding, soapOperationAddress, soapOperationVersion, generateResponse); final SoapPortDto soapPort = new SoapPortDto(); soapPort.setName(portName); soapPort.setOperations(soapOperations); soapPort.setUri(portName); soapPorts.add(soapPort); } } } } return soapPorts; }
From source file:com.evolveum.midpoint.model.impl.filter.PatternFilter.java
private List<Replace> getReplaces() { List<Replace> replaces = new ArrayList<Replace>(); List<Object> parameters = getParameters(); for (Object object : parameters) { if (!(object instanceof Element)) { continue; }/* w ww. j a v a2 s.co m*/ Element element = (Element) object; if (!ELEMENT_REPLACE.getLocalPart().equals(element.getLocalName())) { LOGGER.debug("Ignoring unknown parameter {} in PatternFilter", new Object[] { element.getLocalName() }); continue; } NodeList patternNodeList = element.getElementsByTagNameNS(ELEMENT_PATTERN.getNamespaceURI(), ELEMENT_PATTERN.getLocalPart()); if (patternNodeList.getLength() != 1) { throw new IllegalArgumentException( "Wrong number of " + ELEMENT_PATTERN + " elements (" + patternNodeList.getLength() + ")"); } String patternStr = ((Element) patternNodeList.item(0)).getTextContent(); Pattern pattern = Pattern.compile(patternStr); NodeList replacementNodeList = element.getElementsByTagNameNS(ELEMENT_REPLACEMENT.getNamespaceURI(), ELEMENT_REPLACEMENT.getLocalPart()); if (replacementNodeList.getLength() != 1) { throw new IllegalArgumentException("Wrong number of " + ELEMENT_REPLACEMENT + " elements (" + replacementNodeList.getLength() + ")"); } String replacement = ((Element) replacementNodeList.item(0)).getTextContent(); replaces.add(new Replace(pattern, replacement)); } return replaces; }
From source file:eu.eidas.encryption.SAMLAuthnResponseEncrypter.java
@Nonnull private Response performEncryption(@Nonnull Response samlResponseEncryptee, @Nonnull Credential credential) throws EncryptionException { try {/* ww w .j a v a 2s . c o m*/ // Set Data Encryption parameters EncryptionParameters encParams = new EncryptionParameters(); encParams.setAlgorithm(getDataEncAlgorithm()); // Set Key Encryption parameters KeyEncryptionParameters kekParams = new KeyEncryptionParameters(); kekParams.setEncryptionCredential(credential); kekParams.setAlgorithm(getKeyEncAlgorithm()); KeyInfoGeneratorFactory kigf = Configuration.getGlobalSecurityConfiguration() .getKeyInfoGeneratorManager().getDefaultManager().getFactory(credential); kekParams.setKeyInfoGenerator(kigf.newInstance()); // Setup Open SAML Encrypter Encrypter encrypter = new Encrypter(encParams, kekParams); encrypter.setKeyPlacement(Encrypter.KeyPlacement.INLINE); if (getJcaProviderName() != null) { encrypter.setJCAProviderName(getJcaProviderName()); } for (Assertion assertion : samlResponseEncryptee.getAssertions()) { if (assertion.getDOM() == null) { OpenSamlHelper.marshallToDom(assertion); } manageNamespaces(assertion); } List<EncryptedAssertion> encryptedAssertions = new ArrayList<>(); for (Assertion assertion : samlResponseEncryptee.getAssertions()) { EncryptedAssertion encryptedAssertion = encrypter.encrypt(assertion); encryptedAssertions.add(encryptedAssertion); } Element previousDom = samlResponseEncryptee.getDOM(); if (null == previousDom) { previousDom = OpenSamlHelper.marshallToDom(samlResponseEncryptee); } Document ownerDocument = previousDom.getOwnerDocument(); // Deep copy the previous DOM into a new one using importNode() Document newDocument = DocumentBuilderFactoryUtil.newDocument(); Node copiedRoot = newDocument.importNode(ownerDocument.getDocumentElement(), true); newDocument.appendChild(copiedRoot); Element newRootElement = newDocument.getDocumentElement(); NodeList assertionList = newRootElement.getElementsByTagNameNS( Assertion.DEFAULT_ELEMENT_NAME.getNamespaceURI(), Assertion.DEFAULT_ELEMENT_NAME.getLocalPart()); // Replace the encrypted assertions by the decrypted assertions in the new DOM tree: for (int i = 0, n = assertionList.getLength(); i < n; i++) { Node assertion = assertionList.item(i); EncryptedAssertion encryptedAssertion = encryptedAssertions.get(i); Element encryptedAssertionDOM = encryptedAssertion.getDOM(); Node copiedEncryptedAssertion; if (null == encryptedAssertionDOM) { encryptedAssertionDOM = OpenSamlHelper.marshallToDom(encryptedAssertion); } // we may use adoptNode() instead of importNode() because the unmarshaller rectifies the ID-ness: copiedEncryptedAssertion = newDocument.adoptNode(encryptedAssertionDOM); newRootElement.replaceChild(copiedEncryptedAssertion, assertion); } // Finally unmarshall the updated DOM into a new XMLObject graph: // The unmarshaller rectifies the ID-ness: // See org.opensaml.saml1.core.impl.AssertionUnmarshaller.unmarshall() // See org.opensaml.saml2.core.impl.AssertionUnmarshaller.processAttribute() // And org.opensaml.saml1.core.impl.ResponseAbstractTypeUnmarshaller.unmarshall() // And org.opensaml.saml2.core.impl.StatusResponseTypeUnmarshaller.processAttribute() Response encryptedResponse = (Response) OpenSamlHelper.unmarshallFromDom(newDocument); if (LOGGER.isTraceEnabled()) { try { LOGGER.trace("SAML Response XMLObject encrypted: " + EidasStringUtil.toString(DocumentBuilderFactoryUtil.marshall(newDocument, true))); } catch (TransformerException e) { LOGGER.error(e.getMessage(), e); } } return encryptedResponse; } catch (org.opensaml.xml.encryption.EncryptionException | ParserConfigurationException | MarshallException | UnmarshallException e) { throw new EncryptionException(e); } }