From eec1ca215392724c45288e6bd6fb4b8319d5fa18 Mon Sep 17 00:00:00 2001 From: Marko Strukelj Date: Tue, 29 Jul 2008 20:49:01 +0000 Subject: [PATCH] Added getCompatibleURI() method --- src/main/java/org/jboss/virtual/VFSUtils.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main/java/org/jboss/virtual/VFSUtils.java b/src/main/java/org/jboss/virtual/VFSUtils.java index 79a3df78..3d15ac74 100644 --- a/src/main/java/org/jboss/virtual/VFSUtils.java +++ b/src/main/java/org/jboss/virtual/VFSUtils.java @@ -732,4 +732,37 @@ public static URL getCompatibleURL(VirtualFile file) throws IOException, URISynt } return url; } + + /** + * Get spec compatilbe uri from virtual file. + * + * @param file the virtual file + * @return spec compatible uri + * @throws IOException for any error + * @throws URISyntaxException for any uri syntax error + */ + public static URI getCompatibleURI(VirtualFile file) throws IOException, URISyntaxException + { + if (file == null) + throw new IllegalArgumentException("Null file"); + + URI uri = file.toURI(); + if (uri == null) + throw new IllegalArgumentException("Null uri: " + file); + + // is not nested, so direct VFS URL is not an option + if (isNestedFile(file) == false) + { + String uriString = uri.toString(); + if (uriString.startsWith("vfs")) + { + // treat vfszip as file + if (uriString.startsWith("vfszip")) + uri = new URI("file" + uriString.substring(6)); + else + uri = new URI(uriString.substring(3)); // (vfs)file and (vfs)jar are ok + } + } + return uri; + } }