    001    //$HeadURL: svn+ssh://developername@svn.wald.intevation.org/deegree/base/trunk/resources/eclipse/files_template.xml $
    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.cataloguemanager.servlet;
    037
    038    import java.io.FileInputStream;
    039    import java.io.IOException;
    040    import java.util.Properties;
    041
    042    import javax.servlet.Filter;
    043    import javax.servlet.FilterChain;
    044    import javax.servlet.FilterConfig;
    045    import javax.servlet.ServletContext;
    046    import javax.servlet.ServletException;
    047    import javax.servlet.ServletRequest;
    048    import javax.servlet.ServletResponse;
    049    import javax.servlet.http.HttpServletRequest;
    050
    051    import org.deegree.framework.log.ILogger;
    052    import org.deegree.framework.log.LoggerFactory;
    053
    054    /**
    055     * TODO add class documentation here
    056     *
    057     * @author <a href="mailto:name@deegree.org">Andreas Poth</a>
    058     * @author last edited by: $Author: admin $
    059     *
    060     * @version $Revision: $, $Date: $
    061     */
    062    public class CSWInitFilter implements Filter {
    063
    064        private static ILogger LOG = LoggerFactory.getLogger( CSWInitFilter.class );
    065
    066        /*
    067         * (non-Javadoc)
    068         *
    069         * @see javax.servlet.Filter#destroy()
    070         */
    071        public void destroy() {
    072            // TODO Auto-generated method stub
    073        }
    074
    075        /*
    076         * (non-Javadoc)
    077         *
    078         * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
    079         */
    080        public void init( FilterConfig config )
    081                                throws ServletException {
    082            // TODO Auto-generated method stub
    083        }
    084
    085        /*
    086         * (non-Javadoc)
    087         *
    088         * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse,
    089         * javax.servlet.FilterChain)
    090         */
    091        public void doFilter( ServletRequest req, ServletResponse res, FilterChain chain )
    092                                throws IOException, ServletException {
    093            ServletContext sc = ( (HttpServletRequest) req ).getSession().getServletContext();
    094            String s = sc.getRealPath( "WEB-INF/conf/setup/catalogueManager_config.properties" );
    095            Properties p = new Properties();
    096            p.load( new FileInputStream( s ) );
    097            String tmp = ( (HttpServletRequest) req ).getRequestURI();
    098            if ( tmp.indexOf( "oracle" ) > -1 && tmp.endsWith( ".html" ) ) {
    099                chain.doFilter( req, res );
    100            } else if ( !new Boolean( p.getProperty( "configured" ) ) ) {
    101                req.getRequestDispatcher( "cswsetup.jsp" ).forward( req, res );
    102            } else {
    103                if ( tmp.indexOf( "md_editor.jsp" ) > -1 && !new Boolean( p.getProperty( "editor" ) ) ) {
    104                    req.getRequestDispatcher( "error.jsp" ).forward( req, res );
    105                    LOG.logInfo( "editor is not configured to be available" );
    106                } else if ( tmp.indexOf( "md_search." ) > -1 && !new Boolean( p.getProperty( "searchClient" ) ) ) {
    107                    req.getRequestDispatcher( "error.jsp" ).forward( req, res );
    108                    LOG.logInfo( "search client is not configured to be available" );
    109                } else {
    110                    chain.doFilter( req, res );
    111                }
    112            }
    113
    114        }
    115
    116    }