protected RuleExecutionOutput matchesBase(String url,final HttpServletRequest hsRequest,final HttpServletResponse hsResponse,RuleChain chain) throws IOException, ServletException, InvocationTargetException {
  if (log.isDebugEnabled()) {
    String displayName=getDisplayName();
    log.debug(displayName + " run called with " + url);
  }
  if (!initialised) {
    log.debug("not initialised, skipping");
    return null;
  }
  if (!valid) {
    log.debug("not valid, skipping");
    return null;
  }
  if (!enabled) {
    log.debug("not enabled, skipping");
    return null;
  }
  if (url == null) {
    log.debug("url is null (maybe because of a previous match), skipping");
    return null;
  }
  StringMatchingMatcher matcher=pattern.matcher(url);
  boolean performToReplacement=false;
  if (toEmpty || stopFilterChainOnMatch) {
    if (!matcher.find()) {
      if (log.isTraceEnabled()) {
        log.trace("no match on \"from\" (to is empty)");
      }
      return null;
    }
  }
 else {
    if (!matcher.find()) {
      if (log.isTraceEnabled()) {
        log.trace("no match on \"from\" for " + from + " and "+ url);
      }
      return null;
    }
    if (!toEmpty && !noSubstitution) {
      performToReplacement=true;
    }
  }
  if (log.isDebugEnabled()) {
    log.debug("matched \"from\"");
  }
  int conditionsSize=conditions.size();
  ConditionMatch lastConditionMatch=null;
  if (conditionsSize > 0) {
    boolean processNextOr=false;
    boolean currentResult=true;
    for (int i=0; i < conditionsSize; i++) {
      final Condition condition=(Condition)conditions.get(i);
      ConditionMatch conditionMatch=condition.getConditionMatch(hsRequest);
      if (conditionMatch != null) {
        lastConditionMatch=conditionMatch;
      }
      boolean conditionMatches=conditionMatch != null;
      if (processNextOr) {
        currentResult|=conditionMatches;
      }
 else {
        currentResult&=conditionMatches;
      }
      processNextOr=condition.isProcessNextOr();
    }
    if (!currentResult) {
      log.debug("conditions do not match");
      return null;
    }
 else {
      log.debug("conditions match");
    }
  }
  hsRequest.setAttribute("org.tuckey.web.filters.urlrewrite.RuleMatched",Boolean.TRUE);
  int setAttributesSize=setAttributes.size();
  if (setAttributesSize > 0) {
    log.trace("setting attributes");
    for (int i=0; i < setAttributesSize; i++) {
      SetAttribute setAttribute=(SetAttribute)setAttributes.get(i);
      setAttribute.execute(lastConditionMatch,matcher,hsRequest,hsResponse);
    }
  }
  int runsSize=runs.size();
  RewriteMatch lastRunMatch=null;
  if (runsSize > 0) {
    log.trace("performing runs");
    for (int i=0; i < runsSize; i++) {
      Run run=(Run)runs.get(i);
      lastRunMatch=run.execute(hsRequest,hsResponse,matcher,lastConditionMatch,chain);
    }
  }
  String replacedTo=null;
  if (performToReplacement && to != null) {
    SubstitutionContext substitutionContext=new SubstitutionContext(hsRequest,matcher,lastConditionMatch,to);
    SubstitutionFilterChain substitutionFilter=ChainedSubstitutionFilters.getDefaultSubstitutionChain(true,toContainsFunction,toContainsVariable,toContainsBackReference,servletContext);
    replacedTo=substitutionFilter.substitute(url,substitutionContext);
  }
  RuleExecutionOutput ruleExecutionOutput=new RuleExecutionOutput(replacedTo,true,lastRunMatch);
  if (toEmpty) {
    log.debug("'to' is empty, no rewrite, only 'set' and or 'run'");
    return null;
  }
  if (noSubstitution) {
    log.debug("'to' is '-', no substitution, passing through URL");
    ruleExecutionOutput.setNoSubstitution(true);
    ruleExecutionOutput.setReplacedUrl(url);
  }
  if (stopFilterChainOnMatch) {
    ruleExecutionOutput.setStopFilterMatch(true);
    ruleExecutionOutput.setReplacedUrl(null);
  }
  return ruleExecutionOutput;
}

protected RuleExecutionOutput matchesBase ( String url , final HttpServletRequest hsRequest , final HttpServletResponse hsResponse , RuleChain chain ) throws IOException , ServletException , InvocationTargetException { if ( log . isDebugEnabled ( ) ) { String displayName = getDisplayName ( ) ; log . debug ( displayName + " run called with " + url ) ; } if ( ! initialised ) { log . debug ( "not initialised, skipping" ) ; return null ; } if ( ! valid ) { log . debug ( "not valid, skipping" ) ; return null ; } if ( ! enabled ) { log . debug ( "not enabled, skipping" ) ; return null ; } if ( url == null ) { log . debug ( "url is null (maybe because of a previous match), skipping" ) ; return null ; } StringMatchingMatcher matcher = pattern . matcher ( url ) ; boolean performToReplacement = false ; if ( toEmpty || stopFilterChainOnMatch ) { if ( ! matcher . find ( ) ) { if ( log . isTraceEnabled ( ) ) { log . trace ( "no match on \"from\" (to is empty)" ) ; } return null ; } } else { if ( ! matcher . find ( ) ) { if ( log . isTraceEnabled ( ) ) { log . trace ( "no match on \"from\" for " + from + " and " + url ) ; } return null ; } if ( ! toEmpty && ! noSubstitution ) { performToReplacement = true ; } } if ( log . isDebugEnabled ( ) ) { log . debug ( "matched \"from\"" ) ; } int conditionsSize = conditions . size ( ) ; ConditionMatch lastConditionMatch = null ; if ( conditionsSize > 0 ) { boolean processNextOr = false ; boolean currentResult = true ; for ( int i = 0 ; i < conditionsSize ; i ++ ) { final Condition condition = ( Condition ) conditions . get ( i ) ; ConditionMatch conditionMatch = condition . getConditionMatch ( hsRequest ) ; if ( conditionMatch != null ) { lastConditionMatch = conditionMatch ; } boolean conditionMatches = conditionMatch != null ; if ( processNextOr ) { currentResult |= conditionMatches ; } else { currentResult &= conditionMatches ; } processNextOr = condition . isProcessNextOr ( ) ; } if ( ! currentResult ) { log . debug ( "conditions do not match" ) ; return null ; } else { log . debug ( "conditions match" ) ; } } hsRequest . setAttribute ( "org.tuckey.web.filters.urlrewrite.RuleMatched" , Boolean . TRUE ) ; int setAttributesSize = setAttributes . size ( ) ; if ( setAttributesSize > 0 ) { log . trace ( "setting attributes" ) ; for ( int i = 0 ; i < setAttributesSize ; i ++ ) { SetAttribute setAttribute = ( SetAttribute ) setAttributes . get ( i ) ; setAttribute . execute ( lastConditionMatch , matcher , hsRequest , hsResponse ) ; } } int runsSize = runs . size ( ) ; RewriteMatch lastRunMatch = null ; if ( runsSize > 0 ) { log . trace ( "performing runs" ) ; for ( int i = 0 ; i < runsSize ; i ++ ) { Run run = ( Run ) runs . get ( i ) ; lastRunMatch = run . execute ( hsRequest , hsResponse , matcher , lastConditionMatch , chain ) ; } } String replacedTo = null ; if ( performToReplacement && to != null ) { SubstitutionContext substitutionContext = new SubstitutionContext ( hsRequest , matcher , lastConditionMatch , to ) ; SubstitutionFilterChain substitutionFilter = ChainedSubstitutionFilters . getDefaultSubstitutionChain ( true , toContainsFunction , toContainsVariable , toContainsBackReference , servletContext ) ; replacedTo = substitutionFilter . substitute ( url , substitutionContext ) ; } RuleExecutionOutput ruleExecutionOutput = new RuleExecutionOutput ( replacedTo , true , lastRunMatch ) ; if ( toEmpty ) { log . debug ( "'to' is empty, no rewrite, only 'set' and or 'run'" ) ; return null ; } if ( noSubstitution ) { log . debug ( "'to' is '-', no substitution, passing through URL" ) ; ruleExecutionOutput . setNoSubstitution ( true ) ; ruleExecutionOutput . setReplacedUrl ( url ) ; } if ( stopFilterChainOnMatch ) { ruleExecutionOutput . setStopFilterMatch ( true ) ; ruleExecutionOutput . setReplacedUrl ( null ) ; } return ruleExecutionOutput ; }
will run the rule against the uri and perform action required will return false is not matched otherwise true .
