Index: topia-service/src/java/org/codelutin/topia/migration/kernel/ConfigurationHelper.java diff -u topia-service/src/java/org/codelutin/topia/migration/kernel/ConfigurationHelper.java:1.3 topia-service/src/java/org/codelutin/topia/migration/kernel/ConfigurationHelper.java:1.4 --- topia-service/src/java/org/codelutin/topia/migration/kernel/ConfigurationHelper.java:1.3 Thu Apr 19 16:05:37 2007 +++ topia-service/src/java/org/codelutin/topia/migration/kernel/ConfigurationHelper.java Wed Apr 25 13:46:15 2007 @@ -22,6 +22,8 @@ import java.io.File; import java.io.IOException; import java.io.StringReader; +import java.net.URL; +import java.util.ArrayList; import java.util.List; import javax.xml.parsers.DocumentBuilder; @@ -31,6 +33,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.codelutin.util.FileUtil; +import org.codelutin.util.Resource; import org.dom4j.Attribute; import org.dom4j.Document; import org.dom4j.DocumentException; @@ -50,9 +53,9 @@ * @author Chevallereau Benjamin * @author Eon Sébastien * @author Trève Vincent - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * - * Last update : $Date: 2007/04/19 16:05:37 $ + * Last update : $Date: 2007/04/25 13:46:15 $ */ public class ConfigurationHelper { @@ -75,7 +78,8 @@ * Ici, on pourrait utiliser configuration.addDirectory * mais on modifie les mappings version "entity-map" * - * @param pathDirectory Le dossier ou se trouvent les mappings + * @param pathDirectory Le dossier ou se trouvent les mappings (contient + * la version souhaitee) * @return La configuration associee */ public Configuration getConfigurationInDirectory(String pathDirectory) { @@ -86,29 +90,46 @@ // nouvelle configuration en retour Configuration configuration = null; + // FIXME faire deux cas ici. Soit on est sur le filesystem comme deja + // code. Soit on est dans un jar (a faire). Dans tous les cas, il faut + // ensuite travailler avec des URLs et non pas des Strings. + // + // si mappingDir n'est pas un repertoire, rechercher avec + // ResourceUtil.getUrls(String pattern): List ou equivalent. + // parcourt du dossier File mappingDir = new File(pathDirectory); - if(!mappingDir.isDirectory()) { + + List urls = null; + if(mappingDir.isDirectory()) { + List filesInIt = FileUtil.find(mappingDir, regexFilename, true); + urls = new ArrayList(); + for (File file : filesInIt) { + URL url = file.toURI().toURL(); + urls.add(url); + } + } else { + urls = Resource.getURLs(pathDirectory + regexFilename); throw new IllegalArgumentException("'" + pathDirectory + "' is not a directory"); - } + logger.debug("Loading mappings in " + mappingDir.getAbsolutePath()); - List filesInIt = FileUtil.find(mappingDir,regexFilename); - if (filesInIt != null && filesInIt.size() > 0) { + + if (urls != null && urls.size() > 0) { // s'il y a des fichier a charger configuration = new Configuration(); - for(File fileInIt : filesInIt) { - String xmlmapping = ConfigurationHelper.getEntityMappingFromFile(fileInIt.getAbsolutePath()); + for(URL url : urls) { + String xmlmapping = ConfigurationHelper.getEntityMappingFromFile(url); // lit le fichier avec lutin xml org.w3c.dom.Document domDoc = getDocumentResolvedByHibernate(xmlmapping); configuration.addDocument(domDoc); - logger.debug("Local mapping added : " + fileInIt.getName()); + logger.debug("Local mapping added : " + url); } } else { @@ -124,7 +145,7 @@ * @param fichier le nom du fichier * @return le mapping en forme xml */ - public static String getEntityMappingFromFile(String fichier) { + public static String getEntityMappingFromFile(URL fichier) { String sXml = null; // charge le document en representation dom4j @@ -181,7 +202,7 @@ * @param fichier le nom du fichier * @return un document dom4j */ - private static Document getDom4jDocument(String fichier) { + private static Document getDom4jDocument(URL fichier) { SAXReader reader = new SAXReader(); reader.setValidation(false); //DTDEntityResolver = celui d'hibernate