Index: lutinutil/src/java/org/codelutin/util/FileUtil.java diff -u lutinutil/src/java/org/codelutin/util/FileUtil.java:1.5 lutinutil/src/java/org/codelutin/util/FileUtil.java:1.6 --- lutinutil/src/java/org/codelutin/util/FileUtil.java:1.5 Mon Jan 23 13:48:16 2006 +++ lutinutil/src/java/org/codelutin/util/FileUtil.java Mon Mar 6 17:05:21 2006 @@ -23,9 +23,9 @@ * Created: 22 nov. 2004 * * @author Benjamin Poussin - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * - * Mise a jour: $Date: 2006/01/23 13:48:16 $ + * Mise a jour: $Date: 2006/03/06 17:05:21 $ * par : $Author: bpoussin $ */ @@ -35,10 +35,17 @@ import java.io.BufferedWriter; import java.io.File; import java.io.FileFilter; +import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.UnsupportedEncodingException; +import java.io.Writer; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; @@ -46,6 +53,64 @@ public class FileUtil { // FileUtil + /** Encoding par defaut utilisé si non spécifié */ + static public String ENCODING = "ISO-8859-1"; + + /** + * Retourne un Reader utilisant l'encoding par defaut {@link #ENCODING} + * + * @param file + * @return + * @throws IOException + */ + static public BufferedReader getReader(File file) throws IOException { + return getReader(file, ENCODING); + } + + /** + * Retourne un reader utilisant l'encoding choisi et placé dans un + * BufferedReader + * + * @param file + * @param encoding (ISO-8859-1, UTF-8, ...) + * @return + * @throws IOException + */ + static public BufferedReader getReader(File file, String encoding) throws IOException { + FileInputStream inf = new FileInputStream(file); + InputStreamReader in = new InputStreamReader(inf, encoding); + BufferedReader result = new BufferedReader(in); + return result; + } + + /** + * Retourne un Writer utilisant l'encoding par defaut {@link #ENCODING} + * + * @param file + * @return + * @throws IOException + */ + static public BufferedWriter getWriter(File file) throws IOException { + return getWriter(file, ENCODING); + } + + /** + * Retourne un writer utilisant l'encoding choisi et placé dans un + * BufferedWriter + * + * @param file + * @param encoding (ISO-8859-1, UTF-8, ...) + * @return + * @throws IOException + */ + static public BufferedWriter getWriter(File file, String encoding) throws IOException { + FileOutputStream outf = new FileOutputStream(file); + OutputStreamWriter out = new OutputStreamWriter(outf, encoding); + BufferedWriter result = new BufferedWriter(out); + return result; + } + + /** * Permet de creer un nouveu repertoire temporaire, l'effacement du * répertoire est a la charge de l'appelant @@ -93,7 +158,7 @@ */ static public String readAsString(File file) throws IOException { String result = ""; - BufferedReader in = new BufferedReader(new FileReader(file)); + BufferedReader in = getReader(file); String tmp = in.readLine(); while (tmp != null) { result += tmp + "\n"; @@ -111,7 +176,7 @@ */ static public void writeString(File file, String content) throws IOException { file.getParentFile().mkdirs(); - BufferedWriter out = new BufferedWriter(new FileWriter(file)); + BufferedWriter out = getWriter(file); out.write(content); out.close(); } Index: lutinutil/src/java/org/codelutin/util/Log.java diff -u lutinutil/src/java/org/codelutin/util/Log.java:1.6 lutinutil/src/java/org/codelutin/util/Log.java:1.7 --- lutinutil/src/java/org/codelutin/util/Log.java:1.6 Wed Jan 4 13:26:32 2006 +++ lutinutil/src/java/org/codelutin/util/Log.java Mon Mar 6 17:05:21 2006 @@ -23,9 +23,9 @@ * Created: 12 août 2004 * * @author Benjamin Poussin - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ * - * Mise a jour: $Date: 2006/01/04 13:26:32 $ + * Mise a jour: $Date: 2006/03/06 17:05:21 $ * par : $Author: bpoussin $ */ @@ -82,6 +82,7 @@ static public class LogEvent extends EventObject { /** */ private static final long serialVersionUID = 6597052732707368243L; + protected String category; protected Level level; protected String message; Index: lutinutil/src/java/org/codelutin/util/Resource.java diff -u lutinutil/src/java/org/codelutin/util/Resource.java:1.23 lutinutil/src/java/org/codelutin/util/Resource.java:1.24 --- lutinutil/src/java/org/codelutin/util/Resource.java:1.23 Wed Jan 4 13:26:32 2006 +++ lutinutil/src/java/org/codelutin/util/Resource.java Mon Mar 6 17:05:21 2006 @@ -23,14 +23,17 @@ * * @author POUSSIN Benjamin * Copyright Code Lutin -* @version $Revision: 1.23 $ +* @version $Revision: 1.24 $ * -* Mise a jour: $Date: 2006/01/04 13:26:32 $ +* Mise a jour: $Date: 2006/03/06 17:05:21 $ * par : $Author: bpoussin $ */ package org.codelutin.util; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -40,10 +43,9 @@ import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -58,8 +60,14 @@ */ public class Resource { // Resource + /** + * Logger for this class + */ + private static final Log log = LogFactory.getLog(Resource.class); + + /** to use log facility, just put in your code: log.info(\"...\"); */ - private static Logger log = Logger.getLogger("org.codelutin.util.Resource"); +// private static Logger log = Logger.getLogger("org.codelutin.util.Resource"); protected Resource() { @@ -108,7 +116,7 @@ try{ return file.toURI().toURL(); }catch(MalformedURLException eee){ - Logger.getLogger("org.codelutin.util.Resource.getURL").warning("Le fichier '" + file + "' a été trouvé, mais il n'a pas pu etre converti en URL"); + log.warn("Le fichier '" + file + "' a été trouvé, mais il n'a pas pu etre converti en URL"); } } @@ -138,7 +146,7 @@ try{ return new ImageIcon(getURL(name)); }catch(Exception eee){ - Logger.getLogger(Resource.class.getName() + ".getIcon").log(Level.WARNING, "Can't find icon: " + name, eee); + log.warn("Can't find icon: " + name, eee); return null; } } @@ -212,6 +220,10 @@ HashList urlList = new HashList(); URL[] arrayURL = classLoader.getURLs(); + if (log.isInfoEnabled()) { + log.info("search URLs pattern: " + pattern + " in " + Arrays.toString(arrayURL)); + } + for(int i=0;i 4) { + String ext = name.substring(name.length() - 4, name.length()); + return ".jar".equalsIgnoreCase(ext); + } + return false; } /** @@ -315,7 +357,11 @@ * @return vrai si le fichier se termine par .zip faux sinon */ static public boolean isZip(String name){ - return name.endsWith(".zip"); + if (name != null && name.length() > 4) { + String ext = name.substring(name.length() - 4, name.length()); + return ".zip".equalsIgnoreCase(ext); + } + return false; } /**