1 // ======================================================================== 2 // Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd. 3 // ------------------------------------------------------------------------ 4 // All rights reserved. This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v1.0 6 // and Apache License v2.0 which accompanies this distribution. 7 // The Eclipse Public License is available at 8 // http://www.eclipse.org/legal/epl-v10.html 9 // The Apache License v2.0 is available at 10 // http://www.opensource.org/licenses/apache2.0.php 11 // You may elect to redistribute this code under either of these licenses. 12 // ======================================================================== 13 package org.eclipse.jetty.rewrite.handler; 14 15 import java.io.IOException; 16 17 import javax.servlet.http.HttpServletRequest; 18 import javax.servlet.http.HttpServletResponse; 19 20 /** 21 * An abstract rule for creating rewrite rules. 22 */ 23 public abstract class Rule 24 { 25 protected boolean _terminating; 26 protected boolean _handling; 27 28 /** 29 * This method calls tests the rule against the request/response pair and if the Rule 30 * applies, then the rule's action is triggered. 31 * @param target The target of the request 32 * @param request 33 * @param response 34 * 35 * @return The new target if the rule has matched, else null 36 * @throws IOException TODO 37 */ 38 public abstract String matchAndApply(String target, HttpServletRequest request, HttpServletResponse response) throws IOException; 39 40 /** 41 * Sets terminating to true or false. 42 * If true, this rule will terminate the loop if this rule has been applied. 43 * 44 * @param terminating 45 */ 46 public void setTerminating(boolean terminating) 47 { 48 _terminating = terminating; 49 } 50 51 /** 52 * Returns the terminating flag value. 53 * 54 * @return <code>true</code> if the rule needs to terminate; <code>false</code> otherwise. 55 */ 56 public boolean isTerminating() 57 { 58 return _terminating; 59 } 60 61 /** 62 * Returns the handling flag value. 63 * 64 * @return <code>true</code> if the rule handles the request and nested handlers should not be called. 65 */ 66 public boolean isHandling() 67 { 68 return _handling; 69 } 70 71 /** 72 * Set the handling flag value. 73 * 74 * @param handling true if the rule handles the request and nested handlers should not be called. 75 */ 76 public void setHandling(boolean handling) 77 { 78 _handling=handling; 79 } 80 81 /** 82 * Returns the handling and terminating flag values. 83 */ 84 public String toString() 85 { 86 return this.getClass().getName()+(_handling?"[H":"[h")+(_terminating?"T]":"t]"); 87 } 88 }