X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fuk%2Fac%2Fvamsas%2Fclient%2Fsimpleclient%2FSessionUrn.java;h=36ca50a2d13070bdca68efb1cc80774b2003e870;hb=2a1989506952d17c665b046c43de2e0e02ccda84;hp=18d54501b55d5421c9f4712c4864dfeb83c66f62;hpb=734bcc2a380be2c5aa9e229936cb2e026a86dfef;p=vamsas.git diff --git a/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java b/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java index 18d5450..36ca50a 100644 --- a/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java +++ b/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java @@ -1,80 +1,111 @@ -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} - * @author jimp - * - */ -public class SessionUrn extends uk.ac.vamsas.client.SessionUrn { - /** - * a simple client session urn prefix - */ - public static final String SIMPLECLIENT="simpleclient"; - public static String VAMSASDOCUMENT="vdoc"; - static { - TYPES.put(SIMPLECLIENT, SessionUrn.class); - 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()); - //else - // super(VAMSASDOCUMENT, sessionLocation); - } - 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 -} +/* + * This file is part of the Vamsas Client version 0.1. + * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, + * Andrew Waterhouse and Dominik Lindner. + * + * Earlier versions have also been incorporated into Jalview version 2.4 + * since 2008, and TOPALi version 2 since 2007. + * + * The Vamsas Client is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The Vamsas Client is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the Vamsas Client. If not, see . + */ +package uk.ac.vamsas.client.simpleclient; + +import java.io.File; +import java.net.URI; + +import uk.ac.vamsas.client.InvalidSessionUrnException; + +/** + * SessionUrn for simpleclient sessions: simpleclient://{Absolute path to + * session directory} + * + * For simpleclient urn, it consideres as on the same machine, using the path to + * the session directory to generate the session URN + * + * @author jimp + * + */ +public class SessionUrn extends uk.ac.vamsas.client.SessionUrn { + /** + * a simple client session urn prefix + */ + public static final String SIMPLECLIENT = "simpleclient"; + + public static String VAMSASDOCUMENT = "vdoc"; + static { + TYPES.put(SIMPLECLIENT, SessionUrn.class); + 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); + } + + /** + * Generates a sessionURN from a file with a type of SIMPLECLIENT if it is a directory or VAMSASDOCUMENT if it is a file. + * + * Note: No validation is performed, either for uniqueness of resultant URI or validity of the location. + * + * @param sessionLocation + * the file object to create the sessionURN from. + * + */ + public SessionUrn(File sessionLocation) { + // TODO: refactor this and use a Urn factory - this inline switch is pretty ugly! + super((sessionLocation.isFile() ? VAMSASDOCUMENT : SIMPLECLIENT) + ,sessionLocation.getAbsoluteFile().toURI()); + } + + /** + * Generates a sessionURN bases on a vamsas session + * + * @param session + * a VamsasSession + * + * Should return the same URN string than the creation with the + * session directory + */ + public SessionUrn(VamsasSession session) { + // throws MalformedURLException { + // use URI instead of URL + super(SIMPLECLIENT, session.sessionDir.getAbsoluteFile().toURI()); + } + + /** + * TODO: LATER: think about this again. + * + * Retrieves the file associated to the current sessionURN. The sessionURN + * (URI) is based on the session directory absolute path. Use the raw path of + * the URN and change the scheme to file to generate a new file URI. Then, + * from the URI create the File object (a File object can be created from an + * uri) + * + * @return File object representing the session URN // File(urn.getPath()) + */ + public File asFile() { + String path = this.urn.getRawPath(); + + return new File(URI.create("file://" + path)); + } + // TODO: add abstract 'handler' methods for resolving the URN to a particular + // class +}