Save This Page
Home » tapestry-src-5.0.19 » org.apache.tapestry5.internal.services » [javadoc | source]
    1   // Copyright 2008 The Apache Software Foundation
    2   //
    3   // Licensed under the Apache License, Version 2.0 (the "License");
    4   // you may not use this file except in compliance with the License.
    5   // You may obtain a copy of the License at
    6   //
    7   //     http://www.apache.org/licenses/LICENSE-2.0
    8   //
    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.apache.tapestry5.internal.services;
   16   
   17   import org.apache.tapestry5.services.HttpServletRequestFilter;
   18   import org.apache.tapestry5.services.HttpServletRequestHandler;
   19   
   20   import javax.servlet.http.HttpServletRequest;
   21   import javax.servlet.http.HttpServletResponse;
   22   import java.io.IOException;
   23   import java.util.Collection;
   24   import java.util.regex.Pattern;
   25   
   26   public class IgnoredPathsFilter implements HttpServletRequestFilter
   27   {
   28       private final Pattern[] ignoredPatterns;
   29   
   30       public IgnoredPathsFilter(Collection<String> configuration)
   31       {
   32           ignoredPatterns = new Pattern[configuration.size()];
   33   
   34           int i = 0;
   35   
   36           for (String regexp : configuration)
   37           {
   38               Pattern p = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE);
   39   
   40               ignoredPatterns[i++] = p;
   41           }
   42       }
   43   
   44       public boolean service(HttpServletRequest request, HttpServletResponse response, HttpServletRequestHandler handler)
   45               throws IOException
   46       {
   47           // The servlet path should be "/", and path info is everything after that.
   48   
   49           String path = request.getServletPath();
   50           String pathInfo = request.getPathInfo();
   51   
   52           if (pathInfo != null) path += pathInfo;
   53   
   54   
   55           for (Pattern p : ignoredPatterns)
   56           {
   57               if (p.matcher(path).matches()) return false;
   58           }
   59   
   60           // Not a match, so let it go.
   61   
   62           return handler.service(request, response);
   63       }
   64   }

Save This Page
Home » tapestry-src-5.0.19 » org.apache.tapestry5.internal.services » [javadoc | source]