X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fhelper%2Fflattener%2FSaxDocumentParser.java;fp=dol%2Fsrc%2Fdol%2Fhelper%2Fflattener%2FSaxDocumentParser.java;h=23949913c0ec4649770ed3e79bac130e5c94758c;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/helper/flattener/SaxDocumentParser.java b/dol/src/dol/helper/flattener/SaxDocumentParser.java new file mode 100644 index 0000000..2394991 --- /dev/null +++ b/dol/src/dol/helper/flattener/SaxDocumentParser.java @@ -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){ + } + + } +