Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
tpietzsch committed Oct 15, 2024
1 parent dce2595 commit 946d880
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions src/main/java/mpicbg/spim/data/XmlHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,20 @@ else if ( values.length == 12 )
public static File loadPath( final Element parent, final String name, final String defaultRelativePath, final File basePath )
{
final Element elem = parent.getChild( name );
final String path = ( elem == null ) ? defaultRelativePath : elem.getText();
final boolean isRelative = ( elem == null ) || elem.getAttributeValue( "type" ).equals( "relative" );
final String path;
final boolean isRelative;
if ( elem == null )
{
if ( defaultRelativePath == null )
return null;
path = defaultRelativePath;
isRelative = true;
}
else
{
path = elem.getText();
isRelative = "relative".equals( elem.getAttributeValue( "type" ) );
}
if ( isRelative )
{
if ( basePath == null )
Expand Down Expand Up @@ -332,29 +344,14 @@ public static URI loadPathURI( final Element parent, final String name, final St

public static File loadPath( final Element parent, final String name, final File basePath )
{
final Element elem = parent.getChild( name );
if ( elem == null )
return null;
final String path = elem.getText();
final String pathType = elem.getAttributeValue( "type" );
final boolean isRelative = null != pathType && pathType.equals( "relative" );
if ( isRelative )
{
if ( basePath == null )
return null;
else
return new File( basePath + "/" + path );
}
else
return new File( path );
return loadPath( parent, name, null, basePath );
}

public static URI loadPathURI( final Element parent, final String name, final URI basePath )
{
return loadPathURI( parent, name, null, basePath );
}


/**
* @return {@code true} if the path under {@code parent/name} is stored relative, {@code false} if absolute.
*/
Expand All @@ -363,10 +360,7 @@ public static boolean isPathRelative( final Element parent, final String name )
final Element elem = parent.getChild( name );
if ( elem == null )
return false;
final String path = elem.getText();
final String pathType = elem.getAttributeValue( "type" );
final boolean isRelative = null != pathType && pathType.equals( "relative" );
return isRelative;
return "relative".equals( elem.getAttributeValue( "type" ) );
}

/**
Expand Down

0 comments on commit 946d880

Please sign in to comment.