info.magnolia.cms.util
Class SimpleUrlPattern

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

public final class SimpleUrlPattern
extends 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 String MULTIPLE_CHAR_PATTERN
          Regexp pattern used for the simple keyword *.
static String SINGLE_CHAR_PATTERN
          Regexp pattern used for the simple keyword ?.
static String URL_CHAR_PATTERN
          Any char, newline included.
 
Fields inherited from interface info.magnolia.cms.util.UrlPattern
MATCH_ALL
 
Constructor Summary
SimpleUrlPattern(String string)
          Compile a regexp pattern handling * and ? chars.
 
Method Summary
static String getEncodedString(String str)
          Replace all "*" with RegexWildcardPattern.MULTIPLE_CHAR_PATTERN.
 int getLength()
          Returns the pattern length.
 boolean match(String str)
          Does the patter match the given url?
 boolean matchSiteName(String siteName)
           
 boolean shouldUseFullURI(String pattern, String fullURI)
           
 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 String URL_CHAR_PATTERN
Any char, newline included.

See Also:
Constant Field Values

MULTIPLE_CHAR_PATTERN

public static final 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 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(String string)
Compile a regexp pattern handling * and ? chars.

Parameters:
string - input string
Method Detail

getEncodedString

public static String getEncodedString(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.

shouldUseFullURI

public boolean shouldUseFullURI(String pattern,
                                String fullURI)

match

public boolean match(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)

matchSiteName

public boolean matchSiteName(String siteName)

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 String toString()
Overrides:
toString in class Object


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