    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/portal/portlet/modules/map/actions/portlets/MapActionPortletAction.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.lang.reflect.Constructor;
    039    import java.util.Map;
    040
    041    import javax.servlet.http.HttpServletRequest;
    042
    043    import org.apache.jetspeed.modules.actions.portlets.JspPortletAction;
    044    import org.apache.jetspeed.portal.Portlet;
    045    import org.apache.turbine.om.security.User;
    046    import org.apache.turbine.util.RunData;
    047    import org.deegree.framework.log.ILogger;
    048    import org.deegree.framework.log.LoggerFactory;
    049    import org.deegree.framework.util.KVP2Map;
    050    import org.deegree.portal.PortalException;
    051
    052    /**
    053     *
    054     *
    055     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
    056     * @author last edited by: $Author: mschneider $
    057     *
    058     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
    059     */
    060    public class MapActionPortletAction extends JspPortletAction {
    061
    062        private ILogger LOG = LoggerFactory.getLogger( MapActionPortletAction.class );
    063
    064        /**
    065         * @throws Exception
    066         *
    067         */
    068        @Override
    069        protected void buildNormalContext( Portlet portlet, RunData data )
    070                                throws Exception {
    071
    072            try {
    073                MapActionPortletPerform mapp = new MapActionPortletPerform( data.getRequest(), portlet,
    074                                                                            data.getServletContext() );
    075                mapp.buildNormalContext();
    076                data.getRequest().setAttribute( "User", data.getUser().getUserName() );
    077                data.getRequest().setAttribute( "Password", data.getUser().getPassword() );
    078            } catch ( Exception e ) {
    079                throw e;
    080            }
    081
    082        }
    083
    084        /**
    085         * Changes the CRS of the underlying ViewContext. The actual action is implemented by the
    086         * <code>CRSChooserPortletPerform</code>.
    087         *
    088         * @param data
    089         * @param portlet
    090         * @throws PortalException
    091         */
    092        public void doCrschoose( RunData data, Portlet portlet )
    093                                throws PortalException {
    094
    095            try {
    096                Portlet port = portlet.getPortletConfig().getPortletSet().getPortletByName( "iGeoPortal:CRSChooserPortlet" );
    097                CRSChooserPortletPerform ccpp = new CRSChooserPortletPerform( data.getRequest(), port,
    098                                                                              data.getServletContext() );
    099                ccpp.doCRSChange();
    100            } catch ( Exception e ) {
    101                LOG.logError( e.getMessage(), e );
    102                throw new PortalException( e.getMessage() );
    103            }
    104        }
    105
    106        /**
    107         * returns the MapWindowPortlet targeted by the current action
    108         *
    109         * @param rundata
    110         * @param portlet
    111         * @return the MapWindowPortlet targeted by the current action
    112         */
    113        private Portlet getMapWindowPortlet( RunData rundata, Portlet portlet ) {
    114            Map map = KVP2Map.toMap( rundata.getRequest() );
    115            String id = (String) map.get( "MAPPORTLET" );
    116            Portlet port = portlet.getPortletConfig().getPortletSet().getPortletByID( id );
    117            return port;
    118        }
    119
    120        /**
    121         *
    122         * @param data
    123         * @param portlet
    124         * @throws Exception
    125         */
    126        public void doFeatureinfo( RunData data, Portlet portlet )
    127                                throws Exception {
    128
    129            try {
    130                HttpServletRequest req = data.getRequest();
    131                req.setAttribute( "$U$", data.getUser().getUserName() );
    132                req.setAttribute( "$P$", data.getUser().getPassword() );
    133                Portlet port = getMapWindowPortlet( data, portlet );
    134                FeatureInfoPortletPerform fipp = new FeatureInfoPortletPerform( req, port, data.getServletContext() );
    135                fipp.doGetFeatureInfo();
    136            } catch ( Exception e ) {
    137                e.printStackTrace();
    138            }
    139
    140        }
    141
    142        /**
    143         *
    144         * @param data
    145         * @param portlet
    146         * @throws Exception
    147         */
    148        public void doFeatureinfoForward( RunData data, Portlet portlet )
    149                                throws Exception {
    150
    151            try {
    152                Portlet port = getMapWindowPortlet( data, portlet );
    153                String className = portlet.getPortletConfig().getInitParameter( "performingClass" );
    154                Class[] classes = new Class[3];
    155                classes[0] = data.getRequest().getClass();
    156                classes[1] = port.getClass();
    157                classes[2] = data.getRequest().getClass();
    158                Object[] o = new Object[3];
    159                o[0] = data.getRequest();
    160                o[1] = portlet;
    161                o[2] = data.getRequest();
    162
    163                Class clss = Class.forName( className );
    164                Constructor constructor = clss.getConstructor( classes );
    165                constructor.newInstance( o );
    166
    167                FeatureInfoForwardPortletPerform fifpp = (FeatureInfoForwardPortletPerform) constructor.newInstance( o );
    168                fifpp.doGetFeatureInfo();
    169            } catch ( Exception e ) {
    170                e.printStackTrace();
    171            }
    172
    173        }
    174
    175        /**
    176         * sets a new bounding box for the current ViewContext.
    177         *
    178         * @param data
    179         * @param portlet
    180         */
    181        public void doSetboundingbox( RunData data, Portlet portlet ) {
    182            try {
    183                Portlet port = getMapWindowPortlet( data, portlet );
    184                MapWindowPortletPerform mwpp = new MapWindowPortletPerform( data.getRequest(), port,
    185                                                                            data.getServletContext() );
    186                mwpp.setBoundingBoxFromBBOXParam();
    187                mwpp.setLayers();
    188                mwpp.setCurrentFILayer();
    189            } catch ( Exception e ) {
    190                e.printStackTrace();
    191            }
    192        }
    193
    194        /**
    195         * sets the maps boundingbox to the defined home boundingbox
    196         *
    197         * @param data
    198         * @param portlet
    199         */
    200        public void doSethomeboundingbox( RunData data, Portlet portlet ) {
    201            try {
    202                Portlet port = getMapWindowPortlet( data, portlet );
    203                MapWindowPortletPerform mwpp = new MapWindowPortletPerform( data.getRequest(), port,
    204                                                                            data.getServletContext() );
    205                mwpp.setHomeBoundingbox();
    206                // mwpp.setLayers( port.getID() );
    207                // mwpp.setCurrentFILayer();
    208            } catch ( Exception e ) {
    209                e.printStackTrace();
    210            }
    211
    212        }
    213
    214        /**
    215         * sets a new size of the map (pixel)
    216         *
    217         * @param rundata
    218         * @param portlet
    219         * @throws Exception
    220         */
    221        public void doSetmapsize( RunData rundata, Portlet portlet )
    222                                throws Exception {
    223            try {
    224                Portlet port = getMapWindowPortlet( rundata, portlet );
    225                MapWindowPortletPerform mwpp = new MapWindowPortletPerform( rundata.getRequest(), port,
    226                                                                            rundata.getServletContext() );
    227                mwpp.setMapSize();
    228                mwpp.setBoundingBoxFromBBOXParam();
    229                mwpp.setLayers();
    230                mwpp.setCurrentFILayer();
    231            } catch ( Exception e ) {
    232                e.printStackTrace();
    233            }
    234        }
    235
    236        /**
    237         * Performs a repaint of the current ViewContext by regenerating the assigend OWS requests. In opposite to
    238         * <code>doActualizeViewContext(RunData, Portlet)</code> no parameters from the client are solved to actualize the
    239         * current ViewContext.
    240         *
    241         * @param rundata
    242         * @param portlet
    243         * @throws Exception
    244         */
    245        public void doRepaint( RunData rundata, Portlet portlet )
    246                                throws Exception {
    247            try {
    248                Portlet port = getMapWindowPortlet( rundata, portlet );
    249                if ( port != null ) {
    250                    MapWindowPortletPerform mwpp = new MapWindowPortletPerform( rundata.getRequest(), port,
    251                                                                                rundata.getServletContext() );
    252                    mwpp.setBoundingBoxFromBBOXParam();
    253                    mwpp.setLayers();
    254                    mwpp.setCurrentFILayer();
    255                    mwpp.setMode();
    256                }
    257            } catch ( Exception e ) {
    258                e.printStackTrace();
    259            }
    260        }
    261
    262        /**
    263         * performs a zoomIn or a zoomOut on the current map model (ViewContext)
    264         *
    265         * @param rundata
    266         * @param portlet
    267         * @throws Exception
    268         */
    269        public void doZoom( RunData rundata, Portlet portlet )
    270                                throws Exception {
    271            try {
    272                Portlet port = getMapWindowPortlet( rundata, portlet );
    273                MapWindowPortletPerform mwpp = new MapWindowPortletPerform( rundata.getRequest(), port,
    274                                                                            rundata.getServletContext() );
    275                mwpp.zoom();
    276                mwpp.setLayers();
    277                mwpp.setCurrentFILayer();
    278            } catch ( Exception e ) {
    279                e.printStackTrace();
    280            }
    281        }
    282
    283        /**
    284         * performs a panning on the current map model (ViewContext)
    285         *
    286         * @param rundata
    287         * @param portlet
    288         * @throws Exception
    289         */
    290        public void doPan( RunData rundata, Portlet portlet )
    291                                throws Exception {
    292            try {
    293                Portlet port = getMapWindowPortlet( rundata, portlet );
    294                MapWindowPortletPerform mwpp = new MapWindowPortletPerform( rundata.getRequest(), port,
    295                                                                            rundata.getServletContext() );
    296                mwpp.pan();
    297                mwpp.setLayers();
    298                mwpp.setCurrentFILayer();
    299            } catch ( Exception e ) {
    300                e.printStackTrace();
    301            }
    302        }
    303
    304        /**
    305         * performs a recentering on the current map model (ViewContext)
    306         *
    307         * @param rundata
    308         * @param portlet
    309         * @throws Exception
    310         */
    311        public void doRecenter( RunData rundata, Portlet portlet )
    312                                throws Exception {
    313            try {
    314                Portlet port = getMapWindowPortlet( rundata, portlet );
    315                MapWindowPortletPerform mwpp = new MapWindowPortletPerform( rundata.getRequest(), port,
    316                                                                            rundata.getServletContext() );
    317                mwpp.recenter();
    318                mwpp.setLayers();
    319                mwpp.setCurrentFILayer();
    320            } catch ( Exception e ) {
    321                e.printStackTrace();
    322            }
    323        }
    324
    325        /**
    326         * sets layers of the view context as visible or invisble depending on the incoming request
    327         *
    328         * @param rundata
    329         * @param portlet
    330         *
    331         * @throws Exception
    332         */
    333        public void doSetlayers( RunData rundata, Portlet portlet )
    334                                throws Exception {
    335            try {
    336                Portlet port = getMapWindowPortlet( rundata, portlet );
    337                MapWindowPortletPerform mwpp = new MapWindowPortletPerform( rundata.getRequest(), port,
    338                                                                            rundata.getServletContext() );
    339                mwpp.setLayers();
    340                mwpp.setBoundingBoxFromBBOXParam();
    341                mwpp.setCurrentFILayer();
    342            } catch ( Exception e ) {
    343                e.printStackTrace();
    344            }
    345        }
    346
    347        /**
    348         * moves the layer passed through by the HTTP request up for one position
    349         *
    350         * @param rundata
    351         * @param portlet
    352         * @throws Exception
    353         */
    354        public void doMoveup( RunData rundata, Portlet portlet )
    355                                throws Exception {
    356            try {
    357                Portlet port = getMapWindowPortlet( rundata, portlet );
    358                MapWindowPortletPerform mwpp = new MapWindowPortletPerform( rundata.getRequest(), port,
    359                                                                            rundata.getServletContext() );
    360                mwpp.setLayers();
    361                mwpp.moveUp();
    362                mwpp.setBoundingBoxFromBBOXParam();
    363                mwpp.setCurrentFILayer();
    364            } catch ( Exception e ) {
    365                e.printStackTrace();
    366            }
    367        }
    368
    369        /**
    370         * moves the layer passed through by the HTTP request down for one position
    371         *
    372         * @param rundata
    373         * @param portlet
    374         * @throws Exception
    375         */
    376        public void doMovedown( RunData rundata, Portlet portlet )
    377                                throws Exception {
    378            try {
    379                Portlet port = getMapWindowPortlet( rundata, portlet );
    380                MapWindowPortletPerform mwpp = new MapWindowPortletPerform( rundata.getRequest(), port,
    381                                                                            rundata.getServletContext() );
    382                mwpp.setLayers();
    383                mwpp.moveDown();
    384                mwpp.setBoundingBoxFromBBOXParam();
    385                mwpp.setCurrentFILayer();
    386            } catch ( Exception e ) {
    387                e.printStackTrace();
    388            }
    389        }
    390
    391        /**
    392         * move the map view (just bounding box) to the next entry in the history
    393         *
    394         * @param rundata
    395         * @param portlet
    396         * @throws Exception
    397         */
    398        public void doHistoryforward( RunData rundata, Portlet portlet )
    399                                throws Exception {
    400            try {
    401                Portlet port = getMapWindowPortlet( rundata, portlet );
    402                MapWindowPortletPerform mwpp = new MapWindowPortletPerform( rundata.getRequest(), port,
    403                                                                            rundata.getServletContext() );
    404                mwpp.setLayers();
    405                mwpp.setCurrentFILayer();
    406                mwpp.doHistoryforward();
    407            } catch ( Exception e ) {
    408                e.printStackTrace();
    409            }
    410        }
    411
    412        /**
    413         * move the map view (just bounding box) to the previous entry in the history
    414         *
    415         * @param rundata
    416         * @param portlet
    417         * @throws Exception
    418         */
    419        public void doHistorybackward( RunData rundata, Portlet portlet )
    420                                throws Exception {
    421            try {
    422                Portlet port = getMapWindowPortlet( rundata, portlet );
    423                MapWindowPortletPerform mwpp = new MapWindowPortletPerform( rundata.getRequest(), port,
    424                                                                            rundata.getServletContext() );
    425                mwpp.setLayers();
    426                mwpp.setCurrentFILayer();
    427                mwpp.doHistorybackward();
    428            } catch ( Exception e ) {
    429                e.printStackTrace();
    430            }
    431        }
    432
    433        /**
    434         *
    435         * @param rundata
    436         * @param portlet
    437         * @throws Exception
    438         */
    439        public void doAddows( RunData rundata, Portlet portlet )
    440                                throws Exception {
    441            try {
    442                Portlet port = getMapWindowPortlet( rundata, portlet );
    443                MapWindowPortletPerform mwpp = new MapWindowPortletPerform( rundata.getRequest(), port,
    444                                                                            rundata.getServletContext() );
    445                mwpp.doAddows();
    446            } catch ( Exception e ) {
    447                e.printStackTrace();
    448            }
    449        }
    450
    451        /**
    452         *
    453         * @param rundata
    454         * @param portlet
    455         * @throws Exception
    456         */
    457        public void doRemoveows( RunData rundata, Portlet portlet )
    458                                throws Exception {
    459            try {
    460                Portlet port = getMapWindowPortlet( rundata, portlet );
    461                MapWindowPortletPerform mwpp = new MapWindowPortletPerform( rundata.getRequest(), port,
    462                                                                            rundata.getServletContext() );
    463                mwpp.doRemoveows();
    464            } catch ( Exception e ) {
    465                e.printStackTrace();
    466            }
    467        }
    468
    469        /**
    470         * selects the current context of a MapWindowPortlet
    471         *
    472         * @param data
    473         * @param portlet
    474         * @throws PortalException
    475         */
    476        public void doSelectwmc( RunData data, Portlet portlet )
    477                                throws PortalException {
    478            try {
    479                Portlet port = portlet.getPortletConfig().getPortletSet().getPortletByName( "iGeoPortal:SelectWMCPortlet" );
    480                SelectWMCPortletPerform swp = new SelectWMCPortletPerform( data.getRequest(), port,
    481                                                                           data.getServletContext() );
    482                swp.doSelectwmc();
    483            } catch ( Exception e ) {
    484                e.printStackTrace();
    485                LOG.logError( e.getMessage(), e );
    486                throw new PortalException( e.getMessage() );
    487            }
    488        }
    489
    490        /**
    491         * selects the current context of a MapWindowPortlet
    492         *
    493         * @param data
    494         * @param portlet
    495         * @throws PortalException
    496         */
    497        public void doLoadwmc( RunData data, Portlet portlet )
    498                                throws PortalException {
    499            try {
    500                Portlet port = portlet.getPortletConfig().getPortletSet().getPortletByName( "iGeoPortal:SelectWMCPortlet" );
    501                SelectWMCPortletPerform swp = new SelectWMCPortletPerform( data.getRequest(), port,
    502                                                                           data.getServletContext() );
    503                User user = data.getUser();
    504                org.deegree.security.drm.model.User du = null;
    505                if ( !"anon".equals( user.getUserName() ) ) {
    506                    du = new org.deegree.security.drm.model.User( 1, user.getUserName(), user.getPassword(),
    507                                                                  user.getFirstName(), user.getLastName(), user.getEmail(),
    508                                                                  null );
    509                }
    510                swp.doLoadwmc( du );
    511            } catch ( Exception e ) {
    512                e.printStackTrace();
    513                LOG.logError( e.getMessage(), e );
    514                throw new PortalException( e.getMessage() );
    515            }
    516        }
    517
    518        /**
    519         * Changes the scale.
    520         *
    521         * @param data
    522         * @param portlet
    523         * @throws PortalException
    524         */
    525        public void doChangescale( RunData data, Portlet portlet )
    526                                throws PortalException {
    527            try {
    528                Portlet port = portlet.getPortletConfig().getPortletSet().getPortletByName(
    529                                                                                            "iGeoPortal:ScaleChooserPortlet" );
    530                ScaleChooserPortletPerform swp = new ScaleChooserPortletPerform( data.getRequest(), port,
    531                                                                                 data.getServletContext() );
    532                swp.doChangeScale();
    533            } catch ( Exception e ) {
    534                LOG.logError( e.getMessage(), e );
    535                throw new PortalException( e.getMessage() );
    536            }
    537        }
    538    }