Question

I have the following implementation task and I have no good idea how to solve it.

We have a SAX-based syntax-checker for a xml format that checks a hashsum in some closing endElement(). This hashsum is built using a kind of filtering InputStream that updates a MessageDigest while reading the content. The SAX-syntaxchecker uses this inputstream as its InputSource.

The problem (my task) is, that the hashsum should be built over some canonicalized parts of the input xml (see http://www.w3.org/TR/xml-c14n).

Now the tricky thing: We have a Canonicalizer that also uses SAX to canonicalize the input. (It needs to be aware of the current context to distinguish between attributes and nodes etc, thats why we use SAX)

I want to reuse that Canonicalizer but I see no way how to combine these two SAX-parsers.

I think I want some kind of pipelining:

InputFile -> Canonicalizer -> HashCalculation-InputStream -> SyntaxChecker.

Any ideas/references how to accomplish that? TIA.

Was it helpful?

Solution

Since the hash calculation reads from an input stream, the result of the canonicalization must eventually be presented as an input stream. You could use a PipedInputStream connected to a PipedOutputStream, or a pair of ByteArrayOutputStream / ByteArrayInputStream over a temporary byte array.

Instead, if the two components were designed with pipe lining in mind, you could have used an org.xml.sax.XmlFilterto connect the events from the canonicalizer with the handler of hash calculation/syntax checker

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top