From: Egon W. <eg...@us...> - 2004-03-21 20:57:49
|
Update of /cvsroot/woc/dadml/src/org/openscience/dadml/filereaders In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20762/src/org/openscience/dadml/filereaders Modified Files: DBDEFFileReader.java DBLISTFileReader.java Log Message: DBDEF and DBLIST readers now can work with GNUJAXP and SUN's XML Reader too Index: DBDEFFileReader.java =================================================================== RCS file: /cvsroot/woc/dadml/src/org/openscience/dadml/filereaders/DBDEFFileReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** DBDEFFileReader.java 21 Mar 2004 19:09:51 -0000 1.2 --- DBDEFFileReader.java 21 Mar 2004 20:47:29 -0000 1.3 *************** *** 13,16 **** --- 13,18 ---- public class DBDEFFileReader { + private XMLReader parser; + public DBDEFFileReader() { } *************** *** 36,42 **** private DBDEF read(InputStream is) throws Exception { ! XMLReader parser = (XMLReader)this.getClass().getClassLoader(). ! loadClass("org.apache.xerces.parsers.SAXParser"). ! newInstance(); DBDEFHandler handler = new DBDEFHandler(); parser.setContentHandler(handler); --- 38,42 ---- private DBDEF read(InputStream is) throws Exception { ! initReader(); DBDEFHandler handler = new DBDEFHandler(); parser.setContentHandler(handler); *************** *** 45,47 **** --- 45,89 ---- return dbdef; } + + private void initReader() { + boolean success = false; + // Aelfred is prefered. + if (!success) { + try { + parser = (XMLReader)this.getClass().getClassLoader(). + loadClass("gnu.xml.aelfred2.XmlReader"). + newInstance(); + success = true; + } catch (Exception e) { + System.out.println("Could not instantiate Aelfred2 XML reader:" + e.getMessage()); + } + } + // If Aelfred is not available try Xerces + if (!success) { + try { + parser = (XMLReader)this.getClass().getClassLoader(). + loadClass("org.apache.xerces.parsers.SAXParser"). + newInstance(); + success = true; + } catch (Exception e) { + System.out.println("Could not instantiate Xerces XML reader:" + e.getMessage()); + } + } + // If Xerces is not available try JAXP + if (!success) { + try { + javax.xml.parsers.SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + javax.xml.parsers.SAXParser saxParser = spf.newSAXParser(); + parser = saxParser.getXMLReader(); + success = true; + } catch (Exception e) { + System.out.println("Could not instantiate JAXP/SAX XML reader:" + e.getMessage()); + } + } + if (!success) { + System.out.println("Could not instantiate an XML parser!"); + } + } + } Index: DBLISTFileReader.java =================================================================== RCS file: /cvsroot/woc/dadml/src/org/openscience/dadml/filereaders/DBLISTFileReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** DBLISTFileReader.java 21 Mar 2004 19:09:51 -0000 1.2 --- DBLISTFileReader.java 21 Mar 2004 20:47:29 -0000 1.3 *************** *** 13,16 **** --- 13,18 ---- public class DBLISTFileReader { + private XMLReader parser; + public DBLISTFileReader() { } *************** *** 36,42 **** private DBLIST read(InputStream is) throws Exception { ! XMLReader parser = (XMLReader)this.getClass().getClassLoader(). ! loadClass("org.apache.xerces.parsers.SAXParser"). ! newInstance(); DBLISTHandler handler = new DBLISTHandler(); parser.setContentHandler(handler); --- 38,42 ---- private DBLIST read(InputStream is) throws Exception { ! initReader(); DBLISTHandler handler = new DBLISTHandler(); parser.setContentHandler(handler); *************** *** 45,47 **** --- 45,89 ---- return dblist; } + + private void initReader() { + boolean success = false; + // Aelfred is prefered. + if (!success) { + try { + parser = (XMLReader)this.getClass().getClassLoader(). + loadClass("gnu.xml.aelfred2.XmlReader"). + newInstance(); + success = true; + } catch (Exception e) { + System.out.println("Could not instantiate Aelfred2 XML reader:" + e.getMessage()); + } + } + // If Aelfred is not available try Xerces + if (!success) { + try { + parser = (XMLReader)this.getClass().getClassLoader(). + loadClass("org.apache.xerces.parsers.SAXParser"). + newInstance(); + success = true; + } catch (Exception e) { + System.out.println("Could not instantiate Xerces XML reader:" + e.getMessage()); + } + } + // If Xerces is not available try JAXP + if (!success) { + try { + javax.xml.parsers.SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + javax.xml.parsers.SAXParser saxParser = spf.newSAXParser(); + parser = saxParser.getXMLReader(); + success = true; + } catch (Exception e) { + System.out.println("Could not instantiate JAXP/SAX XML reader:" + e.getMessage()); + } + } + if (!success) { + System.out.println("Could not instantiate an XML parser!"); + } + } + } |