Author: tchemit Date: 2009-05-13 16:41:38 +0000 (Wed, 13 May 2009) New Revision: 204 Added: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/GeneratorTemplatesProcessor.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/I18nExtractor.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/LicenseProcessor.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/LogsProcessor.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/OptimisationProcessor.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/Processor.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ProcessorReader.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ProcessorWriter.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ant/ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ant/I18nExtractorTask.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ant/ProcessorTask.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/ActiveLogsCodeFilter.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/DefaultFilter.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/Filter.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/GeneratorTemplatesFilter.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/GeneratorTemplatesFilterIn.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/I18nFilter.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/LicenseFilter.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/LogsFilter.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/NoActionFilter.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/OptimisationFilter.java nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/RemoveLogsCodeFilter.java Removed: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/GeneratorTemplatesProcessor.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/I18nExtractor.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/LicenseProcessor.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/LogsProcessor.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/OptimisationProcessor.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/Processor.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ProcessorReader.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ProcessorWriter.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ant/I18nExtractorTask.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ant/ProcessorTask.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/ActiveLogsCodeFilter.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/DefaultFilter.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/Filter.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/GeneratorTemplatesFilter.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/GeneratorTemplatesFilterIn.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/I18nFilter.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/LicenseFilter.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/LogsFilter.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/NoActionFilter.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/OptimisationFilter.java nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/RemoveLogsCodeFilter.java Modified: nuitonprocessor/trunk/pom.xml Log: migrate to nuiton Modified: nuitonprocessor/trunk/pom.xml =================================================================== --- nuitonprocessor/trunk/pom.xml 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/pom.xml 2009-05-13 16:41:38 UTC (rev 204) @@ -50,7 +50,7 @@ <properties> - <nuiton.project>nuitonprocessor</nuiton.project> + <redmine.project>nuitonprocessor</redmine.project> <!-- assuprimer du de l'utilisation de mavenpom --> <labs.id>28</labs.id> Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/GeneratorTemplatesProcessor.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/GeneratorTemplatesProcessor.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/GeneratorTemplatesProcessor.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,59 +0,0 @@ -/* *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -/* * - * GeneratorTemplatesProcessor.java - * - * Created: Wed Sep 4 2002 - * - * @author <pineau@codelutin.com> - * Copyright Code Lutin - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ - -package org.codelutin.processor; - -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; - -import org.codelutin.processor.filters.GeneratorTemplatesFilter; - -public class GeneratorTemplatesProcessor extends Processor { - - public GeneratorTemplatesProcessor(){ - setInputFilter(new GeneratorTemplatesFilter()); - } - - static public void process(String filein, String fileout) - throws IOException{ - Processor processor = new GeneratorTemplatesProcessor(); - processor.process(new FileReader(filein), new FileWriter(fileout)); - } - - public static void main(String [] args)throws IOException{ - if(args.length < 2) { - System.out.println("Give source and destination file"); - System.exit(1); - } else { - process(args[0], args[1]); - } - } -} Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/I18nExtractor.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/I18nExtractor.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/I18nExtractor.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,120 +0,0 @@ -/* *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -/* * - * I18nExtractor.java - * - * Created: Aug 16, 2004 - * - * @author Cédric Pineau <pineau@codelutin.com> - * @version $Revision$ - * - * Last update : $Date$ - * by : $Author$ - */ - -package org.codelutin.processor; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.LineNumberReader; -import java.io.OutputStreamWriter; -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(File[] srcFiles, File outputFile) throws IOException { - PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"))); - for (int i = 0; i < srcFiles.length; i++) { - processFile(srcFiles[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(); - writer.println("# "+location); - } - writer.println(i18nString+"="); - } - writer.close(); - } - - protected void processFile(File srcFile) throws IOException { - LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(srcFile), "UTF-8")); - while (lnr.ready()) { - String line = lnr.readLine(); - int lineNumber = lnr.getLineNumber(); - processLine(line, srcFile, lineNumber); - } - } - - protected void processLine(String line, File srcFile, 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(srcFile.getPath()+"("+lineNumber+")"); - } - } - } - - public static void main(String[] args) { - if(args.length < 2) { - System.out.println("Please give at least sources and destination file"); - System.exit(0); - } else if (args.length > 2) { - File[] sources = new File[args.length-1]; - for (int i = 0; i < args.length-1; i++) { - sources[i] =new File(args[i]); - } - File destination = new File(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); - System.out.println("!!! "+eee); // TODO remove this - } - } - - } -} Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/LicenseProcessor.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/LicenseProcessor.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/LicenseProcessor.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,46 +0,0 @@ -/** - * *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. *##% - */ -package org.codelutin.processor; - -import org.codelutin.processor.filters.LicenseFilter; - -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; - -/** @author chemit */ -public class LicenseProcessor extends org.codelutin.processor.Processor { - - protected LicenseFilter licenseFilter; - - public LicenseProcessor(String header) { - licenseFilter = new LicenseFilter(header); - setInputFilter(licenseFilter); - } - - public LicenseFilter getLicenceFilter() { - return licenseFilter; - } - - public void process(File filein, File fileout) throws IOException { - process(new FileReader(filein), new FileWriter(fileout)); - } -} - Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/LogsProcessor.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/LogsProcessor.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/LogsProcessor.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,88 +0,0 @@ -/* *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -/* * -* LogsProcessor.java -* -* Created: Wed Jan 14 2004 -* -* @author <poussin@codelutin.com> -* Copyright Code Lutin -* @version $Revision$ -* -* Mise a jour: $Date$ -* par : $Author$ -*/ - -package org.codelutin.processor; - -import org.codelutin.processor.filters.*; -import java.io.*; - -/* -* This class is a processor for source logs -*/ -public class LogsProcessor extends Processor { - - /** Type of actions */ - protected static class Action {} - /** Do nothing */ - public final static Action NoAction = new Action(); - - /** Active logs in output. This is the default action */ - public final static Action Logs = new Action(); - /** Remove logs in output */ - public final static Action NoLogsCode = new Action(); - - /** Constructor */ - public LogsProcessor (Action action) { - if (action == NoAction) { - // No action is the default filter in Processor - } else if (action == NoLogsCode) { - setInputFilter(new RemoveLogsCodeFilter()); - } else { - // Go for logs - setInputFilter(new ActiveLogsCodeFilter()); - } - } - - public static void main(String [] args) throws Exception { - LogsProcessor processor; - if(args.length < 2) { - System.out.println("Give source and destination file, then action"); - System.out.println("Action may be remove or active (default is no action)"); - System.exit(0); - } else if (args.length > 2) { - if (args[2].equals("remove")) { - processor = new LogsProcessor(NoLogsCode); - System.out.println("Removing logs code"); - } else if (args[2].equals("active")) { - processor = new LogsProcessor(Logs); - System.out.println("Setting logs active"); - } else { - processor = new LogsProcessor(NoAction); - System.out.println("No action taken"); - } - try { - processor.process(new FileReader(args[0]), - new FileWriter(args[1])); - } catch (IOException eee) { - java.util.logging.Logger.getLogger("org.codelutin.processor.LogsProcessor.").severe("Error during log processing: "+eee); - } - } - } -} Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/OptimisationProcessor.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/OptimisationProcessor.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/OptimisationProcessor.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,57 +0,0 @@ -/* *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -/* * -* OptimisationProcessor.java -* -* Created: Wed Sep 4 2002 -* -* @author <poussin@codelutin.com> -* Copyright Code Lutin -* @version $Revision$ -* -* Mise a jour: $Date$ -* par : $Author$ -*/ - -package org.codelutin.processor; - -import java.io.*; -import org.codelutin.processor.filters.OptimisationFilter; - -public class OptimisationProcessor extends Processor { // OptimisationProcessor - - public OptimisationProcessor(){ - setInputFilter(new OptimisationFilter()); - } - - static public void process(String filein, String fileout) - throws IOException{ - Processor processor = new OptimisationProcessor(); - processor.process(new FileReader(filein), new FileWriter(fileout)); - } - - public static void main(String [] args)throws IOException{ - if(args.length < 2) { - System.out.println("Give source and destination file"); - System.exit(1); - } else { - process(args[0], args[1]); - } - } - -} // OptimisationProcessor Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/Processor.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/Processor.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/Processor.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,92 +0,0 @@ -/* *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -/* * -* Processor.java -* -* Created: Wed Jan 14 2004 -* -* @author <poussin@codelutin.com> -* Copyright Code Lutin -* @version $Revision$ -* -* Mise a jour: $Date$ -* par : $Author$ -*/ - -package org.codelutin.processor; - -import org.codelutin.processor.filters.*; -import org.codelutin.processor.filters.Filter; -import java.io.*; -import java.util.logging.Logger; - -/* -* This class is a generic sources processor -* Given a reader class name and a writer class name -*/ -public class Processor { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Logger log = Logger.getLogger("org.codelutin.processor.Processor"); - - protected Filter [] inputFilter = new Filter[]{new NoActionFilter()}; - protected Filter outputFilter = new NoActionFilter(); - - public Processor(){} - public Processor(Filter [] filters){ - setInputFilter(filters); - } - - public void setInputFilter(Filter inFilter){ - setInputFilter(new Filter[]{inFilter}); - } - public void setInputFilter(Filter [] inFilter){ - inputFilter = inFilter; - } - public void setOutputFilter(Filter outFilter){ - outputFilter = outFilter; - } - - protected BufferedReader getReader(Reader externalInput){ - BufferedReader result = new BufferedReader(externalInput); - for(int i=0; i<inputFilter.length; i++){ - result = new ProcessorReader(result, inputFilter[i]); - } - return result; - } - - /** Process all available data */ - public void process (Reader externalInput, Writer externalOutput) throws IOException { - log.finest("Debug du process"); - BufferedReader input = getReader(externalInput); - ProcessorWriter output = - new ProcessorWriter(new BufferedWriter(externalOutput), outputFilter); - - log.finest("input: " + input); - log.finest("output: " + output); - - String line = input.readLine(); - while (line != null) { - log.finest("Ligne lu: " + line); - output.writeLine(line); - line = input.readLine(); - } - output.flush(); - } - -} Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ProcessorReader.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ProcessorReader.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ProcessorReader.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,95 +0,0 @@ -/* *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -/* * -* ProcessorReader.java -* -* Created: Wed Jan 14 2004 -* -* @author <poussin@codelutin.com> -* Copyright Code Lutin -* @version $Revision$ -* -* Mise a jour: $Date$ -* par : $Author$ -*/ - -package org.codelutin.processor; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.StringReader; - -import org.codelutin.processor.filters.Filter; - -public class ProcessorReader extends BufferedReader { - - protected BufferedReader input; - protected Filter filter; - protected String lineSeparator; - - protected ProcessorReader(){ - super(new StringReader("")); - } - - public ProcessorReader(BufferedReader input, Filter filter) { - this(); - setInput(input); - this.filter = filter; - lineSeparator = System.getProperty("line.separator"); - } - - public void setInput(BufferedReader input){ - this.input = input; - } - - public boolean markSupported(){ - return false; - } - - public String readLine() throws IOException { - if (input.ready()) { - String line = input.readLine(); - if(line != null){ - if (!(input instanceof ProcessorReader)){ - line += lineSeparator; - } - return filter.parse(line); - } - } - if(filter.hasCachedData()){ - return filter.flush(); - } else { - return null; - } - } - - public boolean ready() { - try { - boolean ready = input.ready(); - if (ready) return true; - return filter.hasCachedData(); - } catch (IOException eee) { - return false; - } - } - - public void close() throws IOException { - input.close(); - } - -} Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ProcessorWriter.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ProcessorWriter.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ProcessorWriter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,64 +0,0 @@ -/* *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -/** -* ProcessorWriter.java -* -* Created: Wed Jan 14 2004 -* -* @author <poussin@codelutin.com> -* Copyright Code Lutin -* @version $Revision$ -* -* Mise a jour: $Date$ -* par : $Author$ -*/ - -package org.codelutin.processor; - -import org.codelutin.processor.filters.*; -import java.io.*; - -public class ProcessorWriter { - - protected BufferedWriter output; - protected Filter filter; - - public ProcessorWriter(BufferedWriter output, Filter filter) { - this.output = output; - this.filter = filter; - } - - public void writeLine(String line) throws IOException { - - // TODO Euh on se sert quand du filtre de sortie ???? :-) - output.write(line); - } - - public void newLine() throws IOException { - output.newLine(); - } - - public void flush() throws IOException { - output.flush(); - } - - public void close() throws IOException { - output.close(); - } - -} Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ant/I18nExtractorTask.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ant/I18nExtractorTask.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ant/I18nExtractorTask.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,151 +0,0 @@ -/* *##% Lutin file processor - * Copyright (C) 2002 - 2009 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -package org.codelutin.processor.ant; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.DirectoryScanner; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.MatchingTask; -import org.codelutin.processor.I18nExtractor; - -/** - * I18nExtractorTask. - * - * Created: Aug 16, 2004 - * - * @author Cédric Pineau <pineau@codelutin.com> - * @version $Revision$ - * - * Last update : $Date$ - * by : $Author$ - */ -public class I18nExtractorTask extends MatchingTask { - - public static final int MSG_VERBOSE = Project.MSG_VERBOSE; - - protected File srcDir; - - protected File destFile; - - protected String[] includes = new String[] {}; - - protected String[] excludes = new String[] {}; - - protected String[] srcFileNames; - - public I18nExtractorTask() { - - } - - protected void doExecute() throws BuildException { - // creation du repertoire pour le fichier destination - destFile.getParentFile().mkdirs(); - List<File> fileList = new ArrayList<File>(); - for (int i = 0; i < srcFileNames.length; i++) { - fileList.add(new File(srcFileNames[i])); - } - try { - new I18nExtractor() - .extract(fileList.toArray(new File[0]), destFile); - } catch (IOException eee) { - throw new BuildException(eee); - } - } - - public void setSrcdir(File srcDir) { - this.srcDir = srcDir; - } - - public void setDestFile(File destFile) { - this.destFile = destFile; - } - - public void execute() throws BuildException { - // first of all, make sure that we've got a srcdir - if (srcDir == null) { - throw new BuildException("srcdir attribute must be set!", - getLocation()); - } - if (!srcDir.exists()) { - throw new BuildException("srcdir \"" + srcDir.getPath() - + "\" does not exist!", getLocation()); - } - - if (destFile == null) { - throw new BuildException("destFile attribute must be set!", - getLocation()); - } - - // Build the list of files to compute - buildFileList(); - - // generate the source files - doExecute(); - } - - protected void buildFileList() { - - // Obtain this list of files within the source directory - DirectoryScanner ds = getDirectoryScanner(srcDir); - - String[] includes = getIncludes(); - if (includes.length > 0) { - ds.setIncludes(includes); - } - String[] excludes = getExcludes(); - if (excludes.length > 0) { - ds.setExcludes(excludes); - } - - ds.scan(); - - // on met le resultat dans files - srcFileNames = ds.getIncludedFiles(); - } - - protected boolean isNewer(String filein, String fileout) { - boolean result = new File(filein).lastModified() > new File(fileout) - .lastModified(); - if (result) { - log(filein + " is newer than " + fileout, MSG_VERBOSE); - } - return result; - } - - protected String[] getExcludes() { - return excludes; - } - - protected String[] getIncludes() { - return includes; - } - - public void setIncludes(String includes) { - this.includes = includes.split(","); - } - - public void setExcludes(String excludes) { - this.excludes = excludes.split(","); - } - -} Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ant/ProcessorTask.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ant/ProcessorTask.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ant/ProcessorTask.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,243 +0,0 @@ -/* - * *##% Lutin file processor - * Copyright (C) 2002 - 2009 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* - */ - -package org.codelutin.processor.ant; - -import java.io.File; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.taskdefs.MatchingTask; -import org.codelutin.processor.Processor; -import org.codelutin.processor.filters.Filter; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import org.apache.tools.ant.DirectoryScanner; -import org.apache.tools.ant.Project; - -/** - * Tache ant pour lutinprocessor. - * - * To use this task, put this code in ant build file: - * - * <taskdef name="processor" classname="org.codelutin.processor.ant.ProcessorTask" - * classpath="lib/lutinprocessor.jar" /> - * - * and use it with: - * - * <processor srcdir="${src}" destdir="${targetgen}" filters="org.codelutin.processor.filters.GeneratorTemplatesFilter" /> - * - * Created: 14 janv. 2004 - * - * @author Benjamin Poussin <poussin@codelutin.com> Copyright Code Lutin - * - * @version $Revision$ - * - * Mise a jour: $Date$ par : $Author$ - */ -public class ProcessorTask extends MatchingTask { // ProcessorTask - - public static final int MSG_VERBOSE = Project.MSG_VERBOSE; - - protected File srcDir; - - protected File destDir; - - protected String[] includes = new String[] {}; - - protected String[] excludes = new String[] {}; - - protected String[] files; - - protected String fileInPattern = ""; - - protected String fileOutPattern = ""; - - protected String filters = "org.codelutin.processor.filters.NoActionFilter"; - - protected boolean overwrite = true; - - protected boolean verbose = false; - - public ProcessorTask() { - - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - public void setOverwrite(boolean overwrite) { - this.overwrite = overwrite; - } - - public void setFileOutPattern(String fileOutPattern) { - this.fileOutPattern = fileOutPattern; - } - - public void setFileInPattern(String fileInPattern) { - this.fileInPattern = fileInPattern; - } - - public void setSrcdir(File srcDir) { - this.srcDir = srcDir; - } - - public void setDestdir(File destDir) { - this.destDir = destDir; - } - - public void setFilters(String filters) { - this.filters = filters; - } - - protected String applyTransformationFilename(String filename) { - return filename.replaceAll(fileInPattern, fileOutPattern); - } - - protected void doExecute() throws BuildException { - Processor processor = new Processor(getFilters()); - int numberFiles; - for (numberFiles = 0; numberFiles < files.length; numberFiles++) { - String inputFileName = absoluteSourceName(files[numberFiles]); - String outputFileName = absoluteDestinationName(applyTransformationFilename(files[numberFiles])); - if (verbose) { - log("Using " + inputFileName); - } - if (overwrite || isNewer(inputFileName, outputFileName)) { - if (verbose) { - log("Generating " + outputFileName); - } - // creation du repertoire pour le fichier destination - new File(outputFileName).getParentFile().mkdirs(); - try { - processor.process(new FileReader(inputFileName), - new FileWriter(outputFileName)); - } catch (IOException eee) { - throw new BuildException(eee); - } - } - } - log("Generating " + numberFiles + " files to " + destDir); - } - - protected Filter[] getFilters() throws BuildException { - String[] filterList = filters.split(","); - Filter[] result = new Filter[filterList.length]; - for (int i = 0; i < filterList.length; i++) { - try { - // Class.forName semble fonctionner maintenant - // avant il fallait utiliser getClass().forName - result[i] = (Filter) Class.forName(filterList[i].trim()) - .newInstance(); - } catch (Exception eee) { - throw new BuildException("Error during looking for '" - + filterList[i].trim() + "' class", eee); - } - } - return result; - } - - public void execute() throws BuildException { - // first of all, make sure that we've got a srcdir - if (srcDir == null) { - throw new BuildException("srcdir attribute must be set!", - getLocation()); - } - if (!srcDir.exists()) { - throw new BuildException("srcdir \"" + srcDir.getPath() - + "\" does not exist!", getLocation()); - } - - if (destDir == null) { - destDir = srcDir; - } - if (!destDir.isDirectory()) { - throw new BuildException("destination directory \"" + destDir - + "\" does not exist or is not a directory", getLocation()); - } - - // Build the list of files to compute - buildFileList(); - - // generate the source files - doExecute(); - } - - protected void buildFileList() { - - // Obtain this list of files within the source directory - DirectoryScanner ds = getDirectoryScanner(srcDir); - - String[] includes = getIncludes(); - if (includes.length > 0) { - ds.setIncludes(includes); - } - String[] excludes = getExcludes(); - if (excludes.length > 0) { - ds.setExcludes(excludes); - } - - ds.scan(); - - // on recherche ceux que l'on doit vraiment refaire - files = ds.getIncludedFiles(); - } - - protected boolean isNewer(String filein, String fileout) { - boolean result = new File(filein).lastModified() > new File(fileout) - .lastModified(); - if (result) { - log(filein + " is newer than " + fileout, MSG_VERBOSE); - } - return result; - } - - protected String[] getExcludes() { - return excludes; - } - - protected String[] getIncludes() { - return includes; - } - - public void setIncludes(String[] includes) { - this.includes = includes; - } - - public void setIncludes(String includes) { - setIncludes(includes.split(",")); - } - - public void setExcludes(String[] excludes) { - this.excludes = excludes; - } - - public void setExcludes(String excludes) { - setExcludes(excludes.split(",")); - } - - protected String absoluteDestinationName(String fileName) { - return destDir.getPath() + File.separator + fileName; - } - - protected String absoluteSourceName(String fileName) { - return srcDir.getPath() + File.separator + fileName; - } - -} // ProcessorTask Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/ActiveLogsCodeFilter.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/ActiveLogsCodeFilter.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/ActiveLogsCodeFilter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,62 +0,0 @@ -/* *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -/* x* -* ActiveLogsCodeFilter.java -* -* Created: Wed Jan 14 2004 -* -* @author <poussin@codelutin.com> -* Copyright Code Lutin -* @version $Revision$ -* -* Mise a jour: $Date$ -* par : $Author$ -*/ - -package org.codelutin.processor.filters; - -/* -* This class deals with the -*/ -public class ActiveLogsCodeFilter extends LogsFilter { - - /** - * methode appele lorsqu'on a la chaine entiere entre le header - * et le footer. - * @param ch la chaine trouve - * @return ce qu'il faut ecrire dans le fichier de sortie - */ - protected String performInFilter(String ch){ - // Logs must be performed within a try{...}catch{} bloc - return - "try {" + - ch + - "} catch (Exception logsE) { System.err.println(\"Error in Logging instructions\"); logsE.printStackTrace(); }"; - } - - /** - * methode appele lorsqu'on a la chaine entiere a l'exterieur du - * header/footer - * @param ch la chaine trouve - * @return ce qu'il faut ecrire dans le fichier de sortie - */ - protected String performOutFilter(String ch){ - return ch; - } - -} Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/DefaultFilter.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/DefaultFilter.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/DefaultFilter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,144 +0,0 @@ -/* *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -/******************************************************************************* - * DefaultFilter.java - * - * Created: Wed Sep 4 2002 - * - * @author <poussin@codelutin.com>Copyright Code Lutin - * - * @version $Revision$ - * - * Mise a jour: $Date$ par : $Author$ - */ - -package org.codelutin.processor.filters; - -public abstract class DefaultFilter implements Filter { // DefaultFilter - - public static int NOT_FOUND = -1; - - protected StringBuffer cachedContent = new StringBuffer(); - - public DefaultFilter() { - - } - - /** Type of states */ - protected static class State { - /** Looking-for-header state */ - public final static State SEARCH_HEADER = new State(); - - /** Looking-for-footer state */ - public final static State SEARCH_FOOTER = new State(); - } - - protected State currentState = State.SEARCH_HEADER; - - public String parse(String input) { - int matchingIndex; - - // add new input to current content - cachedContent.append(input); - String content = cachedContent.toString(); - - if (currentState.equals(State.SEARCH_HEADER)) { - // Looking for a header - matchingIndex = getMatchIndexFor(content, getHeader()); - if (matchingIndex != NOT_FOUND) { - // Header found, return "out" part of it + recursive process of remaining chars - currentState = State.SEARCH_FOOTER; - cachedContent.setLength(0); - return performOutFilter(content.substring(0, matchingIndex)) - + parse(content.substring(matchingIndex)); - } - // No header found ! - return EMPTY_STRING; - } - - if (currentState.equals(State.SEARCH_FOOTER)) { - // Looking for a footer - matchingIndex = getMatchIndexFor(content, getFooter()); - if (matchingIndex != NOT_FOUND) { - // Footer found, return "in" part of it + recursive process of remaining chars - currentState = State.SEARCH_HEADER; - cachedContent.setLength(0); - int matchingEndIndex = matchingIndex + getMatchLengthFor(getFooter()); - return performInFilter(performHeaderFooterFilter(content.substring(0, matchingEndIndex))) - + parse(content.substring(matchingEndIndex)); - } - // No footer found ! - return EMPTY_STRING; - } - - return "INVALID STATE in DefaultFilter !"; - } - - public String performHeaderFooterFilter(String ch) { - return ch.substring(getHeader().length(), ch.length()-getFooter().length()); - } - - public int getMatchIndexFor(String input, String sequence) { - return input.indexOf(sequence); - } - - public int getMatchLengthFor(String sequence) { - return sequence.length(); - } - - public boolean hasCachedData() { - return (cachedContent.length() > 0); - } - - public String flush() { - String line = cachedContent.toString(); - // Empty the cache, - cachedContent.setLength(0); - // and returns its content - if (currentState.equals(State.SEARCH_HEADER)) - return performOutFilter(line); - return performInFilter(line); - } - - /** - * methode appele lorsqu'on a la chaine entiere entre le header et le - * footer. - * - * @param ch - * la chaine trouve - * @return ce qu'il faut ecrire dans le fichier de sortie - */ - abstract protected String performInFilter(String ch); - - /** - * methode appele lorsqu'on a la chaine entiere a l'exterieur du - * header/footer - * - * @param ch - * la chaine trouve - * @return ce qu'il faut ecrire dans le fichier de sortie - */ - abstract protected String performOutFilter(String ch); - - /** la chaine du header */ - abstract protected String getHeader(); - - /** la chaine du footer */ - abstract protected String getFooter(); - -} // DefaultFilter Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/Filter.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/Filter.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/Filter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,41 +0,0 @@ -/* *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -/* * -* Filter.java -* -* Created: Wed Jan 14 2004 -* -* @author <poussin@codelutin.com> -* Copyright Code Lutin -* @version $Revision$ -* -* Mise a jour: $Date$ -* par : $Author$ -*/ - -package org.codelutin.processor.filters; - -public interface Filter { - - public final static String EMPTY_STRING = ""; - - public String parse (String input); - public boolean hasCachedData(); - public String flush (); - -} Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/GeneratorTemplatesFilter.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/GeneratorTemplatesFilter.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/GeneratorTemplatesFilter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,139 +0,0 @@ -/* *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -/* * - * GeneratorTemplatesFilter.java - * - * Created: Wed Sep 4 2002 - * - * @author <pineau@codelutin.com> - * Copyright Code Lutin - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ - -/** - * MultilinesLitteralsFilter.java - */ - -package org.codelutin.processor.filters; - -/* - * Classe principale du filtre de génération. Ce filtre recherche tout ce qu'il - * y a entre les tag /*{ et }*/ a l'interieur de ces tags un autre filtre - * ({@link org.codelutin.processor.filters.GeneratorTemplatesFilterIn}) est - * utilisé pour générer les tags <% %>, <%= %> et *). - * <ul> - * <li>/*{ et }*/ est remplacer par output.write("..."); pour chaque - * ligne et les " sont coté</li> - * <li><% %></li> - * <li><%= %></li> - * <li>*) permet de fermer un commentaire sans le fermer réeellement, cela - * permet au éditeur faisant une analyse du code de continuer a fonctionner - * ce tag est remplacé par son equivalent */ après génération.</li> - * </ul> - * Vous pouvez modifier le comportement du processor en mettant des options - * Une option est incluse dans le tag et est de la forme - * /*{generator option: <optionName> = valeur}*/ - * les options existantes sont: - * <li>passEmptyLine: boolean; cette option permet de supprimer la première - * et la dernière ligne si elles sont videx</li> - * <li>wtriteString: String, default: output.write</li> - */ -public class GeneratorTemplatesFilter extends DefaultFilter { - - protected boolean passEmptyLine = false; - protected String writeString = "output.write"; - - protected GeneratorTemplatesFilterIn inFilter = new GeneratorTemplatesFilterIn(this); - - public String getWriteString(){ - return writeString; - } - - /** - * methode appele lorsqu'on a la chaine entiere entre le header - * et le footer. - * @param ch la chaine trouve - * @return ce qu'il faut ecrire dans le fichier de sortie - */ - protected String performInFilter(String ch){ - if(ch.matches("generator option: *passEmptyLine *= *(true|false)")){ - passEmptyLine = - "true".equalsIgnoreCase(ch.substring(ch.length()-4)); - return EMPTY_STRING; - }else if(ch.matches("generator option: *writeString *= *.*")){ - writeString = - ch.replaceAll("generator option: *writeString *= *(.*)", "$1"); - return EMPTY_STRING; - }else{ - if (passEmptyLine && ch.length() > 0){ - // suppression des premieres et dernieres lignes si elles sont vides - String [] all = ch.split("\n"); - if (all.length > 0){ - // si la derniere ne match que des blancs - if(all[all.length-1].matches("\\s*")){ - int len = ch.length()-all[all.length-1].length()-1; - ch = ch.substring(0, Math.max(len,0)); - } - - // suppression de la 1er ligne si elle est vide - if(all[0].matches("\\s*")){ - int len = all[0].length()+1; - ch = ch.substring(Math.min(ch.length(),len)); - } - } - } - - String result = inFilter.parse(ch) + inFilter.flush(); - return getWriteString()+ "(\"" + result + "\");"; - } - } - - /** - * methode appele lorsqu'on a la chaine entiere a l'exterieur du - * header/footer - * @param ch la chaine trouve - * @return ce qu'il faut ecrire dans le fichier de sortie - */ - protected String performOutFilter(String ch) { - return ch; - } - - - /** la chaine du header */ - protected String getHeader() { - return "/*{"; - } - - /** la chaine du footer */ - protected String getFooter() { - return "}*/"; - } - - public static void main(String[] args) { - Filter filter = new GeneratorTemplatesFilter(); - String res = filter.parse(" public void generatePackageStatement(Writer output, ObjectModelClassifier clazz) throws IOException {\n/*{\n package <%=clazz.getPackageName()%>.persistence.jdo; \n}*/ }"); - System.out.println(res); - res = filter.flush(); - System.out.println(res); - } - - -} Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/GeneratorTemplatesFilterIn.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/GeneratorTemplatesFilterIn.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/GeneratorTemplatesFilterIn.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,95 +0,0 @@ -/* *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -/* * - * GeneratorTemplatesFilterIn.java - * - * Created: 14 janv. 2004 - * - * @author Benjamin Poussin <poussin@codelutin.com> - * Copyright Code Lutin - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ - -package org.codelutin.processor.filters; - -/** - * Le tag *) n'est substitué que s'il est a l'extérieur du tag <%=...%>ou - * <%...%> - */ -public class GeneratorTemplatesFilterIn extends DefaultFilter { // GeneratorTemplatesFilterIn - - GeneratorTemplatesFilter parent = null; - - public GeneratorTemplatesFilterIn(GeneratorTemplatesFilter parent) { - this.parent = parent; - } - - /** - * méthode appelée lorsqu'on a la chaîne entière entre le header et le - * footer. - * - * @param ch - * la chaîne trouvé - * @return ce qu'il faut écrire dans le fichier de sortie - */ - protected String performInFilter(String ch) { - if (ch.startsWith("=")) - return "\"+" + ch.substring(1) + "+\""; - return "\");" + ch + parent.getWriteString() + "(\""; - } - - /** - * Converti les fin de commentaire *) en fin normal de commentraire - */ - protected String convertEndComment(String ch) { - String result = ch.replaceAll("\\*\\)", "*/"); - return result; - } - - /** - * methode appele lorsqu'on a la chaine entiere a l'exterieur du - * header/footer - * - * @param ch - * la chaine trouve - * @return ce qu'il faut ecrire dans le fichier de sortie - */ - protected String performOutFilter(String ch) { - String result = convertEndComment(ch).replaceAll("\"", "\\\\\"") - .replaceAll("(\r\n|\n|\r)", - "\\\\n\");\n" + parent.getWriteString() + "(\""); - // it's important that \r\n is first in regexp. - - return result; - } - - /** la chaine du header */ - protected String getHeader() { - return "<%"; - } - - /** la chaine du footer */ - protected String getFooter() { - return "%>"; - } - -} // GeneratorTemplatesFilterIn - Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/I18nFilter.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/I18nFilter.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/I18nFilter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,142 +0,0 @@ -/* *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -/******************************************************************************* - * I18nFilter.java - * - * Created: Sun Sep 1 2002 - * - * @author <poussin@codelutin.com> Copyright Code Lutin - * - * @version $Revision$ - * - * Mise a jour: $Date$ par : $Author$ - */ - -package org.codelutin.processor.filters; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - - -public class I18nFilter extends DefaultFilter { // I18nFilter - - private String header = "_\\(\\s*\""; - private String footer = "\"\\s*(\\)|,|\\+|$)"; - - private Pattern headerPattern = Pattern.compile(getHeader()); - private Pattern footerPattern = Pattern.compile(getFooter()); - - protected void setFooter(String footer) { - this.footer = footer; - } - - protected void setHeader(String header) { - this.header = header; - } - - protected String getHeader() { - return header; - } - - protected String getFooter() { - return footer; - } - - private Matcher matcher = null; - public int getMatchIndexFor(String input, String sequence) { - int index = NOT_FOUND; - - setMatcher(null); - if (sequence == getHeader()) { - setMatcher(getHeaderPattern().matcher(input)); - } else if (sequence == getFooter()){ - setMatcher(getFooterPattern().matcher(input)); - } - if (getMatcher() != null) { - try { - getMatcher().find(); - index = getMatcher().start(); - } catch (RuntimeException e) {} - } - - return index; - } - - public int getMatchLengthFor(String sequence) { - int length = NOT_FOUND; - - try { - length = getMatcher().end()-getMatcher().start(); - } catch (RuntimeException e) {} - - return length; - } - - /** - * methode appele lorsqu'on a la chaine entiere entre le header et le - * footer. - * - * @param ch - * la chaine trouve - * @return ce qu'il faut ecrire dans le fichier de sortie - */ - protected String performInFilter(String ch) { - return ch.replaceAll("\"\\s*\\+\\s*\"","") + "="; - } - - public String performHeaderFooterFilter(String ch) { - return ch.substring(ch.indexOf('"')+1, ch.lastIndexOf('"')); - } - - /** - * methode appele lorsqu'on a la chaine entiere a l'exterieur du - * header/footer - * - * @param ch - * la chaine trouve - * @return ce qu'il faut ecrire dans le fichier de sortie - */ - protected String performOutFilter(String ch) { - return EMPTY_STRING; - } - - /** - * @return Returns the footerPattern. - */ - protected Pattern getFooterPattern() { - return footerPattern; - } - /** - * @return Returns the headerPattern. - */ - protected Pattern getHeaderPattern() { - return headerPattern; - } - /** - * @return Returns the matcher. - */ - protected Matcher getMatcher() { - return matcher; - } - /** - * @param matcher The matcher to set. - */ - protected void setMatcher(Matcher matcher) { - this.matcher = matcher; - } -} // I18nFilter Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/LicenseFilter.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/LicenseFilter.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/LicenseFilter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,73 +0,0 @@ -/** - * *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. *##% - */ -package org.codelutin.processor.filters; - -/** - * Un filtre pour remplacer la license d'un fichier source java. - * <p/> - * fixme : il faut ne pas autoriser le process de fichier java qui ne sont pas valide selon le header - footer... - * - * @author chemit - */ -public class LicenseFilter extends DefaultFilter { - - public static final String HEADER = "*" + "#" + "#" + "%"; - public static final String FOOTER = "#" + "#" + "%" + "*"; - /** - * la licence a insere dans le header du fichier source. Ce header est formatte en commentaire (chaque ligne - * commence par un ' * ', sauf pour la premiere et derniere ligne). - */ - protected String licenseHeader; - - /** flag pour indiquer si la licence a ete trouvee entre le header et le footer */ - protected boolean touched; - - public LicenseFilter(String licenseHeader) { - this.licenseHeader = " " + licenseHeader + " "; - } - - protected String performInFilter(String ch) { - if (touched) { - // on autorise pas deux process de la licence dans un fichier java - throw new IllegalStateException("has find more than once the license processor tags in a file"); - } - touched = true; - return HEADER + licenseHeader + FOOTER; - } - - protected String performOutFilter(String ch) { - return ch; - } - - protected String getHeader() { - return HEADER; - } - - protected String getFooter() { - return FOOTER; - } - - public boolean wasTouched() { - return touched; - } - - public void reset() { - touched = false; - } -} Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/LogsFilter.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/LogsFilter.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/LogsFilter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,48 +0,0 @@ -/* *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -/* * -* LogsFilter.java -* -* Created: Wed Jan 14 2004 -* -* @author <poussin@codelutin.com> -* Copyright Code Lutin -* @version $Revision$ -* -* Mise a jour: $Date$ -* par : $Author$ -*/ - -package org.codelutin.processor.filters; - -/* -* This class deals with the -*/ -public abstract class LogsFilter extends DefaultFilter { - - private String header = "/*"+"#"; - private String footer = "#"+"*/"; - - protected String getHeader(){ - return header; - } - protected String getFooter(){ - return footer; - } -} - Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/NoActionFilter.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/NoActionFilter.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/NoActionFilter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,50 +0,0 @@ -/* *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -/* * -* NoActionFilter.java -* -* Created: Wed Jan 14 2004 -* -* @author <poussin@codelutin.com> -* Copyright Code Lutin -* @version $Revision$ -* -* Mise a jour: $Date$ -* par : $Author$ -*/ - -package org.codelutin.processor.filters; - -/* -* This class deals with the -*/ -public class NoActionFilter implements Filter { - - public String parse (String input) { - return input; - } - - public boolean hasCachedData(){ - return false; - } - - public String flush (){ - return EMPTY_STRING; - } - -} Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/OptimisationFilter.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/OptimisationFilter.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/OptimisationFilter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,69 +0,0 @@ -/* *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -/* * -* OptimisationFilter.java -* -* Created: Wed Sep 4 2002 -* -* @author <poussin@codelutin.com> -* Copyright Code Lutin -* @version $Revision$ -* -* Mise a jour: $Date$ -* par : $Author$ -*/ - -package org.codelutin.processor.filters; - -public class OptimisationFilter extends DefaultFilter { // OptimisationFilter - - public OptimisationFilter() { - - } - - private String header = "/*%"; - private String footer = "%*/"; - - protected String getHeader(){ - return header; - } - protected String getFooter(){ - return footer; - } - - /** - * methode appele lorsqu'on a la chaine entiere entre le header - * et le footer. - * @param ch la chaine trouve - * @return ce qu'il faut ecrire dans le fichier de sortie - */ - protected String performInFilter(String ch){ - return ch; - } - - /** - * methode appele lorsqu'on a la chaine entiere a l'exterieur du - * header/footer - * @param ch la chaine trouve - * @return ce qu'il faut ecrire dans le fichier de sortie - */ - protected String performOutFilter(String ch){ - return EMPTY_STRING; - } - -} // OptimisationFilter Deleted: nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/RemoveLogsCodeFilter.java =================================================================== --- nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/RemoveLogsCodeFilter.java 2009-05-13 16:04:45 UTC (rev 203) +++ nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/RemoveLogsCodeFilter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -1,59 +0,0 @@ -/* *##% Lutin file processor - * Copyright (C) 2002 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -/* * -* RemoveLogsCodeFilter.java -* -* Created: Wed Jan 14 2004 -* -* @author <poussin@codelutin.com> -* Copyright Code Lutin -* @version $Revision$ -* -* Mise a jour: $Date$ -* par : $Author$ -*/ - -package org.codelutin.processor.filters; - -/* -* This class deals with the -*/ -public class RemoveLogsCodeFilter extends LogsFilter { - - /** - * methode appele lorsqu'on a la chaine entiere entre le header - * et le footer. - * @param ch la chaine trouve - * @return ce qu'il faut ecrire dans le fichier de sortie - */ - protected String performInFilter(String ch){ - return EMPTY_STRING; - } - - /** - * methode appele lorsqu'on a la chaine entiere a l'exterieur du - * header/footer - * @param ch la chaine trouve - * @return ce qu'il faut ecrire dans le fichier de sortie - */ - protected String performOutFilter(String ch){ - return ch; - } - -} - Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/GeneratorTemplatesProcessor.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/GeneratorTemplatesProcessor.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/GeneratorTemplatesProcessor.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/GeneratorTemplatesProcessor.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,59 @@ +/* *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +/* * + * GeneratorTemplatesProcessor.java + * + * Created: Wed Sep 4 2002 + * + * @author <pineau@codelutin.com> + * Copyright Code Lutin + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ + +package org.nuiton.processor; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +import org.nuiton.processor.filters.GeneratorTemplatesFilter; + +public class GeneratorTemplatesProcessor extends Processor { + + public GeneratorTemplatesProcessor(){ + setInputFilter(new GeneratorTemplatesFilter()); + } + + static public void process(String filein, String fileout) + throws IOException{ + Processor processor = new GeneratorTemplatesProcessor(); + processor.process(new FileReader(filein), new FileWriter(fileout)); + } + + public static void main(String [] args)throws IOException{ + if(args.length < 2) { + System.out.println("Give source and destination file"); + System.exit(1); + } else { + process(args[0], args[1]); + } + } +} Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/GeneratorTemplatesProcessor.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/I18nExtractor.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/I18nExtractor.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/I18nExtractor.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/I18nExtractor.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,120 @@ +/* *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +/* * + * I18nExtractor.java + * + * Created: Aug 16, 2004 + * + * @author Cédric Pineau <pineau@codelutin.com> + * @version $Revision$ + * + * Last update : $Date$ + * by : $Author$ + */ + +package org.nuiton.processor; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.LineNumberReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; + +import org.nuiton.processor.filters.I18nFilter; + +/** + * + */ +public class I18nExtractor { + + protected I18nFilter filter = new I18nFilter(); + + protected HashMap<String,List<String>> i18nStringsMap = new HashMap<String,List<String>>(); + + public void extract(File[] srcFiles, File outputFile) throws IOException { + PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"))); + for (int i = 0; i < srcFiles.length; i++) { + processFile(srcFiles[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(); + writer.println("# "+location); + } + writer.println(i18nString+"="); + } + writer.close(); + } + + protected void processFile(File srcFile) throws IOException { + LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(srcFile), "UTF-8")); + while (lnr.ready()) { + String line = lnr.readLine(); + int lineNumber = lnr.getLineNumber(); + processLine(line, srcFile, lineNumber); + } + } + + protected void processLine(String line, File srcFile, int lineNumber) { + String i18nStringsSet = filter.parse(line); + if (I18nFilter.EMPTY_STRING.equals(i18nStringsSet)) { + // 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<String> locations = i18nStringsMap.get(i18nString); + if (locations == null) { + locations = new ArrayList<String>(); + i18nStringsMap.put(i18nString, locations); + } + locations.add(srcFile.getPath()+"("+lineNumber+")"); + } + } + } + + public static void main(String[] args) { + if(args.length < 2) { + System.out.println("Please give at least sources and destination file"); + System.exit(0); + } else if (args.length > 2) { + File[] sources = new File[args.length-1]; + for (int i = 0; i < args.length-1; i++) { + sources[i] =new File(args[i]); + } + File destination = new File(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); + System.out.println("!!! "+eee); // TODO remove this + } + } + + } +} Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/I18nExtractor.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/LicenseProcessor.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/LicenseProcessor.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/LicenseProcessor.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/LicenseProcessor.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,46 @@ +/** + * *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. *##% + */ +package org.nuiton.processor; + +import org.nuiton.processor.filters.LicenseFilter; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +/** @author chemit */ +public class LicenseProcessor extends org.nuiton.processor.Processor { + + protected LicenseFilter licenseFilter; + + public LicenseProcessor(String header) { + licenseFilter = new LicenseFilter(header); + setInputFilter(licenseFilter); + } + + public LicenseFilter getLicenceFilter() { + return licenseFilter; + } + + public void process(File filein, File fileout) throws IOException { + process(new FileReader(filein), new FileWriter(fileout)); + } +} + Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/LicenseProcessor.java ___________________________________________________________________ Name: svn:mergeinfo + Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/LogsProcessor.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/LogsProcessor.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/LogsProcessor.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/LogsProcessor.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,87 @@ +/* *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +/* * +* LogsProcessor.java +* +* Created: Wed Jan 14 2004 +* +* @author <poussin@codelutin.com> +* Copyright Code Lutin +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + +package org.nuiton.processor; + +import org.nuiton.processor.filters.*; +import java.io.*; + +/* +* This class is a processor for source logs +*/ +public class LogsProcessor extends Processor { + + /** Type of actions */ + protected static class Action {} + /** Do nothing */ + public final static Action NoAction = new Action(); + + /** Active logs in output. This is the default action */ + public final static Action Logs = new Action(); + /** Remove logs in output */ + public final static Action NoLogsCode = new Action(); + + public LogsProcessor (Action action) { + if (action == NoAction) { + // No action is the default filter in Processor + } else if (action == NoLogsCode) { + setInputFilter(new RemoveLogsCodeFilter()); + } else { + // Go for logs + setInputFilter(new ActiveLogsCodeFilter()); + } + } + + public static void main(String [] args) throws Exception { + LogsProcessor processor; + if(args.length < 2) { + System.out.println("Give source and destination file, then action"); + System.out.println("Action may be remove or active (default is no action)"); + System.exit(0); + } else if (args.length > 2) { + if (args[2].equals("remove")) { + processor = new LogsProcessor(NoLogsCode); + System.out.println("Removing logs code"); + } else if (args[2].equals("active")) { + processor = new LogsProcessor(Logs); + System.out.println("Setting logs active"); + } else { + processor = new LogsProcessor(NoAction); + System.out.println("No action taken"); + } + try { + processor.process(new FileReader(args[0]), + new FileWriter(args[1])); + } catch (IOException eee) { + java.util.logging.Logger.getLogger("org.codelutin.processor.LogsProcessor.").severe("Error during log processing: "+eee); + } + } + } +} Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/LogsProcessor.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/OptimisationProcessor.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/OptimisationProcessor.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/OptimisationProcessor.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/OptimisationProcessor.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,57 @@ +/* *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +/* * +* OptimisationProcessor.java +* +* Created: Wed Sep 4 2002 +* +* @author <poussin@codelutin.com> +* Copyright Code Lutin +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + +package org.nuiton.processor; + +import java.io.*; +import org.nuiton.processor.filters.OptimisationFilter; + +public class OptimisationProcessor extends Processor { // OptimisationProcessor + + public OptimisationProcessor(){ + setInputFilter(new OptimisationFilter()); + } + + static public void process(String filein, String fileout) + throws IOException{ + Processor processor = new OptimisationProcessor(); + processor.process(new FileReader(filein), new FileWriter(fileout)); + } + + public static void main(String [] args)throws IOException{ + if(args.length < 2) { + System.out.println("Give source and destination file"); + System.exit(1); + } else { + process(args[0], args[1]); + } + } + +} // OptimisationProcessor Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/OptimisationProcessor.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/Processor.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/Processor.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/Processor.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/Processor.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,97 @@ +/* *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +/* * + * Processor.java + * + * Created: Wed Jan 14 2004 + * + * @author <poussin@codelutin.com> + * Copyright Code Lutin + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +package org.nuiton.processor; + +import org.nuiton.processor.filters.*; +import org.nuiton.processor.filters.Filter; +import java.io.*; +import java.util.logging.Logger; + +/* + * This class is a generic sources processor + * Given a reader class name and a writer class name + */ +public class Processor { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Logger log = Logger.getLogger("org.codelutin.processor.Processor"); + protected Filter[] inputFilter = new Filter[]{new NoActionFilter()}; + protected Filter outputFilter = new NoActionFilter(); + + public Processor() { + } + + public Processor(Filter[] filters) { + setInputFilter(filters); + } + + public void setInputFilter(Filter inFilter) { + setInputFilter(new Filter[]{inFilter}); + } + + public void setInputFilter(Filter[] inFilter) { + inputFilter = inFilter; + } + + public void setOutputFilter(Filter outFilter) { + outputFilter = outFilter; + } + + protected BufferedReader getReader(Reader externalInput) { + BufferedReader result = new BufferedReader(externalInput); + for (int i = 0; i < inputFilter.length; i++) { + result = new ProcessorReader(result, inputFilter[i]); + } + return result; + } + + /** Process all available data + * @param externalInput + * @param externalOutput + * @throws IOException if any pb + */ + public void process(Reader externalInput, Writer externalOutput) throws IOException { + log.finest("Debug du process"); + BufferedReader input = getReader(externalInput); + ProcessorWriter output = + new ProcessorWriter(new BufferedWriter(externalOutput), outputFilter); + + log.finest("input: " + input); + log.finest("output: " + output); + + String line = input.readLine(); + while (line != null) { + log.finest("Ligne lu: " + line); + output.writeLine(line); + line = input.readLine(); + } + output.flush(); + } +} Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/Processor.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ProcessorReader.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ProcessorReader.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ProcessorReader.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ProcessorReader.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,101 @@ +/* *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +/* * +* ProcessorReader.java +* +* Created: Wed Jan 14 2004 +* +* @author <poussin@codelutin.com> +* Copyright Code Lutin +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + +package org.nuiton.processor; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.StringReader; + +import org.nuiton.processor.filters.Filter; + +public class ProcessorReader extends BufferedReader { + + protected BufferedReader input; + protected Filter filter; + protected String lineSeparator; + + protected ProcessorReader(){ + super(new StringReader("")); + } + + public ProcessorReader(BufferedReader input, Filter filter) { + this(); + setInput(input); + this.filter = filter; + lineSeparator = System.getProperty("line.separator"); + } + + public void setInput(BufferedReader input){ + this.input = input; + } + + @Override + public boolean markSupported(){ + return false; + } + + @Override + public String readLine() throws IOException { + if (input.ready()) { + String line = input.readLine(); + if(line != null){ + if (!(input instanceof ProcessorReader)){ + line += lineSeparator; + } + return filter.parse(line); + } + } + if(filter.hasCachedData()){ + return filter.flush(); + } else { + return null; + } + } + + @Override + public boolean ready() { + try { + boolean ready = input.ready(); + if (ready) { + return true; + } + return filter.hasCachedData(); + } catch (IOException eee) { + return false; + } + } + + @Override + public void close() throws IOException { + input.close(); + } + +} Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ProcessorReader.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ProcessorWriter.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ProcessorWriter.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ProcessorWriter.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ProcessorWriter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,64 @@ +/* *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +/** +* ProcessorWriter.java +* +* Created: Wed Jan 14 2004 +* +* @author <poussin@codelutin.com> +* Copyright Code Lutin +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + +package org.nuiton.processor; + +import org.nuiton.processor.filters.*; +import java.io.*; + +public class ProcessorWriter { + + protected BufferedWriter output; + protected Filter filter; + + public ProcessorWriter(BufferedWriter output, Filter filter) { + this.output = output; + this.filter = filter; + } + + public void writeLine(String line) throws IOException { + + // TODO Euh on se sert quand du filtre de sortie ???? :-) + output.write(line); + } + + public void newLine() throws IOException { + output.newLine(); + } + + public void flush() throws IOException { + output.flush(); + } + + public void close() throws IOException { + output.close(); + } + +} Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ProcessorWriter.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ant/I18nExtractorTask.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ant/I18nExtractorTask.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ant/I18nExtractorTask.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ant/I18nExtractorTask.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,154 @@ +/* *##% Lutin file processor + * Copyright (C) 2002 - 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +package org.nuiton.processor.ant; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.MatchingTask; +import org.nuiton.processor.I18nExtractor; + +/** + * I18nExtractorTask. + * + * Created: Aug 16, 2004 + * + * @author Cédric Pineau <pineau@codelutin.com> + * @version $Revision$ + * + * Last update : $Date$ + * by : $Author$ + */ +public class I18nExtractorTask extends MatchingTask { + + public static final int MSG_VERBOSE = Project.MSG_VERBOSE; + + protected File srcDir; + + protected File destFile; + + protected String[] includes = new String[] {}; + + protected String[] excludes = new String[] {}; + + protected String[] srcFileNames; + + public I18nExtractorTask() { + + } + + protected void doExecute() throws BuildException { + // creation du repertoire pour le fichier destination + destFile.getParentFile().mkdirs(); + List<File> fileList = new ArrayList<File>(); + for (int i = 0; i < srcFileNames.length; i++) { + fileList.add(new File(srcFileNames[i])); + } + try { + new I18nExtractor() + .extract(fileList.toArray(new File[0]), destFile); + } catch (IOException eee) { + throw new BuildException(eee); + } + } + + public void setSrcdir(File srcDir) { + this.srcDir = srcDir; + } + + public void setDestFile(File destFile) { + this.destFile = destFile; + } + + @Override + public void execute() throws BuildException { + // first of all, make sure that we've got a srcdir + if (srcDir == null) { + throw new BuildException("srcdir attribute must be set!", + getLocation()); + } + if (!srcDir.exists()) { + throw new BuildException("srcdir \"" + srcDir.getPath() + + "\" does not exist!", getLocation()); + } + + if (destFile == null) { + throw new BuildException("destFile attribute must be set!", + getLocation()); + } + + // Build the list of files to compute + buildFileList(); + + // generate the source files + doExecute(); + } + + protected void buildFileList() { + + // Obtain this list of files within the source directory + DirectoryScanner ds = getDirectoryScanner(srcDir); + + String[] includes = getIncludes(); + if (includes.length > 0) { + ds.setIncludes(includes); + } + String[] excludes = getExcludes(); + if (excludes.length > 0) { + ds.setExcludes(excludes); + } + + ds.scan(); + + // on met le resultat dans files + srcFileNames = ds.getIncludedFiles(); + } + + protected boolean isNewer(String filein, String fileout) { + boolean result = new File(filein).lastModified() > new File(fileout) + .lastModified(); + if (result) { + log(filein + " is newer than " + fileout, MSG_VERBOSE); + } + return result; + } + + protected String[] getExcludes() { + return excludes; + } + + protected String[] getIncludes() { + return includes; + } + + @Override + public void setIncludes(String includes) { + this.includes = includes.split(","); + } + + @Override + public void setExcludes(String excludes) { + this.excludes = excludes.split(","); + } + +} Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ant/I18nExtractorTask.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ant/ProcessorTask.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/ant/ProcessorTask.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ant/ProcessorTask.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ant/ProcessorTask.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,246 @@ +/* + * *##% Lutin file processor + * Copyright (C) 2002 - 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ + +package org.nuiton.processor.ant; + +import java.io.File; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.MatchingTask; +import org.nuiton.processor.Processor; +import org.nuiton.processor.filters.Filter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.Project; + +/** + * Tache ant pour lutinprocessor. + * + * To use this task, put this code in ant build file: + * + * <taskdef name="processor" classname="org.codelutin.processor.ant.ProcessorTask" + * classpath="lib/lutinprocessor.jar" /> + * + * and use it with: + * + * <processor srcdir="${src}" destdir="${targetgen}" filters="org.codelutin.processor.filters.GeneratorTemplatesFilter" /> + * + * Created: 14 janv. 2004 + * + * @author Benjamin Poussin <poussin@codelutin.com> Copyright Code Lutin + * + * @version $Revision$ + * + * Mise a jour: $Date$ par : $Author$ + */ +public class ProcessorTask extends MatchingTask { // ProcessorTask + + public static final int MSG_VERBOSE = Project.MSG_VERBOSE; + + protected File srcDir; + + protected File destDir; + + protected String[] includes = new String[] {}; + + protected String[] excludes = new String[] {}; + + protected String[] files; + + protected String fileInPattern = ""; + + protected String fileOutPattern = ""; + + protected String filters = "org.codelutin.processor.filters.NoActionFilter"; + + protected boolean overwrite = true; + + protected boolean verbose = false; + + public ProcessorTask() { + + } + + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + public void setOverwrite(boolean overwrite) { + this.overwrite = overwrite; + } + + public void setFileOutPattern(String fileOutPattern) { + this.fileOutPattern = fileOutPattern; + } + + public void setFileInPattern(String fileInPattern) { + this.fileInPattern = fileInPattern; + } + + public void setSrcdir(File srcDir) { + this.srcDir = srcDir; + } + + public void setDestdir(File destDir) { + this.destDir = destDir; + } + + public void setFilters(String filters) { + this.filters = filters; + } + + protected String applyTransformationFilename(String filename) { + return filename.replaceAll(fileInPattern, fileOutPattern); + } + + protected void doExecute() throws BuildException { + Processor processor = new Processor(getFilters()); + int numberFiles; + for (numberFiles = 0; numberFiles < files.length; numberFiles++) { + String inputFileName = absoluteSourceName(files[numberFiles]); + String outputFileName = absoluteDestinationName(applyTransformationFilename(files[numberFiles])); + if (verbose) { + log("Using " + inputFileName); + } + if (overwrite || isNewer(inputFileName, outputFileName)) { + if (verbose) { + log("Generating " + outputFileName); + } + // creation du repertoire pour le fichier destination + new File(outputFileName).getParentFile().mkdirs(); + try { + processor.process(new FileReader(inputFileName), + new FileWriter(outputFileName)); + } catch (IOException eee) { + throw new BuildException(eee); + } + } + } + log("Generating " + numberFiles + " files to " + destDir); + } + + protected Filter[] getFilters() throws BuildException { + String[] filterList = filters.split(","); + Filter[] result = new Filter[filterList.length]; + for (int i = 0; i < filterList.length; i++) { + try { + // Class.forName semble fonctionner maintenant + // avant il fallait utiliser getClass().forName + result[i] = (Filter) Class.forName(filterList[i].trim()) + .newInstance(); + } catch (Exception eee) { + throw new BuildException("Error during looking for '" + + filterList[i].trim() + "' class", eee); + } + } + return result; + } + + @Override + public void execute() throws BuildException { + // first of all, make sure that we've got a srcdir + if (srcDir == null) { + throw new BuildException("srcdir attribute must be set!", + getLocation()); + } + if (!srcDir.exists()) { + throw new BuildException("srcdir \"" + srcDir.getPath() + + "\" does not exist!", getLocation()); + } + + if (destDir == null) { + destDir = srcDir; + } + if (!destDir.isDirectory()) { + throw new BuildException("destination directory \"" + destDir + + "\" does not exist or is not a directory", getLocation()); + } + + // Build the list of files to compute + buildFileList(); + + // generate the source files + doExecute(); + } + + protected void buildFileList() { + + // Obtain this list of files within the source directory + DirectoryScanner ds = getDirectoryScanner(srcDir); + + String[] includes = getIncludes(); + if (includes.length > 0) { + ds.setIncludes(includes); + } + String[] excludes = getExcludes(); + if (excludes.length > 0) { + ds.setExcludes(excludes); + } + + ds.scan(); + + // on recherche ceux que l'on doit vraiment refaire + files = ds.getIncludedFiles(); + } + + protected boolean isNewer(String filein, String fileout) { + boolean result = new File(filein).lastModified() > new File(fileout) + .lastModified(); + if (result) { + log(filein + " is newer than " + fileout, MSG_VERBOSE); + } + return result; + } + + protected String[] getExcludes() { + return excludes; + } + + protected String[] getIncludes() { + return includes; + } + + public void setIncludes(String[] includes) { + this.includes = includes; + } + + @Override + public void setIncludes(String includes) { + setIncludes(includes.split(",")); + } + + public void setExcludes(String[] excludes) { + this.excludes = excludes; + } + + @Override + public void setExcludes(String excludes) { + setExcludes(excludes.split(",")); + } + + protected String absoluteDestinationName(String fileName) { + return destDir.getPath() + File.separator + fileName; + } + + protected String absoluteSourceName(String fileName) { + return srcDir.getPath() + File.separator + fileName; + } + +} // ProcessorTask Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/ant/ProcessorTask.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/ActiveLogsCodeFilter.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/ActiveLogsCodeFilter.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/ActiveLogsCodeFilter.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/ActiveLogsCodeFilter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,64 @@ +/* *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +/* x* +* ActiveLogsCodeFilter.java +* +* Created: Wed Jan 14 2004 +* +* @author <poussin@codelutin.com> +* Copyright Code Lutin +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + +package org.nuiton.processor.filters; + +/* +* This class deals with the +*/ +public class ActiveLogsCodeFilter extends LogsFilter { + + /** + * methode appele lorsqu'on a la chaine entiere entre le header + * et le footer. + * @param ch la chaine trouve + * @return ce qu'il faut ecrire dans le fichier de sortie + */ + @Override + protected String performInFilter(String ch){ + // Logs must be performed within a try{...}catch{} bloc + return + "try {" + + ch + + "} catch (Exception logsE) { System.err.println(\"Error in Logging instructions\"); logsE.printStackTrace(); }"; + } + + /** + * methode appele lorsqu'on a la chaine entiere a l'exterieur du + * header/footer + * @param ch la chaine trouve + * @return ce qu'il faut ecrire dans le fichier de sortie + */ + @Override + protected String performOutFilter(String ch){ + return ch; + } + +} Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/ActiveLogsCodeFilter.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/DefaultFilter.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/DefaultFilter.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/DefaultFilter.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/DefaultFilter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,140 @@ +/* *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ +/******************************************************************************* + * DefaultFilter.java + * + * Created: Wed Sep 4 2002 + * + * @author <poussin@codelutin.com>Copyright Code Lutin + * + * @version $Revision$ + * + * Mise a jour: $Date$ par : $Author$ + */ +package org.nuiton.processor.filters; + +public abstract class DefaultFilter implements Filter { // DefaultFilter + + public static int NOT_FOUND = -1; + protected StringBuffer cachedContent = new StringBuffer(); + + public DefaultFilter() { + } + + /** Type of states */ + protected static class State { + + /** Looking-for-header state */ + public final static State SEARCH_HEADER = new State(); + /** Looking-for-footer state */ + public final static State SEARCH_FOOTER = new State(); + } + protected State currentState = State.SEARCH_HEADER; + + @Override + public String parse(String input) { + int matchingIndex; + + // add new input to current content + cachedContent.append(input); + String content = cachedContent.toString(); + + if (currentState.equals(State.SEARCH_HEADER)) { + // Looking for a header + matchingIndex = getMatchIndexFor(content, getHeader()); + if (matchingIndex != NOT_FOUND) { + // Header found, return "out" part of it + recursive process of remaining chars + currentState = State.SEARCH_FOOTER; + cachedContent.setLength(0); + return performOutFilter(content.substring(0, matchingIndex)) + parse(content.substring(matchingIndex)); + } + // No header found ! + return EMPTY_STRING; + } + + if (currentState.equals(State.SEARCH_FOOTER)) { + // Looking for a footer + matchingIndex = getMatchIndexFor(content, getFooter()); + if (matchingIndex != NOT_FOUND) { + // Footer found, return "in" part of it + recursive process of remaining chars + currentState = State.SEARCH_HEADER; + cachedContent.setLength(0); + int matchingEndIndex = matchingIndex + getMatchLengthFor(getFooter()); + return performInFilter(performHeaderFooterFilter(content.substring(0, matchingEndIndex))) + parse(content.substring(matchingEndIndex)); + } + // No footer found ! + return EMPTY_STRING; + } + + return "INVALID STATE in DefaultFilter !"; + } + + public String performHeaderFooterFilter(String ch) { + return ch.substring(getHeader().length(), ch.length() - getFooter().length()); + } + + public int getMatchIndexFor(String input, String sequence) { + return input.indexOf(sequence); + } + + public int getMatchLengthFor(String sequence) { + return sequence.length(); + } + + @Override + public boolean hasCachedData() { + return (cachedContent.length() > 0); + } + + @Override + public String flush() { + String line = cachedContent.toString(); + // Empty the cache, + cachedContent.setLength(0); + // and returns its content + if (currentState.equals(State.SEARCH_HEADER)) { + return performOutFilter(line); + } + return performInFilter(line); + } + + /** + * methode appele lorsqu'on a la chaine entiere entre le header et le + * footer. + * + * @param ch + * la chaine trouve + * @return ce qu'il faut ecrire dans le fichier de sortie + */ + abstract protected String performInFilter(String ch); + + /** + * methode appele lorsqu'on a la chaine entiere a l'exterieur du + * header/footer + * + * @param ch + * la chaine trouve + * @return ce qu'il faut ecrire dans le fichier de sortie + */ + abstract protected String performOutFilter(String ch); + + /** @return la chaine du header */ + abstract protected String getHeader(); + + /** @return la chaine du footer */ + abstract protected String getFooter(); +} // DefaultFilter Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/DefaultFilter.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/Filter.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/Filter.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/Filter.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/Filter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,41 @@ +/* *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +/* * +* Filter.java +* +* Created: Wed Jan 14 2004 +* +* @author <poussin@codelutin.com> +* Copyright Code Lutin +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + +package org.nuiton.processor.filters; + +public interface Filter { + + final static String EMPTY_STRING = ""; + + String parse (String input); + boolean hasCachedData(); + String flush (); + +} Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/Filter.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/GeneratorTemplatesFilter.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/GeneratorTemplatesFilter.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/GeneratorTemplatesFilter.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/GeneratorTemplatesFilter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,139 @@ +/* *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +/* * + * GeneratorTemplatesFilter.java + * + * Created: Wed Sep 4 2002 + * + * @author <pineau@codelutin.com> + * Copyright Code Lutin + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ + +/** + * MultilinesLitteralsFilter.java + */ + +package org.nuiton.processor.filters; + +/* + * Classe principale du filtre de génération. Ce filtre recherche tout ce qu'il + * y a entre les tag /*{ et }*/ a l'interieur de ces tags un autre filtre + * ({@link org.codelutin.processor.filters.GeneratorTemplatesFilterIn}) est + * utilisé pour générer les tags <% %>, <%= %> et *). + * <ul> + * <li>/*{ et }*/ est remplacer par output.write("..."); pour chaque + * ligne et les " sont coté</li> + * <li><% %></li> + * <li><%= %></li> + * <li>*) permet de fermer un commentaire sans le fermer réeellement, cela + * permet au éditeur faisant une analyse du code de continuer a fonctionner + * ce tag est remplacé par son equivalent */ après génération.</li> + * </ul> + * Vous pouvez modifier le comportement du processor en mettant des options + * Une option est incluse dans le tag et est de la forme + * /*{generator option: <optionName> = valeur}*/ + * les options existantes sont: + * <li>passEmptyLine: boolean; cette option permet de supprimer la première + * et la dernière ligne si elles sont videx</li> + * <li>wtriteString: String, default: output.write</li> + */ +public class GeneratorTemplatesFilter extends DefaultFilter { + + protected boolean passEmptyLine = false; + protected String writeString = "output.write"; + + protected GeneratorTemplatesFilterIn inFilter = new GeneratorTemplatesFilterIn(this); + + public String getWriteString(){ + return writeString; + } + + /** + * methode appele lorsqu'on a la chaine entiere entre le header + * et le footer. + * @param ch la chaine trouve + * @return ce qu'il faut ecrire dans le fichier de sortie + */ + protected String performInFilter(String ch){ + if(ch.matches("generator option: *passEmptyLine *= *(true|false)")){ + passEmptyLine = + "true".equalsIgnoreCase(ch.substring(ch.length()-4)); + return EMPTY_STRING; + }else if(ch.matches("generator option: *writeString *= *.*")){ + writeString = + ch.replaceAll("generator option: *writeString *= *(.*)", "$1"); + return EMPTY_STRING; + }else{ + if (passEmptyLine && ch.length() > 0){ + // suppression des premieres et dernieres lignes si elles sont vides + String [] all = ch.split("\n"); + if (all.length > 0){ + // si la derniere ne match que des blancs + if(all[all.length-1].matches("\\s*")){ + int len = ch.length()-all[all.length-1].length()-1; + ch = ch.substring(0, Math.max(len,0)); + } + + // suppression de la 1er ligne si elle est vide + if(all[0].matches("\\s*")){ + int len = all[0].length()+1; + ch = ch.substring(Math.min(ch.length(),len)); + } + } + } + + String result = inFilter.parse(ch) + inFilter.flush(); + return getWriteString()+ "(\"" + result + "\");"; + } + } + + /** + * methode appele lorsqu'on a la chaine entiere a l'exterieur du + * header/footer + * @param ch la chaine trouve + * @return ce qu'il faut ecrire dans le fichier de sortie + */ + protected String performOutFilter(String ch) { + return ch; + } + + + /** la chaine du header */ + protected String getHeader() { + return "/*{"; + } + + /** la chaine du footer */ + protected String getFooter() { + return "}*/"; + } + + public static void main(String[] args) { + Filter filter = new GeneratorTemplatesFilter(); + String res = filter.parse(" public void generatePackageStatement(Writer output, ObjectModelClassifier clazz) throws IOException {\n/*{\n package <%=clazz.getPackageName()%>.persistence.jdo; \n}*/ }"); + System.out.println(res); + res = filter.flush(); + System.out.println(res); + } + + +} Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/GeneratorTemplatesFilter.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/GeneratorTemplatesFilterIn.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/GeneratorTemplatesFilterIn.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/GeneratorTemplatesFilterIn.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/GeneratorTemplatesFilterIn.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,100 @@ +/* *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +/* * + * GeneratorTemplatesFilterIn.java + * + * Created: 14 janv. 2004 + * + * @author Benjamin Poussin <poussin@codelutin.com> + * Copyright Code Lutin + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ + +package org.nuiton.processor.filters; + +/** + * Le tag *) n'est substitué que s'il est a l'extérieur du tag <%=...%>ou + * <%...%> + */ +public class GeneratorTemplatesFilterIn extends DefaultFilter { // GeneratorTemplatesFilterIn + + GeneratorTemplatesFilter parent = null; + + public GeneratorTemplatesFilterIn(GeneratorTemplatesFilter parent) { + this.parent = parent; + } + + /** + * méthode appelée lorsqu'on a la chaîne entière entre le header et le + * footer. + * + * @param ch + * la chaîne trouvé + * @return ce qu'il faut écrire dans le fichier de sortie + */ + @Override + protected String performInFilter(String ch) { + if (ch.startsWith("=")) { + return "\"+" + ch.substring(1) + "+\""; + } + return "\");" + ch + parent.getWriteString() + "(\""; + } + + /** + * Converti les fin de commentaire *) en fin normal de commentraire + * @param ch la chaine a convertir + * @return la chaine convertie + */ + protected String convertEndComment(String ch) { + String result = ch.replaceAll("\\*\\)", "*/"); + return result; + } + + /** + * methode appele lorsqu'on a la chaine entiere a l'exterieur du + * header/footer + * + * @param ch + * la chaine trouve + * @return ce qu'il faut ecrire dans le fichier de sortie + */ + @Override + protected String performOutFilter(String ch) { + String result = convertEndComment(ch).replaceAll("\"", "\\\\\"") + .replaceAll("(\r\n|\n|\r)", + "\\\\n\");\n" + parent.getWriteString() + "(\""); + // it's important that \r\n is first in regexp. + + return result; + } + + @Override + protected String getHeader() { + return "<%"; + } + + @Override + protected String getFooter() { + return "%>"; + } + +} // GeneratorTemplatesFilterIn + Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/GeneratorTemplatesFilterIn.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/I18nFilter.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/I18nFilter.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/I18nFilter.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/I18nFilter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,142 @@ +/* *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +/******************************************************************************* + * I18nFilter.java + * + * Created: Sun Sep 1 2002 + * + * @author <poussin@codelutin.com> Copyright Code Lutin + * + * @version $Revision$ + * + * Mise a jour: $Date$ par : $Author$ + */ + +package org.nuiton.processor.filters; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + + +public class I18nFilter extends DefaultFilter { // I18nFilter + + private String header = "_\\(\\s*\""; + private String footer = "\"\\s*(\\)|,|\\+|$)"; + + private Pattern headerPattern = Pattern.compile(getHeader()); + private Pattern footerPattern = Pattern.compile(getFooter()); + + protected void setFooter(String footer) { + this.footer = footer; + } + + protected void setHeader(String header) { + this.header = header; + } + + protected String getHeader() { + return header; + } + + protected String getFooter() { + return footer; + } + + private Matcher matcher = null; + public int getMatchIndexFor(String input, String sequence) { + int index = NOT_FOUND; + + setMatcher(null); + if (sequence == getHeader()) { + setMatcher(getHeaderPattern().matcher(input)); + } else if (sequence == getFooter()){ + setMatcher(getFooterPattern().matcher(input)); + } + if (getMatcher() != null) { + try { + getMatcher().find(); + index = getMatcher().start(); + } catch (RuntimeException e) {} + } + + return index; + } + + public int getMatchLengthFor(String sequence) { + int length = NOT_FOUND; + + try { + length = getMatcher().end()-getMatcher().start(); + } catch (RuntimeException e) {} + + return length; + } + + /** + * methode appele lorsqu'on a la chaine entiere entre le header et le + * footer. + * + * @param ch + * la chaine trouve + * @return ce qu'il faut ecrire dans le fichier de sortie + */ + protected String performInFilter(String ch) { + return ch.replaceAll("\"\\s*\\+\\s*\"","") + "="; + } + + public String performHeaderFooterFilter(String ch) { + return ch.substring(ch.indexOf('"')+1, ch.lastIndexOf('"')); + } + + /** + * methode appele lorsqu'on a la chaine entiere a l'exterieur du + * header/footer + * + * @param ch + * la chaine trouve + * @return ce qu'il faut ecrire dans le fichier de sortie + */ + protected String performOutFilter(String ch) { + return EMPTY_STRING; + } + + /** + * @return Returns the footerPattern. + */ + protected Pattern getFooterPattern() { + return footerPattern; + } + /** + * @return Returns the headerPattern. + */ + protected Pattern getHeaderPattern() { + return headerPattern; + } + /** + * @return Returns the matcher. + */ + protected Matcher getMatcher() { + return matcher; + } + /** + * @param matcher The matcher to set. + */ + protected void setMatcher(Matcher matcher) { + this.matcher = matcher; + } +} // I18nFilter Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/I18nFilter.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/LicenseFilter.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/LicenseFilter.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/LicenseFilter.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/LicenseFilter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,73 @@ +/** + * *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. *##% + */ +package org.nuiton.processor.filters; + +/** + * Un filtre pour remplacer la license d'un fichier source java. + * <p/> + * fixme : il faut ne pas autoriser le process de fichier java qui ne sont pas valide selon le header - footer... + * + * @author chemit + */ +public class LicenseFilter extends DefaultFilter { + + public static final String HEADER = "*" + "#" + "#" + "%"; + public static final String FOOTER = "#" + "#" + "%" + "*"; + /** + * la licence a insere dans le header du fichier source. Ce header est formatte en commentaire (chaque ligne + * commence par un ' * ', sauf pour la premiere et derniere ligne). + */ + protected String licenseHeader; + + /** flag pour indiquer si la licence a ete trouvee entre le header et le footer */ + protected boolean touched; + + public LicenseFilter(String licenseHeader) { + this.licenseHeader = " " + licenseHeader + " "; + } + + protected String performInFilter(String ch) { + if (touched) { + // on autorise pas deux process de la licence dans un fichier java + throw new IllegalStateException("has find more than once the license processor tags in a file"); + } + touched = true; + return HEADER + licenseHeader + FOOTER; + } + + protected String performOutFilter(String ch) { + return ch; + } + + protected String getHeader() { + return HEADER; + } + + protected String getFooter() { + return FOOTER; + } + + public boolean wasTouched() { + return touched; + } + + public void reset() { + touched = false; + } +} Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/LicenseFilter.java ___________________________________________________________________ Name: svn:mergeinfo + Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/LogsFilter.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/LogsFilter.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/LogsFilter.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/LogsFilter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,48 @@ +/* *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +/* * +* LogsFilter.java +* +* Created: Wed Jan 14 2004 +* +* @author <poussin@codelutin.com> +* Copyright Code Lutin +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + +package org.nuiton.processor.filters; + +/* +* This class deals with the +*/ +public abstract class LogsFilter extends DefaultFilter { + + private String header = "/*"+"#"; + private String footer = "#"+"*/"; + + protected String getHeader(){ + return header; + } + protected String getFooter(){ + return footer; + } +} + Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/LogsFilter.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/NoActionFilter.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/NoActionFilter.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/NoActionFilter.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/NoActionFilter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,50 @@ +/* *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +/* * +* NoActionFilter.java +* +* Created: Wed Jan 14 2004 +* +* @author <poussin@codelutin.com> +* Copyright Code Lutin +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + +package org.nuiton.processor.filters; + +/* +* This class deals with the +*/ +public class NoActionFilter implements Filter { + + public String parse (String input) { + return input; + } + + public boolean hasCachedData(){ + return false; + } + + public String flush (){ + return EMPTY_STRING; + } + +} Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/NoActionFilter.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/OptimisationFilter.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/OptimisationFilter.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/OptimisationFilter.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/OptimisationFilter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,69 @@ +/* *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +/* * +* OptimisationFilter.java +* +* Created: Wed Sep 4 2002 +* +* @author <poussin@codelutin.com> +* Copyright Code Lutin +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + +package org.nuiton.processor.filters; + +public class OptimisationFilter extends DefaultFilter { // OptimisationFilter + + public OptimisationFilter() { + + } + + private String header = "/*%"; + private String footer = "%*/"; + + protected String getHeader(){ + return header; + } + protected String getFooter(){ + return footer; + } + + /** + * methode appele lorsqu'on a la chaine entiere entre le header + * et le footer. + * @param ch la chaine trouve + * @return ce qu'il faut ecrire dans le fichier de sortie + */ + protected String performInFilter(String ch){ + return ch; + } + + /** + * methode appele lorsqu'on a la chaine entiere a l'exterieur du + * header/footer + * @param ch la chaine trouve + * @return ce qu'il faut ecrire dans le fichier de sortie + */ + protected String performOutFilter(String ch){ + return EMPTY_STRING; + } + +} // OptimisationFilter Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/OptimisationFilter.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/RemoveLogsCodeFilter.java (from rev 202, nuitonprocessor/trunk/src/main/java/org/codelutin/processor/filters/RemoveLogsCodeFilter.java) =================================================================== --- nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/RemoveLogsCodeFilter.java (rev 0) +++ nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/RemoveLogsCodeFilter.java 2009-05-13 16:41:38 UTC (rev 204) @@ -0,0 +1,59 @@ +/* *##% Lutin file processor + * Copyright (C) 2002 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +/* * +* RemoveLogsCodeFilter.java +* +* Created: Wed Jan 14 2004 +* +* @author <poussin@codelutin.com> +* Copyright Code Lutin +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + +package org.nuiton.processor.filters; + +/* +* This class deals with the +*/ +public class RemoveLogsCodeFilter extends LogsFilter { + + /** + * methode appele lorsqu'on a la chaine entiere entre le header + * et le footer. + * @param ch la chaine trouve + * @return ce qu'il faut ecrire dans le fichier de sortie + */ + protected String performInFilter(String ch){ + return EMPTY_STRING; + } + + /** + * methode appele lorsqu'on a la chaine entiere a l'exterieur du + * header/footer + * @param ch la chaine trouve + * @return ce qu'il faut ecrire dans le fichier de sortie + */ + protected String performOutFilter(String ch){ + return ch; + } + +} + Property changes on: nuitonprocessor/trunk/src/main/java/org/nuiton/processor/filters/RemoveLogsCodeFilter.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native