List of usage examples for org.w3c.dom Node getNextSibling
public Node getNextSibling();
From source file:org.apache.xml.security.keys.KeyInfo.java
/** * Searches the library wide KeyResolvers for Secret keys * * @return the secret key contained in this KeyInfo * @throws KeyResolverException//from ww w. j av a2 s . c o m */ SecretKey getSecretKeyFromStaticResolvers() throws KeyResolverException { Iterator<KeyResolverSpi> it = KeyResolver.iterator(); while (it.hasNext()) { KeyResolverSpi keyResolver = it.next(); Node currentChild = this.constructionElement.getFirstChild(); String uri = this.getBaseURI(); while (currentChild != null) { if (currentChild.getNodeType() == Node.ELEMENT_NODE) { for (StorageResolver storage : storageResolvers) { SecretKey sk = keyResolver.engineLookupAndResolveSecretKey((Element) currentChild, uri, storage); if (sk != null) { return sk; } } } currentChild = currentChild.getNextSibling(); } } return null; }
From source file:org.apache.xml.security.keys.KeyInfo.java
/** * Searches the per-KeyInfo KeyResolvers for secret keys * * @return the secret key contained in this KeyInfo * @throws KeyResolverException//w ww .j a v a2 s. co m */ SecretKey getSecretKeyFromInternalResolvers() throws KeyResolverException { for (KeyResolverSpi keyResolver : internalKeyResolvers) { if (log.isDebugEnabled()) { log.debug("Try " + keyResolver.getClass().getName()); } Node currentChild = this.constructionElement.getFirstChild(); String uri = this.getBaseURI(); while (currentChild != null) { if (currentChild.getNodeType() == Node.ELEMENT_NODE) { for (StorageResolver storage : storageResolvers) { SecretKey sk = keyResolver.engineLookupAndResolveSecretKey((Element) currentChild, uri, storage); if (sk != null) { return sk; } } } currentChild = currentChild.getNextSibling(); } } return null; }
From source file:org.apache.xml.security.keys.KeyInfo.java
/** * Searches the library wide KeyResolvers for Private keys * * @return the private key contained in this KeyInfo * @throws KeyResolverException// w w w. j a v a2 s. c o m */ PrivateKey getPrivateKeyFromStaticResolvers() throws KeyResolverException { Iterator<KeyResolverSpi> it = KeyResolver.iterator(); while (it.hasNext()) { KeyResolverSpi keyResolver = it.next(); Node currentChild = this.constructionElement.getFirstChild(); String uri = this.getBaseURI(); while (currentChild != null) { if (currentChild.getNodeType() == Node.ELEMENT_NODE) { // not using StorageResolvers at the moment // since they cannot return private keys StorageResolver storage = null; PrivateKey pk = keyResolver.engineLookupAndResolvePrivateKey((Element) currentChild, uri, storage); if (pk != null) { return pk; } } currentChild = currentChild.getNextSibling(); } } return null; }
From source file:org.apache.xml.security.keys.KeyInfo.java
/** * Searches the per-KeyInfo KeyResolvers for private keys * * @return the private key contained in this KeyInfo * @throws KeyResolverException//www. j a v a 2s . com */ PrivateKey getPrivateKeyFromInternalResolvers() throws KeyResolverException { for (KeyResolverSpi keyResolver : internalKeyResolvers) { if (log.isDebugEnabled()) { log.debug("Try " + keyResolver.getClass().getName()); } Node currentChild = this.constructionElement.getFirstChild(); String uri = this.getBaseURI(); while (currentChild != null) { if (currentChild.getNodeType() == Node.ELEMENT_NODE) { // not using StorageResolvers at the moment // since they cannot return private keys StorageResolver storage = null; PrivateKey pk = keyResolver.engineLookupAndResolvePrivateKey((Element) currentChild, uri, storage); if (pk != null) { return pk; } } currentChild = currentChild.getNextSibling(); } } return null; }
From source file:org.apache.xml.security.signature.Reference.java
/** * Method setDigestValueElement//w ww .j a va 2 s . com * * @param digestValue */ private void setDigestValueElement(byte[] digestValue) { Node n = digestValueElement.getFirstChild(); while (n != null) { digestValueElement.removeChild(n); n = n.getNextSibling(); } String base64codedValue = Base64.encode(digestValue); Text t = this.doc.createTextNode(base64codedValue); digestValueElement.appendChild(t); }
From source file:org.apache.xml.security.test.encryption.BaltimoreEncTest.java
/** * Method countNodes//from ww w. ja v a2s . c o m * * Recursively count the number of nodes in the document * * @param n Node to count beneath */ private static int countNodes(Node n) { if (n == null) return 0; // Paranoia int count = 1; // Always count myself Node c = n.getFirstChild(); while (c != null) { count += countNodes(c); c = c.getNextSibling(); } return count; }
From source file:org.apache.xml.security.test.encryption.EncryptContentTest.java
public void testContentRemoved() throws Exception { if (!haveISOPadding) { log.warn("Test testContentRemoved skipped as necessary algorithms not available"); return;/*from www . j a va 2 s.c om*/ } Document doc = db.parse(new ByteArrayInputStream(DATA.getBytes("UTF8"))); NodeList dataToEncrypt = doc.getElementsByTagName("user"); XMLCipher dataCipher = XMLCipher.getInstance(XMLCipher.TRIPLEDES); dataCipher.init(XMLCipher.ENCRYPT_MODE, secretKey); for (int i = 0; i < dataToEncrypt.getLength(); i++) { dataCipher.doFinal(doc, (Element) dataToEncrypt.item(i), true); } // Check that user content has been removed Element user = (Element) dataToEncrypt.item(0); Node child = user.getFirstChild(); while (child != null && child.getNodeType() != Node.ELEMENT_NODE) { child = child.getNextSibling(); } // child should be EncryptedData, if not throw exception Element childElem = (Element) child; if (!childElem.getLocalName().equals("EncryptedData")) { // t.transform(new DOMSource(doc), new StreamResult(System.out)); throw new Exception("Element content not replaced"); } // there shouldn't be any more children elements Node sibling = childElem.getNextSibling(); while (sibling != null && sibling.getNodeType() != Node.ELEMENT_NODE) { sibling = sibling.getNextSibling(); } if (sibling != null) { // t.transform(new DOMSource(doc), new StreamResult(System.out)); throw new Exception("Sibling element content not replaced"); } // t.transform(new DOMSource(doc), new StreamResult(System.out)); }
From source file:org.apache.xml.security.utils.ElementProxy.java
/** * Method length// w w w.ja v a 2 s .c o m * * @param namespace * @param localname * @return the number of elements {namespace}:localname under this element */ public int length(String namespace, String localname) { int number = 0; Node sibling = this.constructionElement.getFirstChild(); while (sibling != null) { if (localname.equals(sibling.getLocalName()) && namespace.equals(sibling.getNamespaceURI())) { number++; } sibling = sibling.getNextSibling(); } return number; }
From source file:org.apache.xml.security.utils.IdResolver.java
private static int getEl(Node currentNode, String id, Element[] els) { Node sibling = null;// ww w. j a v a 2s . c om Node parentNode = null; do { switch (currentNode.getNodeType()) { case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_NODE: sibling = currentNode.getFirstChild(); break; case Node.ELEMENT_NODE: Element currentElement = (Element) currentNode; if (isElement(currentElement, id, els) == 1) { return 1; } sibling = currentNode.getFirstChild(); if (sibling == null) { if (parentNode != null) { sibling = currentNode.getNextSibling(); } } else { parentNode = currentElement; } break; } while (sibling == null && parentNode != null) { sibling = parentNode.getNextSibling(); parentNode = parentNode.getParentNode(); if (parentNode != null && Node.ELEMENT_NODE != parentNode.getNodeType()) { parentNode = null; } } if (sibling == null) { return 1; } currentNode = sibling; sibling = currentNode.getNextSibling(); } while (true); }
From source file:org.apache.xml.security.utils.XMLUtils.java
public static Element getNextElement(Node el) { while ((el != null) && (el.getNodeType() != Node.ELEMENT_NODE)) { el = el.getNextSibling(); }// w ww.j a va 2 s . com return (Element) el; }