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.RESOURCE_URL_PREFIX;
5 import static com.atlassian.plugin.servlet.AbstractFileServerServlet.SERVLET_PATH;
6 import com.atlassian.plugin.Plugin;
7 import com.google.common.collect.ImmutableMap;
8
9 import java.util.Collections;
10 import java.util.Map;
11
12
13
14
15
16
17
18
19
20
21 public class SinglePluginResource implements PluginResource
22 {
23
24
25
26 static final String URL_PREFIX = PATH_SEPARATOR + SERVLET_PATH + PATH_SEPARATOR + RESOURCE_URL_PREFIX;
27
28 private final String resourceName;
29 private final String moduleCompleteKey;
30 private final boolean cached;
31 private final Map<String, String> params;
32
33 public SinglePluginResource(final String resourceName, final String moduleCompleteKey, final boolean cached)
34 {
35 this(resourceName, moduleCompleteKey, cached, Collections.<String, String>emptyMap());
36 }
37
38 public SinglePluginResource(final String resourceName, final String moduleCompleteKey, final boolean cached, final Map<String, String> params)
39 {
40 this.resourceName = resourceName;
41 this.moduleCompleteKey = moduleCompleteKey;
42 this.cached = cached;
43 this.params = ImmutableMap.copyOf(params);
44 }
45
46 public String getResourceName()
47 {
48 return resourceName;
49 }
50
51 public String getModuleCompleteKey()
52 {
53 return moduleCompleteKey;
54 }
55
56 public Map<String, String> getParams()
57 {
58 return params;
59 }
60
61 public String getVersion(WebResourceIntegration integration)
62 {
63 final Plugin plugin = integration.getPluginAccessor().getEnabledPluginModule(getModuleCompleteKey()).getPlugin();
64 return plugin.getPluginInformation().getVersion();
65 }
66
67 public boolean isCacheSupported()
68 {
69 return cached;
70 }
71
72
73
74
75
76
77 public String getUrl()
78 {
79 return URL_PREFIX + PATH_SEPARATOR + moduleCompleteKey + PATH_SEPARATOR + resourceName;
80 }
81 }