antoine 2003/07/19 08:44:58
Modified: src/main/org/apache/tools/ant/taskdefs/optional/i18n
Translate.java
Log:
style
Revision Changes Path
1.29 +73 -18
ant/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java
Index: Translate.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- Translate.java 19 Jul 2003 14:29:40 -0000 1.28
+++ Translate.java 19 Jul 2003 15:44:57 -0000 1.29
@@ -74,12 +74,47 @@
/**
* Translates text embedded in files using Resource Bundle files.
+ * Since ant 1.6 preserves line endings
*
* @author Magesh Umasankar, Don Brown
* @author <a href="mailto:[EMAIL PROTECTED]">Tom Eugelink</a>
*/
public class Translate extends MatchingTask {
-
+ /**
+ * search a bundle matching the specified language, the country and the
variant
+ */
+ private static final int BUNDLE_SPECIFIED_LANGUAGE_COUNTRY_VARIANT = 0;
+ /**
+ * search a bundle matching the specified language, and the country
+ */
+ private static final int BUNDLE_SPECIFIED_LANGUAGE_COUNTRY = 1;
+ /**
+ * search a bundle matching the specified language only
+ */
+ private static final int BUNDLE_SPECIFIED_LANGUAGE = 2;
+ /**
+ * search a bundle matching nothing special
+ */
+ private static final int BUNDLE_NOMATCH = 3;
+ /**
+ * search a bundle matching the language, the country and the variant
+ * of the current locale of the computer
+ */
+ private static final int BUNDLE_DEFAULT_LANGUAGE_COUNTRY_VARIANT = 4;
+ /**
+ * search a bundle matching the language, and the country
+ * of the current locale of the computer
+ */
+ private static final int BUNDLE_DEFAULT_LANGUAGE_COUNTRY = 5;
+ /**
+ * search a bundle matching the language only
+ * of the current locale of the computer
+ */
+ private static final int BUNDLE_DEFAULT_LANGUAGE = 6;
+ /**
+ * number of possibilities for the search
+ */
+ private static final int BUNDLE_MAX_ALTERNATIVES =
BUNDLE_DEFAULT_LANGUAGE + 1;
/**
* Family name of resource bundle
*/
@@ -154,7 +189,7 @@
/**
* Last Modified Timestamp of resource bundle file being used.
*/
- private long[] bundleLastModified = new long[7];
+ private long[] bundleLastModified = new long[BUNDLE_MAX_ALTERNATIVES];
/**
* Last Modified Timestamp of source file being used.
@@ -173,6 +208,7 @@
/**
* Sets Family name of resource bundle; required.
+ * @param bundle family name of resource bundle
*/
public void setBundle(String bundle) {
this.bundle = bundle;
@@ -180,6 +216,7 @@
/**
* Sets locale specific language of resource bundle; optional.
+ * @param bundleLanguage langage of the bundle
*/
public void setBundleLanguage(String bundleLanguage) {
this.bundleLanguage = bundleLanguage;
@@ -187,6 +224,7 @@
/**
* Sets locale specific country of resource bundle; optional.
+ * @param bundleCountry country of the bundle
*/
public void setBundleCountry(String bundleCountry) {
this.bundleCountry = bundleCountry;
@@ -194,6 +232,7 @@
/**
* Sets locale specific variant of resource bundle; optional.
+ * @param bundleVariant locale variant of resource bundle
*/
public void setBundleVariant(String bundleVariant) {
this.bundleVariant = bundleVariant;
@@ -201,6 +240,7 @@
/**
* Sets Destination directory; required.
+ * @param toDir destination directory
*/
public void setToDir(File toDir) {
this.toDir = toDir;
@@ -208,6 +248,7 @@
/**
* Sets starting token to identify keys; required.
+ * @param startToken starting token to identify keys
*/
public void setStartToken(String startToken) {
this.startToken = startToken;
@@ -215,6 +256,7 @@
/**
* Sets ending token to identify keys; required.
+ * @param endToken ending token to identify keys
*/
public void setEndToken(String endToken) {
this.endToken = endToken;
@@ -223,6 +265,7 @@
/**
* Sets source file encoding scheme; optional,
* defaults to encoding of local system.
+ * @param srcEncoding source file encoding
*/
public void setSrcEncoding(String srcEncoding) {
this.srcEncoding = srcEncoding;
@@ -231,6 +274,7 @@
/**
* Sets destination file encoding scheme; optional. Defaults to source
file
* encoding
+ * @param destEncoding destination file encoding scheme
*/
public void setDestEncoding(String destEncoding) {
this.destEncoding = destEncoding;
@@ -239,6 +283,7 @@
/**
* Sets Resource Bundle file encoding scheme; optional. Defaults to
source file
* encoding
+ * @param bundleEncoding bundle file encoding scheme
*/
public void setBundleEncoding(String bundleEncoding) {
this.bundleEncoding = bundleEncoding;
@@ -249,6 +294,7 @@
* whether it is newer than the source file as well as the
* resource bundle file.
* Defaults to false.
+ * @param forceOverwrite whether or not to overwrite existing files
*/
public void setForceOverwrite(boolean forceOverwrite) {
this.forceOverwrite = forceOverwrite;
@@ -256,6 +302,7 @@
/**
* Adds a set of files to translate as a nested fileset element.
+ * @param set the fileset to be added
*/
public void addFileset(FileSet set) {
filesets.addElement(set);
@@ -263,6 +310,12 @@
/**
* Check attributes values, load resource map and translate
+ * @throws BuildException if the required attributes are not set
+ * Required : <ul>
+ * <li>bundle</li>
+ * <li>starttoken</li>
+ * <li>endtoken</li>
+ * </ul>
*/
public void execute() throws BuildException {
if (bundle == null) {
@@ -352,16 +405,16 @@
String variant = locale.getVariant().length() > 0
? "_" + locale.getVariant() : "";
String bundleFile = bundle + language + country + variant;
- processBundle(bundleFile, 0, false);
+ processBundle(bundleFile, BUNDLE_SPECIFIED_LANGUAGE_COUNTRY_VARIANT,
false);
bundleFile = bundle + language + country;
- processBundle(bundleFile, 1, false);
+ processBundle(bundleFile, BUNDLE_SPECIFIED_LANGUAGE_COUNTRY, false);
bundleFile = bundle + language;
- processBundle(bundleFile, 2, false);
+ processBundle(bundleFile, BUNDLE_SPECIFIED_LANGUAGE, false);
bundleFile = bundle;
- processBundle(bundleFile, 3, false);
+ processBundle(bundleFile, BUNDLE_NOMATCH, false);
//Load default locale bundle files
//using default file encoding scheme.
@@ -376,13 +429,13 @@
bundleEncoding = System.getProperty("file.encoding");
bundleFile = bundle + language + country + variant;
- processBundle(bundleFile, 4, false);
+ processBundle(bundleFile, BUNDLE_DEFAULT_LANGUAGE_COUNTRY_VARIANT,
false);
bundleFile = bundle + language + country;
- processBundle(bundleFile, 5, false);
+ processBundle(bundleFile, BUNDLE_DEFAULT_LANGUAGE_COUNTRY, false);
bundleFile = bundle + language;
- processBundle(bundleFile, 6, true);
+ processBundle(bundleFile, BUNDLE_DEFAULT_LANGUAGE, true);
}
/**
@@ -500,15 +553,17 @@
File src = fileUtils.resolveFile(ds.getBasedir(),
srcFiles[j]);
srcLastModified = src.lastModified();
//Check to see if dest file has to be recreated
- if (forceOverwrite
- || destLastModified < srcLastModified
- || destLastModified < bundleLastModified[0]
- || destLastModified < bundleLastModified[1]
- || destLastModified < bundleLastModified[2]
- || destLastModified < bundleLastModified[3]
- || destLastModified < bundleLastModified[4]
- || destLastModified < bundleLastModified[5]
- || destLastModified < bundleLastModified[6]) {
+ boolean needsWork = forceOverwrite
+ || destLastModified < srcLastModified;
+ if (!needsWork) {
+ for (int icounter = 0; icounter <
BUNDLE_MAX_ALTERNATIVES; icounter++) {
+ needsWork = (destLastModified <
bundleLastModified[icounter]);
+ if (needsWork) {
+ break;
+ }
+ }
+ }
+ if (needsWork) {
log("Processing " + srcFiles[j],
Project.MSG_DEBUG);
FileOutputStream fos = new FileOutputStream(dest);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]