List of usage examples for org.w3c.dom Attr getValue
public String getValue();
From source file:org.wso2.carbon.ndatasource.core.utils.DataSourceUtils.java
private static void secureLoadElement(Element element, boolean checkSecureVault) throws CryptoException { if (checkSecureVault) { Attr secureAttr = element.getAttributeNodeNS(DataSourceConstants.SECURE_VAULT_NS, DataSourceConstants.SECRET_ALIAS_ATTR_NAME); if (secureAttr != null) { element.setTextContent(loadFromSecureVault(secureAttr.getValue())); element.removeAttributeNode(secureAttr); }/*from ww w. j av a 2 s.c o m*/ } else { String encryptedStr = element.getAttribute(DataSourceConstants.ENCRYPTED_ATTR_NAME); if (encryptedStr != null) { boolean encrypted = Boolean.parseBoolean(encryptedStr); if (encrypted) { element.setTextContent(new String(CryptoUtil .getDefaultCryptoUtil(DataSourceServiceComponent.getServerConfigurationService(), DataSourceServiceComponent.getRegistryService()) .base64DecodeAndDecrypt(element.getTextContent()))); } } } NodeList childNodes = element.getChildNodes(); int count = childNodes.getLength(); Node tmpNode; for (int i = 0; i < count; i++) { tmpNode = childNodes.item(i); if (tmpNode instanceof Element) { secureLoadElement((Element) tmpNode, checkSecureVault); } } }
From source file:org.wso2.carbon.rssmanager.core.util.RSSManagerUtil.java
private static void secureLoadElement(Element element) throws RSSManagerException { Attr secureAttr = element.getAttributeNodeNS(RSSManagerConstants.SecureValueProperties.SECURE_VAULT_NS, RSSManagerConstants.SecureValueProperties.SECRET_ALIAS_ATTRIBUTE_NAME_WITH_NAMESPACE); if (secureAttr != null) { element.setTextContent(RSSManagerUtil.loadFromSecureVault(secureAttr.getValue())); element.removeAttributeNode(secureAttr); }/*from w w w . ja va2s . c o m*/ NodeList childNodes = element.getChildNodes(); int count = childNodes.getLength(); Node tmpNode; for (int i = 0; i < count; i++) { tmpNode = childNodes.item(i); if (tmpNode instanceof Element) { secureLoadElement((Element) tmpNode); } } }
From source file:org.wso2.developerstudio.eclipse.esb.impl.ModelObjectImpl.java
/** * Extracts any namespace definitions ("xmlns:prefix=uri") declared on the * element.//from w w w. j ava2s . co m * * @param element * {@link Element} to be examined. * @return mapping of namespace prefixes to URIs. */ protected Map<String, String> extractNamespaces(Element element) { Map<String, String> namespaces = new HashMap<String, String>(); NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr) attributes.item(i); if (attr.getName().startsWith("xmlns:")) { namespaces.put(attr.getName().substring("xmlns:".length()), attr.getValue()); } } return namespaces; }
From source file:pl.net.ptak.PrqPrePackageMojo.java
/** * @param fileAttributes/*from ww w . ja va2 s . co m*/ * @return * @throws MojoFailureException */ private File getFileFromPrq(Attr filePath, int index) throws MojoFailureException { if (filePath == null) { throw new MojoFailureException(String.format("No file location in prerequisite file %d", index)); } return new File(basedir, filePath.getValue()); }
From source file:ru.codeinside.gws.crypto.cryptopro.CryptoProvider.java
@Override public AppData normalize(List<QName> namespaces, String appData) { try {//w w w . j av a 2 s . c o m final Document doc = createDocumentFromFragment(namespaces, appData); NodeList childNodes = doc.getDocumentElement().getChildNodes(); Element body = (Element) childNodes.item(0); String _id; Attr id = body.getAttributeNodeNS(WSU, "Id"); if (id == null) { _id = "AppData"; body.setAttributeNS(WSU, "Id", _id); } else { _id = id.getValue(); } final Transforms transforms = new Transforms(doc); // ? ds:Signature, ? // Element signature = doc.createElementNS(Constants.SignatureSpecNS, Constants._TAG_SIGNATURE); // signature = (Element) body.insertBefore(signature, body.getFirstChild()); // transforms.setElement(signature, _id); // transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE); transforms.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS); ByteArrayOutputStream c14nStream = new ByteArrayOutputStream(); MessageDigestAlgorithm mda = MessageDigestAlgorithm.getInstance(doc, MessageDigestAlgorithm.ALGO_ID_DIGEST_GOST3411); mda.reset(); XMLSignatureInput output = transforms.performTransforms(new XMLSignatureInput(body), c14nStream); DigesterOutputStream digesterStream = new DigesterOutputStream(mda); output.updateOutputStream(digesterStream); return new AppData(c14nStream.toByteArray(), digesterStream.getDigestValue()); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (SAXException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } catch (CanonicalizationException e) { throw new RuntimeException(e); } catch (XMLSecurityException e) { throw new RuntimeException(e); } }
From source file:ru.codeinside.gws.crypto.cryptopro.CryptoProvider.java
@Override public String inject(final List<QName> namespaces, final AppData normalized, final X509Certificate certificate, final byte[] sig) { try {//w w w.ja v a 2s . c o m final String normalizedAppData = new String(normalized.content, "UTF8"); final Document doc = createDocumentFromFragment(namespaces, normalizedAppData); NodeList childNodes = doc.getDocumentElement().getChildNodes(); Element body = (Element) childNodes.item(0); Attr idAttr = body.getAttributeNodeNS(WSU, "Id"); if (idAttr == null) { throw new IllegalStateException("? "); } final String id = idAttr.getValue(); final Transforms transforms = new Transforms(doc); Element signature = doc.createElementNS(Constants.SignatureSpecNS, Constants._TAG_SIGNATURE); signature = (Element) body.insertBefore(signature, body.getFirstChild()); transforms.setElement(signature, id); transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE); transforms.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS); ByteArrayOutputStream c14nStream = new ByteArrayOutputStream(); MessageDigestAlgorithm mda = MessageDigestAlgorithm.getInstance(doc, MessageDigestAlgorithm.ALGO_ID_DIGEST_GOST3411); mda.reset(); XMLSignatureInput output = transforms.performTransforms(new XMLSignatureInput(body), c14nStream); DigesterOutputStream digesterStream = new DigesterOutputStream(mda); output.updateOutputStream(digesterStream); AppData check = new AppData(c14nStream.toByteArray(), digesterStream.getDigestValue()); if (!Arrays.equals(check.digest, normalized.digest)) { final StringBuilder sb = new StringBuilder(" ? ?:\n"); sb.append(": ").append(new String(normalized.digest, "UTF8")).append('\n'); sb.append(" : ").append(new String(check.digest, "UTF8")); throw new IllegalStateException(sb.toString()); } Element keyInfo = doc.createElementNS(Constants.SignatureSpecNS, "KeyInfo"); Element securityTokenReference = doc.createElementNS(WSSE, "SecurityTokenReference"); Element reference = doc.createElementNS(WSSE, "Reference"); reference.setAttribute("URI", "#CertId"); reference.setAttribute("ValueType", WSS_X509V3); securityTokenReference.appendChild(reference); keyInfo.appendChild(securityTokenReference); signature.appendChild(keyInfo); Element signatureValueElement = XMLUtils.createElementInSignatureSpace(doc, Constants._TAG_SIGNATUREVALUE); signature.appendChild(signatureValueElement); String base64codedValue = Base64.encode(sig); if (base64codedValue.length() > 76 && !XMLUtils.ignoreLineBreaks()) { base64codedValue = "\n" + base64codedValue + "\n"; } signatureValueElement.appendChild(doc.createTextNode(base64codedValue)); return saxFilter(doc); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (SAXException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } catch (CanonicalizationException e) { throw new RuntimeException(e); } catch (XMLSecurityException e) { throw new RuntimeException(e); } }
From source file:tkwatch.Utilities.java
/** * Recursively travels through a DOM tree. Adapted from Vohra and Vohra, * <i>Pro XML Development with Java Technology</i>, p. 47. This was used * during development and is not called by <strong>TKWatch+</strong>. * Retained for completeness.//ww w. j av a 2s .c om * * @param previousNode * @param visitNode */ public static void visitNode(Element previousNode, Element visitNode) { if (previousNode != null) { System.out.println("Element " + previousNode.getTagName() + " has element:"); } System.out.println("Element Name: " + visitNode.getTagName()); if (visitNode.hasAttributes()) { System.out.println("Element " + visitNode.getTagName() + " has attributes: "); NamedNodeMap attributes = visitNode.getAttributes(); for (int j = 0; j < attributes.getLength(); j++) { Attr attribute = (Attr) (attributes.item(j)); System.out.println("Attribute:" + attribute.getName() + " with value " + attribute.getValue()); } } // Obtain a NodeList of nodes in an Element node. NodeList nodeList = visitNode.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; visitNode(visitNode, element); } else if (node.getNodeType() == Node.TEXT_NODE) { String str = node.getNodeValue().trim(); if (str.length() > 0) { System.out.println("Element Text: " + str); } } } }
From source file:ubic.gemma.core.loader.entrez.pubmed.PubMedXMLParser.java
private boolean isMajorHeading(Node descriptor) { Attr dmajorTopic = (Attr) descriptor.getAttributes().getNamedItem("MajorTopicYN"); return dmajorTopic.getValue().equals("Y"); }
From source file:util.XmlWriter.java
private String writeAttributes(Element element) { StringBuilder attributeString = new StringBuilder(); NamedNodeMap attributeMap = element.getAttributes(); int length = attributeMap.getLength(); for (int i = 0; i < length; i++) { Attr attributeNode = (Attr) attributeMap.item(i); String name = attributeNode.getName(); String value = attributeNode.getValue(); attributeString.append(" ").append(name).append("=\"").append(value).append("\""); }/*from www . jav a2 s. co m*/ return attributeString.toString(); }
From source file:VASSAL.build.module.GlobalOptions.java
public void build(Element e) { if (e == null) return;/*from ww w . j a va 2 s .c om*/ final NamedNodeMap nnm = e.getAttributes(); for (int i = 0; i < nnm.getLength(); ++i) { final Attr att = (Attr) nnm.item(i); setAttribute(att.getName(), att.getValue()); } for (Node n = e.getFirstChild(); n != null; n = n.getNextSibling()) { if (n.getNodeType() == Node.ELEMENT_NODE) { final Element element = (Element) n; if ("option".equals(element.getTagName())) { //$NON-NLS-1$ final String optionName = element.getAttribute("name"); //$NON-NLS-1$ final String value = Builder.getText(element); optionInitialValues.put(optionName, value); // Update the Configurer value if it is already registered final Configurer config = optionConfigurers.get(optionName); if (config != null) { config.setValue(value); } } else { try { final Buildable b = Builder.create(element); b.addTo(this); add(b); } catch (IllegalBuildException ex) { ErrorDialog.bug(ex); } } } } }