1 /* $Id: XmlParser.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.parser.xml;
4 import java.net.MalformedURLException;
7 import org.apache.xerces.parsers.SAXParser;
8 import org.xml.sax.SAXException;
10 import dol.main.UserInterface;
13 * Parser for DOL XML files.
15 public class XmlParser extends org.xml.sax.helpers.DefaultHandler {
18 * Constructor. Initializes the parser.
23 _parser = new SAXParser();
24 _parser.setFeature("http://xml.org/sax/features/validation",
26 _parser.setFeature("http://apache.org/xml/features/"
27 + "validation/schema", true);
28 _parser.setFeature("http://apache.org/xml/features/"
29 + "validation/schema-full-checking", true);
30 _parser.setErrorHandler(new XmlErrorHandler());
31 _parser.setContentHandler(this);
32 _parser.setProperty("http://apache.org/xml/properties/schema/"
33 + "external-schemaLocation",
34 dol.util.SchemaLocation.getInternalSchemaLocation());
35 _parser.setContentHandler(this);
36 _parser.setErrorHandler(new XmlErrorHandler());
37 } catch (SAXException e) {
39 } catch (Throwable t) {
45 * Return a absolute URL reference for the given URL.
48 * @return absolute URL reference
50 protected String _makeAbsoluteURL(String url)
51 throws MalformedURLException {
53 String fileSep = System.getProperty("file.separator");
56 // Replace all separators in given URL
57 url = url.replace(fileSep.charAt(0), '/');
59 // Add working directory if URL is not absolute
60 if (url.charAt(0) != '/' && !url.matches("^[A-Za-z]:/.*")) {
61 base = System.getProperty("user.dir") + '/';
62 base = base.replace(fileSep.charAt(0), '/');
63 if (base.charAt(0) != '/') {
68 // Add front slash to Windows style URLs
69 if (url.matches("^[A-Za-z]:/.*")) {
73 baseURL = new URL("file", null, base);
74 System.out.println(" -- full filename: "
75 + new URL(baseURL, url).toString());
76 return new URL(baseURL, url).toString();
80 protected SAXParser _parser;
82 /** user interface used for messages for users */
83 protected UserInterface _ui = UserInterface.getInstance();