Skip to content

Commit 946d880

Browse files
committed
simplify
1 parent dce2595 commit 946d880

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

src/main/java/mpicbg/spim/data/XmlHelpers.java

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,20 @@ else if ( values.length == 12 )
271271
public static File loadPath( final Element parent, final String name, final String defaultRelativePath, final File basePath )
272272
{
273273
final Element elem = parent.getChild( name );
274-
final String path = ( elem == null ) ? defaultRelativePath : elem.getText();
275-
final boolean isRelative = ( elem == null ) || elem.getAttributeValue( "type" ).equals( "relative" );
274+
final String path;
275+
final boolean isRelative;
276+
if ( elem == null )
277+
{
278+
if ( defaultRelativePath == null )
279+
return null;
280+
path = defaultRelativePath;
281+
isRelative = true;
282+
}
283+
else
284+
{
285+
path = elem.getText();
286+
isRelative = "relative".equals( elem.getAttributeValue( "type" ) );
287+
}
276288
if ( isRelative )
277289
{
278290
if ( basePath == null )
@@ -332,29 +344,14 @@ public static URI loadPathURI( final Element parent, final String name, final St
332344

333345
public static File loadPath( final Element parent, final String name, final File basePath )
334346
{
335-
final Element elem = parent.getChild( name );
336-
if ( elem == null )
337-
return null;
338-
final String path = elem.getText();
339-
final String pathType = elem.getAttributeValue( "type" );
340-
final boolean isRelative = null != pathType && pathType.equals( "relative" );
341-
if ( isRelative )
342-
{
343-
if ( basePath == null )
344-
return null;
345-
else
346-
return new File( basePath + "/" + path );
347-
}
348-
else
349-
return new File( path );
347+
return loadPath( parent, name, null, basePath );
350348
}
351349

352350
public static URI loadPathURI( final Element parent, final String name, final URI basePath )
353351
{
354352
return loadPathURI( parent, name, null, basePath );
355353
}
356354

357-
358355
/**
359356
* @return {@code true} if the path under {@code parent/name} is stored relative, {@code false} if absolute.
360357
*/
@@ -363,10 +360,7 @@ public static boolean isPathRelative( final Element parent, final String name )
363360
final Element elem = parent.getChild( name );
364361
if ( elem == null )
365362
return false;
366-
final String path = elem.getText();
367-
final String pathType = elem.getAttributeValue( "type" );
368-
final boolean isRelative = null != pathType && pathType.equals( "relative" );
369-
return isRelative;
363+
return "relative".equals( elem.getAttributeValue( "type" ) );
370364
}
371365

372366
/**

0 commit comments

Comments
 (0)