@@ -74,7 +74,7 @@ import org.apache.tools.ant.util.FileUtils;
/**
/**
* Translates text embedded in files using Resource Bundle files.
* Translates text embedded in files using Resource Bundle files.
*
*
* @author Magesh Umasankar
* @author Magesh Umasankar, Don Brown
*/
*/
public class Translate extends MatchingTask {
public class Translate extends MatchingTask {
@@ -256,23 +256,11 @@ public class Translate extends MatchingTask {
getLocation());
getLocation());
}
}
if (startToken.length() != 1) {
throw new BuildException(
"The starttoken attribute must be a single character.",
getLocation());
}
if (endToken == null) {
if (endToken == null) {
throw new BuildException("The endtoken attribute must be set.",
throw new BuildException("The endtoken attribute must be set.",
getLocation());
getLocation());
}
}
if (endToken.length() != 1) {
throw new BuildException(
"The endtoken attribute must be a single character.",
getLocation());
}
if (bundleLanguage == null) {
if (bundleLanguage == null) {
Locale l = Locale.getDefault();
Locale l = Locale.getDefault();
bundleLanguage = l.getLanguage();
bundleLanguage = l.getLanguage();
@@ -391,7 +379,7 @@ public class Translate extends MatchingTask {
*/
*/
private void processBundle(final String bundleFile, final int i,
private void processBundle(final String bundleFile, final int i,
final boolean checkLoaded) throws BuildException {
final boolean checkLoaded) throws BuildException {
final File propsFile = new File(bundleFile + ".properties");
final File propsFile = getProject().resolve File(bundleFile + ".properties");
FileInputStream ins = null;
FileInputStream ins = null;
try {
try {
ins = new FileInputStream(propsFile);
ins = new FileInputStream(propsFile);
@@ -520,23 +508,25 @@ public class Translate extends MatchingTask {
BufferedReader in
BufferedReader in
= new BufferedReader(new InputStreamReader(fis, srcEncoding));
= new BufferedReader(new InputStreamReader(fis, srcEncoding));
String line;
String line;
int stLength = startToken.length();
int etLength = endToken.length();
while ((line = in.readLine()) != null) {
while ((line = in.readLine()) != null) {
int startIndex = -1;
int startIndex = -1;
int endIndex = -1;
int endIndex = -1;
outer: while (true) {
outer: while (true) {
startIndex = line.indexOf(startToken, endIndex + 1 );
startIndex = line.indexOf(startToken, endIndex + etLength );
if (startIndex < 0 ||
if (startIndex < 0 ||
startIndex + 1 >= line.length()) {
startIndex + stLength >= line.length()) {
break;
break;
}
}
endIndex = line.indexOf(endToken, startIndex + 1 );
endIndex = line.indexOf(endToken, startIndex + stLength );
if (endIndex < 0) {
if (endIndex < 0) {
break;
break;
}
}
String matches = line.substring(startIndex + 1 ,
String matches = line.substring(startIndex + stLength ,
endIndex);
endIndex);
//If there is a white space or = or :, then
//it isn't to be treated as a valid key.
//If there is a white space or = or :, then
//it isn't to be treated as a valid key.
for (int k = 0; k < matches.length(); k++) {
for (int k = 0; k < matches.length(); k++) {
char c = matches.charAt(k);
char c = matches.charAt(k);
if (c == ':' ||
if (c == ':' ||
@@ -558,9 +548,9 @@ outer: while (true) {
}
}
line = line.substring(0, startIndex)
line = line.substring(0, startIndex)
+ replace
+ replace
+ line.substring(endIndex + 1 );
endIndex = startIndex + replace.length() + 1 ;
if (endIndex + 1 >= line.length()) {
+ line.substring(endIndex + etLength );
endIndex = startIndex + replace.length() + etLength ;
if (endIndex + etLength >= line.length()) {
break;
break;
}
}
}
}