X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Forg%2Fbiojava%2Fdasobert%2Fdas2%2Fio%2FDasSourceReaderImpl.java;h=6b6122af6203d1618ba5aaffc9b1e6239fa6612f;hb=506d60f0e188723ddc91c26824b41ac7034df3fe;hp=3f0a07aa7253a526abeec7eee836808e9a321c22;hpb=714ad67911cdd8e2078cd3e961b5d709f5f0e5ce;p=jalview.git diff --git a/src/org/biojava/dasobert/das2/io/DasSourceReaderImpl.java b/src/org/biojava/dasobert/das2/io/DasSourceReaderImpl.java index 3f0a07a..6b6122a 100755 --- a/src/org/biojava/dasobert/das2/io/DasSourceReaderImpl.java +++ b/src/org/biojava/dasobert/das2/io/DasSourceReaderImpl.java @@ -22,152 +22,161 @@ */ package org.biojava.dasobert.das2.io; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; +import java.io.*; +import java.net.*; +import javax.xml.parsers.*; +import org.biojava.dasobert.das.*; +import org.biojava.dasobert.dasregistry.*; +import org.xml.sax.*; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; +public class DasSourceReaderImpl implements DasSourceReader +{ -//import org.biojava.dasobert.das.AlignmentThread; -import org.biojava.dasobert.das.DAS_FeatureRetrieve; -import org.biojava.dasobert.dasregistry.DasSource; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.XMLReader; + Exception loggedException; -public class DasSourceReaderImpl implements DasSourceReader { + public DasSourceReaderImpl() + { + super(); + loggedException = null; - Exception loggedException; + // open the stream to a server and then parse the result ... + } - public DasSourceReaderImpl() { - super(); - loggedException = null; + private InputStream open(URL url) throws java.io.IOException, + java.net.ConnectException + { + InputStream inStream = null; - // open the stream to a server and then parse the result ... - } - - private InputStream open(URL url) - throws java.io.IOException, java.net.ConnectException - { - InputStream inStream = null; + HttpURLConnection huc = DAS_FeatureRetrieve.openHttpURLConnection(url); + inStream = huc.getInputStream(); - HttpURLConnection huc = DAS_FeatureRetrieve.openHttpURLConnection(url); + return inStream; - inStream = huc.getInputStream(); + } - return inStream; - - } + public DasSource[] readDasSource(URL url) + { + DasSource[] sources = new DasSource[0]; + try + { + InputStream stream = open(url); - public DasSource[] readDasSource(URL url){ - DasSource[] sources = new DasSource[0]; - - try { - InputStream stream = open(url); - - sources = readDasSource(stream); - } catch (Exception e){ - e.printStackTrace(); - loggedException = e; - } - return sources; + sources = readDasSource(stream); + } catch (Exception e) + { + e.printStackTrace(); + loggedException = e; } + return sources; + } - /** read a DAS2 sources response and return a list of DAS sources. - * - */ - public DasSource[] readDasSource(InputStream stream) { - - DasSource[] sources = new DasSource[0]; - - try { - SAXParserFactory spfactory = - SAXParserFactory.newInstance(); - - spfactory.setValidating(false); - - SAXParser saxParser = null ; - - try{ - saxParser = - spfactory.newSAXParser(); - } catch (ParserConfigurationException e) { - e.printStackTrace(); - loggedException = e; - } - - String vali = System.getProperty("XMLVALIDATION"); - - boolean validation = false ; - if ( vali != null ) - if ( vali.equals("true") ) - validation = true ; + /** + * read a DAS2 sources response and return a list of DAS sources. + * + */ + public DasSource[] readDasSource(InputStream stream) + { + DasSource[] sources = new DasSource[0]; - XMLReader xmlreader = saxParser.getXMLReader(); - - //XMLReader xmlreader = XMLReaderFactory.createXMLReader(); - try { - xmlreader.setFeature("http://xml.org/sax/features/validation", validation); - } catch (SAXException e) { - //logger.log(Level.FINE,"Cannot set validation " + validation); - } - - try { - xmlreader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",validation); - } catch (SAXNotRecognizedException e){ - e.printStackTrace(); - //logger.log(Level.FINE,"Cannot set load-external-dtd "+validation); - - } - - DAS2SourceHandler cont_handle = new DAS2SourceHandler() ; - - xmlreader.setContentHandler(cont_handle); - xmlreader.setErrorHandler(new org.xml.sax.helpers.DefaultHandler()); - InputSource insource = new InputSource() ; - insource.setByteStream(stream); + try + { + SAXParserFactory spfactory = SAXParserFactory.newInstance(); + spfactory.setValidating(false); - xmlreader.parse(insource); - sources = cont_handle.getSources(); + SAXParser saxParser = null; + try + { + saxParser = spfactory.newSAXParser(); + } catch (ParserConfigurationException e) + { + e.printStackTrace(); + loggedException = e; + } + String vali = System.getProperty("XMLVALIDATION"); - } catch (Exception e) { - e.printStackTrace(); - loggedException = e; + boolean validation = false; + if (vali != null) + { + if (vali.equals("true")) + { + validation = true; } - return sources; - } - - public Exception getLoggedException(){ - return loggedException; + } + + XMLReader xmlreader = saxParser.getXMLReader(); + + // XMLReader xmlreader = XMLReaderFactory.createXMLReader(); + try + { + xmlreader.setFeature("http://xml.org/sax/features/validation", + validation); + } catch (SAXException e) + { + // logger.log(Level.FINE,"Cannot set validation " + validation); + } + + try + { + xmlreader + .setFeature( + "http://apache.org/xml/features/nonvalidating/load-external-dtd", + validation); + } catch (SAXNotRecognizedException e) + { + e.printStackTrace(); + // logger.log(Level.FINE,"Cannot set load-external-dtd "+validation); + + } + + DAS2SourceHandler cont_handle = new DAS2SourceHandler(); + + xmlreader.setContentHandler(cont_handle); + xmlreader.setErrorHandler(new org.xml.sax.helpers.DefaultHandler()); + InputSource insource = new InputSource(); + insource.setByteStream(stream); + + xmlreader.parse(insource); + sources = cont_handle.getSources(); + + } catch (Exception e) + { + e.printStackTrace(); + loggedException = e; } - - public static void main (String[] args){ - String url = "http://www.spice-3d.org/dasregistry/das2/sources/"; - DasSourceReaderImpl reader = new DasSourceReaderImpl(); - try { - URL u = new URL(url); - DasSource[] sources = reader.readDasSource(u); - for (int i=0; i< sources.length;i++){ - DasSource ds = sources[i]; - System.out.println(ds.toString()); - } - - } catch (Exception e){ - e.printStackTrace(); - } - + return sources; + } + + public Exception getLoggedException() + { + return loggedException; + } + + public static void main(String[] args) + { + String url = "http://www.spice-3d.org/dasregistry/das2/sources/"; + DasSourceReaderImpl reader = new DasSourceReaderImpl(); + try + { + URL u = new URL(url); + DasSource[] sources = reader.readDasSource(u); + for (int i = 0; i < sources.length; i++) + { + DasSource ds = sources[i]; + System.out.println(ds.toString()); + } + + } catch (Exception e) + { + e.printStackTrace(); } - + } }