Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/ImageDao.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/ImageDao.java	(revision 9902)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/ImageDao.java	(revision 9919)
@@ -1,87 +1,14 @@
 package fr.mael.jiwigo.dao;
 
-import java.io.File;
 import java.io.IOException;
 import java.security.NoSuchAlgorithmException;
-import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import sun.misc.BASE64Encoder;
 import fr.mael.jiwigo.om.Image;
-import fr.mael.jiwigo.transverse.enumeration.MethodsEnum;
 import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException;
 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
 import fr.mael.jiwigo.transverse.exception.WrongChunkSizeException;
-import fr.mael.jiwigo.transverse.session.SessionManager;
-import fr.mael.jiwigo.transverse.util.Tools;
 
-/*
- *  jiwigo-ws-api Piwigo webservice access Api
- *  Copyright (c) 2010-2011 Mael mael@le-guevel.com
- *                All Rights Reserved
- *
- *  This library is free software. It comes without any warranty, to
- *  the extent permitted by applicable law. You can redistribute it
- *  and/or modify it under the terms of the Do What The Fuck You Want
- *  To Public License, Version 2, as published by Sam Hocevar. See
- *  http://sam.zoy.org/wtfpl/COPYING for more details.
- */
-/**
-
- * Dao of the images
- * @author mael
- *
- */
-public class ImageDao {
-
-    /**
-     * Logger
-     */
-    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
-	    .getLog(ImageDao.class);
-
-    /**
-     * Singleton
-     */
-    private static ImageDao instance;
-
-    /**
-     * cache to avoid downloading image for each access
-     */
-    private HashMap<Integer, List<Image>> cache;
-
-    /**
-     *
-     */
-    private Integer firstCatInCache;
-
-    private SessionManager sessionManager;
-
-    private ArrayList<File> filesToSend;
-
-    /**
-     * Private singleton, to use a singleton
-     */
-    private ImageDao(SessionManager sessionManager) {
-	cache = new HashMap<Integer, List<Image>>();
-	this.sessionManager = sessionManager;
-    }
-
-    /**
-     * @return le singleton
-     */
-    public static ImageDao getInstance(SessionManager sessionManager) {
-	if (instance == null) {
-	    instance = new ImageDao(sessionManager);
-	}
-	return instance;
-    }
-
+public interface ImageDao {
     /**
      * Lists all images
@@ -90,7 +17,5 @@
      * @throws ProxyAuthenticationException
      */
-    public List<Image> list(boolean refresh) throws IOException, ProxyAuthenticationException {
-	return listByCategory(null, refresh);
-    }
+    public List<Image> list(boolean refresh) throws IOException, ProxyAuthenticationException;
 
     /**
@@ -102,25 +27,5 @@
      */
     public List<Image> listByCategory(Integer categoryId, boolean refresh) throws IOException,
-	    ProxyAuthenticationException {
-	if (refresh || cache.get(categoryId) == null) {
-	    Document doc = null;
-	    if (categoryId != null) {
-		doc = sessionManager.executeReturnDocument(MethodsEnum.LISTER_IMAGES.getLabel(), "cat_id", String
-			.valueOf(categoryId));
-	    } else {
-		doc = sessionManager.executeReturnDocument(MethodsEnum.LISTER_IMAGES.getLabel());
-	    }
-	    Element element = (Element) doc.getDocumentElement().getElementsByTagName("images").item(0);
-	    List<Image> images = getImagesFromElement(element);
-	    cache.remove(categoryId);
-	    cache.put(categoryId, images);
-	    if (firstCatInCache == null) {
-		firstCatInCache = categoryId;
-	    }
-	    return images;
-	} else {
-	    return cache.get(categoryId);
-	}
-    }
+	    ProxyAuthenticationException;
 
     /**
@@ -143,58 +48,5 @@
     //TODO ne pas continuer si une des reponses precedentes est negative
     public boolean create(Image image, Double chunkSize) throws FileAlreadyExistsException, IOException,
-	    ProxyAuthenticationException, NoSuchAlgorithmException, WrongChunkSizeException {
-	//thumbnail converted to base64
-	BASE64Encoder base64 = new BASE64Encoder();
-
-	String thumbnailBase64 = base64.encode(Tools.getBytesFromFile(image.getThumbnail()));
-	//sends the thumbnail and gets the result
-	Document reponseThumb = (sessionManager.executeReturnDocument("pwg.images.addChunk", "data", thumbnailBase64,
-		"type", "thumb", "position", "1", "original_sum", Tools.getMD5Checksum(image.getOriginale()
-			.getAbsolutePath())));
-
-	//begin feature:0001827
-	int chunk = chunkSize.intValue();
-	if (chunk == 0) {
-	    throw new WrongChunkSizeException("Error : the chunk size cannot be 0");
-	}
-	filesToSend = Tools.splitFile(image.getOriginale(), chunk);
-	boolean echec = false;
-	for (int i = 0; i < filesToSend.size(); i++) {
-	    File fichierAEnvoyer = filesToSend.get(i);
-	    String originaleBase64 = base64.encode(Tools.getBytesFromFile(fichierAEnvoyer));
-	    Document reponseOriginale = (sessionManager.executeReturnDocument("pwg.images.addChunk", "data",
-		    originaleBase64, "type", "file", "position", String.valueOf(i), "original_sum", Tools
-			    .getMD5Checksum(image.getOriginale().getAbsolutePath())));
-	    if (!Tools.checkOk(reponseOriginale)) {
-		echec = true;
-		break;
-	    }
-	}
-	//end
-
-	//add the image in the database and get the result of the webservice
-	Document reponseAjout = (sessionManager.executeReturnDocument("pwg.images.add", "file_sum", Tools
-		.getMD5Checksum(image.getOriginale().getAbsolutePath()), "thumbnail_sum", Tools.getMD5Checksum(image
-		.getThumbnail().getCanonicalPath()), "position", "1", "original_sum", Tools.getMD5Checksum(image
-		.getOriginale().getAbsolutePath()), "categories", String.valueOf(image.getIdCategory()), "name", image
-		.getName(), "author", sessionManager.getLogin(), "level", image.getPrivacyLevel()));
-	LOG.debug("Response add : " + Tools.documentToString(reponseAjout));
-	//	System.out.println(Main.sessionManager.executerReturnString("pwg.images.add", "file_sum", Outil
-	//		.getMD5Checksum(image.getOriginale().getAbsolutePath()), "thumbnail_sum", Outil.getMD5Checksum(image
-	//		.getThumbnail().getCanonicalPath()), "position", "1", "original_sum", Outil.getMD5Checksum(image
-	//		.getOriginale().getAbsolutePath()), "categories", String.valueOf(image.getIdCategory()), "name", image
-	//		.getName(), "author", Main.sessionManager.getLogin()));
-	//	Document reponsePrivacy = null;
-	//	if (Outil.checkOk(reponseAjout)) {
-	//	    reponsePrivacy = Main.sessionManager.executerReturnDocument(MethodsEnum.SET_PRIVACY_LEVEL.getLabel());
-	//	}
-	boolean reussite = true;
-	if (!Tools.checkOk(reponseThumb) || echec || !Tools.checkOk(reponseAjout)) {
-	    reussite = false;
-	}
-	deleteTempFiles();
-	return reussite;
-
-    }
+	    ProxyAuthenticationException, NoSuchAlgorithmException, WrongChunkSizeException;
 
     /**
@@ -205,49 +57,5 @@
      * @throws ProxyAuthenticationException
      */
-    public boolean addTags(Integer imageId, String tagId) throws IOException, ProxyAuthenticationException {
-	Document doc = sessionManager.executeReturnDocument(MethodsEnum.SET_INFO.getLabel(), "image_id", String
-		.valueOf(imageId), "tag_ids", tagId);
-	try {
-	    return Tools.checkOk(doc);
-	} catch (FileAlreadyExistsException e) {
-	    LOG.error(Tools.getStackTrace(e));
-	    return false;
-	}
-
-    }
-
-    /**
-     * parse an element to find images
-     * @param element the element to parse
-     * @return the list of images
-     */
-    private List<Image> getImagesFromElement(Element element) {
-	//	List<Element> listElement = (List<Element>) element.getChildren("image");
-	NodeList listImages = element.getElementsByTagName("image");
-	ArrayList<Image> images = new ArrayList<Image>();
-	for (int i = 0; i < listImages.getLength(); i++) {
-	    Node nodeImage = listImages.item(i);
-	    if (nodeImage.getNodeType() == Node.ELEMENT_NODE) {
-		Element im = (Element) nodeImage;
-		Image myImage = new Image();
-		myImage.setThumbnailUrl(im.getAttribute("tn_url"));
-		myImage.setUrl(im.getAttribute("element_url"));
-		myImage.setWidth(Integer.valueOf(im.getAttribute("width")));
-		myImage.setHeight(Integer.valueOf(im.getAttribute("height")));
-		myImage.setFile(im.getAttribute("file"));
-		myImage.setSeen(Integer.valueOf(im.getAttribute("hit")));
-		myImage.setIdentifier(Integer.valueOf(im.getAttribute("id")));
-		myImage.setName(Tools.getStringValueDom(im, "name"));
-		Element elementCategories = (Element) im.getElementsByTagName("categories").item(0);
-		Element elementCategory = (Element) elementCategories.getElementsByTagName("category").item(0);
-		myImage.setIdCategory(Integer.valueOf(elementCategory.getAttribute("id")));
-		if (myImage.getName() == null) {
-		    myImage.setName(myImage.getFile());
-		}
-		images.add(myImage);
-	    }
-	}
-	return images;
-    }
+    public boolean addTags(Integer imageId, String tagId) throws IOException, ProxyAuthenticationException;
 
     /**
@@ -258,22 +66,5 @@
      * @throws ProxyAuthenticationException
      */
-    public List<Image> search(String searchString) throws IOException, ProxyAuthenticationException {
-	Document doc = sessionManager.executeReturnDocument(MethodsEnum.SEARCH.getLabel(), "query", searchString);
-	LOG.debug(doc);
-	Element element = (Element) doc.getDocumentElement().getElementsByTagName("images").item(0);
-	return getImagesFromElement(element);
-
-    }
-
-    private void deleteTempFiles() {
-	File file = new File(System.getProperty("java.io.tmpdir") + "/originale.jpg");
-	file.delete();
-	file = new File(System.getProperty("java.io.tmpdir") + "/thumb.jpg");
-	file.delete();
-	for (File tempCut : filesToSend) {
-	    tempCut.delete();
-	}
-
-    }
+    public List<Image> search(String searchString) throws IOException, ProxyAuthenticationException;
 
 }
