canonAlgo = canonElem.getAttribute("Algorithm");
if (doDebug) {
log.debug("CanonAlgo: " + canonAlgo);
}
}
Canonicalizer canon = Canonicalizer.getInstance(canonAlgo);
ByteArrayOutputStream bos = null;
byte[] buf = null;
if (doDebug) {
buf = input.getBytes();
bos = new ByteArrayOutputStream(buf.length);
bos.write(buf, 0, buf.length);
log.debug("canon bos: " + bos.toString());
}
/*
* Get the input (node) to transform. Currently we support only an
* Element as input format. If other formats are required we must
* get it as bytes and probably reparse it into a DOM tree (How to
* work with nodesets? how to select the right node from a nodeset?)
*/
Element str = null;
if (input.isElement()) {
str = (Element) input.getSubNode();
} else {
throw (new CanonicalizationException(
"Wrong input format - only element input supported"));
}
if (doDebug) {
log.debug("STR: " + str.toString());
}
/*
* The element to transform MUST be a SecurityTokenReference
* element.
*/
SecurityTokenReference secRef = new SecurityTokenReference(str);
/*
* Third and forth step are performed by derefenceSTR()
*/
Element dereferencedToken = dereferenceSTR(thisDoc, secRef);
/*
* C14n with specified algorithm. According to WSS Specification.
*/
buf = canon.canonicalizeSubtree(dereferencedToken, "#default");
if (doDebug) {
bos = new ByteArrayOutputStream(buf.length);
bos.write(buf, 0, buf.length);
log.debug("after c14n: " + bos.toString());
}