    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/enterprise/control/ajax/AbstractListener.java $
    002    /*----------------    FILE HEADER  ------------------------------------------
    003
    004     This file is part of deegree.
    005     Copyright (C) 2001-2008 by:
    006     EXSE, Department of Geography, University of Bonn
    007     http://www.giub.uni-bonn.de/deegree/
    008     lat/lon GmbH
    009     http://www.lat-lon.de
    010
    011     This library is free software; you can redistribute it and/or
    012     modify it under the terms of the GNU Lesser General Public
    013     License as published by the Free Software Foundation; either
    014     version 2.1 of the License, or (at your option) any later version.
    015
    016     This library is distributed in the hope that it will be useful,
    017     but WITHOUT ANY WARRANTY; without even the implied warranty of
    018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    019     Lesser General Public License for more details.
    020
    021     You should have received a copy of the GNU Lesser General Public
    022     License along with this library; if not, write to the Free Software
    023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    024
    025     Contact:
    026
    027     Andreas Poth
    028     lat/lon GmbH
    029     Aennchenstr. 19
    030     53115 Bonn
    031     Germany
    032     E-Mail: poth@lat-lon.de
    033
    034     Prof. Dr. Klaus Greve
    035     Department of Geography
    036     University of Bonn
    037     Meckenheimer Allee 166
    038     53115 Bonn
    039     Germany
    040     E-Mail: greve@giub.uni-bonn.de
    041
    042
    043     ---------------------------------------------------------------------------*/
    044    package org.deegree.enterprise.control.ajax;
    045
    046    import java.io.IOException;
    047    import java.util.List;
    048
    049    import javax.servlet.ServletRequest;
    050    import javax.servlet.http.HttpServletRequest;
    051    import javax.servlet.http.HttpSession;
    052
    053    import org.deegree.datatypes.parameter.ParameterValueIm;
    054
    055    /**
    056     * The abstract listener allows the reuse of basic functionality.
    057     *
    058     * @author <a href="mailto:tfriebe@gmx.net">Torsten Friebe</a>
    059     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
    060     *
    061     * @version $Revision: 24033 $
    062     */
    063
    064    public abstract class AbstractListener {
    065
    066        private WebEvent event;
    067
    068        private List<ParameterValueIm> params;
    069
    070        private String nextPage;
    071
    072        protected static int timeout = 10000;
    073
    074        static {
    075            if ( System.getProperty( "timeout" ) != null ) {
    076                timeout = Integer.parseInt( System.getProperty( "timeout" ) );
    077            }
    078        }
    079
    080        /**
    081         *
    082         * @param event
    083         * @param responseHandler
    084         */
    085        public abstract void actionPerformed( WebEvent event, ResponseHandler responseHandler )
    086                                throws IOException;
    087
    088        /**
    089         *
    090         * @param event
    091         * @param responseHandler
    092         */
    093        final void handle( WebEvent event, ResponseHandler responseHandler )
    094                                throws IOException {
    095            this.event = event;
    096            this.actionPerformed( event, responseHandler );
    097        }
    098
    099        /**
    100         *
    101         *
    102         * @return the servlet request
    103         */
    104        protected ServletRequest getRequest() {
    105            Object source = this.event.getSource();
    106            return (ServletRequest) source;
    107        }
    108
    109        /**
    110         * @return the path from the servlet context
    111         */
    112        protected String getHomePath() {
    113            HttpSession session = ( (HttpServletRequest) this.getRequest() ).getSession( true );
    114            String path2Dir = session.getServletContext().getRealPath( "/" );
    115            if ( !path2Dir.startsWith( "/" ) ) {
    116                path2Dir = '/' + path2Dir;
    117            }
    118            return path2Dir;
    119        }
    120
    121        /**
    122         * sets the list of assigned initialization parameters
    123         *
    124         * @param params
    125         */
    126        void setInitParameterList( List<ParameterValueIm> params ) {
    127            this.params = params;
    128        }
    129
    130        /**
    131         * @see #setInitParameterList(List)
    132         * @return the list of assigned initialization parameters
    133         */
    134        protected List<ParameterValueIm> getInitParameterList() {
    135            return params;
    136        }
    137
    138        /**
    139         * returns a named init parameter or <code>null</code> if the parameter is not known
    140         *
    141         * @param name
    142         * @return a named init parameter or <code>null</code> if the parameter is not known
    143         */
    144        protected String getInitParameter( String name ) {
    145            for ( int i = 0; i < params.size(); i++ ) {
    146                ParameterValueIm param = params.get( i );
    147                if ( param.getDescriptor().getName().equals( name ) ) {
    148                    return (String) param.getValue();
    149                }
    150            }
    151            return null;
    152        }
    153
    154        /**
    155         * @param nextPage
    156         */
    157        void setNextPage( String nextPage ) {
    158            this.nextPage = nextPage;
    159
    160        }
    161
    162        /**
    163         *
    164         * @return
    165         */
    166        public String getNextPage() {
    167            return nextPage;
    168        }
    169
    170    }