[Lutinutil-commits] r962 - in tags/04082008_beforeUTF8: . maven-i18n-plugin maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/ui
Author: tchemit Date: 2008-08-04 11:30:42 +0000 (Mon, 04 Aug 2008) New Revision: 962 Added: tags/04082008_beforeUTF8/maven-i18n-plugin/ tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/PluginHelper.java Modified: tags/04082008_beforeUTF8/maven-i18n-plugin/pom.xml tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/Generate.java tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/Getter.java tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/Parser.java tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/ParserEvent.java tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/ParserException.java tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserJava.java tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserJavaActionConfig.java tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserJavaTabConfig.java tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserJaxx.java tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserSwixat.java tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserXml.java tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/ui/KeysModifier.java Log: before UTF8 Copied: tags/04082008_beforeUTF8/maven-i18n-plugin (from rev 955, trunk/maven-i18n-plugin) Modified: tags/04082008_beforeUTF8/maven-i18n-plugin/pom.xml =================================================================== --- trunk/maven-i18n-plugin/pom.xml 2008-07-31 21:07:05 UTC (rev 955) +++ tags/04082008_beforeUTF8/maven-i18n-plugin/pom.xml 2008-08-04 11:30:42 UTC (rev 962) @@ -31,12 +31,12 @@ <scope>compile</scope> </dependency> - <dependency> + <!--dependency> <groupId>org.codelutin</groupId> <artifactId>lutinutil-no-i18n</artifactId> <version>0.30-SNAPSHOT</version> <scope>compile</scope> - </dependency> + </dependency--> <dependency> <groupId>lutinlib</groupId> @@ -64,7 +64,7 @@ <!-- *** Project Information ************************************* --> <!-- ************************************************************* --> <name>Plugin maven pour lutini18n</name> - <version>0.3-SNAPSHOT</version> + <version>0.4</version> <description> Plugin pour maven 2 pour la génération des bundles pour l'internationnalisation des applications java fait par lutinutil-i18n @@ -142,7 +142,7 @@ <!-- compile with ? --> <maven.compile.source>1.6</maven.compile.source> <maven.compile.target>1.6</maven.compile.target> - <maven.compile.encoding>ISO-8859-15</maven.compile.encoding> + <maven.compile.encoding>UTF-8</maven.compile.encoding> <!-- Lists URL --> <labs.lists> Added: tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/PluginHelper.java =================================================================== --- tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/PluginHelper.java (rev 0) +++ tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/PluginHelper.java 2008-08-04 11:30:42 UTC (rev 962) @@ -0,0 +1,275 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * # #% + */ +package org.codelutin.i18n.plugin; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FilterOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.nio.channels.FileChannel; +import java.text.MessageFormat; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; +import java.util.Properties; +import java.util.Vector; + +/** + * Une classe pour mutualiser toutes les méthodes utiles dans ce plugin. + * <p/> + * Note : On a dupliqué ici du code de la librairie lutinutil, pour casser la dépendance ver ce projet qui utilise ce plugin + * et donc introduit un cycle dans le graphe des dépendances, ce qui n'est pas souhaitable. + * + * @author chemit + */ +public class PluginHelper { + + /** + * @param root le repertoire ou sont stockes les fichiers i18n + * @param artifactId le nom de l'artifact + * @param bundle le nom du bundle + * @param create <code>true</code> pour creer le fichier si non present + * @return le fichier i18n + * @throws java.io.IOException si probleme lors de la creation du fichier + */ + public static File getI18nFile(File root, String artifactId, String bundle, boolean create) throws IOException { + File file = new File(root.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties"); + if (create && !file.exists()) { + if (!file.exists()) { + file.getParentFile().mkdirs(); + } + file.createNewFile(); + } + return file; + } + + /** + * @param root le repertoire ou sont stockes les fichiers getter + * @param getter le nom du getter + * @param create <code>true</code> pour creer le fichier si non present + * @return le fichier i18n + * @throws java.io.IOException si probleme lors de la creation du fichier + */ + public static File getGetterFile(File root, String getter, boolean create) throws IOException { + File file = new File(root.getAbsolutePath() + File.separatorChar + getter); + if (create && !file.exists()) { + if (!file.exists()) { + file.getParentFile().mkdirs(); + } + file.createNewFile(); + } + return file; + } + + /** + * @param root le repertoire ou sont stockes les fichiers getter + * @param getter le nom du getter + * @return le fichier i18n + */ + public static File getGetterFileBackup(File root, String getter) { + return new File(root.getAbsolutePath() + File.separatorChar + getter + '~'); + } + + /** + * @param root le reertoire ou sont stockes les fichiers i18n + * @param artifactId le nom de l'artifact + * @param bundle le nom du bundle + * @return le fichier i18n de backup + */ + public static File getI18nFileBackup(File root, String artifactId, String bundle) { + return new File(root.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties~"); + } + + /** + * Permet de copier le fichier source vers le fichier cible. + * + * @param source le fichier source + * @param target le fichier cible + * @throws java.io.IOException Erreur de copie + */ + public static void copy(File source, File target) throws IOException { + target.getParentFile().mkdirs(); + FileChannel sourceChannel = new FileInputStream(source).getChannel(); + FileChannel targetChannel = new FileOutputStream(target).getChannel(); + sourceChannel.transferTo(0, sourceChannel.size(), targetChannel); + // or + // targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size()); + sourceChannel.close(); + targetChannel.close(); + } + + /** + * Permet de lire un fichier et de retourner sont contenu sous forme d'une + * chaine de carateres + * + * @param file le fichier a lire + * @param encoding encoding to read file + * @return the content of the file + * @throws IOException if IO pb + */ + static public String readAsString(File file, String encoding) throws IOException { + StringBuffer result = new StringBuffer(); + char[] cbuf = new char[2000]; + FileInputStream inf = new FileInputStream(file); + BufferedReader in = new BufferedReader(new InputStreamReader(inf, encoding)); + int nb = in.read(cbuf); + while (nb != -1) { + result.append(cbuf, 0, nb); + nb = in.read(cbuf); + } + in.close(); + return result.toString(); + } + + static public void writeString(File file, String content, String encoding) throws IOException { + file.getParentFile().mkdirs(); + BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), encoding)); + out.write(content); + out.close(); + } + + /** + * Permet de convertir une liste non typee, en une liste typee. + * <p/> + * La liste en entree en juste bien castee. + * <p/> + * On effectue une verification sur le typage des elements de la liste. + * <p/> + * Note : <b>Aucune liste n'est creee, ni recopiee</b> + * + * @param list la liste a convertir + * @param type le type des elements de la liste + * @return la liste typee + * @throws IllegalArgumentException si un element de la liste en entree n'est + * pas en adequation avec le type voulue. + */ + @SuppressWarnings({"unchecked"}) + static public <O> List<O> toGenericList(List list, Class<O> type) throws IllegalArgumentException { + if (list.isEmpty()) { + return list; + } + for (Object o : list) { + if (!(type.isAssignableFrom(o.getClass()))) { + throw new IllegalArgumentException("can not cast List with object of type " + o.getClass() + " to " + type + " type!"); + } + } + return list; + } + + + static final protected double[] timeFactors = {1000000, 1000, 60, 60, 24}; + + static final protected String[] timeUnites = {"ns", "ms", "s", "m", "h", + "d"}; + + static public String convertTime(long value) { + return convert(value, timeFactors, timeUnites); + } + + static public String convertTime(long value, long value2) { + return convertTime(value2 - value); + } + + static public String convert(long value, double[] factors, String[] unites) { + long sign = value == 0 ? 1 : value / Math.abs(value); + int i = 0; + double tmp = Math.abs(value); + while (i < factors.length && i < unites.length && tmp > factors[i]) { + tmp = tmp / factors[i++]; + } + + tmp *= sign; + String result; + result = MessageFormat.format("{0,number,0.###}{1}", tmp, + unites[i]); + return result; + } + + /** + * Permet d'avoir les fichiers de proprietes tries. + * + * @author julien + */ + public static class I18nProperties extends Properties { + + private static final long serialVersionUID = -1147150444452577558L; + + + public I18nProperties() { + super(); + } + + public I18nProperties(Properties defaults) { + super(defaults); + } + + @Override + public synchronized Enumeration<Object> keys() { + List<Object> objects = Collections.list(super.keys()); + Vector<Object> result; + try { + // Attention, si les clef ne sont pas des string, ca ne marchera pas + List<String> list = toGenericList(objects, String.class); + Collections.sort(list); + result = new Vector<Object>(list); + } catch (IllegalArgumentException e) { + // keys are not string !!! + // can not sort keys + result = new Vector<Object>(objects); + } + return result.elements(); + } + + public void store(File bundleOut) throws IOException { + super.store(new PropertiesDateRemoveFilterStream(new FileOutputStream(bundleOut)), null); + } + } + + public static class PropertiesDateRemoveFilterStream extends FilterOutputStream { + + private boolean firstLineOver; + char endChar; + + public PropertiesDateRemoveFilterStream(OutputStream out) { + super(out); + firstLineOver = false; + String lineSeparator = java.security.AccessController + .doPrivileged(new sun.security.action.GetPropertyAction( + "line.separator")); + endChar = lineSeparator.charAt(lineSeparator.length() - 1); + } + + @Override + public void write(int b) throws IOException { + if (!firstLineOver) { + char c = (char) b; + if (c == endChar) { + firstLineOver = true; + } + } else { + out.write(b); + } + } + + } + + +} Modified: tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java 2008-07-31 21:07:05 UTC (rev 955) +++ tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java 2008-08-04 11:30:42 UTC (rev 962) @@ -20,11 +20,15 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.codelutin.i18n.plugin.PluginHelper; import org.codelutin.i18n.plugin.ui.KeysModifier; -import org.codelutin.util.FileUtil; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -36,6 +40,7 @@ * @author tony */ public abstract class AbstractI18nParser extends AbstractI18nPlugin implements Parser { + /** @return the outGetter to use for the instance (java.getter,...) */ protected abstract String getOutGetter(); @@ -82,13 +87,23 @@ oldParser = new Properties(); oldLanguage = new Properties(); out.mkdirs(); - // �v�nements + // �v�nements if (keysModifier) { - addParserEvent(KeysModifier.getInstance(getKeyModifierStart(), getKeyModifierEnd())); + addParserEvent(KeysModifier.getInstance(getKeyModifierStart(), getKeyModifierEnd(), encoding)); } treadedFiles = new ArrayList<File>(); } + /** + * Test if a file is up to date and do not treate. + * + * @param basedir the basdir of sourceentry + * @param file1 the file path relative to basedir + * @param file the file to treate @return <code>true</code> if file is uptodate, says needs no treatment. + * @return <code>true</code> if file is up to date and do not need to be parsed + */ + protected abstract boolean isFileUptodate(File basedir, File file1, String file); + /* * (non-Javadoc) * @see org.apache.maven.plugin.AbstractMojo#execute() @@ -102,25 +117,27 @@ } try { // Reprise sur un ancien parsing - File oldParserFile = new File(out.getAbsolutePath() + File.separatorChar + getOutGetter()); - File saveFile = new File(out.getAbsolutePath() + File.separatorChar + getOutGetter() + "~"); - - if (!oldParserFile.exists()) { + File oldParserFile = PluginHelper.getGetterFile(out, getOutGetter(), true); + //File oldParserFile = new File(out.getAbsolutePath() + File.separatorChar + getOutGetter()); + File saveFile = PluginHelper.getGetterFileBackup(out, getOutGetter()); + //File saveFile = new File(out.getAbsolutePath() + File.separatorChar + getOutGetter() + "~"); + + /*if (!oldParserFile.exists()) { oldParserFile.getParentFile().mkdirs(); } - oldParserFile.createNewFile(); + oldParserFile.createNewFile();*/ + oldParser.load(new FileInputStream(oldParserFile)); + PluginHelper.copy(oldParserFile, saveFile); - FileUtil.copy(oldParserFile, saveFile); - - - // Anciennes cl�s disponnibles - File oldLanguageFile = new File(src.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundles[0] + ".properties"); - if (!oldLanguageFile.exists()) { + // Anciennes cl�s disponnibles + File oldLanguageFile = PluginHelper.getI18nFile(src, artifactId, bundles[0], true); + //File oldLanguageFile = new File(src.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundles[0] + ".properties"); + /*if (!oldLanguageFile.exists()) { oldLanguageFile.getParentFile().mkdirs(); } - oldLanguageFile.createNewFile(); + oldLanguageFile.createNewFile();*/ oldLanguage.load(new FileInputStream(oldLanguageFile)); // Parsing @@ -139,7 +156,7 @@ } - public void parse() { + public void parse() throws IOException { if (treateDefaultEntry) { addDefaultEntry(); } @@ -158,7 +175,7 @@ if (verbose) { getLog().debug(getLogEntry(" parse <" + entry + "> [incoming file(s) : " + foundFiles.length + "]", 0, 0, 0)); } else { - getLog().info(getLogEntry(" parse <" + entry .getBasedir()+ "> [incoming file(s) : " + foundFiles.length + "]", 0, 0, 0)); + getLog().info(getLogEntry(" parse <" + entry.getBasedir() + "> [incoming file(s) : " + foundFiles.length + "]", 0, 0, 0)); } // launch parser for found files parseEntry(entry.getBasedir(), foundFiles); @@ -186,7 +203,7 @@ entries = list.toArray(new SourceEntry[list.size()]); } - protected void parseEntry(File basedir, String[] files) { + protected void parseEntry(File basedir, String[] files) throws IOException { long t00 = System.nanoTime(); for (int i = 0; i < files.length; i++) { String file1 = files[i]; @@ -197,8 +214,21 @@ event.eventChangeFile(file); } touchFile = false; - parseFile(file); + int size = result.size(); + if (strictMode || !isFileUptodate(basedir, file, file1)) { + // on parse toujours en mode strict ou que le fichier n'est pas à jour + getLog().info("parseFile " + file); + parseFile(file); + } + + // D�tection de nouvelles cl�s, sauvegarde du fichier pour pouvoir le restaurer en cas de plantage + if (size != result.size()) { + saveProperties0(); + } if (touchFile) { + if (verbose) { + getLog().info("touched file " + file); + } treadedFiles.add(file); if (verbose) { getLog().debug(getLogEntry(fileName, i, t000, t00)); @@ -209,4 +239,17 @@ } } } + + protected void saveProperties0() throws IOException { + OutputStream outputStream = null; + try { + outputStream = new BufferedOutputStream(new FileOutputStream(PluginHelper.getGetterFile(out, getOutGetter(), false))); + //outputStream = new BufferedOutputStream(new FileOutputStream(out.getAbsolutePath() + File.separatorChar + getOutGetter())); + result.store(outputStream, null); + } finally { + if (outputStream != null) { + outputStream.close(); + } + } + } } Modified: tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java 2008-07-31 21:07:05 UTC (rev 955) +++ tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java 2008-08-04 11:30:42 UTC (rev 962) @@ -19,66 +19,65 @@ package org.codelutin.i18n.plugin.core; +import org.apache.maven.plugin.AbstractMojo; +import org.codelutin.i18n.plugin.PluginHelper; +import org.codelutin.i18n.plugin.PluginHelper.I18nProperties; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Properties; -import org.apache.maven.plugin.AbstractMojo; -import org.codelutin.util.SortedProperties; -import org.codelutin.util.StringUtil; - /** - * Classe permettant d'obenir les param�tres pendant les diff�rentes phases + * Classe permettant d'obenir les parametres pendant les différentes phases * du plugin. - * + * * @author julien */ public abstract class AbstractI18nPlugin extends AbstractMojo { /** - * @description Langues des bundles g�n�r�s. + * @description Langues des bundles generes. * @parameter expression="${i18n.bundles}" default-value="" * @required */ protected String[] bundles; /** - * @description R�pertoire sources des fichiers i18n. + * @description Repertoire sources des fichiers i18n. * @parameter expression="${i18n.src}" default-value="${basedir}/src/resources/i18n" * @required */ protected File src; /** - * @description Met les fichiers g�n�r�s dans le r�pertoire des sources i18n. + * @description Met les fichiers generes dans le repertoire des sources i18n. * @parameter expression="${i18n.genSrc}" default-value="true" */ protected boolean genSrc; - + /** - * @description R�pertoire des fichiers g�n�r�s i18n. + * @description Répertoire des fichiers generes i18n. * @parameter expression="${i18n.out}" default-value="${basedir}/target/gen/i18n" * @required */ protected File out; /** - * @description Active la modification de cl� + * @description Active la modification de cle * @parameter expression="${i18n.keysModifier}" default-value="false" */ protected boolean keysModifier; /** * @description verbose - * @parameter expression="${i18n.verbose}" default-value="${maven.verbose}" + * @parameter expression="${i18n.verbose}" default-value="false" */ protected boolean verbose; - + /** * @description Nom du projet. * @parameter expression="${i18n.artifactId}" default-value="${project.artifactId}" @@ -91,79 +90,93 @@ * @parameter expression="${i18n.keepBackup}" default-value="true" */ protected boolean keepBackup; - + /** + * @description ne conserve que les clef scannees (et donc traite tous les fichiers) + * @parameter expression="${i18n.strictMode}" default-value="false" + */ + protected boolean strictMode; + + /** + * @description ne conserve que les clef scannees (et donc traite tous les fichiers) + * @parameter expression="${i18n.encoding}" default-value="${maven.compile.encoding}" + * @required + */ + protected String encoding; + + /** * Log * Do not use a instance of, use a lazy instancier */ //protected Log log = getLog(); - + /** - * R�pertoire de stockage des fichiers i18n pour la r�cup�ration des fichiers + * Répertoire de stockage des fichiers i18n pour la recuperation des fichiers * de traduction entre librairie */ protected static String DIRECTORY_INSTALL = "i18n" + File.separatorChar; - - /** - * Liste des �v�nements - */ + + /** Liste des évènements */ protected List<ParserEvent> events = new ArrayList<ParserEvent>(); /** - * Ajoute un �v�nement - * @param parserEvent l'�v�nement d'ajout + * Ajoute un évènement + * + * @param parserEvent l'évènement d'ajout */ protected void addParserEvent(ParserEvent parserEvent) { this.events.add(parserEvent); } - + /** - * Supprime un �v�nement - * @param parserEvent l'�v�nement de suppression + * Supprime un évènement + * + * @param parserEvent l'évènement de suppression */ protected void removeParserEvent(ParserEvent parserEvent) { this.events.remove(parserEvent); } - - /** - * Concat�ne deux fichiers de propri�t�s - * @param in le fichier entrant + + /** + * Concatène deux fichiers de proprietes + * + * @param in le fichier entrant * @param out le fichier sortant - * @throws FileNotFoundException si fichier non trouv� - * @throws IOException si probl�me pendant la sauvegarde + * @throws FileNotFoundException si fichier non trouvé + * @throws IOException si problème pendant la sauvegarde */ protected void concactProperties(File in, File out) throws IOException { - Properties propertiesIn = new SortedProperties(); + Properties propertiesIn = new I18nProperties(); propertiesIn.load(new FileInputStream(in)); - - Properties propertiesOut = new SortedProperties(); + + I18nProperties propertiesOut = new I18nProperties(); propertiesOut.load(new FileInputStream(out)); propertiesOut.putAll(propertiesIn); - propertiesOut.store(new FileOutputStream(out), null); + propertiesOut.store(out); } /** - * Construit une chaine de log format�e. + * Construit une chaine de log formatée. * * @param msg le prefix du message - * @param nbFiles le nombre de fichiers actuellement trait�s + * @param nbFiles le nombre de fichiers actuellement traités * @param time le time de traitement de ce fichier * @param all le temps de traitement de tous les fichiers - * @return la chaine de log format�e + * @return la chaine de log formatée */ protected String getLogEntry(String msg, int nbFiles, long time, long all) { long now = System.nanoTime(); long delta = now - time; - String s = "["+artifactId+"] i18n."+getClass().getSimpleName() + " : " + msg; + String s = "[" + artifactId + "] i18n." + getClass().getSimpleName() + " : " + msg; if (time > 0) { - s += " (" + StringUtil.convertTime(delta) + ")"; + s += " (" + PluginHelper.convertTime(delta) + ")"; } if (all > 0 && nbFiles > -1) { - s += "(total time:" + StringUtil.convertTime(now - all) + ") ( ~ " + StringUtil.convertTime(((now - all) / (nbFiles + 1))) + " / file)"; + s += "(total time:" + PluginHelper.convertTime(now - all) + ") ( ~ " + PluginHelper.convertTime(((now - all) / (nbFiles + 1))) + " / file)"; } return s; } - /** Taille du buffer pour les lectures/�critures */ + /** Taille du buffer pour les lectures/écritures */ protected static final int BUFFER_SIZE = 8 * 1024; } Modified: tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/Generate.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/Generate.java 2008-07-31 21:07:05 UTC (rev 955) +++ tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/Generate.java 2008-08-04 11:30:42 UTC (rev 962) @@ -21,18 +21,16 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.codelutin.util.FileUtil; -import org.codelutin.util.PropertiesDateRemoveFilterStream; -import org.codelutin.util.SortedProperties; +import org.codelutin.i18n.plugin.PluginHelper; +import org.codelutin.i18n.plugin.PluginHelper.I18nProperties; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; /** - * Merge des fichiers de propri�t�s avec les anciens. + * Merge des fichiers de propriétés avec les anciens. * * @author julien * @goal gen @@ -49,40 +47,49 @@ for (String bundle : bundles) { try { // Merge - File bundleSrc = new File(src.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties"); - File bundleOut = new File(out.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties"); + //File bundleSrc = new File(src.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties"); + //File bundleOut = new File(out.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties"); + File bundleSrc = PluginHelper.getI18nFile(src, artifactId, bundle, false); + File bundleOut = PluginHelper.getI18nFile(out, artifactId, bundle, false); if (bundleSrc.exists()) { + Properties propertiesSrc = new Properties(); propertiesSrc.load(new FileInputStream(bundleSrc)); - Properties propertiesBundle = new SortedProperties(); - propertiesBundle.load(new FileInputStream(bundleOut)); + I18nProperties propertiesOut = new I18nProperties(); - // Parcours des cl�s - for (Object key : propertiesBundle.keySet()) { - Object oldKey = propertiesBundle.get(key); + if (!strictMode) { + // push back in bundle out, all the bundle src keys + propertiesOut.putAll(propertiesSrc); + } + propertiesOut.load(new FileInputStream(bundleOut)); + + // Parcours des clés + for (Object key : propertiesOut.keySet()) { + Object oldKey = propertiesOut.get(key); Object value = propertiesSrc.get(oldKey); - // R�cup�ration de la cl� si elle a �t� renomm� + // Récupération de la clé si elle a été renommée if (!key.equals(oldKey) && value == null) { value = propertiesSrc.get(key); } if (value != null) { - propertiesBundle.put(key, value); + propertiesOut.put(key, value); } else { - propertiesBundle.put(key, ""); + propertiesOut.put(key, ""); } } - FileOutputStream fileOutputStream = new FileOutputStream(bundleOut); - PropertiesDateRemoveFilterStream filter = new PropertiesDateRemoveFilterStream(fileOutputStream); - propertiesBundle.store(filter, null); + //saveBundle(bundleOut, propertiesOut); + propertiesOut.store(bundleOut); + // Sauvegarde avant copie if (genSrc && keepBackup) { - FileUtil.copy(bundleSrc, new File(src.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties" + "~")); + PluginHelper.copy(bundleSrc, PluginHelper.getI18nFileBackup(src, artifactId, bundle)); + //FileUtil.copy(bundleSrc, new File(src.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties" + "~")); } getLog().info("Merge bundle " + bundleSrc.getAbsolutePath()); @@ -90,7 +97,7 @@ if (genSrc) { // Copie des fichiers dans les sources - FileUtil.copy(bundleOut, bundleSrc); + PluginHelper.copy(bundleOut, bundleSrc); getLog().info("Copy bundle " + bundleSrc.getAbsolutePath()); } @@ -100,4 +107,10 @@ } } } + + /*void saveBundle(File bundleOut, Properties propertiesBundle) throws IOException { + FileOutputStream fileOutputStream = new FileOutputStream(bundleOut); + PropertiesDateRemoveFilterStream filter = new PropertiesDateRemoveFilterStream(fileOutputStream); + propertiesBundle.store(filter, null); + }*/ } Modified: tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/Getter.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/Getter.java 2008-07-31 21:07:05 UTC (rev 955) +++ tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/Getter.java 2008-08-04 11:30:42 UTC (rev 962) @@ -19,19 +19,18 @@ package org.codelutin.i18n.plugin.core; -import java.io.File; -import java.io.IOException; - import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.codehaus.plexus.util.DirectoryScanner; -import org.codelutin.util.FileUtil; +import org.codelutin.i18n.plugin.PluginHelper; +import java.io.File; +import java.io.IOException; + /** - * R�cup�re les diff�rents fichiers des parsers en un fichier de propri�t�s. - * + * Récupère les différents fichiers des parsers en un fichier de propriétés. + * * @author julien - * * @goal get * @phase generate-resources */ @@ -45,16 +44,17 @@ try { File bundleGetters = new File(out.getAbsolutePath() + File.separatorChar + artifactId + ".properties"); bundleGetters.createNewFile(); - + DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir(out); - ds.setIncludes(new String[] {"*.getter"}); + ds.setIncludes(new String[]{"*.getter"}); ds.scan(); String[] files = ds.getIncludedFiles(); - // Fusion des fichiers propri�t�s des diff�rents parsers + // Fusion des fichiers propriétés des différents parsers for (String file : files) { - File bundleGetter = new File(out.getAbsolutePath() + File.separatorChar + file); + File bundleGetter = PluginHelper.getGetterFile(out, file, false); + //File bundleGetter = new File(out.getAbsolutePath() + File.separatorChar + file); concactProperties(bundleGetter, bundleGetters); if (genSrc) { bundleGetter.delete(); @@ -62,13 +62,14 @@ getLog().info("Create bundle with " + bundleGetter.getAbsolutePath()); } - // Cr�ation des bundles + // Création des bundles for (String bundle : bundles) { - File bundleOut = new File(out.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties"); - FileUtil.copy(bundleGetters, bundleOut); + //File bundleOut = new File(out.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle + ".properties"); + File bundleOut = PluginHelper.getI18nFile(out, artifactId, bundle, false); + PluginHelper.copy(bundleGetters, bundleOut); getLog().info("Generate bundle " + bundleOut.getAbsolutePath()); } - + bundleGetters.delete(); } catch (IOException e) { getLog().error("File Error I/O ", e); Modified: tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/Parser.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/Parser.java 2008-07-31 21:07:05 UTC (rev 955) +++ tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/Parser.java 2008-08-04 11:30:42 UTC (rev 962) @@ -20,30 +20,31 @@ package org.codelutin.i18n.plugin.core; import java.io.File; +import java.io.IOException; /** - * Interface type pour la d�finition d'un nouveau parser. + * Interface type pour la définition d'un nouveau parser. * <p/> - * Une implantation abstraite est propos�e : {@link AbstractI18nParser}. + * Une implantation abstraite est proposée : {@link AbstractI18nParser}. * * @author julien */ public interface Parser { /** Lancement du parser */ - public void parse(); + public void parse() throws IOException; /** * Parse sur un fichier * - * @param file le fichier � parser + * @param file le fichier à parser */ public void parseFile(File file); /** * Parse une partie du fichier * - * @param file le fichier � parser + * @param file le fichier à parser * @param args ? TODO */ public void parseLine(File file, String args); Modified: tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/ParserEvent.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/ParserEvent.java 2008-07-31 21:07:05 UTC (rev 955) +++ tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/ParserEvent.java 2008-08-04 11:30:42 UTC (rev 962) @@ -22,7 +22,7 @@ import java.io.File; /** - * Permet d'ajouter des �v�nements sur les parsers + * Permet d'ajouter des évènements sur les parsers * * @author julien * @@ -30,26 +30,26 @@ public interface ParserEvent { /** - * M�thode appel�e quand on change de fichier pars� + * M�thode appelée quand on change de fichier parsé * @param file */ public void eventChangeFile(File file); /** - * M�thode appel�e apr�s le parsing du fichier + * Méthode appelée après le parsing du fichier * @param file */ public void eventNextFile(File file); /** - * M�thode appel�e quand on change de cl� + * M�thode appelée quand on change de clé * @param keyI18n * @param newKey */ public void eventChangeKey(String keyI18n, boolean newKey); /** - * M�thode appel�e pour r�cup�rer la nouvelle valeur de cl� + * M�thode appelée pour récupérer la nouvelle valeur de clé * @return */ public String eventGetRealKey(); Modified: tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/ParserException.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/ParserException.java 2008-07-31 21:07:05 UTC (rev 955) +++ tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/core/ParserException.java 2008-08-04 11:30:42 UTC (rev 962) @@ -20,7 +20,7 @@ package org.codelutin.i18n.plugin.core; /** - * Permet la gestion des exceptions dans les parsers et dans les �v�nements + * Permet la gestion des exceptions dans les parsers et dans les évènements * * @author julien * Modified: tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserJava.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserJava.java 2008-07-31 21:07:05 UTC (rev 955) +++ tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserJava.java 2008-08-04 11:30:42 UTC (rev 962) @@ -19,36 +19,19 @@ package org.codelutin.i18n.plugin.extension; -import org.apache.maven.artifact.Artifact; import org.apache.maven.project.MavenProject; import org.codelutin.i18n.plugin.core.AbstractI18nParser; import org.codelutin.i18n.plugin.core.ParserEvent; import org.codelutin.i18n.plugin.core.ParserException; -import org.codelutin.i18n.plugin.core.SourceEntry; import org.codelutin.processor.filters.I18nFilter; -import org.codelutin.util.FileUtil; -import java.io.BufferedOutputStream; -import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; import java.io.InputStreamReader; import java.io.LineNumberReader; -import java.io.OutputStream; -import java.lang.annotation.Annotation; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.regex.Pattern; /** - * R�cup�ration des cha�ne � traduire depuis les fichiers java. + * Récupération des chaine a traduire depuis les fichiers java. * * @author julien * @goal parserJava @@ -69,33 +52,21 @@ protected File defaultBasedir; /** - * @description D�pendance du projet. + * @description Dependance du projet. * @parameter default-value="${project}" * @readonly */ protected MavenProject project; /** - * @description R�pertoire sources des fichiers i18n. + * @description Repertoire sources des fichiers i18n. * @parameter expression="${i18n.cp}" default-value="${basedir}/target/classes" * @required */ protected File cp; - /** - * @description pour utiliser l'annotation I18nable pour traiter les fichiers - * @parameter expression="${i18n.ea}" default-value="false" - */ - protected boolean ea; + //protected List<String> annotationClass; - /** - * @description pour d�couvrir les fichiers I18nable. - * @parameter expression="${i18n.detectea}" default-value="false" - */ - protected boolean detectea; - - protected List<String> annotationClass; - protected String[] getDefaultIncludes() { return new String[]{defaultIncludes}; } @@ -119,33 +90,40 @@ protected I18nFilter filter; - protected URLClassLoader loader; - protected Annotation annotation; + //protected URLClassLoader loader; + //protected Annotation annotation; @Override public void init() { super.init(); filter = new I18nFilter(); - if (detectea) { + /*if (detectea) { // in detect mode, we do not filter by ea, try all files ea = false; } if (ea) { // in ea mode, we do not detect anything detectea = false; - } + }*/ - if (ea || detectea) { + /*if (ea || detectea) { loader = initClassLoader(); annotationClass = initAnnotations(); - } + }*/ } - protected List<String> initAnnotations() { - return Collections.singletonList("org.codelutin.i18n.I18nable"); + protected boolean isFileUptodate(File basedir, File file1, String file) { + String clazzFile = file.substring(0, file.length() - 4) + "class"; + File clazz = new File(cp + File.separator + clazzFile); + + return clazz.exists() && file1.lastModified() < clazz.lastModified(); } - @Override + /*protected List<String> initAnnotations() { + return Collections.singletonList("org.codelutin.i18n.I18nable"); + }*/ + + /*@Override protected String[] getFilesForEntry(SourceEntry entry) { if (detectea || !ea) { @@ -155,29 +133,28 @@ // filter by annotation return entry.getIncludedFiles(getDefaultBasedir(), getDefaultIncludes(), loader, annotationClass, getLog()); - } + }*/ /* * (non-Javadoc) * @see org.codelutin.i18n.plugin.core.Parser#parseFile(java.io.File) */ + public void parseFile(File srcFile) { try { - int size = result.size(); - parseFile0(srcFile); - - // D�tection de nouvelles cl�s, sauvegarde du fichier pour pouvoir le restaurer en cas de plantage - if (size != result.size()) { - saveProperties0(); + LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(srcFile))); + while (lnr.ready()) { + String line = lnr.readLine(); + parseLine(srcFile, line); } - if (touchFile && detectea) { + /*if (touchFile && detectea) { Annotation annotation = currentEntry.getAnnotation(srcFile, loader, annotationClass, getLog()); if (annotation == null) { addAnnotation(srcFile); } - } + }*/ } catch (Exception e) { throw new ParserException(e); } @@ -209,7 +186,7 @@ } } - private void addAnnotation(File srcFile) throws IOException { + /*private void addAnnotation(File srcFile) throws IOException { String classname = srcFile.getName(); @@ -249,30 +226,18 @@ outputStream.close(); } } - } + }*/ - protected void saveProperties0() throws IOException { - OutputStream outputStream = null; - try { - outputStream = new BufferedOutputStream(new FileOutputStream(out.getAbsolutePath() + File.separatorChar + getOutGetter())); - result.store(outputStream, null); - } finally { - if (outputStream != null) { - outputStream.close(); - } - } - } - - protected void parseFile0(File srcFile) throws IOException { + /*protected void parseFile0(File srcFile) throws IOException { LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(srcFile))); while (lnr.ready()) { String line = lnr.readLine(); parseLine(srcFile, line); } - } + }*/ - @SuppressWarnings({"unchecked"}) - protected URLClassLoader initClassLoader() { + /*@SuppressWarnings({"unchecked"}) + private URLClassLoader initClassLoader() { URLClassLoader loader = null; if (project != null) { URLClassLoader result; @@ -309,5 +274,5 @@ } } return loader; - } + }*/ } Modified: tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserJavaActionConfig.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserJavaActionConfig.java 2008-07-31 21:07:05 UTC (rev 955) +++ tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserJavaActionConfig.java 2008-08-04 11:30:42 UTC (rev 962) @@ -21,8 +21,6 @@ import org.codelutin.i18n.plugin.core.ParserEvent; import java.io.File; -import java.util.ArrayList; -import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -52,20 +50,21 @@ return "java-action-config.getter"; } - @Override + /*@Override protected List<String> initAnnotations() { - List<String> result = new ArrayList<String>(1); - result.add("jaxx.runtime.builder.ActionConfig"); - result.add("jaxx.runtime.builder.SelectActionConfig"); - result.add("jaxx.runtime.builder.TabContentConfig"); - result.add("jaxx.runtime.builder.ToggleActionConfig"); + List<String> result = new ArrayList<String>(4); + result.add("org.codelutin.jaxx.action.ActionConfig"); + result.add("org.codelutin.jaxx.action.SelectActionConfig"); + result.add("org.codelutin.jaxx.action.TabContentConfig"); + result.add("org.codelutin.jaxx.action.ToggleActionConfig"); return result; - } + }*/ /* * (non-Javadoc) * @see org.codelutin.i18n.plugin.extension.XmlParser#extract(java.lang.String) */ + public String extract(String i18nString) { Matcher matcher = MATCH_PATTERN.matcher(i18nString.trim()); if (matcher.matches()) { Modified: tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserJavaTabConfig.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserJavaTabConfig.java 2008-07-31 21:07:05 UTC (rev 955) +++ tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserJavaTabConfig.java 2008-08-04 11:30:42 UTC (rev 962) @@ -14,8 +14,6 @@ */ package org.codelutin.i18n.plugin.extension; -import java.util.Collections; - /** * Un paseur java pour scanner les annotations TabContentConfig. * @@ -30,9 +28,9 @@ return "java-tab-config.getter"; } - @Override + /*@Override protected java.util.List<String> initAnnotations() { return Collections.singletonList("org.codelutin.i18n.I18nable"); - } + }*/ } Modified: tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserJaxx.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserJaxx.java 2008-07-31 21:07:05 UTC (rev 955) +++ tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserJaxx.java 2008-08-04 11:30:42 UTC (rev 962) @@ -19,8 +19,10 @@ package org.codelutin.i18n.plugin.extension; +import java.io.File; + /** - * R�cup�ration des cha�ne � traduire depuis les fichiers xml Jaxx. + * Récupération des chaine à traduire depuis les fichiers xml Jaxx. * * @author julien * @goal parserJaxx @@ -35,7 +37,7 @@ protected String defaultIncludes; /** - * @description R�gles xml. + * @description Règles xml. * @parameter expression="${i18n.rulesJaxx}" default-value="jaxx.rules" */ protected String rulesJaxx; @@ -44,6 +46,10 @@ return new String[]{defaultIncludes}; } + protected boolean isFileUptodate(File basedir, File file1, String file) { + return false; + } + protected String getOutGetter() { return "jaxx.getter"; } Modified: tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserSwixat.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserSwixat.java 2008-07-31 21:07:05 UTC (rev 955) +++ tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserSwixat.java 2008-08-04 11:30:42 UTC (rev 962) @@ -19,8 +19,10 @@ package org.codelutin.i18n.plugin.extension; +import java.io.File; + /** - * R�cup�ration des cha�ne � traduire depuis les fichiers xml Swixat. + * Récupération des chaines à traduire depuis les fichiers xml Swixat. * * @author julien * @goal parserSwixat @@ -35,7 +37,7 @@ protected String defaultIncludes; /** - * @description R�gles xml. + * @description R�gles xml. * @parameter expression="${i18n.rulesSwixat}" default-value="swixat.rules" */ protected String rulesSwixat; @@ -44,7 +46,11 @@ return new String[]{defaultIncludes}; } + protected boolean isFileUptodate(File basedir, File file1, String file) { + return false; + } + protected String getKeyModifierStart() { return "=\\s*[\"\']"; } Modified: tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserXml.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserXml.java 2008-07-31 21:07:05 UTC (rev 955) +++ tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/extension/ParserXml.java 2008-08-04 11:30:42 UTC (rev 962) @@ -34,19 +34,17 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; /** - * R�cup�ration des cha�ne � traduire depuis les fichiers xml. + * Récupération des chaines à traduire depuis les fichiers xml. * * @author julien */ public abstract class ParserXml extends AbstractI18nParser { - /** Taille du buffer pour les lectures/�critures */ + /** Taille du buffer pour les lectures/écritures */ protected static final int BUFFER_SIZE = 8 * 1024; /** @@ -71,7 +69,7 @@ /** @return le fichier des rules */ protected abstract String getFileRules(); - /** @return le fichier des rules de base � toujours charger */ + /** @return le fichier des rules de base à toujours charger */ protected abstract String getCoreFileRules(); @Override @@ -88,12 +86,12 @@ */ public void parseFile(File file) { NodeList list; - InputSource inputSource = new InputSource(file.getAbsolutePath()); // TODO: A d�placer pour les performances + InputSource inputSource = new InputSource(file.getAbsolutePath()); // TODO: A d�placer pour les performances try { int size = result.size(); - // Recherche des cl�s � partir d'un xpath + // Recherche des clés à partir d'un xpath XPathExpression expression = xpath.compile(rules); list = (NodeList) expression.evaluate(inputSource, XPathConstants.NODESET); @@ -102,10 +100,11 @@ parseLine(file, node.getTextContent()); } - // D�tection de nouvelles cl�s, sauvegarde du fichier pour pouvoir le restaurer en cas de plantage + // Détection de nouvelles clés, sauvegarde du fichier pour pouvoir le restaurer en cas de plantage if (size != result.size()) { - OutputStream xmlparserOut = new FileOutputStream(out.getAbsolutePath() + File.separatorChar + getOutGetter()); - result.store(xmlparserOut, null); + saveProperties0(); + //OutputStream xmlparserOut = new FileOutputStream(out.getAbsolutePath() + File.separatorChar + getOutGetter()); + //result.store(xmlparserOut, null); } } catch (Exception e) { throw new ParserException(e); @@ -139,10 +138,10 @@ } /** - * R�cup�re le xpath � partir d'un fichier + * Récupère le xpath à partir d'un fichier * - * @param fileRules le nom du fichier contant les r�gles - * @return le xpath � partir d'un fichier + * @param fileRules le nom du fichier contant les règles + * @return le xpath à partir d'un fichier */ private String getRules(String fileRules) { StringBuilder result = new StringBuilder(); @@ -211,7 +210,7 @@ * * @param in le flux entrant * @return le contenu du flux - * @throws IOException si probl�me de lecture dans flux entrant + * @throws IOException si problème de lecture dans flux entrant */ private String readInputStream(InputStream in) throws IOException { StringBuilder sb = new StringBuilder(); @@ -225,7 +224,7 @@ String result = sb.toString().trim(); result = result.replaceAll("#.*\n", ""); // suppression des commentaires result = result.replaceAll("\\s+", " | "); // contruction du xpath avec des ou - result = result.replaceAll("(^ \\| )|( \\| $)", ""); // suppression des ou de d�but ee fin + result = result.replaceAll("(^ \\| )|( \\| $)", ""); // suppression des ou de début ee fin return result; } } Modified: tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/ui/KeysModifier.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/ui/KeysModifier.java 2008-07-31 21:07:05 UTC (rev 955) +++ tags/04082008_beforeUTF8/maven-i18n-plugin/src/main/java/org/codelutin/i18n/plugin/ui/KeysModifier.java 2008-08-04 11:30:42 UTC (rev 962) @@ -19,6 +19,15 @@ package org.codelutin.i18n.plugin.ui; +import org.codelutin.i18n.plugin.PluginHelper; +import org.codelutin.i18n.plugin.core.ParserEvent; +import org.codelutin.i18n.plugin.core.ParserException; + +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JTextField; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.ActionEvent; @@ -33,32 +42,22 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JTextField; - -import org.codelutin.i18n.plugin.core.ParserEvent; -import org.codelutin.i18n.plugin.core.ParserException; -import org.codelutin.util.FileUtil; - /** - * IHM permettant de modifier les cl�s de traduction en direct dans les fichiers - * pars�s et les fichiers de propri�t�s. - * + * IHM permettant de modifier les clés de traduction en direct dans les fichiers + * parsés et les fichiers de propriétés. + * * @author julien - * */ public class KeysModifier extends JFrame implements ParserEvent { private static final long serialVersionUID = 1L; - - // Modification des cl�s dans le fichier + + // Modification des clés dans le fichier protected List<String> newKeys; protected boolean needModifiedFile; protected String patternLeft; protected String patternRight; + protected String encoding; // Interface protected JLabel name = new JLabel(); @@ -66,33 +65,33 @@ protected JTextField key = new JTextField(); protected JTextField pattern = new JTextField(".*"); protected JCheckBox onlyNewKey = new JCheckBox(); + + protected JButton next = new JButton("Next >>"); + private static KeysModifier keysModifier; - - private static KeysModifier keysModifier; - /** - * Rc�cup�ration d'une instance de l'interface - * @param patternLeft - * @param patternRight - * @return + * Récupération d'une instance de l'interface + * + * @param patternLeft left pattern + * @param patternRight right pattern + * @param encoding encoding + * @return the shared instance with new config */ - public static KeysModifier getInstance(String patternLeft, String patternRight) { - if(keysModifier == null) { + public static KeysModifier getInstance(String patternLeft, String patternRight, String encoding) { + if (keysModifier == null) { keysModifier = new KeysModifier(); } - + + + keysModifier.encoding = encoding; keysModifier.patternLeft = patternLeft; keysModifier.patternRight = patternRight; - + return keysModifier; } - - /** - * Contructeur de l'interface - * @param patternLeft - * @param patternRight - */ + + /** Contructeur de l'interface */ private KeysModifier() { setLayout(new GridLayout(9, 2, 10, 10)); @@ -142,7 +141,7 @@ path.setText(file.getPath()); key.setText(""); repaint(); - + newKeys = new ArrayList<String>(); needModifiedFile = false; } @@ -152,12 +151,12 @@ * @see org.codelutin.i18n.plugin.core.ParserEvent#eventNextFile(java.io.File) */ public void eventNextFile(File file) { - if(needModifiedFile) { + if (needModifiedFile) { String content = ""; int region = 0; try { - content = FileUtil.readAsString(file); + content = PluginHelper.readAsString(file, encoding); } catch (IOException e) { throw new ParserException(e); } @@ -174,22 +173,22 @@ } try { - FileUtil.writeString(file, content); + PluginHelper.writeString(file, content, encoding); } catch (IOException e) { throw new ParserException(e); } } } - + /* - * (non-Javadoc) - * @see org.codelutin.i18n.plugin.core.ParserEvent#eventChangeKey(java.lang.String) - */ + * (non-Javadoc) + * @see org.codelutin.i18n.plugin.core.ParserEvent#eventChangeKey(java.lang.String) + */ public synchronized void eventChangeKey(String keyI18n, boolean newKey) { key.setText(keyI18n); newKeys.add(key.getText()); repaint(); - if(isVisible() && keyI18n.matches(pattern.getText()) && (!onlyNewKey.isSelected() || newKey)) { + if (isVisible() && keyI18n.matches(pattern.getText()) && (!onlyNewKey.isSelected() || newKey)) { try { wait(); } catch (InterruptedException e) { @@ -208,36 +207,42 @@ return key.getText(); } - /** - * Action sur le boutton pour passer � la cl� suivante - */ + /** Action sur le boutton pour passer � la cl� suivante */ class EventNextKey implements ActionListener { public void actionPerformed(ActionEvent e) { eventNextKey(); } } - /** - * Action sur la fermeture de la frame - */ + /** Action sur la fermeture de la frame */ class EventWindows implements WindowListener { - public void windowClosed(WindowEvent e) {} - public void windowActivated(WindowEvent e) {} + public void windowClosed(WindowEvent e) { + } + + public void windowActivated(WindowEvent e) { + } + public void windowClosing(WindowEvent e) { setVisible(false); eventNextKey(); } - public void windowDeactivated(WindowEvent e) {} - public void windowDeiconified(WindowEvent e) {} - public void windowIconified(WindowEvent e) {} - public void windowOpened(WindowEvent e) {} + public void windowDeactivated(WindowEvent e) { + } + + public void windowDeiconified(WindowEvent e) { + } + + public void windowIconified(WindowEvent e) { + } + + public void windowOpened(WindowEvent e) { + } + } - /** - * Permet de passer � la cl� suivante - */ + /** Permet de passer à la clé suivante */ public synchronized void eventNextKey() { notifyAll(); }
participants (1)
-
tchemit@users.labs.libre-entreprise.org