com.opensymphony.xwork2.config.impl

## Class AbstractMatcher<E>

- java.lang.Object
- - com.opensymphony.xwork2.config.impl.AbstractMatcher<E>

- All Implemented Interfaces:
    Serializable
  Direct Known Subclasses:
    ActionConfigMatcher, NamespaceMatcher

      public abstract class AbstractMatcher<E>
      extends Object
      implements 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

    Constructors
    Constructor and Description
    `AbstractMatcher(PatternMatcher<?> helper)` Deprecated. use @{link `AbstractMatcher(PatternMatcher, boolean)` instead
    `AbstractMatcher(PatternMatcher<?> helper, boolean appendNamedParameters)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addPattern(String name, E target, boolean looseMatch)` Finds and precompiles the wildcard patterns.
    `protected abstract E` | `convert(String path, E orig, Map<String,String> vars)` Clones the target object and its children, replacing various properties with the values of the wildcard-matched strings.
    `protected String` | `convertParam(String val, Map<String,String> vars)` Inserts into a value wildcard-matched strings where specified with the {x} syntax.
    `void` | `freeze()`
    `E` | `match(String potentialMatch)` Matches the path against the compiled wildcard patterns.
    `protected Map<String,String>` | `replaceParameters(Map<String,String> orig, Map<String,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,
                         boolean appendNamedParameters)

    - #### AbstractMatcher

          @Deprecated
          public AbstractMatcher(PatternMatcher<?> helper)

      Deprecated. use @{link `AbstractMatcher(PatternMatcher, boolean)` instead
      Creates a matcher with `appendNamedParameters` set to true to keep backward compatibility
      Parameters:
        `helper` - an instance of `PatternMatcher`

  - ### Method Detail

    - #### addPattern

          public void addPattern(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(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(String path,
                  E orig,
                  Map<String,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 Map<String,String> replaceParameters(Map<String,String> orig,
                                             Map<String,String> vars)

      Replaces parameter values

      Parameters:
        `orig` - The original parameters with placeholder values
        `vars` - A Map of wildcard-matched strings
      Returns:
        map with replaced parameters

    - #### convertParam

          protected String convertParam(String val,
                            Map<String,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–2021 Apache Software Foundation. All rights reserved.