com.opensymphony.xwork2.config.impl
Class AbstractMatcher<E>

java.lang.Object
  extended by com.opensymphony.xwork2.config.impl.AbstractMatcher<E>
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ActionConfigMatcher, NamespaceMatcher

public abstract class AbstractMatcher<E>
extends java.lang.Object
implements java.io.Serializable

Matches patterns against pre-compiled wildcard expressions pulled from target objects. It uses the wildcard matcher from the Apache Cocoon project. Patterns will be matched in the order they were added. The first match wins, so more specific patterns should be defined before less specific patterns.

Since:
2.1
See Also:
Serialized Form

Constructor Summary
AbstractMatcher(PatternMatcher<?> helper)
           
 
Method Summary
 void addPattern(java.lang.String name, E target, boolean looseMatch)
           Finds and precompiles the wildcard patterns.
protected abstract  E convert(java.lang.String path, E orig, java.util.Map<java.lang.String,java.lang.String> vars)
           Clones the target object and its children, replacing various properties with the values of the wildcard-matched strings.
protected  java.lang.String convertParam(java.lang.String val, java.util.Map<java.lang.String,java.lang.String> vars)
           Inserts into a value wildcard-matched strings where specified with the {x} syntax.
 void freeze()
           
 E match(java.lang.String potentialMatch)
           Matches the path against the compiled wildcard patterns.
protected  java.util.Map<java.lang.String,java.lang.String> replaceParameters(java.util.Map<java.lang.String,java.lang.String> orig, java.util.Map<java.lang.String,java.lang.String> vars)
           Replaces parameter values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMatcher

public AbstractMatcher(PatternMatcher<?> helper)
Method Detail

addPattern

public void addPattern(java.lang.String name,
                       E target,
                       boolean looseMatch)

Finds and precompiles the wildcard patterns. Patterns will be evaluated in the order they were added. Only patterns that actually contain a wildcard will be compiled.

Patterns can optionally be matched "loosely". When the end of the pattern matches \*[^*]\*$ (wildcard, no wildcard, wildcard), if the pattern fails, it is also matched as if the last two characters didn't exist. The goal is to support the legacy "*!*" syntax, where the "!*" is optional.

Parameters:
name - The pattern
target - The object to associate with the pattern
looseMatch - To loosely match wildcards or not

freeze

public void freeze()

match

public E match(java.lang.String potentialMatch)

Matches the path against the compiled wildcard patterns.

Parameters:
potentialMatch - The portion of the request URI for selecting a config.
Returns:
The action config if matched, else null

convert

protected abstract E convert(java.lang.String path,
                             E orig,
                             java.util.Map<java.lang.String,java.lang.String> vars)

Clones the target object and its children, replacing various properties with the values of the wildcard-matched strings.

Parameters:
path - The requested path
orig - The original object
vars - A Map of wildcard-matched strings
Returns:
A cloned object with appropriate properties replaced with wildcard-matched values

replaceParameters

protected java.util.Map<java.lang.String,java.lang.String> replaceParameters(java.util.Map<java.lang.String,java.lang.String> orig,
                                                                             java.util.Map<java.lang.String,java.lang.String> vars)

Replaces parameter values

Parameters:
orig - The original parameters with placehold values
vars - A Map of wildcard-matched strings

convertParam

protected java.lang.String convertParam(java.lang.String val,
                                        java.util.Map<java.lang.String,java.lang.String> vars)

Inserts into a value wildcard-matched strings where specified with the {x} syntax. If a wildcard-matched value isn't found, the replacement token is turned into an empty string.

Parameters:
val - The value to convert
vars - A Map of wildcard-matched strings
Returns:
The new value


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.