001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/portal/portlet/modules/map/actions/portlets/MapActionPortletPerform.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.util.ArrayList;
040    import java.util.Enumeration;
041    import java.util.List;
042    
043    import javax.servlet.ServletContext;
044    import javax.servlet.http.HttpServletRequest;
045    import javax.servlet.http.HttpSession;
046    
047    import org.apache.jetspeed.portal.Portlet;
048    import org.apache.jetspeed.portal.PortletSet;
049    import org.deegree.framework.log.ILogger;
050    import org.deegree.framework.log.LoggerFactory;
051    import org.deegree.framework.util.StringTools;
052    import org.deegree.portal.PortalException;
053    import org.deegree.portal.context.ViewContext;
054    import org.deegree.portal.portlet.modules.actions.IGeoPortalPortletPerform;
055    
056    /**
057     *
058     *
059     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
060     * @author last edited by: $Author: mschneider $
061     *
062     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
063     */
064    public class MapActionPortletPerform extends IGeoPortalPortletPerform {
065    
066        protected static final ILogger LOG = LoggerFactory.getLogger( MapActionPortletPerform.class );
067    
068        /**
069         *
070         * @param request
071         * @param portlet
072         * @param sc
073         */
074        public MapActionPortletPerform( HttpServletRequest request, Portlet portlet, ServletContext sc ) {
075            super( request, portlet, sc );
076        }
077    
078        @Override
079        public void buildNormalContext()
080                                throws PortalException {
081            super.buildNormalContext();
082    
083            HttpSession ses = request.getSession();
084    
085            List<String> tmp = StringTools.toList( getInitParam( AVAILABLE_WMC ), ";", false );
086            List<String[]> wmc = new ArrayList<String[]>( tmp.size() );
087            for ( int i = 0; i < tmp.size(); i++ ) {
088                String[] t = StringTools.toArray( tmp.get( i ), "|", false );
089                wmc.add( t );
090            }
091            ses.setAttribute( AVAILABLE_WMC, wmc );
092            if ( getNamedViewContext( wmc.get( 0 )[0] ) == null ) {
093                // initial call - init parameter WMCs has not been read
094                for ( int i = 0; i < wmc.size(); i++ ) {
095                    try {
096                        if ( getNamedViewContext( wmc.get( i )[0] ) == null ) {
097                            File f = new File( wmc.get( i )[1] );
098                            if ( !f.isAbsolute() ) {
099                                wmc.get( i )[1] = sc.getRealPath( wmc.get( i )[1] );
100                            }
101                            File file = new File( wmc.get( i )[1] );
102                            LOG.logDebug( "write context to session: " + wmc.get( i )[0] );
103    
104                            setNameContext( wmc.get( i )[0], file.toURL() );
105                        }
106                    } catch ( Exception e ) {
107                        LOG.logError( e.getMessage(), e );
108                        throw new PortalException( e.getMessage() );
109                    }
110                }
111    
112            }
113            // write map model id for each portlet that has registered an
114            // initial WMC into the users session
115            PortletSet ps = portlet.getPortletConfig().getPortletSet();
116            Enumeration enm = ps.getPortlets();
117            while ( enm.hasMoreElements() ) {
118                Portlet port = (Portlet) enm.nextElement();
119                String cntxId = port.getPortletConfig().getInitParameter( INIT_WMC );
120                if ( cntxId != null ) {
121                    try {
122                        if ( getCurrentViewContext( getInitParam( INIT_MAPPORTLETID ) ) == null ) {
123                            ViewContext vc = getNamedViewContext( cntxId );
124                            setCurrentMapContext( vc, getInitParam( INIT_MAPPORTLETID ) );
125                            setCurrentMapContextName( getInitParam( INIT_MAPPORTLETID ), cntxId );
126                        }
127                    } catch ( Throwable e ) {
128                        //LOG.logError( e.getMessage(), e );
129                        throw new PortalException( e.getMessage() );
130                    }
131                }
132            }
133    
134        }
135    
136    }