1 package com.atlassian.plugin.url;
2
3 import java.io.IOException;
4 import java.net.URL;
5 import java.net.URLConnection;
6 import java.net.URLStreamHandler;
7
8
9
10 public class InnerJarURLStreamHandler extends URLStreamHandler {
11 public InnerJarURLStreamHandler() {
12 }
13
14
15
16
17 public URLConnection openConnection(URL url) throws IOException {
18 return new InnerJarURLConnection(url);
19 }
20
21
22
23
24 public void parseURL(URL url, String spec, int start, int limit) {
25 String specPath = spec.substring(start,
26 limit);
27
28 String urlPath;
29
30 if (specPath.charAt(0) == '/') {
31 urlPath = specPath;
32 } else if (specPath.charAt(0) == '!') {
33 String relPath = url.getFile();
34
35 int bangLoc = relPath.lastIndexOf("!");
36
37 if (bangLoc < 0) {
38 urlPath = relPath + specPath;
39 } else {
40 urlPath = relPath.substring(0,
41 bangLoc) + specPath;
42 }
43 } else {
44 String relPath = url.getFile();
45
46 if (relPath != null) {
47 int lastSlashLoc = relPath.lastIndexOf("/");
48
49 if (lastSlashLoc < 0) {
50 urlPath = "/" + specPath;
51 } else {
52 urlPath = relPath.substring(0,
53 lastSlashLoc + 1) + specPath;
54 }
55 } else {
56 urlPath = specPath;
57 }
58 }
59
60 setURL(url, "jar", "", 0, null, null, urlPath, null, null);
61 }
62 }