Index: lutinutil/src/java/org/codelutin/util/URLConverter.java diff -u lutinutil/src/java/org/codelutin/util/URLConverter.java:1.2 lutinutil/src/java/org/codelutin/util/URLConverter.java:1.3 --- lutinutil/src/java/org/codelutin/util/URLConverter.java:1.2 Thu Jan 3 05:53:58 2008 +++ lutinutil/src/java/org/codelutin/util/URLConverter.java Wed Feb 13 15:22:43 2008 @@ -31,8 +31,6 @@ * classe pour convertir une chaine en un objet URL. * * @author chemit - * @see Enum - * @see Enum#ordinal() */ public class URLConverter implements Converter { Index: lutinutil/src/java/org/codelutin/util/ConverterUtil.java diff -u lutinutil/src/java/org/codelutin/util/ConverterUtil.java:1.3 lutinutil/src/java/org/codelutin/util/ConverterUtil.java:1.4 --- lutinutil/src/java/org/codelutin/util/ConverterUtil.java:1.3 Thu Jan 3 05:57:18 2008 +++ lutinutil/src/java/org/codelutin/util/ConverterUtil.java Wed Feb 13 15:22:43 2008 @@ -22,6 +22,7 @@ import org.apache.commons.beanutils.Converter; import java.net.URL; +import java.net.URI; import java.util.Arrays; /** @@ -31,7 +32,7 @@ */ public class ConverterUtil { - private static final Class[] AUTO_REGISTRED_CONVERTER = new Class[]{URL.class,VersionNumber.class}; + private static final Class[] AUTO_REGISTRED_CONVERTER = new Class[]{URL.class, URI.class,VersionNumber.class}; /** * Cherche un converter pour un type donné. *

Index: lutinutil/src/java/org/codelutin/util/URIConverter.java diff -u /dev/null lutinutil/src/java/org/codelutin/util/URIConverter.java:1.1 --- /dev/null Wed Feb 13 15:22:50 2008 +++ lutinutil/src/java/org/codelutin/util/URIConverter.java Wed Feb 13 15:22:43 2008 @@ -0,0 +1,76 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin, +* Benjamin Poussin, 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.util; + +import org.apache.commons.beanutils.ConversionException; +import org.apache.commons.beanutils.Converter; +import static org.apache.commons.logging.LogFactory.getLog; +import static org.codelutin.i18n.I18n._; + +import java.net.URI; +import java.net.URISyntaxException; + +/** + * classe pour convertir une chaine en un objet URI. + * + * @author chemit + */ +public class URIConverter implements Converter { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static org.apache.commons.logging.Log log = getLog(URIConverter.class); + + public Object convert(Class aClass, Object value) { + if (value == null) { + throw new ConversionException(_("lutin.error.convertor.noValue", this)); + } + if (isEnabled(aClass)) { + Object result; + if (isEnabled(value.getClass())) { + result = value; + return result; + } + if (value instanceof String) { + result = valueOf((String) value); + return result; + } + } + throw new ConversionException(_("lutin.error.no.convertor", aClass.getName(), value)); + } + + protected URI valueOf(String value) { + try { + URI result; + result = new URI(value); + return result; + } catch (URISyntaxException e) { + throw new ConversionException(_("lutin.error.url.convertor", value, this, e.getMessage())); + } + } + + public URIConverter() { + log.info(this); + } + + protected boolean isEnabled(Class aClass) { + return aClass == URI.class; + } + +} \ No newline at end of file