org.idoox.xml
Class TokenizerResolver

java.lang.Object
  extended byorg.idoox.xml.TokenizerResolver

public class TokenizerResolver
extends java.lang.Object

Converts Tokenizer to canonical form according to the Exclusive XML Canonicalization specification. For further detail see http://www.w3.org/TR/xml-exc-c14n/. It is useful e.g. for digital signature over an XML.

Since:
4.0
Component:
Core

Nested Class Summary
protected static class TokenizerResolver.PrefixesStack
           
 
Field Summary
protected static boolean trace
           
 
Constructor Summary
TokenizerResolver()
           
 
Method Summary
protected static java.lang.String engineCanonicalizeStartToken(Tokenizer source, Token token, TokenizerResolver.PrefixesStack registeredPrefixes, java.util.Stack tokenNames, boolean root)
           
static java.lang.String normalizeAttr(java.lang.String s)
          Normalizes an {link Attr Attribute} value The string value of the node is modified by replacing all ampersands (&) with &amp; all open angle brackets (<) with &lt; all quotation mark characters with &quot; and the whitespace characters #x9, #xA, and #xD, with character references.
static java.lang.String normalizeText(java.lang.String text)
          Normalizes a Text value.
static byte[] toC14nExcCanonicalForm(Tokenizer source, java.lang.String prefixList)
          Converts tokenizer to c14n exclusive canonical form ( http://www.w3.org/TR/xml-exc-c14n/).
static byte[] toCanonicalForm(Tokenizer source)
          Converts tokenizer to canonical form.
static byte[] toCanonicalForm(Tokenizer source, boolean addAncestorPrefix)
          Converts tokenizer to c14n canonical form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

trace

protected static final boolean trace
See Also:
Constant Field Values
Constructor Detail

TokenizerResolver

public TokenizerResolver()
Method Detail

toCanonicalForm

public static byte[] toCanonicalForm(Tokenizer source)
                              throws TokenizerException,
                                     java.io.IOException
Converts tokenizer to canonical form. The method calls toCanonicalForm(source, addAncestorPrefix) with parameter addAncestorPrefix = false.

Parameters:
source - the tokenizer to resolve
Returns:
the byte array that represents canonical form of tokenizer.
Throws:
TokenizerException - Exception
java.io.IOException - Exception

toCanonicalForm

public static byte[] toCanonicalForm(Tokenizer source,
                                     boolean addAncestorPrefix)
                              throws TokenizerException,
                                     java.io.IOException
Converts tokenizer to c14n canonical form.

Parameters:
source - the tokenizer to resolve
addAncestorPrefix - whether the prefixes of the ancestors is also added to the output
Returns:
the byte array that represents canonical form of tokenizer.
Throws:
TokenizerException - Exception
java.io.IOException - Exception

engineCanonicalizeStartToken

protected static java.lang.String engineCanonicalizeStartToken(Tokenizer source,
                                                               Token token,
                                                               TokenizerResolver.PrefixesStack registeredPrefixes,
                                                               java.util.Stack tokenNames,
                                                               boolean root)

normalizeAttr

public static final java.lang.String normalizeAttr(java.lang.String s)
Normalizes an {link Attr Attribute} value The string value of the node is modified by replacing

Parameters:
s -
Returns:
the normalized attribute value

normalizeText

public static final java.lang.String normalizeText(java.lang.String text)
Normalizes a Text value.

Text Nodes - the string value, except all ampersands (& are replaced by &amp;, all open angle brackets (<) are replaced by &lt;, all closing angle brackets (>) are replaced by &gt;, and all #xD characters are replaced by &#xD;. (See processing model section in the specification )

Parameters:
text - text to be normalized
Returns:
the normalized value

toC14nExcCanonicalForm

public static byte[] toC14nExcCanonicalForm(Tokenizer source,
                                            java.lang.String prefixList)
                                     throws TokenizerException,
                                            java.io.IOException
Converts tokenizer to c14n exclusive canonical form ( http://www.w3.org/TR/xml-exc-c14n/).

It is as defined in the Canonical XML Recommendation [XML-C14N] except for the changes summarized as follows: attributes in the XML namespace, such as xml:lang and xml:space are not imported into orphan nodes of the document subset, and namespace nodes that are not on the InclusiveNamespaces PrefixList are expressed only in start tags where they are visible and if they are not in effect from an output ancestor of that tag.

Parameters:
source - input tokenizer
prefixList - list of the visible prefixes
Returns:
canonicalized tokenizer
Throws:
TokenizerException
java.io.IOException