1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.pluto.portalImpl.om.portlet.impl;
21
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Iterator;
25 import java.util.Map;
26 import java.util.Vector;
27
28 import org.apache.pluto.om.common.ObjectID;
29 import org.apache.pluto.om.portlet.PortletApplicationDefinition;
30 import org.apache.pluto.om.portlet.PortletDefinitionList;
31 import org.apache.pluto.om.servlet.WebApplicationDefinition;
32 import org.apache.pluto.portalImpl.om.common.Support;
33 import org.apache.pluto.portalImpl.om.servlet.impl.WebApplicationDefinitionImpl;
34 import org.apache.pluto.util.StringUtils;
35
36 public class PortletApplicationDefinitionImpl
37 implements PortletApplicationDefinition, java.io.Serializable, Support {
38
39 private String GUID;
40
41 private String appId;
42 private String version;
43
44 private ArrayList customPortletMode = new ArrayList();
45 private ArrayList customPortletState = new ArrayList();
46 private ArrayList userAttribute = new ArrayList();
47 private ArrayList securityConstraint = new ArrayList();
48
49 private PortletDefinitionList portlets = new PortletDefinitionListImpl();
50
51 private WebApplicationDefinition webApplication;
52
53 private ObjectID objectId;
54
55 private String contextPath;
56
57
58
59 public ObjectID getId()
60 {
61 if (objectId==null) {
62 objectId = org.apache.pluto.portalImpl.util.ObjectID.createFromString(getGUID());
63 }
64 return objectId;
65 }
66
67 public String getVersion()
68 {
69 return version;
70 }
71
72 public PortletDefinitionList getPortletDefinitionList()
73 {
74 return portlets;
75 }
76
77 public WebApplicationDefinition getWebApplicationDefinition()
78 {
79 return webApplication;
80 }
81
82
83
84 public void postLoad(Object parameter) throws Exception
85 {
86 ((Support)portlets).postLoad(parameter);
87 }
88
89 public void preBuild(Object parameter) throws Exception
90 {
91 Vector structure = (Vector)parameter;
92 String contextRoot = (String)structure.get(0);
93 WebApplicationDefinition webApplication = (WebApplicationDefinition)structure.get(1);
94 Map servletMap = (Map)structure.get(2);
95
96 setContextRoot(contextRoot);
97
98 setWebApplicationDefinition(webApplication);
99
100 Vector structure2 = new Vector();
101 structure2.add(this);
102 structure2.add(servletMap);
103
104 ((Support)portlets).preBuild(structure2);
105
106 }
107
108 public void postBuild(Object parameter) throws Exception
109 {
110 }
111
112 public void preStore(Object parameter) throws Exception
113 {
114 ((Support)portlets).preStore(parameter);
115 }
116
117 public void postStore(Object parameter) throws Exception
118 {
119 ((Support)portlets).postStore(parameter);
120 }
121
122
123
124 private String getGUID()
125 {
126 if (GUID == null) {
127 GUID = "";
128 String id = "";
129
130 if (webApplication != null) {
131 id = webApplication.getContextRoot();
132 } else {
133 id = contextPath;
134 }
135
136 if (id!=null) {
137 if (id.startsWith("/")) {
138 id = id.substring(id.indexOf("/")+1);
139 }
140
141 GUID += id;
142 }
143 }
144
145 return GUID;
146 }
147
148 private void setContextRoot(String contextRoot)
149 {
150
151 if (contextRoot != null && contextRoot.endsWith(".war"))
152 {
153 contextRoot = contextRoot.substring(0, contextRoot.length()-4);
154 }
155 this.contextPath = contextRoot;
156 }
157
158
159
160 public String getAppId()
161 {
162 return appId;
163 }
164
165 public void setAppId(String appId)
166 {
167 this.appId = appId;
168 }
169
170 public void setVersion(String version)
171 {
172 this.version = version;
173 }
174
175
176
177 public Collection getCustomPortletMode()
178 {
179 return customPortletMode;
180 }
181
182 public void setCustomPortletMode(Collection customPortletMode)
183 {
184 this.customPortletMode = (ArrayList)customPortletMode;
185 }
186
187 public Collection getCustomPortletState()
188 {
189 return customPortletState;
190 }
191
192 public void setCustomPortletState(Collection customPortletState)
193 {
194 this.customPortletState = (ArrayList)customPortletState;
195 }
196
197 public Collection getUserAttribute()
198 {
199 return userAttribute;
200 }
201
202 public void setUserAttribute(Collection userAttribute)
203 {
204 this.userAttribute = (ArrayList)userAttribute;
205 }
206
207 public Collection getSecurityConstraint()
208 {
209 return securityConstraint;
210 }
211
212 public void setSecurityConstraint(Collection securityConstraint)
213 {
214 this.securityConstraint = (ArrayList)securityConstraint;
215 }
216
217
218
219 public Collection getCastorPortlets()
220 {
221 return(PortletDefinitionListImpl)portlets;
222 }
223
224 protected void setWebApplicationDefinition(WebApplicationDefinition webApplication)
225 {
226 this.webApplication = webApplication;
227 }
228
229
230
231 public String toString()
232 {
233 return toString(0);
234 }
235
236 public String toString(int indent)
237 {
238 StringBuffer buffer = new StringBuffer(50);
239 StringUtils.newLine(buffer,indent);
240 buffer.append(getClass().toString()); buffer.append(":");
241 StringUtils.newLine(buffer,indent);
242 buffer.append("{");
243 StringUtils.newLine(buffer,indent);
244 buffer.append("objectID='"); buffer.append(getId().toString()); buffer.append("'");
245 StringUtils.newLine(buffer,indent);
246 buffer.append("GUID='"); buffer.append(GUID); buffer.append("'");
247 StringUtils.newLine(buffer,indent);
248 buffer.append("version='"); buffer.append(version); buffer.append("'");
249
250 Iterator iterator = portlets.iterator();
251 if (iterator.hasNext()) {
252 StringUtils.newLine(buffer,indent);
253 buffer.append("Portlets:");
254 }
255 while (iterator.hasNext()) {
256 buffer.append(((PortletDefinitionImpl)iterator.next()).toString(indent+2));
257 }
258 if (webApplication!=null) {
259 StringUtils.newLine(buffer,indent);
260 buffer.append("webApplication:");
261 buffer.append(((WebApplicationDefinitionImpl)webApplication).toString(indent+2));
262 }
263 StringUtils.newLine(buffer,indent);
264 buffer.append("}");
265 return buffer.toString();
266 }
267
268 }