FortressServletContainer.java :  » Content-Management-System » hippo » nl » hippo » repository » Java Open Source

Java Open Source » Content Management System » hippo 
hippo » nl » hippo » repository » FortressServletContainer.java
/*
 * Copyright (C) 2006 Otego AG, Switzerland
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.hippo.repository;

import org.apache.avalon.fortress.impl.DefaultContainer;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;


/**
 * This class
 */
public final class FortressServletContainer
    extends DefaultContainer
{
    //~ Instance fields ---------------------------------------------------------------------------------

    /** A field */
    private RequestHandler m_cacheManRequestHandler;

    /** A field */
    private RequestHandler m_webdavRequestHandler;

    //~ Methods -----------------------------------------------------------------------------------------

    /**
     * Simple method to handle requests sent to the container from the controlling servlet.
     *
     * @param request a <code>ServletRequest</code> instance
     * @param response a <code>ServletResponse</code> instance
     *
     * @exception ServletException if a servlet error occurs
     * @exception IOException if an IO error occurs
     */
    public void handleRequest( final ServletRequest request,
                               final ServletResponse response )
        throws ServletException, IOException
    {
        final String contextPath = Util.getSubContext( request );

        if( m_cacheManRequestHandler.getContextPath(  ).equals( contextPath ) )
        {
            m_cacheManRequestHandler.handle( contextPath, request, response );
        }
        else
        {
            m_webdavRequestHandler.handle( contextPath, request, response );
        }
    }

    /**
     * The method
     *
     * @param config The <code>config</code>
     *
     * @throws Exception The <code>Exception</code>
     */
    public void setup( final ServletConfig config )
        throws Exception
    {
        final CacheManRequestHandler cacheManRequestHandler =
            (CacheManRequestHandler)m_serviceManager.lookup( RequestHandler.ROLE + "/cacheman-handler" );
        cacheManRequestHandler.init( config );
        m_cacheManRequestHandler = cacheManRequestHandler;

        final WebdavRequestHandler webdavRequestHandler =
            (WebdavRequestHandler)m_serviceManager.lookup( RequestHandler.ROLE + "/webdav-handler" );
        webdavRequestHandler.init( config );
        m_webdavRequestHandler = webdavRequestHandler;
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.