001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/portal/standard/wms/control/MapRequestDispatcher.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    
037    package org.deegree.portal.standard.wms.control;
038    
039    import java.io.File;
040    import java.io.IOException;
041    
042    import javax.servlet.ServletConfig;
043    import javax.servlet.ServletException;
044    import javax.servlet.http.HttpServletRequest;
045    import javax.servlet.http.HttpServletResponse;
046    import javax.servlet.http.HttpSession;
047    
048    import org.deegree.portal.context.ViewContext;
049    import org.deegree.portal.context.WebMapContextFactory;
050    import org.deegree.portal.standard.wms.Constants;
051    
052    /**
053     * This is a <code>RequestDispatcher</code> which creates a event out of a GET or POST requests.
054     * <P>
055     *
056     * Furthermore this class implements
057     *
058     * <HR>
059     * <B>Design Patterns:</B>:<BR>
060     *
061     * The following Design Patterns are used:
062     * <UL>
063     * <LI> Proxy
064     * </UL>
065     *
066     * @author <a href="mailto:friebe@gmx.net">Torsten Friebe</a>
067     * @author last edited by: $Author: mays$
068     *
069     * @version $Revision: 18195 $ $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
070     */
071    public class MapRequestDispatcher extends org.deegree.enterprise.control.RequestDispatcher {
072    
073        private static final long serialVersionUID = -9110528190805632210L;
074    
075        private ViewContext vc = null;
076    
077        /**
078         * This method initializes the servlet.
079         *
080         * @param cfg
081         *            the servlet configuration
082         *
083         * @throws ServletException
084         *             an exception
085         */
086        @Override
087        public void init( ServletConfig cfg )
088                                throws ServletException {
089            super.init( cfg );
090    
091            String controllerFile = getInitParameter( "Handler.configFile" );
092            if ( !( new File( controllerFile ).exists() ) ) {
093                controllerFile = getServletContext().getRealPath( controllerFile );
094            }
095            String clientContext = this.getInitParameter( "MapContext.configFile" );
096            if ( !( new File( clientContext ).exists() ) ) {
097                clientContext = getServletContext().getRealPath( clientContext );
098                try {
099                    File file = new File( clientContext );
100                    vc = WebMapContextFactory.createViewContext( file.toURL(), null, null );
101                    appHandler = new MapApplicationHandler( controllerFile, vc );
102                } catch ( Exception e ) {
103                    e.printStackTrace();
104                }
105            }
106        }
107    
108        /**
109         *
110         *
111         * @param request
112         * @param response
113         *
114         * @throws ServletException
115         * @throws IOException
116         */
117        @Override
118        protected void service( HttpServletRequest request, HttpServletResponse response )
119                                throws ServletException, IOException {
120    
121            HttpSession session = request.getSession( true );
122            session.setAttribute( Constants.DEFAULTMAPCONTEXT, vc );
123            super.service( request, response );
124        }
125    
126    }