1 package com.atlassian.plugin.webresource;
2
3 import com.atlassian.plugin.Plugin;
4 import com.google.common.collect.ImmutableMap;
5 import com.google.common.collect.ImmutableSet;
6
7 import java.util.Map;
8 import java.util.Set;
9
10 import static com.atlassian.plugin.servlet.AbstractFileServerServlet.PATH_SEPARATOR;
11 import static com.atlassian.plugin.servlet.AbstractFileServerServlet.SERVLET_PATH;
12
13
14
15
16
17
18
19
20 public class BatchPluginResource implements PluginResource
21 {
22
23
24
25 static final String URL_PREFIX = PATH_SEPARATOR + SERVLET_PATH + PATH_SEPARATOR + "batch";
26
27 private final ResourceKey resource;
28 private final Map<String, String> params;
29
30
31 private int hash = 0;
32
33 private final BatchedWebResourceDescriptor batchedWebResourceDescriptor;
34
35
36
37
38
39
40
41
42 BatchPluginResource(final ResourceKey resource, final Map<String, String> params, BatchedWebResourceDescriptor batchedWebResourceDescriptor)
43 {
44 this.resource = resource;
45 this.params = ImmutableMap.copyOf(params);
46 this.batchedWebResourceDescriptor = batchedWebResourceDescriptor;
47 }
48
49
50
51
52
53
54
55
56
57
58
59 public String getUrl()
60 {
61 final StringBuilder sb = new StringBuilder();
62 sb.append(URL_PREFIX).append(PATH_SEPARATOR).append(resource.key()).append(PATH_SEPARATOR).append(
63 resource.name());
64 ResourceUtils.addParamsToUrl(sb, params);
65 return sb.toString();
66 }
67
68
69 public String getResourceName()
70 {
71 return resource.name();
72 }
73
74 public Map<String, String> getParams()
75 {
76 return params;
77 }
78
79 public String getVersion(final WebResourceIntegration integration)
80 {
81 final Plugin plugin = integration.getPluginAccessor().getEnabledPluginModule(
82 getModuleCompleteKey()).getPlugin();
83 return plugin.getPluginInformation().getVersion();
84 }
85
86 public String getModuleCompleteKey()
87 {
88 return resource.key();
89 }
90
91 public boolean isCacheSupported()
92 {
93 return !"false".equals(params.get("cache"));
94 }
95
96 @Override
97 public String getType()
98 {
99 return resource.suffix();
100 }
101
102 @Override
103 public Set<BatchedWebResourceDescriptor> getBatchedWebResourceDescriptors()
104 {
105 return ImmutableSet.of(batchedWebResourceDescriptor);
106 }
107
108 @Override
109 public boolean equals(final Object o)
110 {
111 if (this == o)
112 {
113 return true;
114 }
115 if ((o == null) || (getClass() != o.getClass()))
116 {
117 return false;
118 }
119
120 final BatchPluginResource that = (BatchPluginResource) o;
121
122 if (params != null ? !params.equals(that.params) : that.params != null)
123 {
124 return false;
125 }
126 return resource.equals(that.resource);
127 }
128
129 @Override
130 public int hashCode()
131 {
132 if (hash == 0)
133 {
134 int result;
135 result = resource.hashCode();
136 result = 31 * result + (params != null ? params.hashCode() : 0);
137 hash = result;
138 }
139 return hash;
140 }
141
142 @Override
143 public String toString()
144 {
145 return "[moduleCompleteKey=" + resource.key() + ", type=" + resource.suffix() + ", params=" + params + "]";
146 }
147 }