1 package com.atlassian.plugin.webresource;
2
3 import static com.atlassian.plugin.servlet.AbstractFileServerServlet.PATH_SEPARATOR;
4 import static com.atlassian.plugin.servlet.AbstractFileServerServlet.SERVLET_PATH;
5 import static com.atlassian.plugin.servlet.AbstractFileServerServlet.RESOURCE_URL_PREFIX;
6
7 import java.util.Map;
8 import java.util.Collections;
9
10
11
12
13
14
15
16 public class SinglePluginResource implements PluginResource
17 {
18
19
20
21 static final String URL_PREFIX = PATH_SEPARATOR + SERVLET_PATH + PATH_SEPARATOR + RESOURCE_URL_PREFIX;
22
23 final private String resourceName;
24 final private String moduleCompleteKey;
25 final private boolean cached;
26
27 public SinglePluginResource(String resourceName, String moduleCompleteKey, boolean cached)
28 {
29 this.resourceName = resourceName;
30 this.moduleCompleteKey = moduleCompleteKey;
31 this.cached = cached;
32 }
33
34 public String getResourceName()
35 {
36 return resourceName;
37 }
38
39 public String getModuleCompleteKey()
40 {
41 return moduleCompleteKey;
42 }
43
44 public Map<String, String> getParams()
45 {
46 return Collections.EMPTY_MAP;
47 }
48
49 public boolean isCacheSupported()
50 {
51 return cached;
52 }
53
54
55
56
57
58
59 public String getUrl()
60 {
61 return URL_PREFIX + PATH_SEPARATOR + moduleCompleteKey + PATH_SEPARATOR + resourceName;
62 }
63
64 public static boolean matches(String url)
65 {
66 return url.indexOf(URL_PREFIX) != -1;
67 }
68
69
70
71
72
73
74
75 public static SinglePluginResource parse(String url)
76 {
77 int indexOfPrefix = url.indexOf(SinglePluginResource.URL_PREFIX);
78 String libraryAndResource = url.substring(indexOfPrefix + SinglePluginResource.URL_PREFIX.length() + 1);
79
80 if (libraryAndResource.indexOf('?') != -1)
81 {
82 libraryAndResource = libraryAndResource.substring(0, libraryAndResource.indexOf('?'));
83 }
84
85 String[] parts = libraryAndResource.split("/", 2);
86
87 if (parts.length != 2)
88 return null;
89
90 return new SinglePluginResource(parts[1], parts[0], url.substring(0, indexOfPrefix).length() > 0);
91 }
92 }