Thread: [Edevsagetools-commit] SF.net SVN: edevsagetools: [6] trunk/synchro-core/src/main/java/be/edev/ sag
Status: Beta
Brought to you by:
avdyk
From: <av...@us...> - 2007-02-19 15:16:47
|
Revision: 6 http://svn.sourceforge.net/edevsagetools/?rev=6&view=rev Author: avdyk Date: 2007-02-19 07:16:46 -0800 (Mon, 19 Feb 2007) Log Message: ----------- adding new directories Modified Paths: -------------- trunk/synchro-core/src/main/java/be/edev/sagetools/beans/Appellation.java trunk/synchro-core/src/main/java/be/edev/sagetools/beans/SelectedList.java trunk/synchro-core/src/main/java/be/edev/sagetools/utils/StringComparator.java Added Paths: ----------- trunk/synchro-core/src/main/java/be/edev/sagetools/synchro/ trunk/synchro-core/src/main/java/be/edev/sagetools/synchro/core/ trunk/synchro-core/src/main/java/be/edev/sagetools/synchro/core/App.java trunk/synchro-core/src/main/java/be/edev/sagetools/utils/CaracteresUtils.java trunk/synchro-core/src/main/java/be/edev/sagetools/utils/StringToNumber.java trunk/synchro-core/src/main/java/be/edev/sagetools/utils/image/ trunk/synchro-core/src/main/java/be/edev/sagetools/utils/image/ImageMagick.java trunk/synchro-core/src/main/java/be/edev/sagetools/utils/io/ trunk/synchro-core/src/main/java/be/edev/sagetools/utils/io/FindFile.java trunk/synchro-core/src/main/java/be/edev/sagetools/utils/net/ trunk/synchro-core/src/main/java/be/edev/sagetools/utils/net/EdevFTPClient.java Modified: trunk/synchro-core/src/main/java/be/edev/sagetools/beans/Appellation.java =================================================================== --- trunk/synchro-core/src/main/java/be/edev/sagetools/beans/Appellation.java 2007-02-19 15:15:50 UTC (rev 5) +++ trunk/synchro-core/src/main/java/be/edev/sagetools/beans/Appellation.java 2007-02-19 15:16:46 UTC (rev 6) @@ -18,9 +18,9 @@ private String photo; - private Set<Region> region = new HashSet<Region>(); + private Set region = new HashSet(); - private Set<Domaine> domaine = new HashSet<Domaine>(); + private Set domaine = new HashSet(); public Appellation() { @@ -80,7 +80,7 @@ * * @return retourne la valeur de region. */ - public Set<Region> getRegion() + public Set getRegion() { return this.region; } @@ -91,7 +91,7 @@ * @param region * Le region à mettre à jour. */ - public void setRegion(Set<Region> region) + public void setRegion(Set region) { this.region = region; } @@ -111,7 +111,7 @@ * * @return retourne la valeur de domaine. */ - public Set<Domaine> getDomaine() + public Set getDomaine() { return this.domaine; } @@ -122,7 +122,7 @@ * @param domaine * Le domaine à mettre à jour. */ - public void setDomaine(Set<Domaine> domaine) + public void setDomaine(Set domaine) { this.domaine = domaine; } Modified: trunk/synchro-core/src/main/java/be/edev/sagetools/beans/SelectedList.java =================================================================== --- trunk/synchro-core/src/main/java/be/edev/sagetools/beans/SelectedList.java 2007-02-19 15:15:50 UTC (rev 5) +++ trunk/synchro-core/src/main/java/be/edev/sagetools/beans/SelectedList.java 2007-02-19 15:16:46 UTC (rev 6) @@ -15,9 +15,9 @@ public class SelectedList { - private Set<Object> objects = new TreeSet<Object>(new StringComparator<Object>()); + private Set objects = new TreeSet(new StringComparator()); - private Set<Object> disabledObjects = new TreeSet<Object>(new StringComparator<Object>()); + private Set disabledObjects = new TreeSet(new StringComparator()); private Object selectedObject = null; @@ -26,11 +26,11 @@ super(); } - public SelectedList(Comparator<Object> c) + public SelectedList(Comparator c) { super(); - this.objects = new TreeSet<Object>(c); - this.disabledObjects = new TreeSet<Object>(c); + this.objects = new TreeSet(c); + this.disabledObjects = new TreeSet(c); } public boolean addDisabledObject(Object o) @@ -38,7 +38,7 @@ return this.disabledObjects.add(o); } - public boolean addAllDisabledObject(Collection<Object> o) + public boolean addAllDisabledObject(Collection o) { return this.disabledObjects.addAll(o); } @@ -86,12 +86,12 @@ /** * @deprecated utiliser plutôt addAllDisabledObject(Collection) */ - public void setDisabledObjects(Set<Object> disabledObjects) + public void setDisabledObjects(Set disabledObjects) { this.disabledObjects = disabledObjects; } - public Set<Object> getObjects() + public Set getObjects() { return this.objects; } @@ -99,7 +99,7 @@ /** * @deprecated utiliser plutôt addAllObject(Collection) */ - public void setObjects(Set<Object> objects) + public void setObjects(Set objects) { this.objects = objects; } @@ -109,7 +109,7 @@ return this.objects.add(o); } - public boolean addAllObject(Collection<Object> o) + public boolean addAllObject(Collection o) { return this.objects.addAll(o); } @@ -129,7 +129,7 @@ return this.objects.isEmpty(); } - public Iterator<Object> objectIterator() + public Iterator objectIterator() { return this.objects.iterator(); } Added: trunk/synchro-core/src/main/java/be/edev/sagetools/synchro/core/App.java =================================================================== --- trunk/synchro-core/src/main/java/be/edev/sagetools/synchro/core/App.java (rev 0) +++ trunk/synchro-core/src/main/java/be/edev/sagetools/synchro/core/App.java 2007-02-19 15:16:46 UTC (rev 6) @@ -0,0 +1,13 @@ +package be.edev.sagetools.synchro.core; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} Added: trunk/synchro-core/src/main/java/be/edev/sagetools/utils/CaracteresUtils.java =================================================================== --- trunk/synchro-core/src/main/java/be/edev/sagetools/utils/CaracteresUtils.java (rev 0) +++ trunk/synchro-core/src/main/java/be/edev/sagetools/utils/CaracteresUtils.java 2007-02-19 15:16:46 UTC (rev 6) @@ -0,0 +1,33 @@ +package be.edev.sagetools.utils; + +public class CaracteresUtils +{ + + /** + * @param s + * @return + * @deprecated utiliser plutôt la méthode avec l'entier + */ + public static String supprimeHuitCaracteres(String s) + { + return CaracteresUtils.supprimePremiersCaracteres(s, 8); + } + + /** + * Utile car vérifie si la chaîne n'est pas nulle + * + * @param s la chaîne + * @param taille + * le nombre de caractères que l'on veut supprimer en début de chaîne + * @return ("OK", 1) retourne "K" + */ + public static String supprimePremiersCaracteres(String s, int taille) + { + String ret = s; + if (ret != null && ret.length() > taille) + { + ret = s.substring(taille); + } + return ret; + } +} Modified: trunk/synchro-core/src/main/java/be/edev/sagetools/utils/StringComparator.java =================================================================== --- trunk/synchro-core/src/main/java/be/edev/sagetools/utils/StringComparator.java 2007-02-19 15:15:50 UTC (rev 5) +++ trunk/synchro-core/src/main/java/be/edev/sagetools/utils/StringComparator.java 2007-02-19 15:16:46 UTC (rev 6) @@ -2,7 +2,7 @@ import java.util.Comparator; -public class StringComparator<T> implements Comparator<T> +public class StringComparator implements Comparator { private boolean asc = true; @@ -18,7 +18,7 @@ this.asc = asc; } - public int compare(T o1, T o2) + public int compare(Object o1, Object o2) { int value = 0; if (asc) Added: trunk/synchro-core/src/main/java/be/edev/sagetools/utils/StringToNumber.java =================================================================== --- trunk/synchro-core/src/main/java/be/edev/sagetools/utils/StringToNumber.java (rev 0) +++ trunk/synchro-core/src/main/java/be/edev/sagetools/utils/StringToNumber.java 2007-02-19 15:16:46 UTC (rev 6) @@ -0,0 +1,25 @@ +package be.edev.sagetools.utils; + +public class StringToNumber +{ + + public static float parseFloat(String s) { + return Float.parseFloat(StringToNumber.virguleEnPoint(s)); + } + + public static double parseDouble(String s) { + return Double.parseDouble(StringToNumber.virguleEnPoint(s)); + } + + protected static String virguleEnPoint(String s) + { + if (s.indexOf(',') > -1) + { + StringBuffer buf = new StringBuffer(s); + buf.setCharAt(s.indexOf(','), '.'); + s = buf.toString(); + } + return s; + } + +} Added: trunk/synchro-core/src/main/java/be/edev/sagetools/utils/image/ImageMagick.java =================================================================== --- trunk/synchro-core/src/main/java/be/edev/sagetools/utils/image/ImageMagick.java (rev 0) +++ trunk/synchro-core/src/main/java/be/edev/sagetools/utils/image/ImageMagick.java 2007-02-19 15:16:46 UTC (rev 6) @@ -0,0 +1,95 @@ +package be.edev.sagetools.utils.image; + +import java.awt.Canvas; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.MediaTracker; +import java.awt.Toolkit; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +import javax.imageio.ImageIO; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class ImageMagick +{ + + private static Log logger = LogFactory.getLog(ImageMagick.class); + + /** + * Redimensionne une image ATTENTION ImageMagick doit etre dans le path + * + * @param originalPath + * @param destinationPath + * @param size + * @throws InterruptedException + * @deprecated utiliser la version jmagickResize + */ + public static synchronized void resizeJPG(String originalPath, + String destinationPath, String size) throws IOException, + InterruptedException + { + Runtime current = Runtime.getRuntime(); + String[] commande = + { "convert", "-size", size, originalPath, "-resize", size, + destinationPath }; + String commandeComplete = commande[0]; + for (int i = 1; i < commande.length; i++) + { + commandeComplete += " " + commande[i]; + } + ImageMagick.logger.debug("commande: " + commandeComplete); + Process proc = current.exec(commandeComplete); + if (proc.waitFor() != 0) + { + ImageMagick.logger.error("Probleme au niveau du process ImageMagick"); + String error = ""; + InputStream in = proc.getErrorStream(); + int c = -1; + while ((c = in.read()) > -1) + { + error += (char) c; + } + ImageMagick.logger.error(error); + } + proc.destroy(); + proc = null; + } + + /** + * Redimensionne une image ATTENTION ImageMagick doit etre dans le path + * + * @param originalPath + * @param destinationPath + * @param size + * @throws InterruptedException + * @throws InterruptedException + * @throws IOException + */ + public static synchronized void jResize(String originalPath, + String destinationPath, int width, int height) + throws InterruptedException, IOException + { + Toolkit toolkit = Toolkit.getDefaultToolkit(); + Image orig = toolkit.getImage(originalPath); + Canvas fake = new Canvas(); + MediaTracker tracker = new MediaTracker(fake); + tracker.addImage(orig, 0); + tracker.waitForID(0); + tracker.removeImage(orig, 0); + Image scaled = orig.getScaledInstance(width, height, Image.SCALE_SMOOTH); + tracker.addImage(scaled, 1); + tracker.waitForID(1); + tracker.removeImage(scaled, 1); + BufferedImage bi = new BufferedImage(width, height, + BufferedImage.TYPE_INT_RGB); + Graphics2D biContext = bi.createGraphics(); + biContext.drawImage(scaled, 0, 0, null); + ImageIO.write(bi, "jpg", new File(destinationPath)); + } + +} Added: trunk/synchro-core/src/main/java/be/edev/sagetools/utils/io/FindFile.java =================================================================== --- trunk/synchro-core/src/main/java/be/edev/sagetools/utils/io/FindFile.java (rev 0) +++ trunk/synchro-core/src/main/java/be/edev/sagetools/utils/io/FindFile.java 2007-02-19 15:16:46 UTC (rev 6) @@ -0,0 +1,97 @@ +package be.edev.sagetools.utils.io; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FilenameFilter; +import java.io.IOException; +import java.util.Collection; +import java.util.Vector; + +public class FindFile +{ + + /** + * Retrouve un fichier dans le chemin qui commence par la chaine. + * + * @param path + * le chemin de départ + * @param query + * la chaine de départ + * @return tous les fichiers trouvés + * @throws IOException + */ + public static synchronized String[] startsWith(String path, final String query) + throws IOException + { + String[] files = null; + if (path != null && query != null) + { + Vector v = new Vector(); + FilenameFilter filter = new FilenameFilter() + { + + public boolean accept(File dir, String name) + { + File f = new File(dir.getPath() + "/" + name); + boolean accept = f.isDirectory(); + if (!accept) + { + accept = name.startsWith(query); + } + return accept; + } + + }; + // Trouver le répertoire de départ + File depart = new File(path); + v.addAll(FindFile.listFilesInDirectory(depart, filter)); + if (v.size() > 0) + { + files = new String[v.size()]; + files = (String[]) v.toArray(files); + } + else + { + throw new FileNotFoundException(path + "/.../" + query + + "* n'a pas ete trouve"); + } + } + return files; + } + + public static synchronized Collection listFilesInDirectory(File f, + FilenameFilter filter) throws IOException + { + Vector v = new Vector(); + if (f.isDirectory()) + { + File[] files = f.listFiles(filter); + if (files != null && files.length > 0) + { + for (int i = 0; i < files.length; i++) + { + Collection c = FindFile.listFilesInDirectory(files[i], filter); + if (c != null && c.size() > 0) + { + v.addAll(c); + } + } + } + } + else + { + v.add(f.getPath()); + } + return v; + } + + public static boolean newer(String newer, String older) + { + File newerFile = new File(newer); + File olderFile = new File(older); + long newerDate = newerFile.lastModified(); + long olderDate = olderFile.lastModified(); + return newerDate > olderDate; + } + +} Added: trunk/synchro-core/src/main/java/be/edev/sagetools/utils/net/EdevFTPClient.java =================================================================== --- trunk/synchro-core/src/main/java/be/edev/sagetools/utils/net/EdevFTPClient.java (rev 0) +++ trunk/synchro-core/src/main/java/be/edev/sagetools/utils/net/EdevFTPClient.java 2007-02-19 15:16:46 UTC (rev 6) @@ -0,0 +1,61 @@ +package be.edev.sagetools.utils.net; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.SocketException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.commons.net.ftp.FTPClient; + +public class EdevFTPClient +{ + + private static final Log logger = LogFactory.getLog(EdevFTPClient.class); + + public static void upload(String imageLocale, String host, + String username, String password, String dir, String filename) + throws SocketException, IOException + { + InputStream local = new FileInputStream(imageLocale); + FTPClient ftp = new FTPClient(); + ftp.connect(host); + ftp.login(username, password); + ftp.changeWorkingDirectory(dir); + ftp.setFileType(FTPClient.BINARY_FILE_TYPE); + ftp.storeFile(filename, local); + ftp.logout(); + ftp.disconnect(); + } + + public static void download(String imageLocale, String host, + String username, String password, String dir, String filename) + throws SocketException, IOException + { + FTPClient ftp = new FTPClient(); + logger.debug("connexion au host: " + host); + ftp.connect(host); + logger.debug("login et mot de passe"); + ftp.login(username, password); + logger.debug("changement de repertoire: " + dir); + ftp.changeWorkingDirectory(dir); + logger.debug("recuperation de l'inputstream"); + InputStream in = ftp.retrieveFileStream(filename); + logger.debug("creation du fichier local"); + OutputStream out = new FileOutputStream(imageLocale); + int b = -1; + while((b=in.read())>-1) { + out.write(b); + } + logger.debug("fermeture de tous les flux"); + in.close(); + out.flush(); + out.close(); + ftp.logout(); + ftp.disconnect(); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |