Methods Summary |
---|
public synchronized void | addConfiguredFilterSet(org.apache.tools.ant.types.FilterSet filterSet)Add a Filterset to this filter set.
if (isReference()) {
throw noChildrenAllowed();
}
for (Enumeration e = filterSet.getFilters().elements(); e.hasMoreElements();) {
addFilter((Filter) e.nextElement());
}
|
public synchronized void | addFilter(org.apache.tools.ant.types.FilterSet$Filter filter)Add a new filter.
if (isReference()) {
throw noChildrenAllowed();
}
filters.addElement(filter);
filterHash = null;
|
public synchronized void | addFilter(java.lang.String token, java.lang.String value)Add a new filter made from the given token and value.
if (isReference()) {
throw noChildrenAllowed();
}
addFilter(new Filter(token, value));
|
public synchronized java.lang.Object | clone()Clone the filterset.
if (isReference()) {
return ((FilterSet) getRef()).clone();
}
try {
FilterSet fs = (FilterSet) super.clone();
fs.filters = (Vector) getFilters().clone();
fs.setProject(getProject());
return fs;
} catch (CloneNotSupportedException e) {
throw new BuildException(e);
}
|
public org.apache.tools.ant.types.FilterSet$FiltersFile | createFiltersfile()Create a new FiltersFile.
if (isReference()) {
throw noChildrenAllowed();
}
return new FiltersFile();
|
public java.lang.String | getBeginToken()Get the begin token for this filterset.
if (isReference()) {
return getRef().getBeginToken();
}
return startOfToken;
|
public java.lang.String | getEndToken()Get the end token for this filterset.
if (isReference()) {
return getRef().getEndToken();
}
return endOfToken;
|
public synchronized java.util.Hashtable | getFilterHash()Gets the filter hash of the FilterSet.
if (filterHash == null) {
filterHash = new Hashtable(getFilters().size());
for (Enumeration e = getFilters().elements(); e.hasMoreElements();) {
Filter filter = (Filter) e.nextElement();
filterHash.put(filter.getToken(), filter.getValue());
}
}
return filterHash;
|
protected synchronized java.util.Vector | getFilters()Get the filters in the filter set.
if (isReference()) {
return getRef().getFilters();
}
//silly hack to avoid stack overflow...
if (!readingFiles) {
readingFiles = true;
for (int i = 0, sz = filtersFiles.size(); i < sz; i++) {
readFiltersFromFile((File) filtersFiles.get(i));
}
filtersFiles.clear();
readingFiles = false;
}
return filters;
|
public org.apache.tools.ant.types.FilterSet$OnMissing | getOnMissingFiltersFile()Get the onMissingFiltersFile setting.
return onMissingFiltersFile;
|
protected org.apache.tools.ant.types.FilterSet | getRef()Get the referenced filter set.
return (FilterSet) getCheckedRef(FilterSet.class, "filterset");
|
private void | handleMissingFile(java.lang.String message)
switch (onMissingFiltersFile.getIndex()) {
case OnMissing.IGNORE_INDEX:
return;
case OnMissing.FAIL_INDEX:
throw new BuildException(message);
case OnMissing.WARN_INDEX:
log(message, Project.MSG_WARN);
return;
default:
throw new BuildException("Invalid value for onMissingFiltersFile");
}
|
public synchronized boolean | hasFilters()Test to see if this filter set has filters.
return getFilters().size() > 0;
|
private synchronized java.lang.String | iReplaceTokens(java.lang.String line)Does replacement on the given string with token matching.
This uses the defined begintoken and endtoken values which default
to @ for both.
String beginToken = getBeginToken();
String endToken = getEndToken();
int index = line.indexOf(beginToken);
if (index > -1) {
Hashtable tokens = getFilterHash();
try {
StringBuffer b = new StringBuffer();
int i = 0;
String token = null;
String value = null;
while (index > -1) {
//can't have zero-length token
int endIndex = line.indexOf(endToken,
index + beginToken.length() + 1);
if (endIndex == -1) {
break;
}
token
= line.substring(index + beginToken.length(), endIndex);
b.append(line.substring(i, index));
if (tokens.containsKey(token)) {
value = (String) tokens.get(token);
if (recurse && !value.equals(token)) {
// we have another token, let's parse it.
value = replaceTokens(value, token);
}
log("Replacing: " + beginToken + token + endToken
+ " -> " + value, Project.MSG_VERBOSE);
b.append(value);
i = index + beginToken.length() + token.length()
+ endToken.length();
} else {
// just append beginToken and search further
b.append(beginToken);
i = index + beginToken.length();
}
index = line.indexOf(beginToken, i);
}
b.append(line.substring(i));
return b.toString();
} catch (StringIndexOutOfBoundsException e) {
return line;
}
} else {
return line;
}
|
public boolean | isRecurse()Get whether recursive token expansion is enabled.
return recurse;
|
public synchronized void | readFiltersFromFile(java.io.File filtersFile)Read the filters from the given file.
if (isReference()) {
throw tooManyAttributes();
}
if (!filtersFile.exists()) {
handleMissingFile("Could not read filters from file "
+ filtersFile + " as it doesn't exist.");
}
if (filtersFile.isFile()) {
log("Reading filters from " + filtersFile, Project.MSG_VERBOSE);
FileInputStream in = null;
try {
Properties props = new Properties();
in = new FileInputStream(filtersFile);
props.load(in);
Enumeration e = props.propertyNames();
Vector filts = getFilters();
while (e.hasMoreElements()) {
String strPropName = (String) e.nextElement();
String strValue = props.getProperty(strPropName);
filts.addElement(new Filter(strPropName, strValue));
}
} catch (Exception ex) {
throw new BuildException("Could not read filters from file: "
+ filtersFile);
} finally {
FileUtils.close(in);
}
} else {
handleMissingFile(
"Must specify a file rather than a directory in "
+ "the filtersfile attribute:" + filtersFile);
}
filterHash = null;
|
public synchronized java.lang.String | replaceTokens(java.lang.String line)Does replacement on the given string with token matching.
This uses the defined begintoken and endtoken values which default
to @ for both.
This resets the passedTokens and calls iReplaceTokens to
do the actual replacements.
return iReplaceTokens(line);
|
private synchronized java.lang.String | replaceTokens(java.lang.String line, java.lang.String parent)This parses tokens which point to tokens.
It also maintains a list of currently used tokens, so we cannot
get into an infinite loop.
String beginToken = getBeginToken();
String endToken = getEndToken();
if (recurseDepth == 0) {
passedTokens = new Vector();
}
recurseDepth++;
if (passedTokens.contains(parent) && !duplicateToken) {
duplicateToken = true;
System.out.println(
"Infinite loop in tokens. Currently known tokens : "
+ passedTokens.toString() + "\nProblem token : " + beginToken
+ parent + endToken + " called from " + beginToken
+ passedTokens.lastElement().toString() + endToken);
recurseDepth--;
return parent;
}
passedTokens.addElement(parent);
String value = iReplaceTokens(line);
if (value.indexOf(beginToken) == -1 && !duplicateToken
&& recurseDepth == 1) {
passedTokens = null;
} else if (duplicateToken) {
// should always be the case...
if (passedTokens.size() > 0) {
value = (String) passedTokens.remove(passedTokens.size() - 1);
if (passedTokens.size() == 0) {
value = beginToken + value + endToken;
duplicateToken = false;
}
}
}
recurseDepth--;
return value;
|
public void | setBeginToken(java.lang.String startOfToken)Set the string used to id the beginning of a token.
if (isReference()) {
throw tooManyAttributes();
}
if (startOfToken == null || "".equals(startOfToken)) {
throw new BuildException("beginToken must not be empty");
}
this.startOfToken = startOfToken;
|
public void | setEndToken(java.lang.String endOfToken)Set the string used to id the end of a token.
if (isReference()) {
throw tooManyAttributes();
}
if (endOfToken == null || "".equals(endOfToken)) {
throw new BuildException("endToken must not be empty");
}
this.endOfToken = endOfToken;
|
public void | setFiltersfile(java.io.File filtersFile)Set the file containing the filters for this filterset.
if (isReference()) {
throw tooManyAttributes();
}
filtersFiles.add(filtersFile);
|
public void | setOnMissingFiltersFile(org.apache.tools.ant.types.FilterSet$OnMissing onMissingFiltersFile)Set the behavior WRT missing filtersfiles.
this.onMissingFiltersFile = onMissingFiltersFile;
|
public void | setRecurse(boolean recurse)Set whether recursive token expansion is enabled.
this.recurse = recurse;
|