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