1 /*
2  * @(#) $Id: Canonicalize.java,v 1.2 2003/07/08 08:13:52 pankaj Exp $
3  *
4  * Copyright (c) 2002-03 by Pankaj Kumar (http://www.pankaj-k.net). 
5  * All rights reserved.
6  *
7  * The license governing the use of this file can be found in the 
8  * root directory of the containing software.
9  */
10import org.w3c.dom.Document;
11
12import com.verisign.c14n.*;
13import com.verisign.domutil.*;
14import com.verisign.xpath.*;
15
16public class Canonicalize {
17    private static String NORMAL_C14N = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
18    private static String NORMAL_C14NWC = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments";
19    private static String EXC_C14N = "http://www.w3.org/2001/10/xml-exc-c14n#";
20    private static String EXC_C14NWC = "http://www.w3.org/2001/10/xml-exc-c14n#WithComments";
21    public static void main(String[] args) throws Exception {
22        // Input to signature.
23        String datafile = "../../../../data/book.xml";
24
25        // Read the XML file
26        Document doc = XmlUtility.readXML(datafile);
27        Canonicalizer c = CanonicalizerFactory.getInstance(NORMAL_C14N);
28        byte[] ba = c.canonicalize(doc);
29        System.out.println("Output of Normal Canonicalization:");
30        System.out.write(ba);
31        System.out.println();
32
33
34        Canonicalizer c1 = CanonicalizerFactory.getInstance(NORMAL_C14N);
35        DOMCursor dc1 = new DOMCursor(doc);
36        dc1.moveToXPath(new XPath("id('book_title')"));
37        byte[] ba1 = c1.canonicalize(dc1.getElement());
38        System.out.println("Output of Normal Canonicalization:");
39        System.out.write(ba1);
40        System.out.println();
41
42        Canonicalizer c2 = CanonicalizerFactory.getInstance(EXC_C14N);
43        DOMCursor dc2 = new DOMCursor(doc);
44        dc2.moveToXPath(new XPath("id('book_title')"));
45        byte[] ba2 = c2.canonicalize(dc2.getElement());
46        System.out.println("Output of Exclusive Canonicalization:");
47        System.out.write(ba2);
48        System.out.println();
49    }
50}