@@ -73,14 +73,14 @@ public class Replace extends MatchingTask {
private FileUtils fileUtils = FileUtils.newFileUtils();
private FileUtils fileUtils = FileUtils.newFileUtils();
/**
/**
* an inline string to use as the replacement text
* An inline string to use as the replacement text.
*/
*/
public class NestedString {
public class NestedString {
private StringBuffer buf = new StringBuffer();
private StringBuffer buf = new StringBuffer();
/**
/**
* the text of the element
* The text of the element.
*
*
* @param val the string to add
* @param val the string to add
*/
*/
@@ -109,8 +109,8 @@ public class Replace extends MatchingTask {
private StringBuffer outputBuffer = new StringBuffer();
private StringBuffer outputBuffer = new StringBuffer();
/**
/**
* validate the filter's configuration
* @throws BuildException if any part is invalid
* Validate the filter's configuration.
* @throws BuildException if any part is invalid.
*/
*/
public void validate() throws BuildException {
public void validate() throws BuildException {
//Validate mandatory attributes
//Validate mandatory attributes
@@ -173,16 +173,16 @@ public class Replace extends MatchingTask {
}
}
/**
/**
* Set the token to replace
* @param token token
* Set the token to replace,
* @param token <code>String</code> token.
*/
*/
public void setToken(String token) {
public void setToken(String token) {
this.token = token;
this.token = token;
}
}
/**
/**
* Get the string to search for
* @return current token
* Get the string to search for.
* @return current <code>String</code> token.
*/
*/
public String getToken() {
public String getToken() {
return token;
return token;
@@ -190,16 +190,16 @@ public class Replace extends MatchingTask {
/**
/**
* The replacement string; required if <code>property<code>
* The replacement string; required if <code>property<code>
* is not set
* @param value value to replace
* is not set.
* @param value <code>String</code> value to replace.
*/
*/
public void setValue(String value) {
public void setValue(String value) {
this.value = value;
this.value = value;
}
}
/**
/**
* Get replacements string
* @return replacement or null
* Get replacement <code>String</code>.
* @return replacement or null.
*/
*/
public String getValue() {
public String getValue() {
return value;
return value;
@@ -208,7 +208,7 @@ public class Replace extends MatchingTask {
/**
/**
* Set the name of the property whose value is to serve as
* Set the name of the property whose value is to serve as
* the replacement value; required if <code>value</code> is not set.
* the replacement value; required if <code>value</code> is not set.
* @param property propname
* @param property property name.
*/
*/
public void setProperty(String property) {
public void setProperty(String property) {
this.property = property;
this.property = property;
@@ -216,8 +216,8 @@ public class Replace extends MatchingTask {
/**
/**
* Get the name of the property whose value is to serve as
* Get the name of the property whose value is to serve as
* the replacement value;
* @return property or null
* the replacement value.
* @return property or null.
*/
*/
public String getProperty() {
public String getProperty() {
return property;
return property;
@@ -235,7 +235,7 @@ public class Replace extends MatchingTask {
/**
/**
* Sets the input buffer for this filter.
* Sets the input buffer for this filter.
* The filter expects from the component providing the input that data
* The filter expects from the component providing the input that data
* is only addd ed by that component to the end of this StringBuffer.
* is only added by that component to the end of this StringBuffer.
* This StringBuffer will be modified by this filter, and expects that
* This StringBuffer will be modified by this filter, and expects that
* another component will only apped to this StringBuffer.
* another component will only apped to this StringBuffer.
* @param input The input for this filter.
* @param input The input for this filter.
@@ -250,7 +250,7 @@ public class Replace extends MatchingTask {
* received data, when the token is split over the "old" and the "new"
* received data, when the token is split over the "old" and the "new"
* part.
* part.
* @return true if some data has been made available in the
* @return true if some data has been made available in the
* outputB uffer.
* output b uffer.
*/
*/
boolean process() {
boolean process() {
if (inputBuffer.length() > token.length()) {
if (inputBuffer.length() > token.length()) {
@@ -294,7 +294,7 @@ public class Replace extends MatchingTask {
}
}
/**
/**
* Class reading a file in small chunc ks, and presenting these chunc ks in
* Class reading a file in small chunks, and presenting these chunks in
* a StringBuffer. Compatible with the Replacefilter.
* a StringBuffer. Compatible with the Replacefilter.
* @since 1.7
* @since 1.7
*/
*/
@@ -334,7 +334,7 @@ public class Replace extends MatchingTask {
* @return true when the end of the file has not been reached.
* @return true when the end of the file has not been reached.
* @throws IOException When the file cannot be read from.
* @throws IOException When the file cannot be read from.
*/
*/
boolean readChunc k() throws IOException {
boolean readChunk() throws IOException {
int bufferLength = 0;
int bufferLength = 0;
bufferLength = reader.read(buffer);
bufferLength = reader.read(buffer);
if (bufferLength < 0) {
if (bufferLength < 0) {
@@ -355,7 +355,7 @@ public class Replace extends MatchingTask {
}
}
/**
/**
* Component writing a file in chunc ks, taking the chunks from the
* Component writing a file in chunks, taking the chunks from the
* Replacefilter.
* Replacefilter.
* @since 1.7
* @since 1.7
*/
*/
@@ -380,9 +380,9 @@ public class Replace extends MatchingTask {
/**
/**
* Sets the input buffer for this component.
* Sets the input buffer for this component.
* The filter expects from the component providing the input that data
* The filter expects from the component providing the input that data
* is only addd ed by that component to the end of this StringBuffer.
* is only added by that component to the end of this StringBuffer.
* This StringBuffer will be modified by this filter, and expects that
* This StringBuffer will be modified by this filter, and expects that
* another component will only apped to this StringBuffer.
* another component will only appen d to this StringBuffer.
* @param input The input for this filter.
* @param input The input for this filter.
*/
*/
void setInputBuffer(StringBuffer input) {
void setInputBuffer(StringBuffer input) {
@@ -494,7 +494,7 @@ public class Replace extends MatchingTask {
* Validate attributes provided for this task in .xml build file.
* Validate attributes provided for this task in .xml build file.
*
*
* @exception BuildException if any supplied attribute is invalid or any
* @exception BuildException if any supplied attribute is invalid or any
* mandatory attribute is missing
* mandatory attribute is missing.
*/
*/
public void validateAttributes() throws BuildException {
public void validateAttributes() throws BuildException {
if (src == null && dir == null) {
if (src == null && dir == null) {
@@ -522,7 +522,7 @@ public class Replace extends MatchingTask {
* Validate nested elements.
* Validate nested elements.
*
*
* @exception BuildException if any supplied attribute is invalid or any
* @exception BuildException if any supplied attribute is invalid or any
* mandatory attribute is missing
* mandatory attribute is missing.
*/
*/
public void validateReplacefilters()
public void validateReplacefilters()
throws BuildException {
throws BuildException {
@@ -534,11 +534,10 @@ public class Replace extends MatchingTask {
}
}
/**
/**
* helper method to load a properties file and throw a build exception
* if it cannot be loaded
* @param propertyFile the file to load the properties from
* @return loaded properties collection
* @throws BuildException if the file could not be found or read
* Load a properties file.
* @param propertyFile the file to load the properties from.
* @return loaded <code>Properties</code> object.
* @throws BuildException if the file could not be found or read.
*/
*/
public Properties getProperties(File propertyFile) throws BuildException {
public Properties getProperties(File propertyFile) throws BuildException {
Properties props = new Properties();
Properties props = new Properties();
@@ -574,7 +573,7 @@ public class Replace extends MatchingTask {
* The replacement is performed on a temporary file which then
* The replacement is performed on a temporary file which then
* replaces the original file.
* replaces the original file.
*
*
* @param src the source file
* @param src the source <code>File</code>.
*/
*/
private void processFile(File src) throws BuildException {
private void processFile(File src) throws BuildException {
if (!src.exists()) {
if (!src.exists()) {
@@ -598,7 +597,7 @@ public class Replace extends MatchingTask {
out.setInputBuffer(buildFilterChain(in.getOutputBuffer()));
out.setInputBuffer(buildFilterChain(in.getOutputBuffer()));
while (in.readChunc k()) {
while (in.readChunk()) {
if (processFilterChain()) {
if (processFilterChain()) {
out.process();
out.process();
}
}
@@ -670,8 +669,9 @@ public class Replace extends MatchingTask {
/**
/**
* Creates the chain of filters to operate.
* Creates the chain of filters to operate.
* @param inputBuffer The buffer that contains the input for the first filter
* @return The StringBuffer that cointains the output of the last filter.
* @param inputBuffer <code>StringBuffer</code> containing the input for the
* first filter.
* @return <code>StringBuffer</code> containing the output of the last filter.
*/
*/
private StringBuffer buildFilterChain(StringBuffer inputBuffer) {
private StringBuffer buildFilterChain(StringBuffer inputBuffer) {
StringBuffer buf = inputBuffer;
StringBuffer buf = inputBuffer;
@@ -685,7 +685,7 @@ public class Replace extends MatchingTask {
/**
/**
* Logs the chain of filters to operate on the file.
* Logs the chain of filters to operate on the file.
* @param filename
* @param filename <code>String</code>.
*/
*/
private void logFilterChain(String filename) {
private void logFilterChain(String filename) {
for (int i = 0; i < replacefilters.size(); i++) {
for (int i = 0; i < replacefilters.size(); i++) {
@@ -696,7 +696,7 @@ public class Replace extends MatchingTask {
}
}
/**
/**
* Set the source file; required unless <code>dir</code> is set.
* Set the source file; required unless <code>dir</code> is set.
* @param file source file
* @param file source <code>File</code>.
*/
*/
public void setFile(File file) {
public void setFile(File file) {
this.src = file;
this.src = file;
@@ -705,10 +705,10 @@ public class Replace extends MatchingTask {
/**
/**
* Indicates whether a summary of the replace operation should be
* Indicates whether a summary of the replace operation should be
* produced, detailing how many token occurrences and files were
* produced, detailing how many token occurrences and files were
* processed; optional, default=false
* processed; optional, default=<code> false</code>.
*
*
* @param summary true if you would like a summary logged of the
* replace operation
* @param summary <code>boolean</code> whether a summary of the
* replace operation should be logged.
*/
*/
public void setSummary(boolean summary) {
public void setSummary(boolean summary) {
this.summary = summary;
this.summary = summary;
@@ -717,30 +717,28 @@ public class Replace extends MatchingTask {
/**
/**
* Sets the name of a property file containing filters; optional.
* Sets the name of a property file containing filters; optional.
* Each property will be treated as a
* replacefilter where token is the name of the property and value
* is the value of the property.
* @param filename file to load
* Each property will be treated as a replacefilter where token is the name
* of the property and value is the value of the property.
* @param replaceFilterFile <code>File</code> to load.
*/
*/
public void setReplaceFilterFile(File filenam e) {
replaceFilterFile = filenam e;
public void setReplaceFilterFile(File replaceFilterFil e) {
this.replaceFilterFile = replaceFilterFil e;
}
}
/**
/**
* The base directory to use when replacing a token in multiple files;
* The base directory to use when replacing a token in multiple files;
* required if <code>file</code> is not defined.
* required if <code>file</code> is not defined.
* @param dir base dir
* @param dir <code>File</code> representing the base directory.
*/
*/
public void setDir(File dir) {
public void setDir(File dir) {
this.dir = dir;
this.dir = dir;
}
}
/**
/**
* Set the string token to replace;
* required unless a nested
* Set the string token to replace; required unless a nested
* <code>replacetoken</code> element or the <code>replacefilterfile</code>
* <code>replacetoken</code> element or the <code>replacefilterfile</code>
* attribute is used.
* attribute is used.
* @param token token string
* @param token token <code>String</code>.
*/
*/
public void setToken(String token) {
public void setToken(String token) {
createReplaceToken().addText(token);
createReplaceToken().addText(token);
@@ -748,8 +746,8 @@ public class Replace extends MatchingTask {
/**
/**
* Set the string value to use as token replacement;
* Set the string value to use as token replacement;
* optional, default is the empty string ""
* @param value replacement value
* optional, default is the empty string "".
* @param value replacement value.
*/
*/
public void setValue(String value) {
public void setValue(String value) {
createReplaceValue().addText(value);
createReplaceValue().addText(value);
@@ -757,17 +755,17 @@ public class Replace extends MatchingTask {
/**
/**
* Set the file encoding to use on the files read and written by the task;
* Set the file encoding to use on the files read and written by the task;
* optional, defaults to default JVM encoding
* optional, defaults to default JVM encoding.
*
*
* @param encoding the encoding to use on the files
* @param encoding the encoding to use on the files.
*/
*/
public void setEncoding(String encoding) {
public void setEncoding(String encoding) {
this.encoding = encoding;
this.encoding = encoding;
}
}
/**
/**
* th e token to filter as the text of a nested element
* @return nested token to configure
* Crea te a token to filter as the text of a nested element.
* @return nested token <code>NestedString</code> to configure.
*/
*/
public NestedString createReplaceToken() {
public NestedString createReplaceToken() {
if (token == null) {
if (token == null) {
@@ -777,27 +775,26 @@ public class Replace extends MatchingTask {
}
}
/**
/**
* th e string to replace the token as the text of a nested element
* @return replacement value to configure
* Crea te a string to replace the token as the text of a nested element.
* @return replacement value <code>NestedString</code> to configure.
*/
*/
public NestedString createReplaceValue() {
public NestedString createReplaceValue() {
return value;
return value;
}
}
/**
/**
* The name of a property file from which properties specified using
* nested <code><replacefilter></code> elements are drawn;
* Required only if <i>property</i> attribute of
* <code><replacefilter></code> is used.
* @param filename file to load
* The name of a property file from which properties specified using nested
* <code><replacefilter></code> elements are drawn; required only if
* the <i>property</i> attribute of <code><replacefilter></code> is used.
* @param propertyFile <code>File</code> to load.
*/
*/
public void setPropertyFile(File filenam e) {
propertyFile = filenam e;
public void setPropertyFile(File propertyFil e) {
this.propertyFile = propertyFil e;
}
}
/**
/**
* Add a nested <replacefilter> element.
* Add a nested <replacefilter> element.
* @return a nested ReplaceFilter object to be configured
* @return a nested <code>Replacefilter</code> object to be configured.
*/
*/
public Replacefilter createReplacefilter() {
public Replacefilter createReplacefilter() {
Replacefilter filter = new Replacefilter();
Replacefilter filter = new Replacefilter();
@@ -808,15 +805,16 @@ public class Replace extends MatchingTask {
/**
/**
* Adds the token and value as first <replacefilter> element.
* Adds the token and value as first <replacefilter> element.
* The token and value are always processed first.
* The token and value are always processed first.
* @return a nested ReplaceFilter object to be configured
* @return a nested <code>Replacefilter</code> object to be configured.
*/
*/
private Replacefilter createPrimaryfilter() {
private Replacefilter createPrimaryfilter() {
Replacefilter filter = new Replacefilter();
Replacefilter filter = new Replacefilter();
replacefilters.insertElementAt(filter, 0);
replacefilters.insertElementAt(filter, 0);
return filter;
return filter;
}
}
/**
/**
* Replace occurrences of str1 in stringbuffer str with str2
* Replace occurrences of str1 in StringBuffer str with str2.
*/
*/
private void stringReplace(StringBuffer str, String str1, String str2) {
private void stringReplace(StringBuffer str, String str1, String str2) {
int found = str.toString().indexOf(str1);
int found = str.toString().indexOf(str1);