public Data canonicalize(Data data, XMLCryptoContext xc) throws TransformException { return canonicalize(data, xc, null); }
public Data canonicalize(Data data, XMLCryptoContext xc, OutputStream os) throws TransformException { if (apacheCanonicalizer == null) { try { apacheCanonicalizer = Canonicalizer.getInstance(getAlgorithm()); if (log.isLoggable(java.util.logging.Level.FINE)) { log.log(java.util.logging.Level.FINE, "Created canonicalizer for algorithm: " + getAlgorithm()); } } catch (InvalidCanonicalizerException ice) { throw new TransformException ("Couldn't find Canonicalizer for: " + getAlgorithm() + ": " + ice.getMessage(), ice); } } if (os != null) { apacheCanonicalizer.setWriter(os); } else { apacheCanonicalizer.setWriter(new ByteArrayOutputStream()); } try { Set<Node> nodeSet = null; if (data instanceof ApacheData) { XMLSignatureInput in = ((ApacheData)data).getXMLSignatureInput(); if (in.isElement()) { if (inclusiveNamespaces != null) { return new OctetStreamData(new ByteArrayInputStream (apacheCanonicalizer.canonicalizeSubtree (in.getSubNode(), inclusiveNamespaces))); } else { return new OctetStreamData(new ByteArrayInputStream (apacheCanonicalizer.canonicalizeSubtree (in.getSubNode()))); } } else if (in.isNodeSet()) { nodeSet = in.getNodeSet(); } else { return new OctetStreamData(new ByteArrayInputStream( apacheCanonicalizer.canonicalize( Utils.readBytesFromStream(in.getOctetStream())))); } } else if (data instanceof DOMSubTreeData) { DOMSubTreeData subTree = (DOMSubTreeData)data; if (inclusiveNamespaces != null) { return new OctetStreamData(new ByteArrayInputStream (apacheCanonicalizer.canonicalizeSubtree (subTree.getRoot(), inclusiveNamespaces))); } else { return new OctetStreamData(new ByteArrayInputStream (apacheCanonicalizer.canonicalizeSubtree (subTree.getRoot()))); } } else if (data instanceof NodeSetData) { NodeSetData<?> nsd = (NodeSetData<?>)data; // convert Iterator to Set<Node> nodeSet = Utils.toNodeSet(nsd.iterator()); if (log.isLoggable(java.util.logging.Level.FINE)) { log.log(java.util.logging.Level.FINE, "Canonicalizing " + nodeSet.size() + " nodes"); } } else { return new OctetStreamData(new ByteArrayInputStream( apacheCanonicalizer.canonicalize( Utils.readBytesFromStream( ((OctetStreamData)data).getOctetStream())))); } if (inclusiveNamespaces != null) { return new OctetStreamData(new ByteArrayInputStream( apacheCanonicalizer.canonicalizeXPathNodeSet (nodeSet, inclusiveNamespaces))); } else { return new OctetStreamData(new ByteArrayInputStream( apacheCanonicalizer.canonicalizeXPathNodeSet(nodeSet))); } } catch (Exception e) { throw new TransformException(e); } }
public Data transform(Data data, XMLCryptoContext context, OutputStream os) throws TransformException { LOG.debug("transform(data,context,os)"); return null; }
/** * Transforms the specified data using the underlying transform algorithm. * * @param data the data to be transformed * @param xc the <code>XMLCryptoContext</code> containing * additional context (may be <code>null</code> if not applicable) * @return the transformed data * @throws NullPointerException if <code>data</code> is <code>null</code> * @throws XMLSignatureException if an unexpected error occurs while * executing the transform */ @Override public Data transform(Data data, XMLCryptoContext xc) throws TransformException { return spi.transform(data, xc); }
/** * Transforms the specified data using the underlying transform algorithm. * * @param data the data to be transformed * @param xc the <code>XMLCryptoContext</code> containing * additional context (may be <code>null</code> if not applicable) * @param os the <code>OutputStream</code> that should be used to write * the transformed data to * @return the transformed data * @throws NullPointerException if <code>data</code> is <code>null</code> * @throws XMLSignatureException if an unexpected error occurs while * executing the transform */ @Override public Data transform(Data data, XMLCryptoContext xc, OutputStream os) throws TransformException { return spi.transform(data, xc, os); }
/** * Transforms the specified data using the underlying transform algorithm. * This method invokes the {@link #marshal marshal} method and passes it * the specified <code>DOMSignContext</code> before transforming the data. * * @param data the data to be transformed * @param sc the <code>XMLCryptoContext</code> containing * additional context (may be <code>null</code> if not applicable) * @param context the marshalling context * @return the transformed data * @throws MarshalException if an exception occurs while marshalling * @throws NullPointerException if <code>data</code> or <code>context</code> * is <code>null</code> * @throws XMLSignatureException if an unexpected error occurs while * executing the transform */ Data transform(Data data, XMLCryptoContext xc, DOMSignContext context) throws MarshalException, TransformException { Node parent = context.getParent(); XmlWriter xwriter = new XmlWriterToTree(Marshaller.getMarshallers(), parent); marshal(xwriter, DOMUtils.getSignaturePrefix(context), context); return transform(data, xc); }