Package nu.xom.canonical

Examples of nu.xom.canonical.Canonicalizer


   * @return the bytes representing canonical XML
   * @see Canonicalizer
   */
  public static byte[] toCanonicalXML(Document doc) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Canonicalizer canon = new Canonicalizer(out);
    try {
      canon.write(doc);
    } catch (IOException e) {
      throw new RuntimeException("should never happen", e);
    } catch (NoSuchMethodError e) {
      try { // xom < 1.1 uses write(Document) signature
        Canonicalizer.class.getMethod("write", new Class[] {Document.class});
View Full Code Here


            return;
        }
       
        Builder builder = new Builder();
        try {
            Canonicalizer outputter = new Canonicalizer(System.out);
            Document input = builder.build(args[0]);
            outputter.write(input);
        }
        catch (Exception ex) {
            System.err.println(ex);
            ex.printStackTrace();
        }
View Full Code Here

        pdu.addAttribute(new Attribute("a1", "v1"));
        pdu.addAttribute(new Attribute("a2", "v2"));
       
        String expected = " a1=\"v1\" a2=\"v2\"";
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Canonicalizer canonicalizer = new Canonicalizer(out);
       
        Document doc = new Document(pdu);
        canonicalizer.write(doc.query("//@*"))
       
        byte[] result = out.toByteArray();
        out.close();
        String s = new String(out.toByteArray(), "UTF8");
        assertEquals(expected, s);
View Full Code Here

        Attribute a2 = new Attribute("a2", "v2");
        pdu.addAttribute(a2);
       
        String expected = " a1=\"v1\" a2=\"v2\"";
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Canonicalizer canonicalizer = new Canonicalizer(out);
       
        Document doc = new Document(pdu);
        Nodes subset = doc.query("//@*");
        subset.append(a1);
        subset.append(a2);
        canonicalizer.write(subset)
       
        byte[] result = out.toByteArray();
        out.close();
        String s = new String(out.toByteArray(), "UTF8");
        assertEquals(expected, s);
View Full Code Here

       
        Element pdu = new Element("doc", "http://www.example.com");
       
        String expected = " xmlns=\"http://www.example.com\"";
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Canonicalizer canonicalizer = new Canonicalizer(out);
       
        Document doc = new Document(pdu);
        canonicalizer.write(doc.query("//namespace::node()"))
       
        byte[] result = out.toByteArray();
        out.close();
        String s = new String(out.toByteArray(), "UTF8");
        assertEquals(expected, s);
View Full Code Here

       
        Element pdu = new Element("pre:doc", "http://www.example.com");
       
        String expected = " xmlns:pre=\"http://www.example.com\"";
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Canonicalizer canonicalizer = new Canonicalizer(out);
       
        Document doc = new Document(pdu);
        canonicalizer.write(doc.query("//namespace::node()"))
       
        byte[] result = out.toByteArray();
        out.close();
        String s = new String(out.toByteArray(), "UTF8");
        assertEquals(expected, s);
View Full Code Here

    public void testCanonicalizeWithNullAlgorithm()
      throws IOException {
       
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            new Canonicalizer(out, null);
            fail("Allowed null algorithm");
        }
        catch (NullPointerException success) {
            assertNotNull(success.getMessage());
        }
View Full Code Here

        doc.appendChild(new Comment("comment 3"));
        doc.appendChild(new Comment("comment 4"));
       
        String expected = "<!--comment 1-->\n<!--comment 2-->\n\n<!--comment 3-->\n<!--comment 4-->";
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Canonicalizer canonicalizer = new Canonicalizer(out);
       
        canonicalizer.write(doc.query("//comment()"))
       
        byte[] result = out.toByteArray();
        out.close();
        String s = new String(out.toByteArray(), "UTF8");
        assertEquals(expected, s);
View Full Code Here

       
        String input = "<ns1:root xmlns:ns1='http://www.example.org/'><elt1></elt1></ns1:root>";
        Document doc = builder.build(input, null);
       
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Canonicalizer canonicalizer = new Canonicalizer(out);
       
        canonicalizer.write(doc)
       
        byte[] result = out.toByteArray();
        out.close();
        String s = new String(out.toByteArray(), "UTF8");
        assertEquals("<ns1:root xmlns:ns1=\"http://www.example.org/\"><elt1></elt1></ns1:root>", s);
View Full Code Here

        doc.appendChild(new Comment("comment 3"));
        doc.appendChild(new ProcessingInstruction("target", "value"));
       
        String expected = "<?target value?>\n<!--comment 2-->\n<doc></doc>\n<!--comment 3-->\n<?target value?>";
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Canonicalizer canonicalizer = new Canonicalizer(out);
       
        canonicalizer.write(doc)
       
        byte[] result = out.toByteArray();
        out.close();
        String s = new String(out.toByteArray(), "UTF8");
        assertEquals(expected, s);
View Full Code Here

TOP

Related Classes of nu.xom.canonical.Canonicalizer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.