FileDocCategorySizeDatePackage
GlobPatternMapper.javaAPI DocApache Ant 1.705179Wed Dec 13 06:16:24 GMT 2006org.apache.tools.ant.util

GlobPatternMapper

public class GlobPatternMapper extends Object implements FileNameMapper
Implementation of FileNameMapper that does simple wildcard pattern replacements.

This does simple translations like *.foo -> *.bar where the prefix to .foo will be left unchanged. It only handles a single * character, use regular expressions for more complicated situations.

This is one of the more useful Mappers, it is used by javac for example.

Fields Summary
protected String
fromPrefix
Part of "from" pattern before the *.
protected String
fromPostfix
Part of "from" pattern after the *.
protected int
prefixLength
Length of the prefix ("from" pattern).
protected int
postfixLength
Length of the postfix ("from" pattern).
protected String
toPrefix
Part of "to" pattern before the *.
protected String
toPostfix
Part of "to" pattern after the *.
private boolean
handleDirSep
private boolean
caseSensitive
Constructors Summary
Methods Summary
protected java.lang.StringextractVariablePart(java.lang.String name)
Returns the part of the given string that matches the * in the "from" pattern.

param
name the source file name
return
the variable part of the name

        return name.substring(prefixLength,
                              name.length() - postfixLength);
    
public java.lang.String[]mapFileName(java.lang.String sourceFileName)
Returns null if the source file name doesn't match the "from" pattern, an one-element array containing the translated file otherwise.

param
sourceFileName the filename to map
return
a list of converted filenames

        if (fromPrefix == null
            || !modifyName(sourceFileName).startsWith(modifyName(fromPrefix))
            || !modifyName(sourceFileName).endsWith(modifyName(fromPostfix))) {
            return null;
        }
        return new String[] {toPrefix
                                 + extractVariablePart(sourceFileName)
                                 + toPostfix};
    
private java.lang.StringmodifyName(java.lang.String name)
modify string based on dir char mapping and case sensitivity

param
name the name to convert
return
the converted name

        if (!caseSensitive) {
            name = name.toLowerCase();
        }
        if (handleDirSep) {
            if (name.indexOf('\\") != -1) {
                name = name.replace('\\", '/");
            }
        }
        return name;
    
public voidsetCaseSensitive(boolean caseSensitive)
Attribute specifing whether to ignore the case difference in the names.

param
caseSensitive a boolean, default is false.
since
Ant 1.6.3

        this.caseSensitive = caseSensitive;
    
public voidsetFrom(java.lang.String from)
Sets the "from" pattern. Required.

param
from a string

        int index = from.lastIndexOf("*");
        if (index == -1) {
            fromPrefix = from;
            fromPostfix = "";
        } else {
            fromPrefix = from.substring(0, index);
            fromPostfix = from.substring(index + 1);
        }
        prefixLength = fromPrefix.length();
        postfixLength = fromPostfix.length();
    
public voidsetHandleDirSep(boolean handleDirSep)
Attribute specifing whether to ignore the difference between / and \ (the two common directory characters).

param
handleDirSep a boolean, default is false.
since
Ant 1.6.3


                                   
        
        this.handleDirSep = handleDirSep;
    
public voidsetTo(java.lang.String to)
Sets the "to" pattern. Required.

param
to a string

        int index = to.lastIndexOf("*");
        if (index == -1) {
            toPrefix = to;
            toPostfix = "";
        } else {
            toPrefix = to.substring(0, index);
            toPostfix = to.substring(index + 1);
        }