001 //$HeadURL: http://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/portal/portlet/modules/actions/AbstractPortletPerform.java $
002 /*----------------------------------------------------------------------------
003 This file is part of deegree, http://deegree.org/
004 Copyright (C) 2001-2009 by:
005 Department of Geography, University of Bonn
006 and
007 lat/lon GmbH
008
009 This library is free software; you can redistribute it and/or modify it under
010 the terms of the GNU Lesser General Public License as published by the Free
011 Software Foundation; either version 2.1 of the License, or (at your option)
012 any later version.
013 This library is distributed in the hope that it will be useful, but WITHOUT
014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016 details.
017 You should have received a copy of the GNU Lesser General Public License
018 along with this library; if not, write to the Free Software Foundation, Inc.,
019 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020
021 Contact information:
022
023 lat/lon GmbH
024 Aennchenstr. 19, 53177 Bonn
025 Germany
026 http://lat-lon.de/
027
028 Department of Geography, University of Bonn
029 Prof. Dr. Klaus Greve
030 Postfach 1147, 53001 Bonn
031 Germany
032 http://www.geographie.uni-bonn.de/deegree/
033
034 e-mail: info@deegree.org
035 ----------------------------------------------------------------------------*/
036 package org.deegree.portal.portlet.modules.actions;
037
038 import java.util.Enumeration;
039 import java.util.HashMap;
040 import java.util.Map;
041
042 import javax.servlet.http.HttpServletRequest;
043
044 import org.apache.jetspeed.portal.Portlet;
045 import org.apache.jetspeed.portal.PortletSet;
046 import org.deegree.framework.util.KVP2Map;
047 import org.deegree.portal.PortalException;
048
049 /**
050 *
051 *
052 * @version $Revision: 18195 $
053 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
054 * @author last edited by: $Author: mschneider $
055 *
056 * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Thu, 18 Jun 2009) $
057 */
058 public abstract class AbstractPortletPerform {
059
060 /**
061 * define 'mapPortletID'
062 */
063 public static final String INIT_MAPPORTLETID = "mapPortletID";
064
065 /**
066 * define 'wmc'
067 */
068 public static final String INIT_WMC = "wmc";
069
070 /**
071 * define 'availableWMC'
072 */
073 public static final String AVAILABLE_WMC = "availableWMC";
074
075 // attributes stored in the users session
076 /**
077 * define 'HOME'
078 */
079 public static final String SESSION_HOME = "HOME";
080
081 /**
082 * define 'CURRENTWMC'
083 */
084 public static final String CURRENT_WMC = "CURRENTWMC";
085
086 /**
087 * define 'CURRENTWMCNAME'
088 */
089 public static final String CURRENT_WMC_NAME = "CURRENTWMCNAME";
090
091 /**
092 * define 'VIEWCONTEXT'
093 */
094 public static final String SESSION_VIEWCONTEXT = "VIEWCONTEXT";
095
096 /**
097 * define 'CURRENTFILAYER'
098 */
099 public static final String SESSION_CURRENTFILAYER = "CURRENTFILAYER";
100
101 /**
102 * define 'MAPPORTLET'
103 */
104 public static final String PARAM_MAPPORTLET = "MAPPORTLET";
105
106 /**
107 * define 'MAPACTIONPORTLET'
108 */
109 public static final String PARAM_MAPACTION = "MAPACTIONPORTLET";
110
111 /**
112 * define 'MODE'
113 */
114 public static final String PARAM_MODE = "MODE";
115
116 protected Portlet portlet = null;
117
118 protected HttpServletRequest request = null;
119
120 protected Map<String, String> parameter = null;
121
122 /**
123 * @param portlet
124 * @param request
125 */
126 public AbstractPortletPerform( HttpServletRequest request, Portlet portlet ) {
127 this.portlet = portlet;
128 this.request = request;
129 parameter = KVP2Map.toMap( request );
130 if ( portlet != null ) {
131 setMapActionPortletID();
132 }
133 }
134
135 /**
136 * returns the value of the passed init parameter. This method shal be used to hide functional
137 * implementation from concrete portlet implementation.
138 *
139 * @param name
140 * @return the value of the passed init parameter.
141 */
142 protected String getInitParam( String name ) {
143 if ( portlet != null ) {
144 return portlet.getPortletConfig().getInitParameter( name );
145 }
146 return null;
147 }
148
149 /**
150 * returns the ID of the mapmodel assigned to a portlet. First the method tries to read it from
151 * the portlets initparameter. If not present it returns the ID of the first
152 * iGeoPortal:MapWindowPortlet it finds.
153 *
154 * @return the ID of the mapmodel assigned to a portlet. First the method tries to read it from
155 * the portlets initparameter. If not present it returns the ID of the first
156 * iGeoPortal:MapWindowPortlet it finds.
157 */
158 protected String getMapPortletID() {
159 String mmid = portlet.getPortletConfig().getInitParameter( INIT_MAPPORTLETID );
160 if ( mmid == null ) {
161 PortletSet ps = portlet.getPortletConfig().getPortletSet();
162 Portlet port = ps.getPortletByName( "iGeoPortal:MapWindowPortlet" );
163 mmid = port.getID();
164 }
165 return mmid;
166 }
167
168 /**
169 * this method will be called each time a portlet will be repainted. It determines all portlets
170 * visible in a page and writes a Map with the portlets name as key and the portlets ID as value
171 * into the forwarded HttpRequest object
172 *
173 * @throws PortalException
174 */
175 public void buildNormalContext()
176 throws PortalException {
177
178 request.setAttribute( "PORTLETID", portlet.getID() );
179 Map<String, String> map = new HashMap<String, String>();
180 Enumeration enume = portlet.getPortletConfig().getPortletSet().getPortlets();
181 while ( enume.hasMoreElements() ) {
182 Portlet p = (Portlet) enume.nextElement();
183 map.put( p.getName(), p.getID() );
184 }
185 request.setAttribute( "PORTLETS", map );
186 request.setAttribute( PARAM_MAPPORTLET, getInitParam( INIT_MAPPORTLETID ) );
187 }
188
189 protected String readMapContextID_() {
190 String pid = null;
191
192 String cntxID = null;
193 if ( portlet != null ) {
194 cntxID = (String) request.getSession().getAttribute( portlet.getID() + "_" + CURRENT_WMC );
195 if ( cntxID == null ) {
196 pid = portlet.getPortletConfig().getInitParameter( AbstractPortletPerform.INIT_MAPPORTLETID );
197 }
198 }
199
200 if ( cntxID == null ) {
201 if ( pid == null ) {
202 cntxID = getInitParam( INIT_WMC );
203 } else {
204 Portlet port = portlet.getPortletConfig().getPortletSet().getPortletByID( pid );
205 if ( port == null ) {
206 // try to access first MapWindowPortlet found in a page
207 pid = getMapPortletID();
208 port = portlet.getPortletConfig().getPortletSet().getPortletByID( pid );
209 }
210 if ( port != null ) {
211 cntxID = port.getPortletConfig().getInitParameter( INIT_WMC );
212 }
213 }
214 }
215 return cntxID;
216 }
217
218 /**
219 *
220 *
221 */
222 private void setMapActionPortletID() {
223 Portlet port = portlet.getPortletConfig().getPortletSet().getPortletByName( "iGeoPortal:MapActionPortlet" );
224 if ( port != null ) {
225 request.setAttribute( PARAM_MAPACTION, port.getID() );
226 }
227 }
228 }