info.magnolia.cms.util
Class SimpleUrlPattern

java.lang.Object
  extended by info.magnolia.cms.util.SimpleUrlPattern
All Implemented Interfaces:
UrlPattern, java.io.Serializable

public final class SimpleUrlPattern
extends java.lang.Object
implements UrlPattern

An implementation of URLPattern which matches strings using simple * or ? wildcards.

Version:
$Revision $ ($Author $)
Author:
Sameer Charles, Fabrizio Giustina TODO rewrite this class using ant-style path comparison and avoiding regexp. See org.springframework.util.AntPathMatcher in spring 1.2 for a nice implementation.
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface info.magnolia.cms.util.UrlPattern
UrlPattern.MatchAllPattern
 
Field Summary
static java.lang.String MULTIPLE_CHAR_PATTERN
          Regexp pattern used for the simple keyword *.
static java.lang.String SINGLE_CHAR_PATTERN
          Regexp pattern used for the simple keyword ?.
static java.lang.String URL_CHAR_PATTERN
          Any char, newline included.
 
Fields inherited from interface info.magnolia.cms.util.UrlPattern
MATCH_ALL
 
Constructor Summary
SimpleUrlPattern(java.lang.String string)
          Compile a regexp pattern handling * and ? chars.
 
Method Summary
static java.lang.String getEncodedString(java.lang.String str)
          Replace all "*" with RegexWildcardPattern.MULTIPLE_CHAR_PATTERN.
 int getLength()
          Returns the pattern length.
 boolean match(java.lang.String str)
          Does the patter match the given url?
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

URL_CHAR_PATTERN

public static final java.lang.String URL_CHAR_PATTERN
Any char, newline included.

See Also:
Constant Field Values

MULTIPLE_CHAR_PATTERN

public static final java.lang.String MULTIPLE_CHAR_PATTERN
Regexp pattern used for the simple keyword *. Matches 0 or more characters.

See Also:
Constant Field Values

SINGLE_CHAR_PATTERN

public static final java.lang.String SINGLE_CHAR_PATTERN
Regexp pattern used for the simple keyword ?. Matches 0 or 1 character.

See Also:
Constant Field Values
Constructor Detail

SimpleUrlPattern

public SimpleUrlPattern(java.lang.String string)
Compile a regexp pattern handling * and ? chars.

Parameters:
string - input string
Method Detail

getEncodedString

public static java.lang.String getEncodedString(java.lang.String str)
Replace all "*" with RegexWildcardPattern.MULTIPLE_CHAR_PATTERN.

Parameters:
str - input string
Returns:
string where all the occurrences of * and ? are replaced with a regexp pattern.

match

public boolean match(java.lang.String str)
Description copied from interface: UrlPattern
Does the patter match the given url?

Specified by:
match in interface UrlPattern
Parameters:
str - url to match
Returns:
true if the given URL matches the pattern
See Also:
UrlPattern.match(java.lang.String)

getLength

public int getLength()
Description copied from interface: UrlPattern
Returns the pattern length. Longer patterns have higher priority.

Specified by:
getLength in interface UrlPattern
Returns:
pattern length
See Also:
UrlPattern.getLength()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2003-2011 Magnolia International Ltd.. All Rights Reserved.