View Javadoc

    1   //========================================================================
    2   //$Id: Rule.java 966 2008-04-17 13:53:44Z gregw $
    3   //Copyright 2004-2005 Mort Bay Consulting Pty. Ltd.
    4   //------------------------------------------------------------------------
    5   //Licensed under the Apache License, Version 2.0 (the "License");
    6   //you may not use this file except in compliance with the License.
    7   //You may obtain a copy of the License at
    8   //http://www.apache.org/licenses/LICENSE-2.0
    9   //Unless required by applicable law or agreed to in writing, software
    10  //distributed under the License is distributed on an "AS IS" BASIS,
    11  //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  //See the License for the specific language governing permissions and
    13  //limitations under the License.
    14  //========================================================================
    15  package org.mortbay.jetty.handler.rewrite;
    16
    17  import java.io.IOException;
    18
    19  import javax.servlet.http.HttpServletRequest;
    20  import javax.servlet.http.HttpServletResponse;
    21
    22  /**
    23   * An abstract rule for creating rewrite rules.
    24   */
    25  public abstract class Rule
    26  {
    27      protected boolean _terminating;
    28      protected boolean _handling;
    29
    30      /**
    31       * This method calls tests the rule against the request/response pair and if the Rule
    32       * applies, then the rule's action is triggered.
    33       * @param target The target of the request
    34       * @param request
    35       * @param response
    36       *
    37       * @return The new target if the rule has matched, else null
    38       * @throws IOException TODO
    39       */
    40      public abstract String matchAndApply(String target, HttpServletRequest request, HttpServletResponse response) throws IOException;
    41
    42      /**
    43       * Sets terminating to true or false.
    44       * If true, this rule will terminate the loop if this rule has been applied.
    45       *
    46       * @param terminating
    47       */
    48      public void setTerminating(boolean terminating)
    49      {
    50          _terminating = terminating;
    51      }
    52
    53      /**
    54       * Returns the terminating flag value.
    55       *
    56       * @return <code>true</code> if the rule needs to terminate; <code>false</code> otherwise.
    57       */
    58      public boolean isTerminating()
    59      {
    60          return _terminating;
    61      }
    62
    63      /**
    64       * Returns the handling flag value.
    65       *
    66       * @return <code>true</code> if the rule handles the request and nested handlers should not be called.
    67       */
    68      public boolean isHandling()
    69      {
    70          return _handling;
    71      }
    72
    73      /**
    74       * Set the handling flag value.
    75       *
    76       * @param handling true if the rule handles the request and nested handlers should not be called.
    77       */
    78      public void setHandling(boolean handling)
    79      {
    80          _handling=handling;
    81      }
    82
    83      /**
    84       * Returns the handling and terminating flag values.
    85       */
    86      public String toString()
    87      {
    88          return this.getClass().getName()+(_handling?"[H":"[h")+(_terminating?"T]":"t]");
    89      }
    90  }