(no commit message)
[jalview.git] / forester / java / src / org / forester / io / parsers / phyloxml / PhyloXmlParser.java
index 5c08974..4779189 100644 (file)
@@ -21,7 +21,7 @@
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 //
 // Contact: phylosoft @ gmail . com
-// WWW: www.phylosoft.org/forester
+// WWW: https://sites.google.com/site/cmzmasek/home/software/forester
 
 package org.forester.io.parsers.phyloxml;
 
@@ -75,7 +75,7 @@ public class PhyloXmlParser implements PhylogenyParser {
     private StringBuffer         _error_messages;
     private StringBuffer         _warning_messages;
 
-    public PhyloXmlParser() {
+    private PhyloXmlParser() {
         init();
         reset();
     }
@@ -182,7 +182,7 @@ public class PhyloXmlParser implements PhylogenyParser {
                     final Reader reader = getReaderFromZipFile();
                     if ( reader == null ) {
                         throw new PhylogenyParserException( "zip file \"" + getSource()
-                                + "\" appears not to contain any entries" );
+                                                            + "\" appears not to contain any entries" );
                     }
                     xml_reader.parse( new InputSource( reader ) );
                 }
@@ -193,18 +193,12 @@ public class PhyloXmlParser implements PhylogenyParser {
             else if ( getSource() instanceof InputStream ) {
                 if ( !isZippedInputstream() ) {
                     final InputStream is = ( InputStream ) getSource();
-                    final Reader reader = new InputStreamReader( is );
-                    xml_reader.parse( new InputSource( reader ) );
+                    xml_reader.parse( new InputSource( new InputStreamReader( is ) ) );
                 }
                 else {
                     final ZipInputStream zip_is = new ZipInputStream( ( InputStream ) getSource() );
                     zip_is.getNextEntry();
-                    final Reader reader = new InputStreamReader( zip_is );
-                    if ( reader == null ) {
-                        throw new PhylogenyParserException( "zip input stream \"" + getSource()
-                                + "\" appears not to contain any (phyloXML) data" );
-                    }
-                    xml_reader.parse( new InputSource( reader ) );
+                    xml_reader.parse( new InputSource( new InputStreamReader( zip_is ) ) );
                 }
             }
             else if ( getSource() instanceof String ) {
@@ -230,7 +224,7 @@ public class PhyloXmlParser implements PhylogenyParser {
         }
         catch ( final ParserConfigurationException parser_config_exception ) {
             throw new PhylogenyParserException( "failed to parse [" + getSource()
-                    + "]. Problem with XML parser configuration: " + parser_config_exception.getLocalizedMessage() );
+                                                + "]. Problem with XML parser configuration: " + parser_config_exception.getLocalizedMessage() );
         }
         catch ( final IOException e ) {
             throw new PhylogenyParserException( "problem with input source: " + e.getLocalizedMessage() );
@@ -285,6 +279,11 @@ public class PhyloXmlParser implements PhylogenyParser {
         return xml_parser;
     }
 
+    public static PhyloXmlParser createPhyloXmlParser() {
+        final PhyloXmlParser xml_parser = new PhyloXmlParser();
+        return xml_parser;
+    }
+
     private class PhyloXmlParserErrorHandler extends DefaultHandler {
 
         @Override
@@ -312,4 +311,9 @@ public class PhyloXmlParser implements PhylogenyParser {
             _warning_messages.append( "[line: " + e.getLineNumber() + "] " + e.getMessage() );
         }
     }
+
+    @Override
+    public String getName() {
+        return "phyloXML Parser";
+    }
 }