Index: lutinprocessor/src/java/org/codelutin/processor/ProcessorReader.java diff -u lutinprocessor/src/java/org/codelutin/processor/ProcessorReader.java:1.3 lutinprocessor/src/java/org/codelutin/processor/ProcessorReader.java:1.4 --- lutinprocessor/src/java/org/codelutin/processor/ProcessorReader.java:1.3 Wed Jun 23 10:48:28 2004 +++ lutinprocessor/src/java/org/codelutin/processor/ProcessorReader.java Mon Aug 16 20:47:12 2004 @@ -23,10 +23,10 @@ * * @author * Copyright Code Lutin -* @version $Revision: 1.3 $ +* @version $Revision: 1.4 $ * -* Mise a jour: $Date: 2004/06/23 10:48:28 $ -* par : $Author: bpoussin $ +* Mise a jour: $Date: 2004/08/16 20:47:12 $ +* par : $Author: pineau $ */ package org.codelutin.processor; @@ -36,7 +36,6 @@ import java.io.StringReader; import org.codelutin.processor.filters.Filter; -import org.codelutin.processor.filters.DefaultFilter; public class ProcessorReader extends BufferedReader { @@ -70,9 +69,8 @@ line += lineSeparator; } return filter.parse(line); - } else { - return filter.flush(); } + return filter.flush(); } public boolean ready() { Index: lutinprocessor/src/java/org/codelutin/processor/I18nExtractor.java diff -u /dev/null lutinprocessor/src/java/org/codelutin/processor/I18nExtractor.java:1.1 --- /dev/null Mon Aug 16 20:47:17 2004 +++ lutinprocessor/src/java/org/codelutin/processor/I18nExtractor.java Mon Aug 16 20:47:12 2004 @@ -0,0 +1,117 @@ +/* *##% + * Copyright (C) 2002, 2003, 2004 + * Code Lutin, Cédric Pineau, Benjamin Poussin + * + * 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 (at your option) any later version. + * + * 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. + *##%*/ + +/* * + * I18nExtractor.java + * + * Created: Aug 16, 2004 + * + * @author Cédric Pineau + * @version $Revision: 1.1 $ + * + * Last update : $Date: 2004/08/16 20:47:12 $ + * by : $Author: pineau $ + */ + +package org.codelutin.processor; + +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.LineNumberReader; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; + +import org.codelutin.processor.filters.I18nFilter; + +/** + * + */ +public class I18nExtractor { + + protected I18nFilter filter = new I18nFilter(); + + protected HashMap i18nStringsMap = new HashMap(); + + public void extract(String[] srcFileNames, String outputFileName) throws IOException { + PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(outputFileName))); + for (int i = 0; i < srcFileNames.length; i++) { + processFile(srcFileNames[i]); + } + for (Iterator iter = i18nStringsMap.keySet().iterator(); iter.hasNext();) { + String i18nString = (String) iter.next(); + List locations = (List) i18nStringsMap.get(i18nString); + for (Iterator iterator = locations.iterator(); iterator.hasNext();) { + String location = (String) iterator.next(); + output.println("# "+location); + } + output.println(i18nString+"="); + } + output.close(); + } + + protected void processFile(String srcFileName) throws IOException { + LineNumberReader lnr = new LineNumberReader(new FileReader(srcFileName)); + while (lnr.ready()) { + String line = lnr.readLine(); + int lineNumber = lnr.getLineNumber(); + processLine(line, srcFileName, lineNumber); + } + } + + protected void processLine(String line, String srcFileName, int lineNumber) { + String i18nStringsSet = filter.parse(line); + if (i18nStringsSet != I18nFilter.EMPTY_STRING) { + // Found a set of i18n Strings, split it. + String[] i18nStrings = i18nStringsSet.split("="); + for (int i = 0; i < i18nStrings.length; i++) { + String i18nString = i18nStrings[i]; + List locations = (List) i18nStringsMap.get(i18nString); + if (locations == null) { + locations = new ArrayList(); + i18nStringsMap.put(i18nString, locations); + } + locations.add(srcFileName+"("+lineNumber+")"); + } + } + } + + public static void main(String[] args) { + if(args.length < 2) { + System.out.println("Give sources and destination file"); + System.exit(0); + } else if (args.length > 2) { + String[] sources = new String[args.length-1]; + for (int i = 0; i < args.length-1; i++) { + sources[i] = args[i]; + } + String destination = args[args.length-1]; + try { + new I18nExtractor().extract(sources, destination); + } catch (IOException eee) { + java.util.logging.Logger.getLogger("org.codelutin.processor.I18nExtractor.").severe("Error during i18n extraction : "+eee); + } + } + + } +}