001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/portal/portlet/modules/map/actions/portlets/OverviewPortletPerform.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 javax.servlet.ServletContext;
039    import javax.servlet.http.HttpServletRequest;
040    
041    import org.apache.jetspeed.portal.Portlet;
042    import org.deegree.framework.util.StringTools;
043    import org.deegree.model.spatialschema.GeometryFactory;
044    import org.deegree.model.spatialschema.Point;
045    import org.deegree.portal.PortalException;
046    import org.deegree.portal.context.ViewContext;
047    import org.deegree.portal.portlet.modules.actions.IGeoPortalPortletPerform;
048    
049    /**
050     * handles actions performed on a map overview
051     *
052     *
053     * @version $Revision: 18195 $
054     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
055     * @author last edited by: $Author: mschneider $
056     *
057     * @version 1.0. $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
058     *
059     * @since 2.0
060     */
061    public class OverviewPortletPerform extends IGeoPortalPortletPerform {
062    
063        protected static String PARAM_OVRECTCOLOR = "rectColor";
064    
065        protected static String PARAM_OVWIDTH = "width";
066    
067        protected static String PARAM_OVHEIGHT = "height";
068    
069        protected static String PARAM_OVTITLE = "title";
070    
071        protected static String PARAM_OVFOOTER = "footer";
072    
073        protected static String PARAM_OVSRC = "imageSource";
074    
075        /**
076         *
077         * @param request
078         * @param portlet
079         * @param sc
080         */
081        public OverviewPortletPerform( HttpServletRequest request, Portlet portlet, ServletContext sc ) {
082            super( request, portlet, sc );
083        }
084    
085        @Override
086        public void buildNormalContext()
087                                throws PortalException {
088            super.buildNormalContext();
089    
090            ViewContext vc = getCurrentViewContext( getInitParam( INIT_MAPPORTLETID ) );
091    
092            // static bbox of the map overview
093            double[] bbox = null;
094    
095            Point[] env = null;
096            String crs = "";
097            if ( vc != null ) {
098                env = vc.getGeneral().getBoundingBox();
099                crs = env[0].getCoordinateSystem().getPrefixedName();
100                String tmp = getInitParam( crs + ':' + PARAM_BBOX );
101                if ( tmp == null ) {
102                    tmp = getInitParam( PARAM_BBOX );
103                }
104                bbox = StringTools.toArrayDouble( tmp, "," );
105            } else {
106                String tmp = getInitParam( PARAM_BBOX );
107                bbox = StringTools.toArrayDouble( tmp, "," );
108                // use overviews bbox if no map model is available
109                env = new Point[2];
110                env[0] = GeometryFactory.createPoint( bbox[0], bbox[1], null );
111                env[1] = GeometryFactory.createPoint( bbox[2], bbox[3], null );
112            }
113    
114            String rectColor = getInitParam( PARAM_OVRECTCOLOR );
115            if ( rectColor == null ) {
116                // default color = red
117                rectColor = "#FF0000";
118            }
119            String tmp = getInitParam( PARAM_OVWIDTH );
120            if ( tmp == null ) {
121                tmp = "150";
122            }
123            int width = new Integer( tmp );
124            tmp = getInitParam( PARAM_OVHEIGHT );
125            if ( tmp == null ) {
126                tmp = "150";
127            }
128            int height = new Integer( tmp );
129            String title = getInitParam( PARAM_OVTITLE );
130            String footer = getInitParam( PARAM_OVFOOTER );
131            String src = getInitParam( crs + ':' + PARAM_OVSRC );
132            if ( src == null ) {
133                src = getInitParam( PARAM_OVSRC );
134            }
135            request.setAttribute( "TITLE", title );
136            request.setAttribute( "FOOTER", footer );
137            request.setAttribute( "RECTCOLOR", rectColor );
138            request.setAttribute( "WIDTH", width );
139            request.setAttribute( "HEIGHT", height );
140            request.setAttribute( "SRC", src );
141            request.setAttribute( "MINX", bbox[0] );
142            request.setAttribute( "MINY", bbox[1] );
143            request.setAttribute( "MAXX", bbox[2] );
144            request.setAttribute( "MAXY", bbox[3] );
145            request.setAttribute( "VIEWMINX", env[0].getX() );
146            request.setAttribute( "VIEWMINY", env[0].getY() );
147            request.setAttribute( "VIEWMAXX", env[1].getX() );
148            request.setAttribute( "VIEWMAXY", env[1].getY() );
149        }
150    
151    }