org.jcp.xml.dsig.internal.dom.DOMXPathTransform Maven / Gradle / Ivy
The newest version!
/* */ package org.jcp.xml.dsig.internal.dom;
/* */
/* */ import java.security.InvalidAlgorithmParameterException;
/* */ import java.util.HashMap;
/* */ import java.util.Iterator;
/* */ import java.util.Map;
/* */ import java.util.Map.Entry;
/* */ import java.util.Set;
/* */ import javax.xml.crypto.MarshalException;
/* */ import javax.xml.crypto.XMLCryptoContext;
/* */ import javax.xml.crypto.XMLStructure;
/* */ import javax.xml.crypto.dsig.spec.TransformParameterSpec;
/* */ import javax.xml.crypto.dsig.spec.XPathFilterParameterSpec;
/* */ import org.w3c.dom.Attr;
/* */ import org.w3c.dom.Document;
/* */ import org.w3c.dom.Element;
/* */ import org.w3c.dom.NamedNodeMap;
/* */ import org.w3c.dom.Node;
/* */
/* */ public final class DOMXPathTransform extends ApacheTransform
/* */ {
/* */ public void init(TransformParameterSpec params)
/* */ throws InvalidAlgorithmParameterException
/* */ {
/* 31 */ if (params == null)
/* 32 */ throw new InvalidAlgorithmParameterException("params are required");
/* 33 */ if (!(params instanceof XPathFilterParameterSpec)) {
/* 34 */ throw new InvalidAlgorithmParameterException("params must be of type XPathFilterParameterSpec");
/* */ }
/* */
/* 37 */ this.params = params;
/* */ }
/* */
/* */ public void init(XMLStructure parent, XMLCryptoContext context)
/* */ throws InvalidAlgorithmParameterException
/* */ {
/* 43 */ super.init(parent, context);
/* 44 */ unmarshalParams(DOMUtils.getFirstChildElement(this.transformElem));
/* */ }
/* */
/* */ private void unmarshalParams(Element paramsElem) {
/* 48 */ String xPath = paramsElem.getFirstChild().getNodeValue();
/* */
/* 50 */ NamedNodeMap attributes = paramsElem.getAttributes();
/* 51 */ if (attributes != null) {
/* 52 */ int length = attributes.getLength();
/* 53 */ Map namespaceMap = new HashMap(length);
/* 54 */ for (int i = 0; i < length; i++) {
/* 55 */ Attr attr = (Attr)attributes.item(i);
/* 56 */ String prefix = attr.getPrefix();
/* 57 */ if ((prefix != null) && (prefix.equals("xmlns"))) {
/* 58 */ namespaceMap.put(attr.getLocalName(), attr.getValue());
/* */ }
/* */ }
/* 61 */ this.params = new XPathFilterParameterSpec(xPath, namespaceMap);
/* */ } else {
/* 63 */ this.params = new XPathFilterParameterSpec(xPath);
/* */ }
/* */ }
/* */
/* */ public void marshalParams(XMLStructure parent, XMLCryptoContext context)
/* */ throws MarshalException
/* */ {
/* 70 */ super.marshalParams(parent, context);
/* 71 */ XPathFilterParameterSpec xp = (XPathFilterParameterSpec)getParameterSpec();
/* */
/* 73 */ Element xpathElem = DOMUtils.createElement(this.ownerDoc, "XPath", "http://www.w3.org/2000/09/xmldsig#", DOMUtils.getSignaturePrefix(context));
/* */
/* 76 */ xpathElem.appendChild(this.ownerDoc.createTextNode(xp.getXPath()));
/* */
/* 79 */ Iterator i = xp.getNamespaceMap().entrySet().iterator();
/* 80 */ while (i.hasNext()) {
/* 81 */ Map.Entry entry = (Map.Entry)i.next();
/* 82 */ xpathElem.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + (String)entry.getKey(), (String)entry.getValue());
/* */ }
/* */
/* 86 */ this.transformElem.appendChild(xpathElem);
/* */ }
/* */ }
/* Location: E:\HYN\Java\trunk\ref\lib-dep\xmldsig\xmldsig.jar
* Qualified Name: org.jcp.xml.dsig.internal.dom.DOMXPathTransform
* JD-Core Version: 0.6.2
*/