?? translate.java
字號(hào):
/*
* $Header: /cvsroot/mvnforum/mvnforum/i18n/tool/Translate.java,v 1.3 2004/04/30 03:39:14 drjavanomous Exp $
* $Revision: 1.3 $
* $Date: 2004/04/30 03:39:14 $
*
* ====================================================================
*
* Copyright (C) 2002, 2003 by MyVietnam.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* All copyright notices regarding MyVietnam and MyVietnam CoreLib
* MUST remain intact in the scripts and source code.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Correspondence and Marketing Questions can be sent to:
* info@MyVietnam.net
*
* @author: Minh Nguyen minhnn@MyVietnam.net
* @author: Mai Nguyen mai.nh@MyVietnam.net
*/
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
//package org.apache.tools.ant.taskdefs.optional.i18n;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.FileOutputStream;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.util.Vector;
import java.util.Hashtable;
import java.util.Locale;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.taskdefs.MatchingTask;
/**
* Translates text embedded in files using Resource Bundle files.
*
* @author Magesh Umasankar
*/
public class Translate extends MatchingTask {
/**
* Family name of resource bundle
*/
private String bundle;
/**
* Locale specific language of the resource bundle
*/
private String bundleLanguage;
/**
* Locale specific country of the resource bundle
*/
private String bundleCountry;
/**
* Locale specific variant of the resource bundle
*/
private String bundleVariant;
/**
* Destination directory
*/
private File toDir;
/**
* Source file encoding scheme
*/
private String srcEncoding;
/**
* Destination file encoding scheme
*/
private String destEncoding;
/**
* Resource Bundle file encoding scheme, defaults to srcEncoding
*/
private String bundleEncoding;
/**
* Starting token to identify keys
*/
private String startToken;
/**
* Ending token to identify keys
*/
private String endToken;
/**
* Whether or not to create a new destination file.
* Defaults to <code>false</code>.
*/
private boolean forceOverwrite;
/**
* Vector to hold source file sets.
*/
private Vector filesets = new Vector();
/**
* Holds key value pairs loaded from resource bundle file
*/
private Hashtable resourceMap = new Hashtable();
/**
* Generated locale based on user attributes
*/
private Locale locale;
/**
* Used to resolve file names.
*/
private FileUtils fileUtils = FileUtils.newFileUtils();
/**
* Last Modified Timestamp of resource bundle file being used.
*/
private long[] bundleLastModified = new long[7];
/**
* Last Modified Timestamp of source file being used.
*/
private long srcLastModified;
/**
* Last Modified Timestamp of destination file being used.
*/
private long destLastModified;
/**
* Has at least one file from the bundle been loaded?
*/
private boolean loaded = false;
/**
* Sets Family name of resource bundle; required.
*/
public void setBundle(String bundle) {
this.bundle = bundle;
}
/**
* Sets locale specific language of resource bundle; optional.
*/
public void setBundleLanguage(String bundleLanguage) {
this.bundleLanguage = bundleLanguage;
}
/**
* Sets locale specific country of resource bundle; optional.
*/
public void setBundleCountry(String bundleCountry) {
this.bundleCountry = bundleCountry;
}
/**
* Sets locale specific variant of resource bundle; optional.
*/
public void setBundleVariant(String bundleVariant) {
this.bundleVariant = bundleVariant;
}
/**
* Sets Destination directory; required.
*/
public void setToDir(File toDir) {
this.toDir = toDir;
}
/**
* Sets starting token to identify keys; required.
*/
public void setStartToken(String startToken) {
this.startToken = startToken;
}
/**
* Sets ending token to identify keys; required.
*/
public void setEndToken(String endToken) {
this.endToken = endToken;
}
/**
* Sets source file encoding scheme; optional,
* defaults to encoding of local system.
*/
public void setSrcEncoding(String srcEncoding) {
this.srcEncoding = srcEncoding;
}
/**
* Sets destination file encoding scheme; optional. Defaults to source file
* encoding
*/
public void setDestEncoding(String destEncoding) {
this.destEncoding = destEncoding;
}
/**
* Sets Resource Bundle file encoding scheme; optional. Defaults to source file
* encoding
*/
public void setBundleEncoding(String bundleEncoding) {
this.bundleEncoding = bundleEncoding;
}
/**
* Whether or not to overwrite existing file irrespective of
* whether it is newer than the source file as well as the
* resource bundle file.
* Defaults to false.
*/
public void setForceOverwrite(boolean forceOverwrite) {
this.forceOverwrite = forceOverwrite;
}
/**
* Adds a set of files to translate as a nested fileset element.
*/
public void addFileset(FileSet set) {
filesets.addElement(set);
}
/**
* Check attributes values, load resource map and translate
*/
public void execute() throws BuildException {
if (bundle == null) {
throw new BuildException("The bundle attribute must be set.",
getLocation());
}
if (startToken == null) {
throw new BuildException("The starttoken attribute must be set.",
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();
}
if (bundleCountry == null) {
bundleCountry = Locale.getDefault().getCountry();
}
locale = new Locale(bundleLanguage, bundleCountry);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -