net.pandoragames.far.ui
Class SimpleFileNamePattern

java.lang.Object
  extended by net.pandoragames.far.ui.SimpleFileNamePattern
Direct Known Subclasses:
SimpleFileNamePatternFAR, SimpleFileNamePatternShell

public abstract class SimpleFileNamePattern
extends java.lang.Object

Utility for simplified regular expresions. At several places, especially for the selection of file names, the application will accept a simple pattern as alternative to an ordinary regular expression. A simple pattern is a simpliefied regular expression syntax, typically allowing * as a wild card for "any number of characters" (in contrast to .* in proper regular expressions).

The default implementation for a simple pattern is SimpleFileNamePatternFAR, but an alternative SimpleFileNamePatternFAR is provided and others could be added. See the respective implementations for details of the pattern syntax.

Author:
Olivier Wehner

Field Summary
protected  java.util.Set<java.lang.Character> forbiddenCharacters
          Set of characters that should not be tolerated in a simple pattern.
protected  org.apache.commons.logging.Log logger
          Never leave without a logger.
protected  java.util.Set<java.lang.Character> toBeEscaped
          Set of characters that must be escaped when producing a regular expression.
 
Constructor Summary
protected SimpleFileNamePattern()
          Protected constructor for inheriting classes.
 
Method Summary
abstract  java.util.regex.Pattern createPattern(java.lang.String simplePattern, boolean ignoreCase)
          Create a java.util.regex.Pattern from a simple string pattern.
static SimpleFileNamePattern getInstance()
          Returns an instance of this utility class.
protected static void setInstance(SimpleFileNamePattern instance)
          Sets a new implementation of this class as to be returned by the getInstance() method.
 boolean validateFileNamePattern(FileNamePattern pattern)
          Validates the specified FileNamePattern for syntactically correctness.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

forbiddenCharacters

protected java.util.Set<java.lang.Character> forbiddenCharacters
Set of characters that should not be tolerated in a simple pattern. This set contains the characters '/','\',':' and ';'. In addition, the platform file separator (/ on *X, \ on Windows) and the platform file-name separator (: on *X, ; on Windows) are not permitted. Implementations should not allow characters below below u20 (blank, ascii 32) either.


toBeEscaped

protected java.util.Set<java.lang.Character> toBeEscaped
Set of characters that must be escaped when producing a regular expression. The set contains the following characters: '.', '^', '$', '+', '-', '*', '?', '(', ')', '[', ']', '{', '}' and '|'.


logger

protected org.apache.commons.logging.Log logger
Never leave without a logger.

Constructor Detail

SimpleFileNamePattern

protected SimpleFileNamePattern()
Protected constructor for inheriting classes.

Method Detail

getInstance

public static SimpleFileNamePattern getInstance()
Returns an instance of this utility class. By default this returns an instance of class SimpleFileNamePatternFAR. This behaviour can be changed by calling the setInstance() method.

Returns:
instance of this class

setInstance

protected static void setInstance(SimpleFileNamePattern instance)
Sets a new implementation of this class as to be returned by the getInstance() method. Null values will be ignored.

Parameters:
instance - new default instance for getInstance() method.

createPattern

public abstract java.util.regex.Pattern createPattern(java.lang.String simplePattern,
                                                      boolean ignoreCase)
                                               throws PatternException
Create a java.util.regex.Pattern from a simple string pattern. The syntax of the simple pattern is implementation dependend.

Parameters:
simplePattern - see class description
ignoreCase - should letter case be considdered
Returns:
Pattern object for specified simple pattern string
Throws:
PatternException - if the simple pattern is not valid

validateFileNamePattern

public boolean validateFileNamePattern(FileNamePattern pattern)
Validates the specified FileNamePattern for syntactically correctness.

Parameters:
pattern - to be validated
Returns:
true if pattern is ok