From 56897503b2dfa9a5743d3032f970d1e9b86fc7a6 Mon Sep 17 00:00:00 2001 From: pmarguerite Date: Fri, 15 Dec 2006 15:46:51 +0000 Subject: [PATCH] SessionUrn: modified to scope with windows (space ... in file name. Use URI instead of URL git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@324 be28352e-c001-0410-b1a7-c7978e42abec --- src/uk/ac/vamsas/client/SessionUrn.java | 17 ++++++++++- .../ac/vamsas/client/simpleclient/SessionUrn.java | 30 ++++++++++++-------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/uk/ac/vamsas/client/SessionUrn.java b/src/uk/ac/vamsas/client/SessionUrn.java index 158389c..54f7226 100644 --- a/src/uk/ac/vamsas/client/SessionUrn.java +++ b/src/uk/ac/vamsas/client/SessionUrn.java @@ -34,7 +34,7 @@ public abstract class SessionUrn { if (!TYPES.containsKey(type.toLowerCase())) throw new Error("Unknown "+this.getClass().getName()+" type '"+type+"' for URL '"+url+"'"); try { - //urn = URI.create(type+"://"+urlString); + this.setURN(type+"://"+url.getPath()); // urn = URI.create(type+"://"+url.getPath()); } catch (Exception e) { @@ -43,6 +43,21 @@ public abstract class SessionUrn { throw new Error(e); } } + + protected SessionUrn(String type, URI uri) { + if (!TYPES.containsKey(type.toLowerCase())) + throw new Error("Unknown "+this.getClass().getName()+" type '"+type+"' for URI '"+uri+"'"); + try { + // this.setURN(type+"://"+uri.getPath()); + //bad hack but should do the trick + this.setURN(type+"://"+uri.getRawPath()); + } catch (Exception e) { + // TODO: something better than throwing an error should be done here. + e.printStackTrace(System.err); + throw new Error(e); + } + } + public String getSessionUrn() { return this.urn.toString(); } diff --git a/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java b/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java index 18d5450..4098e17 100644 --- a/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java +++ b/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java @@ -2,6 +2,7 @@ package uk.ac.vamsas.client.simpleclient; import java.io.File; import java.net.MalformedURLException; +import java.net.URI; import uk.ac.vamsas.client.InvalidSessionUrnException; @@ -34,9 +35,13 @@ public class SessionUrn extends uk.ac.vamsas.client.SessionUrn { 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()); + // super(SIMPLECLIENT, sessionLocation.getAbsoluteFile().toURL()); + // super(SIMPLECLIENT, sessionLocation.getAbsoluteFile().toURL()); + super(SIMPLECLIENT, sessionLocation.getAbsoluteFile().toURI()); //else // super(VAMSASDOCUMENT, sessionLocation); } @@ -58,23 +63,24 @@ public class SessionUrn extends uk.ac.vamsas.client.SessionUrn { * @return File(urn.getPath()) */ public File asFile() { - String path = urn.getPath(); + String path = this.urn.getRawPath(); 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); + /* not needed anymore if (path.charAt(path.length() - 1) == '/')path = path.substring(0, path.length() - 1); path = path.replaceAll("/", "\\\\"); + */ + int index = path.indexOf(File.separator); + + if (index >-1) + {//separator found, keep last part of the urn - filename + path = path.substring(index+1, path.length()); + } } - 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()); + /*shall we use URI or String to create the object*/ + /* from URI : URI.create("file://path") , but first / */ + return new File(path); } // TODO: add abstract 'handler' methods for resolving the URN to a particular class } -- 1.7.10.2