in src/main/java/org/apache/jcp/xml/dsig/internal/dom/ApacheTransform.java [136:209]
private Data transformIt(Data data, XMLCryptoContext xc, OutputStream os)
throws TransformException
{
if (ownerDoc == null) {
throw new TransformException("transform must be marshalled");
}
if (transform == null) {
try {
transform =
new Transform(ownerDoc, getAlgorithm(), transformElem.getChildNodes());
transform.setElement(transformElem, xc.getBaseURI());
LOG.log(Level.DEBUG, "Created transform for algorithm: {0}", getAlgorithm());
} catch (Exception ex) {
throw new TransformException("Couldn't find Transform for: " +
getAlgorithm(), ex);
}
}
if (Utils.secureValidation(xc)) {
String algorithm = getAlgorithm();
if (Transforms.TRANSFORM_XSLT.equals(algorithm)) {
throw new TransformException(
"Transform " + algorithm + " is forbidden when secure validation is enabled"
);
}
}
XMLSignatureInput in;
if (data instanceof ApacheData) {
LOG.log(Level.DEBUG, "ApacheData = true");
in = ((ApacheData)data).getXMLSignatureInput();
} else if (data instanceof NodeSetData) {
LOG.log(Level.DEBUG, "isNodeSet() = true");
if (data instanceof DOMSubTreeData) {
LOG.log(Level.DEBUG, "DOMSubTreeData = true");
DOMSubTreeData subTree = (DOMSubTreeData)data;
in = new XMLSignatureNodeInput(subTree.getRoot());
in.setExcludeComments(subTree.excludeComments());
} else {
@SuppressWarnings({"unchecked", "rawtypes"})
Set<Node> nodeSet =
Utils.toNodeSet(((NodeSetData)data).iterator());
in = new XMLSignatureNodeSetInput(nodeSet);
}
} else {
LOG.log(Level.DEBUG, "isNodeSet() = false");
try {
in = new XMLSignatureStreamInput(((OctetStreamData) data).getOctetStream());
} catch (Exception ex) {
throw new TransformException(ex);
}
}
boolean secVal = Utils.secureValidation(xc);
in.setSecureValidation(secVal);
try {
if (os != null) {
in = transform.performTransform(in, os, secVal);
if (!in.isNodeSet() && !in.isElement()) {
return null;
}
} else {
in = transform.performTransform(in, secVal);
}
if (in.hasUnprocessedInput()) {
return new ApacheOctetStreamData(in);
} else {
return new ApacheNodeSetData(in);
}
} catch (Exception ex) {
throw new TransformException(ex);
}
}