From 1dd390137b8f8e921f129269855d1fe5621473a6 Mon Sep 17 00:00:00 2001 From: Magesh Umasankar Date: Thu, 21 Nov 2002 21:35:41 +0000 Subject: [PATCH] Allow start and end tokens to be multiple characters long. PR: 13939 Submitted by: "Don Brown" git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273569 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 ++ .../ant/taskdefs/optional/i18n/Translate.java | 36 +++++++------------ 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 50f6f502b..8040d12a9 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -61,6 +61,9 @@ Fixed bugs: Other changes: -------------- +* The start and end tokens for may now be longer than a + single character. + * lets you set the username and password for proxies that want authentication * has a new encoding attribute. diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java b/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java index b90d81571..758fade17 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java @@ -74,7 +74,7 @@ import org.apache.tools.ant.util.FileUtils; /** * Translates text embedded in files using Resource Bundle files. * - * @author Magesh Umasankar + * @author Magesh Umasankar, Don Brown */ public class Translate extends MatchingTask { @@ -256,23 +256,11 @@ public class Translate extends MatchingTask { getLocation()); } - if (startToken.length() != 1) { - throw new BuildException( - "The starttoken attribute must be a single character.", - getLocation()); - } - if (endToken == null) { throw new BuildException("The endtoken attribute must be set.", getLocation()); } - if (endToken.length() != 1) { - throw new BuildException( - "The endtoken attribute must be a single character.", - getLocation()); - } - if (bundleLanguage == null) { Locale l = Locale.getDefault(); bundleLanguage = l.getLanguage(); @@ -391,7 +379,7 @@ public class Translate extends MatchingTask { */ private void processBundle(final String bundleFile, final int i, final boolean checkLoaded) throws BuildException { - final File propsFile = new File(bundleFile + ".properties"); + final File propsFile = getProject().resolveFile(bundleFile + ".properties"); FileInputStream ins = null; try { ins = new FileInputStream(propsFile); @@ -520,23 +508,25 @@ public class Translate extends MatchingTask { BufferedReader in = new BufferedReader(new InputStreamReader(fis, srcEncoding)); String line; + int stLength = startToken.length(); + int etLength = endToken.length(); while ((line = in.readLine()) != null) { int startIndex = -1; int endIndex = -1; outer: while (true) { - startIndex = line.indexOf(startToken, endIndex + 1); + startIndex = line.indexOf(startToken, endIndex + etLength); if (startIndex < 0 || - startIndex + 1 >= line.length()) { + startIndex + stLength >= line.length()) { break; } - endIndex = line.indexOf(endToken, startIndex + 1); + endIndex = line.indexOf(endToken, startIndex + stLength); if (endIndex < 0) { break; } - String matches = line.substring(startIndex + 1, + String matches = line.substring(startIndex + stLength, 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++) { char c = matches.charAt(k); if (c == ':' || @@ -558,9 +548,9 @@ outer: while (true) { } line = line.substring(0, startIndex) + 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; } }