1// This file is part of TagSoup and is Copyright 2002-2008 by John Cowan.
2//
3// TagSoup is licensed under the Apache License,
4// Version 2.0.  You may obtain a copy of this license at
5// http://www.apache.org/licenses/LICENSE-2.0 .  You may also have
6// additional legal rights not granted by this license.
7//
8// TagSoup is distributed in the hope that it will be useful, but
9// unless required by applicable law or agreed to in writing, TagSoup
10// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
11// OF ANY KIND, either express or implied; not even the implied warranty
12// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14package org.ccil.cowan.tagsoup.jaxp;
15
16import java.io.*;
17
18import javax.xml.parsers.*;
19import org.w3c.dom.Document;
20
21/**
22 * Trivial non-robust test class, to show that TagSoup can be accessed using
23 * JAXP interface.
24 */
25public class JAXPTest
26{
27    public static void main(String[] args)
28        throws Exception
29    {
30        new JAXPTest().test(args);
31    }
32
33    private void test(String[] args)
34        throws Exception
35    {
36        if (args.length != 1) {
37            System.err.println("Usage: java "+getClass()+" [input-file]");
38            System.exit(1);
39        }
40        File f = new File(args[0]);
41        //System.setProperty("javax.xml.parsers.SAXParserFactory", SAXFactoryImpl.class.toString());
42        System.setProperty("javax.xml.parsers.SAXParserFactory", "org.ccil.cowan.tagsoup.jaxp.SAXFactoryImpl");
43
44        SAXParserFactory spf = SAXParserFactory.newInstance();
45        System.out.println("Ok, SAX factory JAXP creates is: "+spf);
46        System.out.println("Let's parse...");
47        spf.newSAXParser().parse(f, new org.xml.sax.helpers.DefaultHandler());
48        System.out.println("Done. And then DOM build:");
49
50        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(f);
51
52        System.out.println("Succesfully built DOM tree from '"+f+"', -> "+doc);
53    }
54}
55