dol: initial dol commit
[jump.git] / dol / src / dol / helper / flattener / SaxDocumentParser.java
diff --git a/dol/src/dol/helper/flattener/SaxDocumentParser.java b/dol/src/dol/helper/flattener/SaxDocumentParser.java
new file mode 100644 (file)
index 0000000..2394991
--- /dev/null
@@ -0,0 +1,107 @@
+/* $Id: SaxDocumentParser.java 1 2010-02-24 13:03:05Z haidw $ */
+package dol.helper.flattener;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import org.apache.xerces.parsers.SAXParser;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ *
+ */
+class SaxDocumentParser implements ContentHandler{
+
+  public ErrorHandler bc = new BugCatcher();
+  public SAXParser sp = null;
+  protected boolean foundIterator = false;
+
+  public SaxDocumentParser() {
+    try {
+      sp = new SAXParser();
+      sp.setFeature("http://xml.org/sax/features/validation",true);
+      sp.setFeature("http://apache.org/xml/features/validation/schema", true);
+      sp.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
+      sp.setErrorHandler(bc);
+      sp.setContentHandler(this);
+      sp.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
+                     dol.util.SchemaLocation.getInternalSchemaLocation());
+    }
+    catch (Exception ex) {
+      ex.printStackTrace();
+    }
+  }
+
+  public boolean parseDocument(String pathToFile){
+    return parseDocument(new File(pathToFile));
+  }
+
+  public boolean parseDocument(File file){
+    try{
+        InputStream is = new FileInputStream(file);
+        InputSource iss = new InputSource(is);
+        sp.parse(iss);
+    }
+    catch (Exception e){
+        e.printStackTrace();
+    }
+    return true;//foundIterator;
+  }
+
+    /**
+     * Action to be done while parsing a start element of an XML
+     *
+     * @param  elementName Description of the Parameter
+     * @param  attributes Description of the Parameter
+     * @exception  SAXException MyException If such and such occurs
+     */
+    public void startElement(String namespaceURI, String localName, String elementName, Attributes attributes) throws SAXException {
+
+      if (elementName.equals("iterator")) {
+          //System.out.println();
+          //System.out.println("Iterator found in document");
+          foundIterator = true;
+      }
+      else {
+          System.out.print(".");
+      }
+    }
+
+
+    public void startDocument() throws SAXException {
+    }
+
+    public void startPrefixMapping(String prefix, String uri) throws  SAXException {
+    }
+
+    public void endDocument() throws SAXException {
+    }
+
+    public void endElement(String namespaceURI, String localName, String elementName) throws SAXException {
+    }
+
+    public void endPrefixMapping(String prefix) throws SAXException {
+    }
+
+    public void characters(char buf[], int offset, int len) throws SAXException {
+    }
+
+    public void skippedEntity(String string){
+    }
+
+    public void processingInstruction(String string1, String string2){
+    }
+
+    public void ignorableWhitespace(char[] characters,int int1,int int2){
+    }
+
+    public void setDocumentLocator(org.xml.sax.Locator dl){
+    }
+
+  }
+