001 /*
002 // $Id: //open/util/resgen/src/org/eigenbase/resgen/PropertiesFileTask.java#4 $
003 // Package org.eigenbase.resgen is an i18n resource generator.
004 // Copyright (C) 2005-2005 The Eigenbase Project
005 // Copyright (C) 2005-2005 Disruptive Tech
006 // Copyright (C) 2005-2005 LucidEra, Inc.
007 // Portions Copyright (C) 2001-2005 Kana Software, Inc. and others.
008 //
009 // This library is free software; you can redistribute it and/or modify it
010 // under the terms of the GNU Lesser General Public License as published by the
011 // Free Software Foundation; either version 2 of the License, or (at your
012 // option) any later version approved by The Eigenbase Project.
013 //
014 // This library is distributed in the hope that it will be useful,
015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017 // GNU Lesser General Public License for more details.
018 //
019 // You should have received a copy of the GNU Lesser General Public License
020 // along with this library; if not, write to the Free Software
021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022 */
023
024 package org.eigenbase.resgen;
025
026 import java.io.File;
027 import java.io.IOException;
028 import java.net.URL;
029 import java.util.Locale;
030
031 /**
032 * Ant task which processes a properties file and generates a C++ or Java class
033 * from the resources in it.
034 *
035 * @author jhyde
036 * @since 19 September, 2005
037 * @version $Id: //open/util/resgen/src/org/eigenbase/resgen/PropertiesFileTask.java#4 $
038 */
039 class PropertiesFileTask extends FileTask
040 {
041 final Locale locale;
042
043 PropertiesFileTask(ResourceGenTask.Include include, String fileName) {
044 this.include = include;
045 this.fileName = fileName;
046 this.className = Util.fileNameToClassName(fileName, ".properties");
047 this.locale = Util.fileNameToLocale(fileName, ".properties");
048 }
049
050 /**
051 * Given an existing properties file such as
052 * <code>happy/Birthday_fr_FR.properties</code>, generates the
053 * corresponding Java class happy.Birthday_fr_FR.java</code>.
054 *
055 * <p>todo: Validate.
056 */
057 void process(ResourceGen generator) throws IOException
058 {
059 // e.g. happy/Birthday_fr_FR.properties
060 String s = Util.fileNameSansLocale(fileName, ".properties");
061 File file = new File(include.root.src, s + ".xml");
062 URL url = Util.convertPathToURL(file);
063 ResourceDef.ResourceBundle resourceList = Util.load(url);
064
065 if (outputJava) {
066 generateJava(generator, resourceList, locale);
067 }
068 if (outputCpp) {
069 // We don't generate any C++ code from .properties file -- yet.
070 }
071 }
072 }
073
074 // End PropertiesFileTask.java
075