001 /* 002 * Copyright 2006 Stephen McConnell. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package net.dpml.http; 017 018 import net.dpml.logging.Logger; 019 020 /** 021 * Context handler with enhanced support for symbolic property dereferencing. 022 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a> 023 * @version 0.2.0 024 */ 025 public class ResourceContextHandler extends org.mortbay.jetty.handler.ContextHandler 026 { 027 /** 028 * HTTP static resource context handler parameters. 029 */ 030 public interface Context extends ContextHandlerContext 031 { 032 /** 033 * Get the http context resource base. The value may contain symbolic 034 * property references and should resolve to a local directory. 035 * 036 * @return the resource base 037 */ 038 String getResourceBase(); 039 } 040 041 /** 042 * Creation of a new resource context handler. 043 * @param logger the assigned logging channel 044 * @param context the deployment context 045 * @exception Exception if an instantiation error occurs 046 */ 047 public ResourceContextHandler( Logger logger, Context context ) throws Exception 048 { 049 ContextHelper helper = new ContextHelper( logger ); 050 helper.contextualize( this, context ); 051 052 String base = context.getResourceBase(); 053 super.setResourceBase( base ); 054 logger.debug( "resource path: " + base ); 055 056 ResourceHandler handler = new ResourceHandler( "static", "/" ); 057 super.setHandler( handler ); 058 } 059 }