X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fparser%2Fxml%2FXmlParser.java;fp=dol%2Fsrc%2Fdol%2Fparser%2Fxml%2FXmlParser.java;h=20327880b1435f52caad4bc54faef4954048376a;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/parser/xml/XmlParser.java b/dol/src/dol/parser/xml/XmlParser.java new file mode 100644 index 0000000..2032788 --- /dev/null +++ b/dol/src/dol/parser/xml/XmlParser.java @@ -0,0 +1,84 @@ +/* $Id: XmlParser.java 1 2010-02-24 13:03:05Z haidw $ */ +package dol.parser.xml; + +import java.net.MalformedURLException; +import java.net.URL; + +import org.apache.xerces.parsers.SAXParser; +import org.xml.sax.SAXException; + +import dol.main.UserInterface; + +/** + * Parser for DOL XML files. + */ +public class XmlParser extends org.xml.sax.helpers.DefaultHandler { + + /** + * Constructor. Initializes the parser. + */ + public XmlParser() { + super(); + try { + _parser = new SAXParser(); + _parser.setFeature("http://xml.org/sax/features/validation", + true); + _parser.setFeature("http://apache.org/xml/features/" + + "validation/schema", true); + _parser.setFeature("http://apache.org/xml/features/" + + "validation/schema-full-checking", true); + _parser.setErrorHandler(new XmlErrorHandler()); + _parser.setContentHandler(this); + _parser.setProperty("http://apache.org/xml/properties/schema/" + + "external-schemaLocation", + dol.util.SchemaLocation.getInternalSchemaLocation()); + _parser.setContentHandler(this); + _parser.setErrorHandler(new XmlErrorHandler()); + } catch (SAXException e) { + e.printStackTrace(); + } catch (Throwable t) { + t.printStackTrace(); + } + } + + /** + * Return a absolute URL reference for the given URL. + * + * @param url url + * @return absolute URL reference + */ + protected String _makeAbsoluteURL(String url) + throws MalformedURLException { + URL baseURL; + String fileSep = System.getProperty("file.separator"); + String base = ""; + + // Replace all separators in given URL + url = url.replace(fileSep.charAt(0), '/'); + + // Add working directory if URL is not absolute + if (url.charAt(0) != '/' && !url.matches("^[A-Za-z]:/.*")) { + base = System.getProperty("user.dir") + '/'; + base = base.replace(fileSep.charAt(0), '/'); + if (base.charAt(0) != '/') { + base = "/" + base; + } + } + + // Add front slash to Windows style URLs + if (url.matches("^[A-Za-z]:/.*")) { + url = "/" + url; + } + + baseURL = new URL("file", null, base); + System.out.println(" -- full filename: " + + new URL(baseURL, url).toString()); + return new URL(baseURL, url).toString(); + } + + /** XML parser */ + protected SAXParser _parser; + + /** user interface used for messages for users */ + protected UserInterface _ui = UserInterface.getInstance(); +}