dol: initial dol commit
[jump.git] / dol / src / dol / helper / flattener / SaxDocumentParser.java
1 /* $Id: SaxDocumentParser.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.helper.flattener;
3
4 import java.io.File;
5 import java.io.FileInputStream;
6 import java.io.InputStream;
7
8 import org.apache.xerces.parsers.SAXParser;
9 import org.xml.sax.Attributes;
10 import org.xml.sax.ContentHandler;
11 import org.xml.sax.ErrorHandler;
12 import org.xml.sax.InputSource;
13 import org.xml.sax.SAXException;
14
15 /**
16  *
17  */
18 class SaxDocumentParser implements ContentHandler{
19
20   public ErrorHandler bc = new BugCatcher();
21   public SAXParser sp = null;
22   protected boolean foundIterator = false;
23
24   public SaxDocumentParser() {
25     try {
26       sp = new SAXParser();
27       sp.setFeature("http://xml.org/sax/features/validation",true);
28       sp.setFeature("http://apache.org/xml/features/validation/schema", true);
29       sp.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
30       sp.setErrorHandler(bc);
31       sp.setContentHandler(this);
32       sp.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
33                      dol.util.SchemaLocation.getInternalSchemaLocation());
34     }
35     catch (Exception ex) {
36       ex.printStackTrace();
37     }
38   }
39
40   public boolean parseDocument(String pathToFile){
41     return parseDocument(new File(pathToFile));
42   }
43
44   public boolean parseDocument(File file){
45     try{
46         InputStream is = new FileInputStream(file);
47         InputSource iss = new InputSource(is);
48         sp.parse(iss);
49     }
50     catch (Exception e){
51         e.printStackTrace();
52     }
53     return true;//foundIterator;
54   }
55
56     /**
57      * Action to be done while parsing a start element of an XML
58      *
59      * @param  elementName Description of the Parameter
60      * @param  attributes Description of the Parameter
61      * @exception  SAXException MyException If such and such occurs
62      */
63     public void startElement(String namespaceURI, String localName, String elementName, Attributes attributes) throws SAXException {
64
65       if (elementName.equals("iterator")) {
66           //System.out.println();
67           //System.out.println("Iterator found in document");
68           foundIterator = true;
69       }
70       else {
71           System.out.print(".");
72       }
73     }
74
75
76     public void startDocument() throws SAXException {
77     }
78
79     public void startPrefixMapping(String prefix, String uri) throws  SAXException {
80     }
81
82     public void endDocument() throws SAXException {
83     }
84
85     public void endElement(String namespaceURI, String localName, String elementName) throws SAXException {
86     }
87
88     public void endPrefixMapping(String prefix) throws SAXException {
89     }
90
91     public void characters(char buf[], int offset, int len) throws SAXException {
92     }
93
94     public void skippedEntity(String string){
95     }
96
97     public void processingInstruction(String string1, String string2){
98     }
99
100     public void ignorableWhitespace(char[] characters,int int1,int int2){
101     }
102
103     public void setDocumentLocator(org.xml.sax.Locator dl){
104     }
105
106   }
107