org.apache.shale.application
Class AbstractRegExpFilter

java.lang.Object
  extended by org.apache.shale.application.AbstractRegExpFilter
All Implemented Interfaces:
Command
Direct Known Subclasses:
ContextRelativePathFilter, RemoteAddrFilter, RemoteHostFilter

public abstract class AbstractRegExpFilter
extends Object
implements Command

Convenience base class for Command implementations that perform regular expression matching against a set of zero or more patterns. The default Command implementation will perform the following algorithm.

USAGE NOTE: - See the class JavaDocs for java.util.regex.Pattern for the valid syntax for regular expression patterns supported by this command.

USAGE NOTE: - Commands based on this class will only be effective if used before the regular filter chain is processed. In other words, you should invoke it as part of a preprocess chain in the shale catalog.

$Id: AbstractRegExpFilter.java 464373 2006-10-16 04:21:54Z rahul $


Field Summary
 
Fields inherited from interface org.apache.commons.chain.Command
CONTINUE_PROCESSING, PROCESSING_COMPLETE
 
Constructor Summary
AbstractRegExpFilter()
           
 
Method Summary
protected  void accept(ShaleWebContext context)
          Perform whatever processing is necessary to mark this request as being accepted.
 boolean execute(Context context)
          Perform the matching algorithm described in our class Javadocs against the value returned by the value() method.
 String getExcludes()
          Return the comma-delimited regular expresson patterns to exclude remote host names that match, if any; otherwise, return null.
 String getIncludes()
          Return the comma-delimited regular expresson patterns to include remote host names that match, if any; otherwise, return null.
protected  Pattern[] getIncludesPatterns()
          Returns an array of regular expression patterns for the includes list.
protected  boolean matches(String expr, Pattern[] patterns, boolean unrestricted)
          Match the specified expression against the specified precompiled patterns.
protected  void reject(ShaleWebContext context)
          Perform whatever processing is necessary to mark this request as being rejected.
 void setExcludes(String excludes)
          Set the comma-delimited regular expression patterns to exclude remote host names that match, if any; or null for no restrictions.
 void setIncludes(String includes)
          Set the comma-delimited regular expression patterns to include remote host names that match, if any; or null for no restrictions.
protected abstract  String value(ShaleWebContext context)
          Return the value, from the specified context, that should be used to match against the configured exclude and include patterns.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractRegExpFilter

public AbstractRegExpFilter()
Method Detail

getIncludesPatterns

protected Pattern[] getIncludesPatterns()

Returns an array of regular expression patterns for the includes list.


getExcludes

public String getExcludes()

Return the comma-delimited regular expresson patterns to exclude remote host names that match, if any; otherwise, return null.


setExcludes

public void setExcludes(String excludes)

Set the comma-delimited regular expression patterns to exclude remote host names that match, if any; or null for no restrictions.

Parameters:
excludes - New exclude pattern(s)

getIncludes

public String getIncludes()

Return the comma-delimited regular expresson patterns to include remote host names that match, if any; otherwise, return null.


setIncludes

public void setIncludes(String includes)

Set the comma-delimited regular expression patterns to include remote host names that match, if any; or null for no restrictions.

Parameters:
includes - New include pattern(s)

execute

public boolean execute(Context context)
                throws Exception

Perform the matching algorithm described in our class Javadocs against the value returned by the value() method.

Specified by:
execute in interface Command
Parameters:
context - ShaleWebContext for this request
Throws:
Exception - if an error occurs

accept

protected void accept(ShaleWebContext context)
               throws Exception

Perform whatever processing is necessary to mark this request as being accepted. The default implementation does nothing.

Parameters:
context - Context for the current request
Throws:
Exception - if an error occurs

reject

protected void reject(ShaleWebContext context)
               throws Exception

Perform whatever processing is necessary to mark this request as being rejected. The default implementation returns a status code of HttpServletResponse.SC_FORBIDDEN.

Parameters:
context - Context for the current request
Throws:
Exception - if an error occurs

value

protected abstract String value(ShaleWebContext context)

Return the value, from the specified context, that should be used to match against the configured exclude and include patterns. This method must be implemented by a concrete subclass.

Parameters:
context - Context for the current request

matches

protected boolean matches(String expr,
                          Pattern[] patterns,
                          boolean unrestricted)

Match the specified expression against the specified precompiled patterns. If there are no patterns, return the specified unrestricted return value; otherwise, return true if the expression matches one of the patterns, or false otherwise.

Parameters:
expr - Expression to be tested
patterns - Array of Pattern to be tested against
unrestricted - Result to be returned if there are no matches


Copyright © 2004-2007 Apache Software Foundation. All Rights Reserved.