(no commit message)
[jalview.git] / forester / java / src / org / forester / io / parsers / phyloxml / PhyloXmlHandler.java
index c4c5be2..3e2f6a7 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;
 
@@ -55,9 +55,11 @@ import org.forester.phylogeny.data.Date;
 import org.forester.phylogeny.data.Distribution;
 import org.forester.phylogeny.data.Event;
 import org.forester.phylogeny.data.Identifier;
+import org.forester.phylogeny.data.NodeVisualData;
 import org.forester.phylogeny.data.PhylogenyDataUtil;
 import org.forester.phylogeny.data.PropertiesMap;
 import org.forester.phylogeny.data.Property;
+import org.forester.phylogeny.data.Property.AppliesTo;
 import org.forester.phylogeny.data.Reference;
 import org.forester.phylogeny.data.Sequence;
 import org.forester.phylogeny.data.SequenceRelation;
@@ -120,6 +122,9 @@ public final class PhyloXmlHandler extends DefaultHandler {
                 catch ( final PhylogenyParserException ex ) {
                     throw new SAXException( ex.getMessage() );
                 }
+                catch ( final PhyloXmlDataFormatException e ) {
+                    throw new SAXException( e.getMessage() );
+                }
             }
             else if ( local_name.equals( PhyloXmlMapping.SEQUENCE_RELATION ) ) {
                 try {
@@ -173,7 +178,7 @@ public final class PhyloXmlHandler extends DefaultHandler {
                         }
                     }
                 }
-                catch ( final PhylogenyParserException ex ) {
+                catch ( final PhyloXmlDataFormatException ex ) {
                     throw new SAXException( ex.getMessage() );
                 }
             }
@@ -181,8 +186,11 @@ public final class PhyloXmlHandler extends DefaultHandler {
                 try {
                     PhyloXmlHandler.mapElementToPhylogeny( getCurrentXmlElement(), getCurrentPhylogeny() );
                 }
-                catch ( final PhylogenyParserException ex ) {
-                    throw new SAXException( ex.getMessage() );
+                catch ( final PhylogenyParserException e ) {
+                    throw new SAXException( e.getMessage() );
+                }
+                catch ( final PhyloXmlDataFormatException e ) {
+                    throw new SAXException( e.getMessage() );
                 }
                 finishPhylogeny();
                 reset();
@@ -245,7 +253,7 @@ public final class PhyloXmlHandler extends DefaultHandler {
     }
 
     private void mapElementToPhylogenyNode( final XmlElement xml_element, final PhylogenyNode node )
-            throws PhylogenyParserException {
+            throws PhylogenyParserException, PhyloXmlDataFormatException {
         if ( xml_element.isHasAttribute( PhyloXmlMapping.BRANCH_LENGTH ) ) {
             double d = 0;
             try {
@@ -301,7 +309,7 @@ public final class PhyloXmlHandler extends DefaultHandler {
             }
             else if ( qualified_name.equals( PhyloXmlMapping.BINARY_CHARACTERS ) ) {
                 node.getNodeData().setBinaryCharacters( ( BinaryCharacters ) BinaryCharactersParser.getInstance()
-                        .parse( element ) );
+                                                        .parse( element ) );
             }
             else if ( qualified_name.equals( PhyloXmlMapping.COLOR ) ) {
                 node.getBranchData().setBranchColor( ( BranchColor ) ColorParser.getInstance().parse( element ) );
@@ -316,11 +324,20 @@ public final class PhyloXmlHandler extends DefaultHandler {
                 node.getNodeData().setEvent( ( Event ) EventParser.getInstance().parse( element ) );
             }
             else if ( qualified_name.equals( PhyloXmlMapping.PROPERTY ) ) {
-                if ( !node.getNodeData().isHasProperties() ) {
-                    node.getNodeData().setProperties( new PropertiesMap() );
+                final Property prop = ( Property ) PropertyParser.getInstance().parse( element );
+                if ( prop.getRef().startsWith( NodeVisualData.APTX_VISUALIZATION_REF )
+                        && ( prop.getAppliesTo() == AppliesTo.NODE ) ) {
+                    if ( node.getNodeData().getNodeVisualData() == null ) {
+                        node.getNodeData().setNodeVisualData( new NodeVisualData() );
+                    }
+                    node.getNodeData().getNodeVisualData().parseProperty( prop );
+                }
+                else {
+                    if ( !node.getNodeData().isHasProperties() ) {
+                        node.getNodeData().setProperties( new PropertiesMap() );
+                    }
+                    node.getNodeData().getProperties().addProperty( prop );
                 }
-                node.getNodeData().getProperties()
-                        .addProperty( ( Property ) PropertyParser.getInstance().parse( element ) );
             }
         }
     }
@@ -389,15 +406,15 @@ public final class PhyloXmlHandler extends DefaultHandler {
                 final XmlElement element = new XmlElement( namespace_uri, local_name, local_name, attributes );
                 if ( element.isHasAttribute( PhyloXmlMapping.PHYLOGENY_IS_REROOTABLE_ATTR ) ) {
                     getCurrentPhylogeny().setRerootable( Boolean.parseBoolean( element
-                            .getAttribute( PhyloXmlMapping.PHYLOGENY_IS_REROOTABLE_ATTR ) ) );
+                                                                               .getAttribute( PhyloXmlMapping.PHYLOGENY_IS_REROOTABLE_ATTR ) ) );
                 }
                 if ( element.isHasAttribute( PhyloXmlMapping.PHYLOGENY_BRANCHLENGTH_UNIT_ATTR ) ) {
                     getCurrentPhylogeny()
-                            .setDistanceUnit( element.getAttribute( PhyloXmlMapping.PHYLOGENY_BRANCHLENGTH_UNIT_ATTR ) );
+                    .setDistanceUnit( element.getAttribute( PhyloXmlMapping.PHYLOGENY_BRANCHLENGTH_UNIT_ATTR ) );
                 }
                 if ( element.isHasAttribute( PhyloXmlMapping.PHYLOGENY_IS_ROOTED_ATTR ) ) {
                     getCurrentPhylogeny().setRooted( Boolean.parseBoolean( element
-                            .getAttribute( PhyloXmlMapping.PHYLOGENY_IS_ROOTED_ATTR ) ) );
+                                                                           .getAttribute( PhyloXmlMapping.PHYLOGENY_IS_ROOTED_ATTR ) ) );
                 }
                 if ( element.isHasAttribute( PhyloXmlMapping.PHYLOGENY_TYPE_ATTR ) ) {
                     getCurrentPhylogeny().setType( ( element.getAttribute( PhyloXmlMapping.PHYLOGENY_TYPE_ATTR ) ) );
@@ -440,7 +457,7 @@ public final class PhyloXmlHandler extends DefaultHandler {
     }
 
     private static void mapElementToPhylogeny( final XmlElement xml_element, final Phylogeny phylogeny )
-            throws PhylogenyParserException {
+            throws PhylogenyParserException, PhyloXmlDataFormatException {
         for( int i = 0; i < xml_element.getNumberOfChildElements(); ++i ) {
             final XmlElement element = xml_element.getChildElement( i );
             final String qualified_name = element.getQualifiedName();