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
6 import java.util.Collections;
7 import java.util.HashSet;
8 import java.util.List;
9 import java.util.Map;
10 import java.util.Set;
11
12 import com.google.common.collect.ImmutableMap;
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 class ContextBatchPluginResource implements PluginResource
29 {
30 static final String URL_PREFIX = PATH_SEPARATOR + SERVLET_PATH + PATH_SEPARATOR + "contextbatch" + PATH_SEPARATOR;
31
32 private final ResourceKey resource;
33 private final String key;
34 private final String hash;
35 private final List<String> contexts;
36 private final Iterable<String> excludedContexts;
37 private final Map<String, String> params;
38 private final Set<BatchedWebResourceDescriptor> batchedWebResourceDescriptors;
39
40 ContextBatchPluginResource(final String key, List<String> contexts, final Iterable<String> excludedContexts,
41 final String hash, final String type, final Map<String, String> params, Set<BatchedWebResourceDescriptor> batchedWebResourceDescriptor)
42 {
43 resource = ResourceKey.Builder.batch(type);
44 this.params = ImmutableMap.copyOf(params);
45 this.key = key;
46 this.hash = hash;
47 this.contexts = contexts;
48 this.excludedContexts = excludedContexts;
49 this.batchedWebResourceDescriptors = Collections.unmodifiableSet(batchedWebResourceDescriptor);
50 }
51
52 ContextBatchPluginResource(final String key, final String hash, final String type, final Map<String, String> params, Set<BatchedWebResourceDescriptor> batchedWebResourceDescriptor)
53 {
54 this(key, Collections.<String>emptyList(), Collections.<String>emptyList(), hash, type, params, batchedWebResourceDescriptor);
55 }
56
57 Iterable<String> getContexts()
58 {
59 return contexts;
60 }
61
62 public Iterable<String> getExcludedContexts()
63 {
64 return excludedContexts;
65 }
66
67 public String getUrl()
68 {
69 final StringBuilder buf = new StringBuilder(URL_PREFIX.length() + 20);
70 buf.append(URL_PREFIX).append(getType()).append(PATH_SEPARATOR).append(key).append(PATH_SEPARATOR).append(getResourceName());
71 ResourceUtils.addParamsToUrl(buf, getParams());
72 return buf.toString();
73 }
74
75 public Map<String, String> getParams()
76 {
77 return params;
78 }
79
80 public String getVersion(final WebResourceIntegration integration)
81 {
82 return hash;
83 }
84
85 public String getType()
86 {
87 return resource.suffix();
88 }
89
90 public boolean isCacheSupported()
91 {
92 return true;
93 }
94
95 public String getResourceName()
96 {
97 return resource.name();
98 }
99
100 public String getModuleCompleteKey()
101 {
102 return "contextbatch-" + resource.name();
103 }
104
105 @Override
106 public Set<BatchedWebResourceDescriptor> getBatchedWebResourceDescriptors()
107 {
108 return batchedWebResourceDescriptors;
109 }
110
111 @Override
112 public String toString()
113 {
114 return "[Context Batch type=" + getType() + ", params=" + params + "]";
115 }
116 }