www.pudn.com > SecurityFilter.rar > URLPatternMatcher.java


package dev.trade.common.securityfilter.filter; 
 
import org.apache.oro.text.regex.*; 
 
import java.util.Collection; 
 
/** 
 * URLPatternMatcher - A non-thread safe object to be used to match a request 
 * pattern with URLPattern objects. 
 */ 
public class URLPatternMatcher { 
   private PatternMatcher patternMatcher; 
 
   /** 
    * Constructor 
    */ 
   public URLPatternMatcher() { 
      patternMatcher = new Perl5Matcher(); 
   } 
 
   /** 
    * Test to see if a string pattern matches a URLPattern. 
    * 
    * @param pattern a String pattern to check for a match 
    * @param urlPattern a URLPattern object to match against 
    * @return true if the pattern matched the urlPattern, false otherwise 
    * @throws Exception 
    */ 
   public boolean match(String pattern, URLPattern urlPattern) throws Exception { 
      return patternMatcher.matches(pattern, urlPattern.getCompiledPattern()); 
   } 
 
   /** 
    * Test to see if a string pattern and HTTP method matches a URLPattern. 
    * 
    * @param pattern a String pattern to check for a match 
    * @param httpMethod an HTTP pattern to check for a match 
    * @param urlPattern a URLPattern object to match against 
    * @return true if the pattern matched the urlPattern, false otherwise 
    * @throws Exception 
    */ 
   public boolean match(String pattern, String httpMethod, URLPattern urlPattern) throws Exception { 
      if (match(pattern, urlPattern)) { 
         Collection methods = urlPattern.getWebResourceCollection().getHttpMethods(); 
         if (methods.isEmpty() || methods.contains(httpMethod.toUpperCase())) { 
            return true; 
         } 
      } 
      return false; 
   } 
}