001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.tools.ant;
034:
035: import org.apache.tools.ant.BuildException;
036: import org.apache.tools.ant.Task;
037: import org.apache.tools.ant.taskdefs.Concat;
038: import org.apache.tools.ant.types.FileSet;
039:
040: import java.io.File;
041:
042: /**
043: * Builds message property files.
044: *
045: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
046: * @version $Rev: 181 $
047: */
048: public class MakeMessagesTask extends Task {
049: private String srcdir;
050: private String dest;
051: private String srcprefix = "";
052: private String languages = "en,de";
053:
054: @Override
055: public void execute() throws BuildException {
056: final String[] langs = languages.split(",");
057: // create language-specific property files
058: for (String language : langs) {
059: createMessages(language, language);
060: }
061: // create default property files
062: createMessages(null, null); // without suffix
063: createMessages(null, langs[0]); // with default language suffix, used if the JVM locale
064: // is not equal to the default language
065: }
066:
067: private void createMessages(String language, String destSuffix) {
068: final File dest = new File(this .dest
069: + (destSuffix != null ? "_" + destSuffix : "")
070: + ".properties");
071: final Concat concat = (Concat) getProject()
072: .createTask("concat");
073: concat.setDestfile(dest);
074: final FileSet fileSet = new FileSet();
075: fileSet.setProject(getProject());
076: fileSet.setDir(new File(srcdir));
077: if (language == null) {
078: fileSet.setIncludes((srcprefix != null ? srcprefix + "*"
079: : "*")
080: + ".properties");
081: fileSet.setExcludes(srcprefix + "*_??.properties");
082: } else {
083: fileSet.setIncludes(srcprefix + "*_" + language
084: + ".properties");
085: }
086: concat.addFileset(fileSet);
087: concat.setFixLastLine(true);
088: concat.setForce(false);
089: concat.execute();
090: }
091:
092: /**
093: * Sets the source directory containing all .properties files.
094: *
095: * @param srcdir the source directory containing all .properties files.
096: */
097: public void setSrcdir(String srcdir) {
098: this .srcdir = srcdir;
099: }
100:
101: /**
102: * Sets the target name of the output property file (e.g. "ApplicationResources").
103: * @param dest the base name of the output property file (e.g. "ApplicationResources")
104: */
105: public void setDest(String dest) {
106: this .dest = dest;
107: }
108:
109: /**
110: * Sets the common prefix of the files to be included (may be null).
111: *
112: * @param srcprefix the common prefix of the files to be included (e.g. "Ex", may be null). Should
113: * not contain wildcards.
114: */
115: public void setSrcprefix(String srcprefix) {
116: this .srcprefix = srcprefix;
117: }
118:
119: /**
120: * Sets the language(s) to be processed (comma separated). The first language
121: * is used as the default language, i.e. will be used to created the fallback
122: * properties file without a language suffix.
123: *
124: * @param languages the language(s) to be processed (comma separated).
125: */
126: public void setLanguages(String languages) {
127: this.languages = languages;
128: }
129: }
|