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