Home » apache-tomcat-6.0.26-src » org.apache » catalina » deploy » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    * 
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    * 
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   
   18   
   19   package org.apache.catalina.deploy;
   20   
   21   
   22   import org.apache.catalina.util.RequestUtil;
   23   import java.io.Serializable;
   24   
   25   
   26   /**
   27    * Representation of a filter mapping for a web application, as represented
   28    * in a <code>&lt;filter-mapping&gt;</code> element in the deployment
   29    * descriptor.  Each filter mapping must contain a filter name plus either
   30    * a URL pattern or a servlet name.
   31    *
   32    * @author Craig R. McClanahan
   33    * @version $Revision: 504726 $ $Date: 2007-02-07 23:53:07 +0100 (Wed, 07 Feb 2007) $
   34    */
   35   
   36   public class FilterMap implements Serializable {
   37   
   38   
   39       // ------------------------------------------------------------- Properties
   40   
   41   
   42       /**
   43        * The name of this filter to be executed when this mapping matches
   44        * a particular request.
   45        */
   46       
   47       public static final int ERROR = 1;
   48       public static final int FORWARD = 2;
   49       public static final int FORWARD_ERROR =3;  
   50       public static final int INCLUDE = 4;
   51       public static final int INCLUDE_ERROR  = 5;
   52       public static final int INCLUDE_ERROR_FORWARD  =6;
   53       public static final int INCLUDE_FORWARD  = 7;
   54       public static final int REQUEST = 8;
   55       public static final int REQUEST_ERROR = 9;
   56       public static final int REQUEST_ERROR_FORWARD = 10;
   57       public static final int REQUEST_ERROR_FORWARD_INCLUDE = 11;
   58       public static final int REQUEST_ERROR_INCLUDE = 12;
   59       public static final int REQUEST_FORWARD = 13;
   60       public static final int REQUEST_INCLUDE = 14;
   61       public static final int REQUEST_FORWARD_INCLUDE= 15;
   62       
   63       // represents nothing having been set. This will be seen 
   64       // as equal to a REQUEST
   65       private static final int NOT_SET = -1;
   66       
   67       private int dispatcherMapping=NOT_SET;
   68       
   69       private String filterName = null;    
   70   
   71       public String getFilterName() {
   72           return (this.filterName);
   73       }
   74   
   75       public void setFilterName(String filterName) {
   76           this.filterName = filterName;
   77       }
   78   
   79   
   80       /**
   81        * The servlet name this mapping matches.
   82        */
   83       private String[] servletNames = new String[0];
   84   
   85       public String[] getServletNames() {
   86           return (this.servletNames);
   87       }
   88   
   89       public void addServletName(String servletName) {
   90           if ("*".equals(servletName)) {
   91               this.matchAllServletNames = true;
   92           } else {
   93               String[] results = new String[servletNames.length + 1];
   94               System.arraycopy(servletNames, 0, results, 0, servletNames.length);
   95               results[servletNames.length] = servletName;
   96               servletNames = results;
   97           }
   98       }
   99   
  100       
  101       /**
  102        * The flag that indicates this mapping will match all url-patterns
  103        */
  104       private boolean matchAllUrlPatterns = false;
  105       
  106       public boolean getMatchAllUrlPatterns() {
  107           return matchAllUrlPatterns;
  108       }
  109       
  110   
  111       /**
  112        * The flag that indicates this mapping will match all servlet-names
  113        */
  114       private boolean matchAllServletNames = false;
  115       
  116       public boolean getMatchAllServletNames() {
  117           return matchAllServletNames;
  118       }
  119   
  120       
  121       /**
  122        * The URL pattern this mapping matches.
  123        */
  124       private String[] urlPatterns = new String[0];
  125   
  126       public String[] getURLPatterns() {
  127           return (this.urlPatterns);
  128       }
  129   
  130       public void addURLPattern(String urlPattern) {
  131           if ("*".equals(urlPattern)) {
  132               this.matchAllUrlPatterns = true;
  133           } else {
  134               String[] results = new String[urlPatterns.length + 1];
  135               System.arraycopy(urlPatterns, 0, results, 0, urlPatterns.length);
  136               results[urlPatterns.length] = RequestUtil.URLDecode(urlPattern);
  137               urlPatterns = results;
  138           }
  139       }
  140       
  141       /**
  142        *
  143        * This method will be used to set the current state of the FilterMap
  144        * representing the state of when filters should be applied:
  145        *
  146        *        ERROR
  147        *        FORWARD
  148        *        FORWARD_ERROR
  149        *        INCLUDE
  150        *        INCLUDE_ERROR
  151        *        INCLUDE_ERROR_FORWARD
  152        *        REQUEST
  153        *        REQUEST_ERROR
  154        *        REQUEST_ERROR_INCLUDE
  155        *        REQUEST_ERROR_FORWARD_INCLUDE
  156        *        REQUEST_INCLUDE
  157        *        REQUEST_FORWARD,
  158        *        REQUEST_FORWARD_INCLUDE
  159        *
  160        */
  161       public void setDispatcher(String dispatcherString) {
  162           String dispatcher = dispatcherString.toUpperCase();
  163           
  164           if (dispatcher.equals("FORWARD")) {
  165   
  166               // apply FORWARD to the global dispatcherMapping.
  167               switch (dispatcherMapping) {
  168                   case NOT_SET  :  dispatcherMapping = FORWARD; break;
  169                   case ERROR : dispatcherMapping = FORWARD_ERROR; break;
  170                   case INCLUDE  :  dispatcherMapping = INCLUDE_FORWARD; break;
  171                   case INCLUDE_ERROR  :  dispatcherMapping = INCLUDE_ERROR_FORWARD; break;
  172                   case REQUEST : dispatcherMapping = REQUEST_FORWARD; break;
  173                   case REQUEST_ERROR : dispatcherMapping = REQUEST_ERROR_FORWARD; break;
  174                   case REQUEST_ERROR_INCLUDE : dispatcherMapping = REQUEST_ERROR_FORWARD_INCLUDE; break;
  175                   case REQUEST_INCLUDE : dispatcherMapping = REQUEST_FORWARD_INCLUDE; break;
  176               }
  177           } else if (dispatcher.equals("INCLUDE")) {
  178               // apply INCLUDE to the global dispatcherMapping.
  179               switch (dispatcherMapping) {
  180                   case NOT_SET  :  dispatcherMapping = INCLUDE; break;
  181                   case ERROR : dispatcherMapping = INCLUDE_ERROR; break;
  182                   case FORWARD  :  dispatcherMapping = INCLUDE_FORWARD; break;
  183                   case FORWARD_ERROR  :  dispatcherMapping = INCLUDE_ERROR_FORWARD; break;
  184                   case REQUEST : dispatcherMapping = REQUEST_INCLUDE; break;
  185                   case REQUEST_ERROR : dispatcherMapping = REQUEST_ERROR_INCLUDE; break;
  186                   case REQUEST_ERROR_FORWARD : dispatcherMapping = REQUEST_ERROR_FORWARD_INCLUDE; break;
  187                   case REQUEST_FORWARD : dispatcherMapping = REQUEST_FORWARD_INCLUDE; break;
  188               }
  189           } else if (dispatcher.equals("REQUEST")) {
  190               // apply REQUEST to the global dispatcherMapping.
  191               switch (dispatcherMapping) {
  192                   case NOT_SET  :  dispatcherMapping = REQUEST; break;
  193                   case ERROR : dispatcherMapping = REQUEST_ERROR; break;
  194                   case FORWARD  :  dispatcherMapping = REQUEST_FORWARD; break;
  195                   case FORWARD_ERROR  :  dispatcherMapping = REQUEST_ERROR_FORWARD; break;
  196                   case INCLUDE  :  dispatcherMapping = REQUEST_INCLUDE; break;
  197                   case INCLUDE_ERROR  :  dispatcherMapping = REQUEST_ERROR_INCLUDE; break;
  198                   case INCLUDE_FORWARD : dispatcherMapping = REQUEST_FORWARD_INCLUDE; break;
  199                   case INCLUDE_ERROR_FORWARD : dispatcherMapping = REQUEST_ERROR_FORWARD_INCLUDE; break;
  200               }
  201           }  else if (dispatcher.equals("ERROR")) {
  202               // apply ERROR to the global dispatcherMapping.
  203               switch (dispatcherMapping) {
  204                   case NOT_SET  :  dispatcherMapping = ERROR; break;
  205                   case FORWARD  :  dispatcherMapping = FORWARD_ERROR; break;
  206                   case INCLUDE  :  dispatcherMapping = INCLUDE_ERROR; break;
  207                   case INCLUDE_FORWARD : dispatcherMapping = INCLUDE_ERROR_FORWARD; break;
  208                   case REQUEST : dispatcherMapping = REQUEST_ERROR; break;
  209                   case REQUEST_INCLUDE : dispatcherMapping = REQUEST_ERROR_INCLUDE; break;
  210                   case REQUEST_FORWARD : dispatcherMapping = REQUEST_ERROR_FORWARD; break;
  211                   case REQUEST_FORWARD_INCLUDE : dispatcherMapping = REQUEST_ERROR_FORWARD_INCLUDE; break;
  212               }
  213           }
  214       }
  215       
  216       public int getDispatcherMapping() {
  217           // per the SRV.6.2.5 absence of any dispatcher elements is
  218           // equivelant to a REQUEST value
  219           if (dispatcherMapping == NOT_SET) return REQUEST;
  220           else return dispatcherMapping; 
  221       }
  222   
  223   
  224       // --------------------------------------------------------- Public Methods
  225   
  226   
  227       /**
  228        * Render a String representation of this object.
  229        */
  230       public String toString() {
  231   
  232           StringBuffer sb = new StringBuffer("FilterMap[");
  233           sb.append("filterName=");
  234           sb.append(this.filterName);
  235           for (int i = 0; i < servletNames.length; i++) {
  236               sb.append(", servletName=");
  237               sb.append(servletNames[i]);
  238           }
  239           for (int i = 0; i < urlPatterns.length; i++) {
  240               sb.append(", urlPattern=");
  241               sb.append(urlPatterns[i]);
  242           }
  243           sb.append("]");
  244           return (sb.toString());
  245   
  246       }
  247   
  248   
  249   }

Home » apache-tomcat-6.0.26-src » org.apache » catalina » deploy » [javadoc | source]