From: pmarguerite Date: Fri, 15 Dec 2006 09:24:24 +0000 (+0000) Subject: SessionUrn: added a constructor to build a SessionURN from a String X-Git-Tag: Release_0.2~211 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=734bcc2a380be2c5aa9e229936cb2e026a86dfef;p=vamsas.git SessionUrn: added a constructor to build a SessionURN from a String git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@309 be28352e-c001-0410-b1a7-c7978e42abec --- diff --git a/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java b/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java index dfcd5b3..18d5450 100644 --- a/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java +++ b/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java @@ -3,6 +3,8 @@ package uk.ac.vamsas.client.simpleclient; import java.io.File; import java.net.MalformedURLException; +import uk.ac.vamsas.client.InvalidSessionUrnException; + /** * SessionUrn for simpleclient sessions: * simpleclient://{Absolute path to session directory} @@ -20,6 +22,18 @@ public class SessionUrn extends uk.ac.vamsas.client.SessionUrn { TYPES.put(SessionUrn.VAMSASDOCUMENT, SessionUrn.class); } + /** + * Creates a SessionUrn object from a String. + * The string must be a string representation of a URI + * @param urnString + * @throws InvalidSessionUrnException + */ + public SessionUrn(String urnString) throws InvalidSessionUrnException + { + super(); + this.setURN(urnString); + } + public SessionUrn(File sessionLocation) throws MalformedURLException { // TODO: LATER: implement switch to have vamsas document or simpleclient sessions for same constructor super(SIMPLECLIENT, sessionLocation.getAbsoluteFile().toURL()); @@ -29,11 +43,37 @@ public class SessionUrn extends uk.ac.vamsas.client.SessionUrn { public SessionUrn(VamsasSession session) throws MalformedURLException { super(SIMPLECLIENT, session.sessionDir.getAbsoluteFile().toURL()); } + + + + /** + * @see uk.ac.vamsas.client.SessionUrn#setURN(java.lang.String) + */ + protected void setURN(String urnString) throws NullPointerException, IllegalArgumentException { + super.setURN(urnString); + } + /** * TODO: LATER: think about this again. * @return File(urn.getPath()) */ public File asFile() { + String path = urn.getPath(); + + if ("\\".equals(File.separator)) + { + //remove last separator at last position if found + if (path.charAt(path.length() - 1) == '/')path = path.substring(0, path.length() - 1); + path = path.replaceAll("/", "\\\\"); + } + int index = path.lastIndexOf(File.separator); + /*don t remember why + if (index >-1) + {//separator found, keep last part of the urn - filename + path = path.substring(index+1, path.length()); + } + *yop + */ return new File(urn.getPath()); } // TODO: add abstract 'handler' methods for resolving the URN to a particular class