1 package com.atlassian.plugins.codegen.modules.common.web;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.List;
6
7 import com.atlassian.plugins.codegen.modules.common.Resource;
8 import com.atlassian.plugins.codegen.modules.common.ResourcedProperties;
9
10
11
12
13 public class WebResourceProperties extends AbstractConditionsProperties implements ResourcedProperties
14 {
15 public static final String RESOURCES = "RESOURCES";
16 public static final String DEPENDENCIES = "DEPENDENCIES";
17 public static final String CONTEXTS = "CONTEXTS";
18 public static final String TRANSFORMATIONS = "TRANSFORMATIONS";
19 public static final List<String> KNOWN_CONTEXTS = initContexts();
20
21 private static List<String> initContexts()
22 {
23 List<String> contexts = new ArrayList<String>(3);
24 contexts.add("atl.general");
25 contexts.add("atl.admin");
26 contexts.add("atl.userprofile");
27
28 return Collections.unmodifiableList(contexts);
29 }
30
31 public WebResourceProperties()
32 {
33 this("My Web Resource");
34 }
35
36 public WebResourceProperties(String moduleName)
37 {
38 super(moduleName);
39 setDependencies(new ArrayList<String>());
40 setContexts(new ArrayList<String>());
41 setTransformations(new ArrayList<WebResourceTransformation>());
42 setResources(new ArrayList<Resource>());
43 }
44
45 public void setResources(List<Resource> resources)
46 {
47 put(RESOURCES, resources);
48 }
49
50 public void addResource(Resource resource)
51 {
52 getResources().add(resource);
53 }
54
55 public List<Resource> getResources()
56 {
57 return (List<Resource>) get(RESOURCES);
58 }
59
60 public void setDependencies(List<String> dependencies)
61 {
62 put(DEPENDENCIES, dependencies);
63 }
64
65 public List<String> getDependencies()
66 {
67 return (List<String>) get(DEPENDENCIES);
68 }
69
70 @SuppressWarnings(value = "unchecked")
71 public void addDependency(String dependency)
72 {
73 List<String> dependencies = (List<String>) get(DEPENDENCIES);
74 if (dependencies == null)
75 {
76 dependencies = new ArrayList<String>();
77 setDependencies(dependencies);
78 }
79
80 dependencies.add(dependency);
81 }
82
83 public void setContexts(List<String> contexts)
84 {
85 put(CONTEXTS, contexts);
86 }
87
88 public List<String> getContexts()
89 {
90 return (List<String>) get(CONTEXTS);
91 }
92
93 @SuppressWarnings(value = "unchecked")
94 public void addContext(String context)
95 {
96 List<String> contexts = (List<String>) get(CONTEXTS);
97 if (contexts == null)
98 {
99 contexts = new ArrayList<String>();
100 setContexts(contexts);
101 }
102
103 contexts.add(context);
104 }
105
106 public void setTransformations(List<WebResourceTransformation> transformations)
107 {
108 put(TRANSFORMATIONS, transformations);
109 }
110
111 public List<WebResourceTransformation> getTransformations()
112 {
113 return (List<WebResourceTransformation>) get(TRANSFORMATIONS);
114 }
115
116 @SuppressWarnings(value = "unchecked")
117 public void addTransformation(WebResourceTransformation transformation)
118 {
119 List<WebResourceTransformation> transformations = (List<WebResourceTransformation>) get(TRANSFORMATIONS);
120 if (transformations == null)
121 {
122 transformations = new ArrayList<WebResourceTransformation>();
123 setTransformations(transformations);
124 }
125
126 transformations.add(transformation);
127 }
128
129 public List<String> knownContexts()
130 {
131 return KNOWN_CONTEXTS;
132 }
133 }