Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud #9

Merged
merged 10 commits into from
Jul 23, 2024
22 changes: 12 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version>31.1.0</version>
<version>37.0.0</version>
<relativePath />
</parent>

<groupId>sc.fiji</groupId>
<artifactId>spim_data</artifactId>
<version>2.2.8-SNAPSHOT</version>
<version>2.3.0-SNAPSHOT</version>

<name>SPIM Data</name>
<description>representation of multi-angle, multi-channel (etc.) SPIM images and their registration</description>
<url>http://github.com/bigdataviewer/spimdata</url>
<url>https://github.com/bigdataviewer/spimdata</url>
<inceptionYear>2013</inceptionYear>
<organization>
<name>BigDataViewer</name>
<url>https://imagej.net/BigDataViewer</url>
<url>https://imagej.net/plugins/bdv</url>
</organization>
<licenses>
<license>
<name>Simplified BSD License</name>
<url>http://opensource.org/licenses/BSD-2-Clause</url>
<url>https://opensource.org/licenses/BSD-2-Clause</url>
<distribution>repo</distribution>
</license>
</licenses>
Expand All @@ -33,7 +33,7 @@
<developer>
<id>tpietzsch</id>
<name>Tobias Pietzsch</name>
<url>https://imagej.net/User:Pietzsch</url>
<url>https://imagej.net/people/tpietzsch</url>
<roles>
<role>founder</role>
<role>lead</role>
Expand All @@ -47,7 +47,7 @@
<developer>
<id>StephanPreibisch</id>
<name>Stephan Preibisch</name>
<url>https://imagej.net/User:StephanP</url>
<url>https://imagej.net/people/StephanPreibisch</url>
<roles>
<role>founder</role>
<role>lead</role>
Expand All @@ -60,7 +60,7 @@
<developer>
<id>ctrueden</id>
<name>Curtis Rueden</name>
<url>https://imagej.net/User:Rueden</url>
<url>https://imagej.net/people/ctrueden</url>
<roles>
<role>maintainer</role>
</roles>
Expand All @@ -69,7 +69,7 @@
<contributors>
<contributor>
<name>Johannes Schindelin</name>
<url>https://imagej.net/User:Schindelin</url>
<url>https://imagej.net/people/dscho</url>
<properties><id>dscho</id></properties>
<roles><role>founder</role></roles>
</contributor>
Expand All @@ -79,7 +79,7 @@
</contributor>
<contributor>
<name>Stephan Saalfeld</name>
<url>https://imagej.net/User:Saalfeld</url>
<url>https://imagej.net/people/axtimwalde</url>
<properties><id>axtimwalde</id></properties>
</contributor>
</contributors>
Expand Down Expand Up @@ -146,6 +146,8 @@
<groupId>net.sf.trove4j</groupId>
<artifactId>trove4j</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/mpicbg/spim/data/SpimDataExample2.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
package mpicbg.spim.data;

import java.io.IOException;
import java.net.URI;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -175,7 +176,7 @@ public static void exampleSequenceDescription() throws IOException, ParseExcepti
final Document doc = new Document( io.toXml( sequence, null ) );
new XMLOutputter( Format.getPrettyFormat() ).output( doc, System.out );

final SequenceDescription fromXml = io.fromXml( doc.getRootElement(), null );
final SequenceDescription fromXml = io.fromXml( doc.getRootElement(), ( URI ) null );
new XMLOutputter( Format.getPrettyFormat() ).output( new Document( new XmlIoSequenceDescription().toXml( fromXml, null ) ), System.out );
}

Expand Down
90 changes: 89 additions & 1 deletion src/main/java/mpicbg/spim/data/XmlHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import net.imglib2.Dimensions;
import net.imglib2.FinalDimensions;
Expand Down Expand Up @@ -270,7 +272,7 @@ public static File loadPath( final Element parent, final String name, final Stri
{
final Element elem = parent.getChild( name );
final String path = ( elem == null ) ? defaultRelativePath : elem.getText();
final boolean isRelative = ( elem == null ) ? true : elem.getAttributeValue( "type" ).equals( "relative" );
final boolean isRelative = ( elem == null ) || elem.getAttributeValue( "type" ).equals( "relative" );
if ( isRelative )
{
if ( basePath == null )
Expand All @@ -282,6 +284,31 @@ public static File loadPath( final Element parent, final String name, final Stri
return new File( path );
}

public static URI loadPathURI( final Element parent, final String name, final String defaultRelativePath, final URI 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" );
if ( isRelative )
{
if ( basePath == null )
return null;
else
return basePath.resolve( path );
}
else
{
try
{
return new URI( path );
}
catch ( URISyntaxException e )
{
return null;
}
}
}

public static File loadPath( final Element parent, final String name, final File basePath )
{
final Element elem = parent.getChild( name );
Expand All @@ -301,6 +328,35 @@ public static File loadPath( final Element parent, final String name, final File
return new File( path );
}

public static URI loadPathURI( final Element parent, final String name, final URI 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 basePath.resolve( path );
}
else
{
try
{
return new URI( path );
}
catch ( URISyntaxException e )
{
return null;
}
}
}


/**
* @return {@code true} if the path under {@code parent/name} is stored relative, {@code false} if absolute.
*/
Expand Down Expand Up @@ -358,6 +414,38 @@ public static File getRelativePath( final File file, final File relativeToThis )
}
}

/**
* @param basePath if null put the absolute path, otherwise relative to this
*/
public static Element pathElementURI( final String name, final URI path, final URI basePath )
{
final Element e = new Element( name );
if ( basePath == null )
{
e.setAttribute( "type", "absolute" );
e.setText( path.normalize().toString() );
}
else
{
// Try to build a relative path. If can't, make it absolute.
URI relativePath = basePath.relativize( path ).normalize();
if ( relativePath.equals( path ) )
{
e.setAttribute( "type", "absolute" );
e.setText( path.toString() );
}
else
{
if ( relativePath.toString().isEmpty() )
relativePath = URI.create( "." );
e.setAttribute( "type", "relative" );
e.setText( relativePath.toString() );
}
}

return e;
}

private static File getRelativePath( final File file, final File relativeToThis, final String relativeInitial )
{
File parent = file;
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/mpicbg/spim/data/generic/AbstractSpimData.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
package mpicbg.spim.data.generic;

import java.io.File;
import java.net.URI;

import mpicbg.spim.data.generic.sequence.AbstractSequenceDescription;
import mpicbg.spim.data.registration.ViewRegistrations;
Expand All @@ -38,15 +39,15 @@ public class AbstractSpimData< S extends AbstractSequenceDescription< ?, ?, ? >
/**
* Relative paths in the XML should be interpreted with respect to this.
*/
private File basePath;
private URI basePathURI;

private S sequenceDescription;

private ViewRegistrations viewRegistrations;

public AbstractSpimData( final File basePath, final S sequenceDescription, final ViewRegistrations viewRegistrations )
{
this.basePath = basePath;
this.basePathURI = basePath == null ? null : basePath.toURI();
this.sequenceDescription = sequenceDescription;
this.viewRegistrations = viewRegistrations;
}
Expand All @@ -59,7 +60,12 @@ public AbstractSpimData( final File basePath, final S sequenceDescription, final
*/
public File getBasePath()
{
return basePath;
return new File( basePathURI );
}

public URI getBasePathURI()
{
return basePathURI;
}

public S getSequenceDescription()
Expand All @@ -74,7 +80,12 @@ public ViewRegistrations getViewRegistrations()

public void setBasePath( final File basePath )
{
this.basePath = basePath;
this.basePathURI = basePath.toURI();
}

public void setBasePathURI( final URI basePathURI )
{
this.basePathURI = basePathURI;
}

protected void setSequenceDescription( final S sequenceDescription )
Expand Down
Loading
Loading