001 //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/portal/portlet/modules/map/actions/portlets/SelectWMCPortletPerform.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.map.actions.portlets;
037
038 import java.io.File;
039 import java.io.UnsupportedEncodingException;
040 import java.net.URLDecoder;
041 import java.util.List;
042
043 import javax.servlet.ServletContext;
044 import javax.servlet.http.HttpServletRequest;
045
046 import org.apache.jetspeed.portal.Portlet;
047 import org.apache.jetspeed.portal.PortletSet;
048 import org.deegree.framework.log.ILogger;
049 import org.deegree.framework.log.LoggerFactory;
050 import org.deegree.framework.util.CharsetUtils;
051 import org.deegree.model.spatialschema.Point;
052 import org.deegree.portal.PortalException;
053 import org.deegree.portal.context.ContextException;
054 import org.deegree.portal.context.ViewContext;
055 import org.deegree.portal.context.WebMapContextFactory;
056 import org.deegree.portal.portlet.modules.actions.IGeoPortalPortletPerform;
057 import org.deegree.security.drm.model.User;
058
059 /**
060 *
061 *
062 *
063 * @version $Revision: 18195 $
064 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
065 * @author last edited by: $Author: mschneider $
066 *
067 * @version 1.0. $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
068 *
069 * @since 2.0
070 */
071 public class SelectWMCPortletPerform extends IGeoPortalPortletPerform {
072
073 private static ILogger LOG = LoggerFactory.getLogger( SelectWMCPortletPerform.class );
074
075 private static String INIT_KEEP_BBOX = "keep_bbox";
076
077 /**
078 *
079 * @param request
080 * @param portlet
081 * @param sc
082 */
083 public SelectWMCPortletPerform( HttpServletRequest request, Portlet portlet, ServletContext sc ) {
084 super( request, portlet, sc );
085
086 }
087
088 @Override
089 public void buildNormalContext()
090 throws PortalException {
091 super.buildNormalContext();
092
093 if ( request.getSession().getAttribute( CURRENT_WMC ) == null ) {
094 List<String[]> wmc = (List<String[]>) request.getSession().getAttribute( AVAILABLE_WMC );
095 request.getSession().setAttribute( CURRENT_WMC, wmc.get( 0 )[1] );
096 }
097 }
098
099 /**
100 * selects the current context of a MapWindowPortlet
101 *
102 * @throws PortalException
103 *
104 */
105 void doSelectwmc()
106 throws PortalException {
107
108 String cntxid = parameter.get( "WMCID" );
109
110 PortletSet ps = portlet.getPortletConfig().getPortletSet();
111 String mapid = ps.getPortletByName( "iGeoPortal:MapActionPortlet" ).getID();
112 Portlet port = ps.getPortletByID( mapid );
113 port.getPortletConfig().setInitParameter( INIT_WMC, cntxid );
114
115 String mwinid = getInitParam( INIT_MAPPORTLETID );
116 port = ps.getPortletByID( mwinid );
117 port.getPortletConfig().setInitParameter( INIT_WMC, cntxid );
118
119 request.setAttribute( PARAM_MAPPORTLET, mwinid );
120
121 ViewContext vc = null;
122 if ( "true".equals( getInitParam( INIT_KEEP_BBOX ) ) ) {
123 // get old current context to read its bounding box
124 vc = getCurrentViewContext( parameter.get( "MAPPORTLET" ) );
125 Point[] currentEnv = vc.getGeneral().getBoundingBox();
126
127 // get new current context to set its bounding box with value of the
128 // old current context bounding box to keep viewing area
129 vc = getNamedViewContext( cntxid );
130 try {
131 vc.getGeneral().setBoundingBox( currentEnv );
132 } catch ( ContextException e ) {
133 LOG.logError( e.getMessage(), e );
134 throw new PortalException( e.getMessage(), e );
135 }
136 } else {
137 vc = getNamedViewContext( cntxid );
138 }
139
140 setCurrentMapContext( vc, getInitParam( INIT_MAPPORTLETID ) );
141 setCurrentMapContextName( getInitParam( INIT_MAPPORTLETID ), cntxid );
142
143 }
144
145 /**
146 * loads a context defined by its absolut path passed in URL encoded parameter 'FILENAME'
147 *
148 * @throws PortalException
149 */
150 void doLoadwmc( User user )
151 throws PortalException {
152
153 String filename = null;
154 try {
155 filename = URLDecoder.decode( parameter.get( "FILENAME" ), CharsetUtils.getSystemCharset() );
156 } catch ( UnsupportedEncodingException e1 ) {
157 e1.printStackTrace();
158 }
159 File file = new File( filename );
160 String cntxid = file.getName();
161
162 PortletSet ps = portlet.getPortletConfig().getPortletSet();
163 String mapid = ps.getPortletByName( "iGeoPortal:MapActionPortlet" ).getID();
164 Portlet port = ps.getPortletByID( mapid );
165 port.getPortletConfig().setInitParameter( INIT_WMC, cntxid );
166
167 String mwinid = getInitParam( INIT_MAPPORTLETID );
168 port = ps.getPortletByID( mwinid );
169 port.getPortletConfig().setInitParameter( INIT_WMC, cntxid );
170
171 request.setAttribute( PARAM_MAPPORTLET, mwinid );
172
173 ViewContext vc = null;
174 try {
175 vc = WebMapContextFactory.createViewContext( file.toURI().toURL(), user, null );
176 } catch ( Exception e ) {
177 LOG.logError( e.getMessage(), e );
178 return;
179 }
180
181 setCurrentMapContext( vc, getInitParam( INIT_MAPPORTLETID ) );
182 setCurrentMapContextName( getInitParam( INIT_MAPPORTLETID ), cntxid );
183
184 }
185
186 }