View Javadoc
1 /* Reattore HTTP Server 2 3 Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz> 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 $Id: PartitioningInterceptor.java,v 1.3 2003/03/05 04:31:57 michaelh Exp $ 20 */ 21 22 package juju.reattore.server.intercept.impl; 23 24 import java.util.*; 25 26 import juju.reattore.protocol.http.*; 27 import juju.reattore.server.intercept.Interceptor; 28 29 /*** Interceptor that hands off to a different child interceptor based 30 on the original request. Can be used to re-map directories or to 31 add servlets. 32 33 Top down only. Does not handle conflicts. 34 <br/> 35 Examples: 36 <ul> 37 <li>add('/foo/', ...) - hand off /foo/ and below.</li> 38 <li>add('/~', ...) - user dir like, hand off ~ and below.</li> 39 </ul> 40 <ul> 41 <li>/foo/bar.html - sub request for bar.html</li> 42 <li>~michaelh/bar.html - sub request for michaelh/bar.html</li> 43 </ul> 44 45 @tag part 46 @group Interceptor 47 @children Target 48 */ 49 public class PartitioningInterceptor 50 implements Interceptor { 51 52 private Map parts = new LinkedHashMap(); 53 54 /*** Add a new child that handles 'path' and below. 55 56 @param path The path the interceptor handles. 57 @param inter The interceptor to use on match. 58 */ 59 public void add(String path, Interceptor inter) { 60 parts.put(path, inter); 61 } 62 63 /*** Configuration helper method. 64 @see #add 65 */ 66 public void addTarget(Target target) { 67 add(target.getPath(), target.getChild()); 68 } 69 70 /*** @see Interceptor */ 71 public boolean process(HttpRequest req, HttpResponse resp) { 72 73 String path = req.getPath(); 74 75 for (Iterator i = parts.entrySet().iterator(); i.hasNext();) { 76 Map.Entry entry = (Map.Entry)i.next(); 77 String key = (String)entry.getKey(); 78 79 if (path.startsWith(key)) { 80 req.changePath(path.substring(key.length())); 81 82 try { 83 return ((Interceptor)entry.getValue()).process(req, resp); 84 } 85 finally { 86 req.changePath(path); 87 } 88 } 89 else { 90 /* Keep looking */ 91 } 92 } 93 94 return false; 95 } 96 }

This page was automatically generated by Maven