001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.portal.pluto.om;
018:
019: import java.util.ArrayList;
020: import java.util.Collection;
021: import java.util.Map;
022: import java.util.Vector;
023:
024: import org.apache.pluto.om.common.ObjectID;
025: import org.apache.pluto.om.portlet.PortletApplicationDefinition;
026: import org.apache.pluto.om.portlet.PortletDefinitionList;
027: import org.apache.pluto.om.servlet.WebApplicationDefinition;
028: import org.apache.cocoon.portal.pluto.om.common.AbstractSupportSet;
029: import org.apache.cocoon.portal.pluto.om.common.Support;
030:
031: /**
032: *
033: *
034: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
035: *
036: * @version CVS $Id: PortletApplicationDefinitionImpl.java 433543 2006-08-22 06:22:54Z crossley $
037: */
038: public class PortletApplicationDefinitionImpl extends
039: AbstractSupportSet implements PortletApplicationDefinition {
040:
041: protected String GUID;
042:
043: protected String appId;
044: protected String version;
045: protected PortletDefinitionRegistryImpl registry;
046:
047: private ArrayList customPortletMode = new ArrayList();
048: private ArrayList customPortletState = new ArrayList();
049: private ArrayList userAttribute = new ArrayList();
050: private ArrayList securityConstraint = new ArrayList();
051:
052: private PortletDefinitionListImpl portlets = new PortletDefinitionListImpl();
053:
054: private WebApplicationDefinition webApplication;
055:
056: private ObjectID objectId;
057:
058: private String contextPath;
059:
060: /*
061: * (non-Javadoc)
062: * @return The PortletDefinitionRegistryImpl.
063: */
064: public PortletDefinitionRegistryImpl getRegistry() {
065: return this .registry;
066: }
067:
068: /*
069: * (non-Javadoc)
070: * @param service The PortletDefnitionRegistryImpl.
071: */
072: public void setRegistry(PortletDefinitionRegistryImpl registry) {
073: this .registry = registry;
074: }
075:
076: /* (non-Javadoc)
077: * @see org.apache.pluto.om.portlet.PortletApplicationDefinition#getId()
078: */
079: public ObjectID getId() {
080: if (this .objectId == null) {
081: this .objectId = org.apache.cocoon.portal.pluto.om.common.ObjectIDImpl
082: .createFromString(getGUID());
083: }
084: return this .objectId;
085: }
086:
087: /* (non-Javadoc)
088: * @see org.apache.pluto.om.portlet.PortletApplicationDefinition#getVersion()
089: */
090: public String getVersion() {
091: return this .version;
092: }
093:
094: /* (non-Javadoc)
095: * @see org.apache.pluto.om.portlet.PortletApplicationDefinition#getPortletDefinitionList()
096: */
097: public PortletDefinitionList getPortletDefinitionList() {
098: return this .portlets;
099: }
100:
101: /* (non-Javadoc)
102: * @see org.apache.pluto.om.portlet.PortletApplicationDefinition#getWebApplicationDefinition()
103: */
104: public WebApplicationDefinition getWebApplicationDefinition() {
105: return this .webApplication;
106: }
107:
108: /* (non-Javadoc)
109: * @see org.apache.cocoon.portal.pluto.om.common.Support#postLoad(java.lang.Object)
110: */
111: public void postLoad(Object parameter) throws Exception {
112: ((Support) portlets).postLoad(parameter);
113: }
114:
115: /* (non-Javadoc)
116: * @see org.apache.cocoon.portal.pluto.om.common.Support#preBuild(java.lang.Object)
117: */
118: public void preBuild(Object parameter) throws Exception {
119: Vector structure = (Vector) parameter;
120: String contextRoot = (String) structure.get(0);
121: WebApplicationDefinition webApplication = (WebApplicationDefinition) structure
122: .get(1);
123: Map servletMap = (Map) structure.get(2);
124:
125: this .setContextRoot(contextRoot);
126:
127: setWebApplicationDefinition(webApplication);
128:
129: Vector structure2 = new Vector();
130: structure2.add(this );
131: structure2.add(servletMap);
132:
133: ((Support) portlets).preBuild(structure2);
134:
135: }
136:
137: /* (non-Javadoc)
138: * @see org.apache.cocoon.portal.pluto.om.common.Support#postBuild(java.lang.Object)
139: */
140: public void postBuild(Object parameter) throws Exception {
141: // nothing to do
142: }
143:
144: /* (non-Javadoc)
145: * @see org.apache.cocoon.portal.pluto.om.common.Support#preStore(java.lang.Object)
146: */
147: public void preStore(Object parameter) throws Exception {
148: ((Support) portlets).preStore(parameter);
149: }
150:
151: /* (non-Javadoc)
152: * @see org.apache.cocoon.portal.pluto.om.common.Support#postStore(java.lang.Object)
153: */
154: public void postStore(Object parameter) throws Exception {
155: ((Support) portlets).postStore(parameter);
156: }
157:
158: // internal methods.
159:
160: protected String getGUID() {
161: if (GUID == null) {
162: GUID = "";
163: String id = "";
164:
165: if (webApplication != null) {
166: id = webApplication.getContextRoot();
167: } else {
168: id = contextPath;
169: }
170:
171: if (id != null) {
172: if (id.startsWith("/")) {
173: id = id.substring(id.indexOf("/") + 1);
174: }
175:
176: GUID += id;
177: }
178: }
179:
180: return GUID;
181: }
182:
183: private void setContextRoot(String contextRoot) {
184: // PATCH for IBM WebSphere
185: if (contextRoot != null && contextRoot.endsWith(".war")) {
186: this .contextPath = contextRoot.substring(0, contextRoot
187: .length() - 4);
188: } else {
189: this .contextPath = contextRoot;
190: }
191: }
192:
193: // additional methods.
194:
195: public String getAppId() {
196: return appId;
197: }
198:
199: public void setAppId(String appId) {
200: this .appId = appId;
201: }
202:
203: public void setVersion(String version) {
204: this .version = version;
205: }
206:
207: // not yet fully supported:
208: public Collection getCustomPortletMode() {
209: return customPortletMode;
210: }
211:
212: public void setCustomPortletMode(Collection customPortletMode) {
213: this .customPortletMode = (ArrayList) customPortletMode;
214: }
215:
216: public Collection getCustomPortletState() {
217: return customPortletState;
218: }
219:
220: public void setCustomPortletState(Collection customPortletState) {
221: this .customPortletState = (ArrayList) customPortletState;
222: }
223:
224: public Collection getUserAttribute() {
225: return userAttribute;
226: }
227:
228: public void setUserAttribute(Collection userAttribute) {
229: this .userAttribute = (ArrayList) userAttribute;
230: }
231:
232: public Collection getSecurityConstraint() {
233: return securityConstraint;
234: }
235:
236: public void setSecurityConstraint(Collection securityConstraint) {
237: this .securityConstraint = (ArrayList) securityConstraint;
238: }
239:
240: // additional internal methods
241:
242: public Collection getCastorPortlets() {
243: return portlets;
244: }
245:
246: protected void setWebApplicationDefinition(
247: WebApplicationDefinition webApplication) {
248: this.webApplication = webApplication;
249: }
250:
251: }
|