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) {
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();
}
import java.io.File;
import java.net.MalformedURLException;
+import java.net.URI;
import uk.ac.vamsas.client.InvalidSessionUrnException;
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);
}
* @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
}