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