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 org.mortbay.jetty.servlet.ServletHolder; 019 import org.mortbay.jetty.servlet.ServletMapping; 020 021 /** 022 * A ServletHandler maintains a collection of servlets and a collection 023 * servlet name to context mappings. 024 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a> 025 * @version 0.0.4 026 */ 027 public class ServletHandler extends org.mortbay.jetty.servlet.ServletHandler 028 { 029 /** 030 * Creation of a new servlet handler. 031 * @param servlets the servlet holder array 032 * @param entries the servlet name to path mappings 033 */ 034 public ServletHandler( ServletHolder[] servlets, ServletEntry[] entries ) 035 { 036 super(); 037 038 setServlets( servlets ); 039 ServletMapping[] mapping = getServletMappings( entries ); 040 setServletMappings( mapping ); 041 } 042 043 private ServletMapping[] getServletMappings( ServletEntry[] entries ) 044 { 045 ServletMapping[] maps = new ServletMapping[ entries.length ]; 046 for( int i=0; i<entries.length; i++ ) 047 { 048 ServletEntry entry = entries[i]; 049 String name = entry.getName(); 050 String path = entry.getPath(); 051 ServletMapping map = new ServletMapping(); 052 map.setServletName( name ); 053 map.setPathSpec( path ); 054 maps[i] = map; 055 } 056 return maps; 057 } 058 }