Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.opensymphony.xwork2.util
Class NamedVariablePatternMatcher

    java.lang.Object
      com.opensymphony.xwork2.util.NamedVariablePatternMatcher

All Implemented Interfaces:
  PatternMatcher<NamedVariablePatternMatcher.CompiledPattern>

    public class NamedVariablePatternMatcher

extends java.lang.Object
implements PatternMatcher<NamedVariablePatternMatcher.CompiledPattern>

An implementation of a pattern matcher that uses simple named wildcards. The named wildcards are defined using the `{VARIABLE_NAME}` syntax and will match any characters that aren't '/'. Internally, the pattern is converted into a regular expression where the named wildcard will be translated into `([^/]+)` so that at least one character must match in order for the wildcard to be matched successfully. Matched values will be available in the variable map, indexed by the name they were given in the pattern.

For example, the following patterns will be processed as so:

Pattern | Example | Variable Map Contents
--- | --- | ---
`/animals/{animal}` | `/animals/dog` | {animal -> dog}
`/animals/{animal}/tag/No{id}` | `/animals/dog/tag/No23` | {animal -> dog, id -> 23}
`/{language}` | `/en` | {language -> en}

Excaping hasn't been implemented since the intended use of these patterns will be in matching URLs.

Nested Class Summary
`static class` | `NamedVariablePatternMatcher.CompiledPattern` Stores the compiled pattern and the variable names matches will correspond to.

Constructor Summary
`NamedVariablePatternMatcher()`

Method Summary
`NamedVariablePatternMatcher.CompiledPattern` | `compilePattern(java.lang.String data)` Compiles the pattern.
`boolean` | `isLiteral(java.lang.String pattern)` Determines if the pattern is a simple literal string or contains wildcards that will need to be processed
`boolean` | `match(java.util.Map<java.lang.String,java.lang.String> map, java.lang.String data, NamedVariablePatternMatcher.CompiledPattern expr)` Tries to process the data against the compiled expression.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### NamedVariablePatternMatcher

    public NamedVariablePatternMatcher()

Method Detail

### isLiteral

    public boolean isLiteral(java.lang.String pattern)

  Description copied from interface: `PatternMatcher`
  Determines if the pattern is a simple literal string or contains wildcards that will need to be processed

  Specified by:
    `isLiteral` in interface `PatternMatcher<NamedVariablePatternMatcher.CompiledPattern>`
  Parameters:
    `pattern` - The string pattern
  Returns:
    True if the pattern doesn't contain processing elements, false otherwise

### compilePattern

    public NamedVariablePatternMatcher.CompiledPattern compilePattern(java.lang.String data)

  Compiles the pattern.

  Specified by:
    `compilePattern` in interface `PatternMatcher<NamedVariablePatternMatcher.CompiledPattern>`
  Parameters:
    `data` - The pattern, must not be null or empty
  Returns:
    The compiled pattern, null if the pattern was null or empty

### match

    public boolean match(java.util.Map<java.lang.String,java.lang.String> map,
                         java.lang.String data,
                         NamedVariablePatternMatcher.CompiledPattern expr)

  Tries to process the data against the compiled expression. If successful, the map will contain the matched data, using the specified variable names in the original pattern.

  Specified by:
    `match` in interface `PatternMatcher<NamedVariablePatternMatcher.CompiledPattern>`
  Parameters:
    `map` - The map of variables
    `data` - The data to match
    `expr` - The compiled pattern
  Returns:
    True if matched, false if not matched, the data was null, or the data was an empty string

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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