BEA Systems, Inc.

com.beasys.commerce.util
Class GlobHelper

java.lang.Object
  |
  +--com.beasys.commerce.util.GlobHelper

public class GlobHelper
extends java.lang.Object
implements java.io.FilenameFilter

A utility class for doing DOS-style pattern matching (GLOBing).

This supports only '?' and '*' pattern characters. No bounded (e.g. "[abcd] file") patterns are supported.

To do a simple pattern match, you can use the matches class method. Additionally, GlobHelper is a FilenameFilter.

This requires the OROMatcher regular expression libraries, which are bundled with WebLogic Server.

Since:
2.0

Field Summary
protected  java.util.List patterns
          Our list of file patterns to match.
 
Constructor Summary
GlobHelper()
          Constructor.
GlobHelper(java.util.Collection c)
          Constructor with patterns.
GlobHelper(java.util.Iterator i)
          Constructor with patterns.
GlobHelper(java.lang.String pattern)
          Constructor with pattern.
GlobHelper(java.lang.String[] patterns)
          Constructor with patterns.
 
Method Summary
 boolean accept(java.io.File dir, java.lang.String name)
          Tell if the specified directory and filename matches our current list patterns.
 void addPattern(java.lang.String pat)
          Add a pattern.
static com.oroinc.text.regex.Pattern getPattern(java.lang.String patStr)
          Get a pattern from the pattern cache, which is a soft reference map of pattern string to Pattern.
 java.util.List getPatterns()
          Get the patterns.
static boolean matches(java.lang.String patStr, java.lang.String str)
          Determine if the given input string matches the specified input pattern.
 boolean removePattern(java.lang.String pat)
          Remove a pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

patterns

protected java.util.List patterns
Our list of file patterns to match.
Constructor Detail

GlobHelper

public GlobHelper()
Constructor.

GlobHelper

public GlobHelper(java.lang.String pattern)
Constructor with pattern.

GlobHelper

public GlobHelper(java.lang.String[] patterns)
Constructor with patterns.

GlobHelper

public GlobHelper(java.util.Collection c)
Constructor with patterns.

GlobHelper

public GlobHelper(java.util.Iterator i)
Constructor with patterns.
Method Detail

addPattern

public void addPattern(java.lang.String pat)
Add a pattern.

removePattern

public boolean removePattern(java.lang.String pat)
Remove a pattern.

getPatterns

public java.util.List getPatterns()
Get the patterns.

accept

public boolean accept(java.io.File dir,
                      java.lang.String name)
Tell if the specified directory and filename matches our current list patterns.
Specified by:
accept in interface java.io.FilenameFilter

matches

public static boolean matches(java.lang.String patStr,
                              java.lang.String str)
                       throws java.lang.IllegalArgumentException
Determine if the given input string matches the specified input pattern.
Parameters:
pat - the pattern (e.g. "Some*Cl?.java").
str - the input string.
Returns:
true if the input string matches the pattern, false if not
Throws:
java.lang.IllegalArgumentException - thrown on a bad pattern string.

getPattern

public static com.oroinc.text.regex.Pattern getPattern(java.lang.String patStr)
                                                throws com.oroinc.text.regex.MalformedPatternException
Get a pattern from the pattern cache, which is a soft reference map of pattern string to Pattern.

By using a sort reference map, the garbage collector can clean it out as needed because we can always recreate the Pattern objects from the strings.

Throws:
com.oroinc.text.regex.MalformedPatternException - thrown on a bad pattern string

BEA Systems, Inc.

Copyright © 2000 BEA Systems, Inc. All Rights Reserved