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