Index: extensions/jiwigo-ws-api/.classpath
===================================================================
--- extensions/jiwigo-ws-api/.classpath	(revision 9902)
+++ extensions/jiwigo-ws-api/.classpath	(revision 9919)
@@ -5,17 +5,11 @@
   <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
   <classpathentry kind="output" path="target/classes"/>
-  <classpathentry kind="var" path="M2_REPO/javax/servlet/servlet-api/2.3/servlet-api-2.3.jar"/>
-  <classpathentry kind="var" path="M2_REPO/avalon-framework/avalon-framework/4.1.3/avalon-framework-4.1.3.jar"/>
-  <classpathentry kind="var" path="M2_REPO/commons-beanutils/commons-beanutils/1.8.3/commons-beanutils-1.8.3.jar"/>
   <classpathentry kind="var" path="M2_REPO/commons-codec/commons-codec/1.4/commons-codec-1.4.jar"/>
   <classpathentry kind="var" path="M2_REPO/commons-lang/commons-lang/2.5/commons-lang-2.5.jar"/>
-  <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1/commons-logging-1.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpclient/4.1/httpclient-4.1.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpcore/4.1/httpcore-4.1.jar"/>
-  <classpathentry kind="var" path="M2_REPO/junit/junit/4.8.1/junit-4.8.1.jar"/>
-  <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.16/log4j-1.2.16.jar"/>
-  <classpathentry kind="var" path="M2_REPO/logkit/logkit/1.0.1/logkit-1.0.1.jar"/>
-  <classpathentry kind="var" path="M2_REPO/com/drew/metadata-extractor/2.3.1/metadata-extractor-2.3.1.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/apache/sanselan/sanselan/0.97-incubator/sanselan-0.97-incubator.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar"/>
   <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-6-openjdk"/>
 </classpath>
Index: extensions/jiwigo-ws-api/.project
===================================================================
--- extensions/jiwigo-ws-api/.project	(revision 9902)
+++ extensions/jiwigo-ws-api/.project	(revision 9919)
@@ -1,23 +1,17 @@
-<?xml version="1.0" encoding="UTF-8"?>
 <projectDescription>
-	<name>jiwigo-ws-api</name>
-	<comment>NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
-	<projects>
-	</projects>
-	<buildSpec>
-		<buildCommand>
-			<name>org.eclipse.jdt.core.javabuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.maven.ide.eclipse.maven2Builder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-	</buildSpec>
-	<natures>
-		<nature>org.maven.ide.eclipse.maven2Nature</nature>
-		<nature>org.eclipse.jdt.core.javanature</nature>
-	</natures>
+  <name>jiwigo-ws-api</name>
+  <comment>NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
+  <projects/>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+    </buildCommand>
+    <buildCommand>
+      <name>org.maven.ide.eclipse.maven2Builder</name>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.maven.ide.eclipse.maven2Nature</nature>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+  </natures>
 </projectDescription>
Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/CategoryDao.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/CategoryDao.java	(revision 9902)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/CategoryDao.java	(revision 9919)
@@ -2,65 +2,10 @@
 
 import java.io.IOException;
-import java.util.ArrayList;
 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 fr.mael.jiwigo.om.Category;
+import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
 
-import fr.mael.jiwigo.om.Category;
-import fr.mael.jiwigo.transverse.enumeration.CategoryEnum;
-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.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 for the categories
- * @author mael
- *
- */
-public class CategoryDao {
-    /**
-     * Logger
-     */
-    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
-	    .getLog(CategoryDao.class);
-    /**
-     * Instance to use a singleton
-     */
-    private static CategoryDao instance;
-
-    private SessionManager sessionManager;
-
-    /**
-     * Private constructor to use a singleton
-     */
-    private CategoryDao(SessionManager sessionManager) {
-	this.sessionManager = sessionManager;
-    }
-
-    /**
-     * @return the instance
-     */
-    public static CategoryDao getInstance(SessionManager sessionManager) {
-	if (instance == null) {
-	    instance = new CategoryDao(sessionManager);
-	}
-	return instance;
-    }
+public interface CategoryDao {
 
     /**
@@ -71,34 +16,5 @@
      * @throws ProxyAuthenticationException
      */
-    public List<Category> list(boolean recursive) throws IOException, ProxyAuthenticationException {
-	Document doc = sessionManager.executeReturnDocument(MethodsEnum.LISTER_CATEGORIES.getLabel(), "recursive",
-		String.valueOf(recursive));
-	Element element = (Element) doc.getDocumentElement().getElementsByTagName("categories").item(0);
-	NodeList nodeList = element.getElementsByTagName("category");
-	ArrayList<Category> categories = new ArrayList<Category>();
-	for (int i = 0; i < nodeList.getLength(); i++) {
-	    Node catNode = nodeList.item(i);
-	    if (catNode.getNodeType() == Node.ELEMENT_NODE) {
-		Element cat = (Element) catNode;
-		Category myCat = new Category();
-		myCat.setIdentifier(Integer.valueOf(cat.getAttribute(CategoryEnum.ID.getLabel())));
-		myCat.setUrlCategory(cat.getAttribute(CategoryEnum.URL.getLabel()));
-		myCat.setNbImages(Integer.valueOf(cat.getAttribute(CategoryEnum.NB_IMAGES.getLabel())));
-		myCat.setNbTotalImages(Integer.valueOf(cat.getAttribute(CategoryEnum.NB_TOTAL_IMAGES.getLabel())));
-		myCat.setName(Tools.getStringValueDom(cat, CategoryEnum.NAME.getLabel()));
-		String catMeres = Tools.getStringValueDom(cat, CategoryEnum.CAT_MERES.getLabel());
-		ArrayList<Integer> idCategoriesMeres = new ArrayList<Integer>();
-		myCat.setIdParentCategoriesString(catMeres);
-		for (String catA : catMeres.split(",")) {
-		    if (!catA.equals("")) {
-			idCategoriesMeres.add(Integer.valueOf(catA));
-		    }
-		}
-		myCat.setIdParentCategories(idCategoriesMeres);
-		categories.add(myCat);
-	    }
-	}
-	return categories;
-    }
+    public List<Category> list(boolean recursive) throws IOException, ProxyAuthenticationException;
 
     /**
@@ -108,20 +24,4 @@
      * @throws ProxyAuthenticationException
      */
-    public boolean create(Category category) throws ProxyAuthenticationException {
-	try {
-	    if (category.getDirectParent() != null) {
-		return Tools.checkOk(sessionManager.executeReturnDocument(MethodsEnum.AJOUTER_CATEGORIE.getLabel(),
-			"name", category.getName(), "parent", String.valueOf(category.getDirectParent())));
-	    } else {
-		return Tools.checkOk(sessionManager.executeReturnDocument(MethodsEnum.AJOUTER_CATEGORIE.getLabel(),
-			"name", category.getName()));
-	    }
-	} catch (IOException e) {
-	    LOG.error(Tools.getStackTrace(e));
-	} catch (FileAlreadyExistsException e) {
-	    LOG.error(Tools.getStackTrace(e));
-	}
-	return false;
-    }
-
+    public boolean create(Category category) throws ProxyAuthenticationException;
 }
Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/CommentDao.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/CommentDao.java	(revision 9902)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/CommentDao.java	(revision 9919)
@@ -2,66 +2,10 @@
 
 import java.io.IOException;
-import java.util.ArrayList;
 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 fr.mael.jiwigo.om.Comment;
+import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
 
-import fr.mael.jiwigo.om.Comment;
-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.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 for the comments
- * @author mael
- *
- */
-public class CommentDao {
-    /**
-     * Logger
-     */
-    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
-	    .getLog(CommentDao.class);
-    /**
-     *  Instance that allows to use a singleton
-     */
-    private static CommentDao instance;
-
-    private SessionManager sessionManager;
-
-    /**
-     * private constructor, to use a singleton
-     */
-    private CommentDao(SessionManager sessionManager) {
-	this.sessionManager = sessionManager;
-    }
-
-    /**
-     * @return the singleton
-     */
-    public static CommentDao getInstance(SessionManager sessionManager) {
-	if (instance == null) {
-	    instance = new CommentDao(sessionManager);
-	}
-	return instance;
-    }
-
+public interface CommentDao {
     /**
      * Listing of the comments for the given image
@@ -71,25 +15,5 @@
      * @throws ProxyAuthenticationException
      */
-    public List<Comment> list(Integer idImage) throws IOException, ProxyAuthenticationException {
-	Document doc = (sessionManager.executeReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", String
-		.valueOf(idImage), "comments_per_page", "100"));
-	Element elementImage = (Element) doc.getDocumentElement().getElementsByTagName("image").item(0);
-	Element elementComments = (Element) elementImage.getElementsByTagName("comments").item(0);
-	NodeList listComments = elementComments.getElementsByTagName("comment");
-	ArrayList<Comment> comments = new ArrayList<Comment>();
-	for (int i = 0; i < listComments.getLength(); i++) {
-	    Node nodeCom = listComments.item(i);
-	    if (nodeCom.getNodeType() == Node.ELEMENT_NODE) {
-		Element com = (Element) nodeCom;
-		Comment myCom = new Comment();
-		myCom.setIdentifier(Integer.valueOf(com.getAttribute("id")));
-		myCom.setDate(com.getAttribute("date"));
-		myCom.setAuthor(Tools.getStringValueDom(com, "author"));
-		myCom.setContent(Tools.getStringValueDom(com, "content"));
-		comments.add(myCom);
-	    }
-	}
-	return comments;
-    }
+    public List<Comment> list(Integer idImage) throws IOException, ProxyAuthenticationException;
 
     /**
@@ -100,12 +24,5 @@
      * @throws ProxyAuthenticationException
      */
-    public String getKey(Integer idImage) throws IOException, ProxyAuthenticationException {
-	Document doc = (sessionManager.executeReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", String
-		.valueOf(idImage)));
-	//	String key = doc.getRootElement().getChild("image").getChild("comment_post").getAttributeValue("key");
-	Element elementImage = (Element) doc.getDocumentElement().getElementsByTagName("image").item(0);
-	Element elementCommentPost = (Element) elementImage.getElementsByTagName("comment_post").item(0);
-	return elementCommentPost.getAttribute("key");
-    }
+    public String getKey(Integer idImage) throws IOException, ProxyAuthenticationException;
 
     /**
@@ -116,20 +33,4 @@
      * @throws ProxyAuthenticationException
      */
-    public boolean create(Comment commentaire) throws IOException, ProxyAuthenticationException {
-	String key = getKey(commentaire.getImageId());
-	try {
-	    Thread.sleep(2200);
-	} catch (InterruptedException e) {
-	    e.printStackTrace();
-	}
-	try {
-	    return Tools.checkOk(sessionManager.executeReturnDocument(MethodsEnum.AJOUTER_COMMENTAIRE.getLabel(),
-		    "image_id", String.valueOf(commentaire.getImageId()), "author", commentaire.getAuthor(), "content",
-		    commentaire.getContent(), "key", key));
-	} catch (FileAlreadyExistsException e) {
-	    LOG.error(Tools.getStackTrace(e));
-	    return false;
-	}
-
-    }
+    public boolean create(Comment commentaire) throws IOException, ProxyAuthenticationException;
 }
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;
 
 }
Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/TagDao.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/TagDao.java	(revision 9902)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/TagDao.java	(revision 9919)
@@ -2,66 +2,11 @@
 
 import java.io.IOException;
-import java.util.ArrayList;
 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 fr.mael.jiwigo.om.Image;
 import fr.mael.jiwigo.om.Tag;
-import fr.mael.jiwigo.transverse.enumeration.MethodsEnum;
-import fr.mael.jiwigo.transverse.enumeration.TagEnum;
-import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException;
 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
-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 categories
- * @author mael
- *
- */
-public class TagDao {
-    /**
-     * Logger
-     */
-    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(TagDao.class);
-    /**
-     * Instance, to use a singleton
-     */
-    private static TagDao instance;
-
-    private SessionManager sessionManager;
-
-    /**
-     * private constructor to use a singleton
-     */
-    private TagDao(SessionManager sessionManager) {
-	this.sessionManager = sessionManager;
-    }
-
-    /**
-     * @return the instance
-     */
-    public static TagDao getInstance(SessionManager sessionManager) {
-	if (instance == null) {
-	    instance = new TagDao(sessionManager);
-	}
-	return instance;
-    }
-
+public interface TagDao {
     /**
      * lists the tags
@@ -70,35 +15,5 @@
      * @throws ProxyAuthenticationException
      */
-    public List<Tag> list() throws IOException, ProxyAuthenticationException {
-	Document doc = sessionManager.executeReturnDocument(MethodsEnum.TAGS_ADMIN_LIST.getLabel());
-	//	System.out.println(Outil.documentToString(doc));
-
-	return getTagsFromDocument((Element) doc.getDocumentElement().getElementsByTagName("tags"));
-
-    }
-
-    /**
-     * COnstructs a list of tags from a document
-     * @param doc the document
-     * @return the list of tags
-     */
-    private List<Tag> getTagsFromDocument(Element element) {
-	NodeList listTags = element.getElementsByTagName("tag");
-
-	//	List<Element> listElement = (List<Element>) element.getChildren("tag");
-	ArrayList<Tag> tags = new ArrayList<Tag>();
-	for (int i = 0; i < listTags.getLength(); i++) {
-	    Node nodeTag = listTags.item(0);
-	    if (nodeTag.getNodeType() == Node.ELEMENT_NODE) {
-		Element tagElement = (Element) nodeTag;
-		Tag tag = new Tag();
-		tag.setIdentifier(Integer.valueOf(tagElement.getAttribute(TagEnum.ID.getLabel())));
-		tag.setName(tagElement.getAttribute(TagEnum.NAME.getLabel()));
-		tags.add(tag);
-	    }
-	}
-	return tags;
-
-    }
+    public List<Tag> list() throws IOException, ProxyAuthenticationException;
 
     /**
@@ -108,15 +23,5 @@
      * @throws ProxyAuthenticationException
      */
-    public boolean create(Tag tag) throws ProxyAuthenticationException {
-	try {
-	    return Tools.checkOk(sessionManager.executeReturnDocument(MethodsEnum.ADD_TAG.getLabel(), "name", tag
-		    .getName()));
-	} catch (IOException e) {
-	    LOG.error(Tools.getStackTrace(e));
-	} catch (FileAlreadyExistsException e) {
-	    e.printStackTrace();
-	}
-	return false;
-    }
+    public boolean create(Tag tag) throws ProxyAuthenticationException;
 
     /**
@@ -127,11 +32,4 @@
      * @throws ProxyAuthenticationException
      */
-    public List<Tag> tagsForImage(Image image) throws IOException, ProxyAuthenticationException {
-	Document doc = sessionManager.executeReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", String
-		.valueOf(image.getIdentifier()));
-	Element elementImage = (Element) doc.getDocumentElement().getElementsByTagName("image").item(0);
-	Element elementTag = (Element) elementImage.getElementsByTagName("tags").item(0);
-	return getTagsFromDocument(elementTag);
-    }
-
+    public List<Tag> tagsForImage(Image image) throws IOException, ProxyAuthenticationException;
 }
Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/CategoryDaoImpl.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/CategoryDaoImpl.java	(revision 9919)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/CategoryDaoImpl.java	(revision 9919)
@@ -0,0 +1,120 @@
+package fr.mael.jiwigo.dao.impl;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import fr.mael.jiwigo.dao.CategoryDao;
+import fr.mael.jiwigo.om.Category;
+import fr.mael.jiwigo.transverse.enumeration.CategoryEnum;
+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.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 for the categories
+ * @author mael
+ *
+ */
+public class CategoryDaoImpl implements CategoryDao {
+    /**
+     * Logger
+     */
+    private final Logger LOG = LoggerFactory.getLogger(CategoryDaoImpl.class);
+    /**
+     * Instance to use a singleton
+     */
+    private static CategoryDaoImpl instance;
+
+    private SessionManager sessionManager;
+
+    /**
+     * Lists the categories
+     * @param recursive true : recursive listing of the categories
+     * @return the list of categories
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public List<Category> list(boolean recursive) throws IOException, ProxyAuthenticationException {
+	Document doc = sessionManager.executeReturnDocument(MethodsEnum.LISTER_CATEGORIES.getLabel(), "recursive",
+		String.valueOf(recursive));
+	Element element = (Element) doc.getDocumentElement().getElementsByTagName("categories").item(0);
+	NodeList nodeList = element.getElementsByTagName("category");
+	ArrayList<Category> categories = new ArrayList<Category>();
+	for (int i = 0; i < nodeList.getLength(); i++) {
+	    Node catNode = nodeList.item(i);
+	    if (catNode.getNodeType() == Node.ELEMENT_NODE) {
+		Element cat = (Element) catNode;
+		Category myCat = new Category();
+		myCat.setIdentifier(Integer.valueOf(cat.getAttribute(CategoryEnum.ID.getLabel())));
+		myCat.setUrlCategory(cat.getAttribute(CategoryEnum.URL.getLabel()));
+		myCat.setNbImages(Integer.valueOf(cat.getAttribute(CategoryEnum.NB_IMAGES.getLabel())));
+		myCat.setNbTotalImages(Integer.valueOf(cat.getAttribute(CategoryEnum.NB_TOTAL_IMAGES.getLabel())));
+		myCat.setName(Tools.getStringValueDom(cat, CategoryEnum.NAME.getLabel()));
+		String catMeres = Tools.getStringValueDom(cat, CategoryEnum.CAT_MERES.getLabel());
+		ArrayList<Integer> idCategoriesMeres = new ArrayList<Integer>();
+		myCat.setIdParentCategoriesString(catMeres);
+		for (String catA : catMeres.split(",")) {
+		    if (!catA.equals("")) {
+			idCategoriesMeres.add(Integer.valueOf(catA));
+		    }
+		}
+		myCat.setIdParentCategories(idCategoriesMeres);
+		categories.add(myCat);
+	    }
+	}
+	return categories;
+    }
+
+    /**
+     * Creation of a category
+     * @param category the category to create
+     * @return true if the category is successfully created
+     * @throws ProxyAuthenticationException
+     */
+    public boolean create(Category category) throws ProxyAuthenticationException {
+	try {
+	    if (category.getDirectParent() != null) {
+		return Tools.checkOk(sessionManager.executeReturnDocument(MethodsEnum.AJOUTER_CATEGORIE.getLabel(),
+			"name", category.getName(), "parent", String.valueOf(category.getDirectParent())));
+	    } else {
+		return Tools.checkOk(sessionManager.executeReturnDocument(MethodsEnum.AJOUTER_CATEGORIE.getLabel(),
+			"name", category.getName()));
+	    }
+	} catch (IOException e) {
+	    LOG.error(Tools.getStackTrace(e));
+	} catch (FileAlreadyExistsException e) {
+	    LOG.error(Tools.getStackTrace(e));
+	}
+	return false;
+    }
+
+    public SessionManager getSessionManager() {
+	return sessionManager;
+    }
+
+    public void setSessionManager(SessionManager sessionManager) {
+	this.sessionManager = sessionManager;
+    }
+
+}
Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/CommentDaoImpl.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/CommentDaoImpl.java	(revision 9919)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/CommentDaoImpl.java	(revision 9919)
@@ -0,0 +1,125 @@
+package fr.mael.jiwigo.dao.impl;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import fr.mael.jiwigo.dao.CommentDao;
+import fr.mael.jiwigo.om.Comment;
+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.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 for the comments
+ * @author mael
+ *
+ */
+public class CommentDaoImpl implements CommentDao {
+    /**
+     * Logger
+     */
+    private final Logger LOG = LoggerFactory.getLogger(CommentDaoImpl.class);
+
+    private SessionManager sessionManager;
+
+    /**
+     * Listing of the comments for the given image
+     * @param idImage id of the  image
+     * @return list of comments
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public List<Comment> list(Integer idImage) throws IOException, ProxyAuthenticationException {
+	Document doc = (sessionManager.executeReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", String
+		.valueOf(idImage), "comments_per_page", "100"));
+	Element elementImage = (Element) doc.getDocumentElement().getElementsByTagName("image").item(0);
+	Element elementComments = (Element) elementImage.getElementsByTagName("comments").item(0);
+	NodeList listComments = elementComments.getElementsByTagName("comment");
+	ArrayList<Comment> comments = new ArrayList<Comment>();
+	for (int i = 0; i < listComments.getLength(); i++) {
+	    Node nodeCom = listComments.item(i);
+	    if (nodeCom.getNodeType() == Node.ELEMENT_NODE) {
+		Element com = (Element) nodeCom;
+		Comment myCom = new Comment();
+		myCom.setIdentifier(Integer.valueOf(com.getAttribute("id")));
+		myCom.setDate(com.getAttribute("date"));
+		myCom.setAuthor(Tools.getStringValueDom(com, "author"));
+		myCom.setContent(Tools.getStringValueDom(com, "content"));
+		comments.add(myCom);
+	    }
+	}
+	return comments;
+    }
+
+    /**
+     * Gets the key essential to add a comment
+     * @param idImage the id of the image
+     * @return the key
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public String getKey(Integer idImage) throws IOException, ProxyAuthenticationException {
+	Document doc = (sessionManager.executeReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", String
+		.valueOf(idImage)));
+	//	String key = doc.getRootElement().getChild("image").getChild("comment_post").getAttributeValue("key");
+	Element elementImage = (Element) doc.getDocumentElement().getElementsByTagName("image").item(0);
+	Element elementCommentPost = (Element) elementImage.getElementsByTagName("comment_post").item(0);
+	return elementCommentPost.getAttribute("key");
+    }
+
+    /**
+     * Creates a comment
+     * @param commentaire the comment to add
+     * @return true if the comment is successfully added
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public boolean create(Comment commentaire) throws IOException, ProxyAuthenticationException {
+	String key = getKey(commentaire.getImageId());
+	try {
+	    Thread.sleep(2200);
+	} catch (InterruptedException e) {
+	    e.printStackTrace();
+	}
+	try {
+	    return Tools.checkOk(sessionManager.executeReturnDocument(MethodsEnum.AJOUTER_COMMENTAIRE.getLabel(),
+		    "image_id", String.valueOf(commentaire.getImageId()), "author", commentaire.getAuthor(), "content",
+		    commentaire.getContent(), "key", key));
+	} catch (FileAlreadyExistsException e) {
+	    LOG.error(Tools.getStackTrace(e));
+	    return false;
+	}
+
+    }
+
+    public SessionManager getSessionManager() {
+	return sessionManager;
+    }
+
+    public void setSessionManager(SessionManager sessionManager) {
+	this.sessionManager = sessionManager;
+    }
+
+}
Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/ImageDaoImpl.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/ImageDaoImpl.java	(revision 9919)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/ImageDaoImpl.java	(revision 9919)
@@ -0,0 +1,270 @@
+package fr.mael.jiwigo.dao.impl;
+
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+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.dao.ImageDao;
+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 ImageDaoImpl implements ImageDao {
+
+    /**
+     * Logger
+     */
+    private final Logger LOG = LoggerFactory.getLogger(ImageDaoImpl.class);
+
+    /**
+     * cache to avoid downloading image for each access
+     */
+    private HashMap<Integer, List<Image>> cache;
+
+    /**
+     *
+     */
+    private Integer firstCatInCache;
+
+    private SessionManager sessionManager;
+
+    private ArrayList<File> filesToSend;
+
+    public ImageDaoImpl() {
+	cache = new HashMap<Integer, List<Image>>();
+    }
+
+    /**
+     * Lists all images
+     * @return the list of images
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public List<Image> list(boolean refresh) throws IOException, ProxyAuthenticationException {
+	return listByCategory(null, refresh);
+    }
+
+    /**
+     * Listing of the images for a category
+     * @param categoryId the id of the category
+     * @return the list of images
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    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);
+	}
+    }
+
+    /**
+     * Creation of an image<br/>
+     * Sequence : <br/>
+     * <li>
+     * <ul>sending of the thumbnail in base64, thanks to the method addchunk.</ul>
+     * <ul>sending of the image in base64, thanks to the method addchunk</ul>
+     * <ul>using of the add method to add the image to the database<ul>
+     * </li>
+     * Finally, the response of the webservice is checked
+     *
+     * @param image the image to create
+     * @return true if the creation of the image was the successful
+     * @throws IOException
+     * @throws NoSuchAlgorithmException
+     * @throws WrongChunkSizeException
+     * @throws Exception
+     */
+    //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;
+
+    }
+
+    /**
+     * Add tags to an image
+     * @param imageId id of the image
+     * @param tagId ids of the tags
+     * @throws IOException
+     * @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;
+    }
+
+    /**
+     * Search images
+     * @param searchString the string to search
+     * @return the list of images matching the string
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public List<Image> search(String searchString) throws IOException, ProxyAuthenticationException {
+	Document doc = sessionManager.executeReturnDocument(MethodsEnum.SEARCH.getLabel(), "query", searchString);
+	LOG.debug(Tools.documentToString(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 SessionManager getSessionManager() {
+	return sessionManager;
+    }
+
+    public void setSessionManager(SessionManager sessionManager) {
+	this.sessionManager = sessionManager;
+    }
+
+}
Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/TagDaoImpl.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/TagDaoImpl.java	(revision 9919)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/impl/TagDaoImpl.java	(revision 9919)
@@ -0,0 +1,127 @@
+package fr.mael.jiwigo.dao.impl;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import fr.mael.jiwigo.dao.TagDao;
+import fr.mael.jiwigo.om.Image;
+import fr.mael.jiwigo.om.Tag;
+import fr.mael.jiwigo.transverse.enumeration.MethodsEnum;
+import fr.mael.jiwigo.transverse.enumeration.TagEnum;
+import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException;
+import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
+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 categories
+ * @author mael
+ *
+ */
+public class TagDaoImpl implements TagDao {
+    /**
+     * Logger
+     */
+    private final Logger LOG = LoggerFactory.getLogger(ImageDaoImpl.class);
+
+    private SessionManager sessionManager;
+
+    /**
+     * lists the tags
+     * @return the list of tags
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public List<Tag> list() throws IOException, ProxyAuthenticationException {
+	Document doc = sessionManager.executeReturnDocument(MethodsEnum.TAGS_ADMIN_LIST.getLabel());
+	//	System.out.println(Outil.documentToString(doc));
+
+	return getTagsFromDocument((Element) doc.getDocumentElement().getElementsByTagName("tags"));
+
+    }
+
+    /**
+     * COnstructs a list of tags from a document
+     * @param doc the document
+     * @return the list of tags
+     */
+    private List<Tag> getTagsFromDocument(Element element) {
+	NodeList listTags = element.getElementsByTagName("tag");
+
+	//	List<Element> listElement = (List<Element>) element.getChildren("tag");
+	ArrayList<Tag> tags = new ArrayList<Tag>();
+	for (int i = 0; i < listTags.getLength(); i++) {
+	    Node nodeTag = listTags.item(0);
+	    if (nodeTag.getNodeType() == Node.ELEMENT_NODE) {
+		Element tagElement = (Element) nodeTag;
+		Tag tag = new Tag();
+		tag.setIdentifier(Integer.valueOf(tagElement.getAttribute(TagEnum.ID.getLabel())));
+		tag.setName(tagElement.getAttribute(TagEnum.NAME.getLabel()));
+		tags.add(tag);
+	    }
+	}
+	return tags;
+
+    }
+
+    /**
+     * Creation of a tag
+     * @param tag the tag to create
+     * @return true if the tag as been successfully created
+     * @throws ProxyAuthenticationException
+     */
+    public boolean create(Tag tag) throws ProxyAuthenticationException {
+	try {
+	    return Tools.checkOk(sessionManager.executeReturnDocument(MethodsEnum.ADD_TAG.getLabel(), "name", tag
+		    .getName()));
+	} catch (IOException e) {
+	    LOG.error(Tools.getStackTrace(e));
+	} catch (FileAlreadyExistsException e) {
+	    e.printStackTrace();
+	}
+	return false;
+    }
+
+    /**
+     * Function that returns the tags for an image
+     * @param image the image
+     * @return the tags list
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public List<Tag> tagsForImage(Image image) throws IOException, ProxyAuthenticationException {
+	Document doc = sessionManager.executeReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", String
+		.valueOf(image.getIdentifier()));
+	Element elementImage = (Element) doc.getDocumentElement().getElementsByTagName("image").item(0);
+	Element elementTag = (Element) elementImage.getElementsByTagName("tags").item(0);
+	return getTagsFromDocument(elementTag);
+    }
+
+    public SessionManager getSessionManager() {
+	return sessionManager;
+    }
+
+    public void setSessionManager(SessionManager sessionManager) {
+	this.sessionManager = sessionManager;
+    }
+
+}
Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/CategoryService.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/CategoryService.java	(revision 9902)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/CategoryService.java	(revision 9919)
@@ -4,57 +4,8 @@
 import java.util.List;
 
-import fr.mael.jiwigo.dao.CategoryDao;
 import fr.mael.jiwigo.om.Category;
 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
-import fr.mael.jiwigo.transverse.session.SessionManager;
 
-/*
- *  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.
- */
-/**
-
- * @author mael
- *
- */
-public class CategoryService {
-    /**
-     * Logger
-     */
-    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
-	    .getLog(CategoryService.class);
-
-    /**
-     * singleton
-     */
-    private static CategoryService instance;
-
-    private SessionManager sessionManager;
-
-    /**
-     * @return the singleton
-     */
-    public static CategoryService getInstance(SessionManager sessionManager) {
-	if (instance == null) {
-	    instance = new CategoryService(sessionManager);
-	}
-	return instance;
-    }
-
-    /**
-     * private constructor to use a singleton
-     */
-    private CategoryService(SessionManager sessionManager) {
-	this.sessionManager = sessionManager;
-
-    }
-
+public interface CategoryService {
     /**
      * Lists all categories
@@ -64,7 +15,5 @@
      * @throws ProxyAuthenticationException
      */
-    public List<Category> list(boolean recursive) throws IOException, ProxyAuthenticationException {
-	return CategoryDao.getInstance(sessionManager).list(recursive);
-    }
+    public List<Category> list(boolean recursive) throws IOException, ProxyAuthenticationException;
 
     /**
@@ -74,21 +23,5 @@
      * @throws ProxyAuthenticationException
      */
-    public List<Category> makeTree() throws IOException, ProxyAuthenticationException {
-	List<Category> list = CategoryDao.getInstance(sessionManager).list(true);
-	for (Category category : list) {
-	    for (Category category2 : list) {
-		if (category2.getIdParentCategories().size() != 1
-			&& category.getIdentifier().equals(
-				category2.getIdParentCategories().get(category2.getIdParentCategories().size() - 2))) {
-		    category.getChildCategories().add(category2);
-		    category2.getParentCategories().add(category);
-		}
-
-	    }
-	}
-
-	return list;
-
-    }
+    public List<Category> makeTree() throws IOException, ProxyAuthenticationException;
 
     /**
@@ -99,10 +32,5 @@
      * @throws ProxyAuthenticationException
      */
-    public boolean create(String nom, Integer parent) throws ProxyAuthenticationException {
-	Category category = new Category();
-	category.setDirectParent(parent);
-	category.setName(nom);
-	return CategoryDao.getInstance(sessionManager).create(category);
-    }
+    public boolean create(String nom, Integer parent) throws ProxyAuthenticationException;
 
     /**
@@ -112,8 +40,4 @@
      * @throws ProxyAuthenticationException
      */
-    public boolean create(String nom) throws ProxyAuthenticationException {
-	Category category = new Category();
-	category.setName(nom);
-	return CategoryDao.getInstance(sessionManager).create(category);
-    }
+    public boolean create(String nom) throws ProxyAuthenticationException;
 }
Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/CommentService.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/CommentService.java	(revision 9902)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/CommentService.java	(revision 9919)
@@ -4,56 +4,8 @@
 import java.util.List;
 
-import fr.mael.jiwigo.dao.CommentDao;
 import fr.mael.jiwigo.om.Comment;
 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
-import fr.mael.jiwigo.transverse.session.SessionManager;
 
-/*
- *  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.
- */
-/**
-
- * @author mael
- *
- */
-public class CommentService {
-    /**
-     * Logger
-     */
-    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
-	    .getLog(CommentService.class);
-
-    /**
-     * singleton
-     */
-    private static CommentService instance;
-
-    private SessionManager sessionManager;
-
-    /**
-     * @return the singleton
-     */
-    public static CommentService getInstance(SessionManager sessionManager) {
-	if (instance == null) {
-	    instance = new CommentService(sessionManager);
-	}
-	return instance;
-    }
-
-    /**
-     * private constructor, to use a singleton
-     */
-    private CommentService(SessionManager sessionManager) {
-	this.sessionManager = sessionManager;
-    }
-
+public interface CommentService {
     /**
      * Lists all comments for an image
@@ -63,7 +15,5 @@
      * @throws ProxyAuthenticationException
      */
-    public List<Comment> list(Integer imageId) throws IOException, ProxyAuthenticationException {
-	return CommentDao.getInstance(sessionManager).list(imageId);
-    }
+    public List<Comment> list(Integer imageId) throws IOException, ProxyAuthenticationException;
 
     /**
@@ -77,11 +27,5 @@
      */
     public boolean create(String content, Integer imageId, String auteur) throws IOException,
-	    ProxyAuthenticationException {
-	Comment comment = new Comment();
-	comment.setContent(content);
-	comment.setImageId(imageId);
-	comment.setAuthor(auteur);
-	return CommentDao.getInstance(sessionManager).create(comment);
-    }
+	    ProxyAuthenticationException;
 
 }
Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/ImageService.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/ImageService.java	(revision 9902)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/ImageService.java	(revision 9919)
@@ -1,66 +1,14 @@
 package fr.mael.jiwigo.service;
 
-import java.io.File;
 import java.io.IOException;
 import java.security.NoSuchAlgorithmException;
 import java.util.List;
 
-import fr.mael.jiwigo.dao.ImageDao;
 import fr.mael.jiwigo.om.Image;
 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.ImagesUtil;
-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.
- */
-/**
- *
-
- * @author mael
- *
- */
-public class ImageService {
-
-    /**
-     * Logger
-     */
-    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
-	    .getLog(ImageService.class);
-
-    /**
-     * Singleton
-     */
-    private static ImageService instance;
-
-    private SessionManager sessionManager;
-
-    /**
-     * @return the singleton
-     */
-    public static ImageService getInstance(SessionManager sessionManager) {
-	if (instance == null) {
-	    instance = new ImageService(sessionManager);
-	}
-	return instance;
-    }
-
-    /**
-     * private constructor to use a singleton
-     */
-    private ImageService(SessionManager sessionManager) {
-	this.sessionManager = sessionManager;
-    }
+public interface ImageService {
 
     /**
@@ -72,7 +20,5 @@
      */
     public List<Image> listByCategory(Integer categoryId, boolean rafraichir) throws IOException,
-	    ProxyAuthenticationException {
-	return ImageDao.getInstance(sessionManager).listByCategory(categoryId, rafraichir);
-    }
+	    ProxyAuthenticationException;
 
     /**
@@ -92,41 +38,5 @@
     public boolean create(String filePath, Integer idCategory, Integer originalWidth, Integer originalHeight,
 	    Double chunckSize, Integer privacyLevel) throws IOException, NoSuchAlgorithmException,
-	    FileAlreadyExistsException, ProxyAuthenticationException, WrongChunkSizeException {
-	File originalFile = new File(filePath);
-	//get the byte array of the original file, to keep metadata
-	byte[] bytesFichierOriginal = Tools.getBytesFromFile(originalFile);
-
-	//resize the picture (or not)
-	boolean originaleRedimensionnee = ImagesUtil.scale(filePath, "originale.jpg", originalWidth, originalHeight);
-	//create the thumbnail
-	ImagesUtil.scale(filePath, "thumb.jpg", 120, 90);
-	//get the thumbnail
-	File thumbnail = new File(System.getProperty("java.io.tmpdir") + "/thumb.jpg");
-	File originale = null;
-	if (originaleRedimensionnee) {
-	    originale = new File(System.getProperty("java.io.tmpdir") + "/originale.jpg");
-	    //if the original file has been resized, we put the metadata in the resized file
-	    //I use here a try catch because if the original file isn't a jpeg
-	    //the methode Outil.enrich will fail, but the procedure has to continue
-	    try {
-		byte[] fichierEnrichi = Tools.enrich(bytesFichierOriginal, Tools.getBytesFromFile(new File(System
-			.getProperty("java.io.tmpdir")
-			+ "/originale.jpg")));
-		Tools.byteToFile(System.getProperty("java.io.tmpdir") + "/originale.jpg", fichierEnrichi);
-	    } catch (Exception e) {
-	    }
-	} else {
-	    originale = originalFile;
-
-	}
-	Image image = new Image();
-	image.setName(getImageName(filePath));
-	image.setThumbnail(thumbnail);
-	image.setOriginale(originale);
-	image.setIdCategory(idCategory);
-	image.setPrivacyLevel(String.valueOf(privacyLevel));
-	//now we call the dao to send the image to the webservice
-	return ImageDao.getInstance(sessionManager).create(image, chunckSize * 1000000);
-    }
+	    FileAlreadyExistsException, ProxyAuthenticationException, WrongChunkSizeException;
 
     /**
@@ -138,7 +48,5 @@
      * @throws ProxyAuthenticationException
      */
-    public boolean addTags(Image image, String tagId) throws IOException, ProxyAuthenticationException {
-	return ImageDao.getInstance(sessionManager).addTags(image.getIdentifier(), tagId);
-    }
+    public boolean addTags(Image image, String tagId) throws IOException, ProxyAuthenticationException;
 
     /**
@@ -149,19 +57,5 @@
      * @throws ProxyAuthenticationException
      */
-    public List<Image> search(String queryString) throws IOException, ProxyAuthenticationException {
-	return ImageDao.getInstance(sessionManager).search(queryString);
-    }
-
-    /**
-     * Deletes the file extension
-     * @param path
-     * @return
-     */
-    private String getImageName(String path) {
-	File fichier = new File(path);
-	StringBuffer name = new StringBuffer(fichier.getName());
-	return (name.delete(name.lastIndexOf("."), name.length())).toString();
-
-    }
+    public List<Image> search(String queryString) throws IOException, ProxyAuthenticationException;
 
 }
Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/TagService.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/TagService.java	(revision 9902)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/TagService.java	(revision 9919)
@@ -4,57 +4,9 @@
 import java.util.List;
 
-import fr.mael.jiwigo.dao.TagDao;
 import fr.mael.jiwigo.om.Image;
 import fr.mael.jiwigo.om.Tag;
 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
-import fr.mael.jiwigo.transverse.session.SessionManager;
 
-/*
- *  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.
- */
-/**
- *
-
- * @author mael
- *
- */
-public class TagService {
-    /**
-     * Logger
-     */
-    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
-	    .getLog(TagService.class);
-
-    /**
-     * The instance, to use a singleton
-     */
-    private static TagService instance;
-
-    private SessionManager sessionManager;
-
-    /**
-     * @return the singleton
-     */
-    public static TagService getInstance(SessionManager sessionManager) {
-	if (instance == null) {
-	    instance = new TagService(sessionManager);
-	}
-	return instance;
-    }
-
-    /**
-     * private constructor
-     */
-    private TagService(SessionManager sessionManager) {
-	this.sessionManager = sessionManager;
-    }
+public interface TagService {
 
     /**
@@ -64,7 +16,5 @@
      * @throws ProxyAuthenticationException
      */
-    public List<Tag> list() throws IOException, ProxyAuthenticationException {
-	return TagDao.getInstance(sessionManager).list();
-    }
+    public List<Tag> list() throws IOException, ProxyAuthenticationException;
 
     /**
@@ -75,9 +25,5 @@
      * @throws ProxyAuthenticationException
      */
-    public boolean create(String nom) throws IOException, ProxyAuthenticationException {
-	Tag tag = new Tag();
-	tag.setName(nom);
-	return TagDao.getInstance(sessionManager).create(tag);
-    }
+    public boolean create(String nom) throws IOException, ProxyAuthenticationException;
 
     /**
@@ -88,7 +34,4 @@
      * @throws ProxyAuthenticationException
      */
-    public List<Tag> tagsForImage(Image image) throws IOException, ProxyAuthenticationException {
-	return TagDao.getInstance(sessionManager).tagsForImage(image);
-    }
-
+    public List<Tag> tagsForImage(Image image) throws IOException, ProxyAuthenticationException;
 }
Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/CategoryServiceImpl.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/CategoryServiceImpl.java	(revision 9919)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/CategoryServiceImpl.java	(revision 9919)
@@ -0,0 +1,107 @@
+package fr.mael.jiwigo.service.impl;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fr.mael.jiwigo.dao.CategoryDao;
+import fr.mael.jiwigo.om.Category;
+import fr.mael.jiwigo.service.CategoryService;
+import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
+
+/*
+ *  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.
+ */
+/**
+
+ * @author mael
+ *
+ */
+public class CategoryServiceImpl implements CategoryService {
+    /**
+     * Logger
+     */
+    private final Logger LOG = LoggerFactory.getLogger(CategoryServiceImpl.class);
+
+    private CategoryDao dao;
+
+    /**
+     * Lists all categories
+     * @param recursive true : recursive listing
+     * @return the list of categories
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public List<Category> list(boolean recursive) throws IOException, ProxyAuthenticationException {
+	return dao.list(recursive);
+    }
+
+    /**
+     * Allows to create the categories tree
+     * @return list of categories
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public List<Category> makeTree() throws IOException, ProxyAuthenticationException {
+	List<Category> list = dao.list(true);
+	for (Category category : list) {
+	    for (Category category2 : list) {
+		if (category2.getIdParentCategories().size() != 1
+			&& category.getIdentifier().equals(
+				category2.getIdParentCategories().get(category2.getIdParentCategories().size() - 2))) {
+		    category.getChildCategories().add(category2);
+		    category2.getParentCategories().add(category);
+		}
+
+	    }
+	}
+
+	return list;
+
+    }
+
+    /**
+     * creation of a category
+     * @param nom name of the category
+     * @param parent parent category
+     * @return true if successful
+     * @throws ProxyAuthenticationException
+     */
+    public boolean create(String nom, Integer parent) throws ProxyAuthenticationException {
+	Category category = new Category();
+	category.setDirectParent(parent);
+	category.setName(nom);
+	return dao.create(category);
+    }
+
+    /**
+     * creation of a category without parent
+     * @param nom name of the category
+     * @return true if successful
+     * @throws ProxyAuthenticationException
+     */
+    public boolean create(String nom) throws ProxyAuthenticationException {
+	Category category = new Category();
+	category.setName(nom);
+	return dao.create(category);
+    }
+
+    public CategoryDao getDao() {
+	return dao;
+    }
+
+    public void setDao(CategoryDao dao) {
+	this.dao = dao;
+    }
+
+}
Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/CommentServiceImpl.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/CommentServiceImpl.java	(revision 9919)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/CommentServiceImpl.java	(revision 9919)
@@ -0,0 +1,75 @@
+package fr.mael.jiwigo.service.impl;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fr.mael.jiwigo.dao.CommentDao;
+import fr.mael.jiwigo.om.Comment;
+import fr.mael.jiwigo.service.CommentService;
+import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
+
+/*
+ *  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.
+ */
+/**
+
+ * @author mael
+ *
+ */
+public class CommentServiceImpl implements CommentService {
+    /**
+     * Logger
+     */
+    private final Logger LOG = LoggerFactory.getLogger(CommentServiceImpl.class);
+
+    private CommentDao dao;
+
+    /**
+     * Lists all comments for an image
+     * @param imageId the id of the image
+     * @return the list of comments
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public List<Comment> list(Integer imageId) throws IOException, ProxyAuthenticationException {
+	return dao.list(imageId);
+    }
+
+    /**
+     * Creates a comment for an image
+     * @param content the comment
+     * @param imageId the id of the image
+     * @param auteur the author of the comment
+     * @return true if successful
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public boolean create(String content, Integer imageId, String auteur) throws IOException,
+	    ProxyAuthenticationException {
+	Comment comment = new Comment();
+	comment.setContent(content);
+	comment.setImageId(imageId);
+	comment.setAuthor(auteur);
+	return dao.create(comment);
+    }
+
+    public CommentDao getDao() {
+	return dao;
+    }
+
+    public void setDao(CommentDao dao) {
+	this.dao = dao;
+    }
+
+}
Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/ImageServiceImpl.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/ImageServiceImpl.java	(revision 9919)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/ImageServiceImpl.java	(revision 9919)
@@ -0,0 +1,155 @@
+package fr.mael.jiwigo.service.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fr.mael.jiwigo.dao.ImageDao;
+import fr.mael.jiwigo.om.Image;
+import fr.mael.jiwigo.service.ImageService;
+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.util.ImagesUtil;
+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.
+ */
+/**
+ *
+
+ * @author mael
+ *
+ */
+public class ImageServiceImpl implements ImageService {
+
+    /**
+     * Logger
+     */
+    private final Logger LOG = LoggerFactory.getLogger(ImageServiceImpl.class);
+
+    private ImageDao dao;
+
+    /**
+     * Lists all images for a category
+     * @param categoryId the id of the category
+     * @return the list of images
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public List<Image> listByCategory(Integer categoryId, boolean rafraichir) throws IOException,
+	    ProxyAuthenticationException {
+	return dao.listByCategory(categoryId, rafraichir);
+    }
+
+    /**
+     * Method called to send an image to the server.
+     * @param filePath
+     * @param idCategory
+     * @param originalWidth width for the original image
+     * @param originalHeight height for the original image
+     * @return true if the image is created
+     * @throws IOException
+     * @throws WrongChunkSizeException
+     * @throws ProxyAuthenticationException
+     * @throws FileAlreadyExistsException
+     * @throws NoSuchAlgorithmException
+     * @throws Exception
+     */
+    public boolean create(String filePath, Integer idCategory, Integer originalWidth, Integer originalHeight,
+	    Double chunckSize, Integer privacyLevel) throws IOException, NoSuchAlgorithmException,
+	    FileAlreadyExistsException, ProxyAuthenticationException, WrongChunkSizeException {
+	File originalFile = new File(filePath);
+	//get the byte array of the original file, to keep metadata
+	byte[] bytesFichierOriginal = Tools.getBytesFromFile(originalFile);
+
+	//resize the picture (or not)
+	boolean originaleRedimensionnee = ImagesUtil.scale(filePath, "originale.jpg", originalWidth, originalHeight);
+	//create the thumbnail
+	ImagesUtil.scale(filePath, "thumb.jpg", 120, 90);
+	//get the thumbnail
+	File thumbnail = new File(System.getProperty("java.io.tmpdir") + "/thumb.jpg");
+	File originale = null;
+	if (originaleRedimensionnee) {
+	    originale = new File(System.getProperty("java.io.tmpdir") + "/originale.jpg");
+	    //if the original file has been resized, we put the metadata in the resized file
+	    //I use here a try catch because if the original file isn't a jpeg
+	    //the methode Outil.enrich will fail, but the procedure has to continue
+	    try {
+		byte[] fichierEnrichi = Tools.enrich(bytesFichierOriginal, Tools.getBytesFromFile(new File(System
+			.getProperty("java.io.tmpdir")
+			+ "/originale.jpg")));
+		Tools.byteToFile(System.getProperty("java.io.tmpdir") + "/originale.jpg", fichierEnrichi);
+	    } catch (Exception e) {
+	    }
+	} else {
+	    originale = originalFile;
+
+	}
+	Image image = new Image();
+	image.setName(getImageName(filePath));
+	image.setThumbnail(thumbnail);
+	image.setOriginale(originale);
+	image.setIdCategory(idCategory);
+	image.setPrivacyLevel(String.valueOf(privacyLevel));
+	//now we call the dao to send the image to the webservice
+	return dao.create(image, chunckSize * 1000000);
+    }
+
+    /**
+     * Add tags to an existing image
+     * @param image the image
+     * @param tagId the ids of the tags
+     * @return true if successful
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public boolean addTags(Image image, String tagId) throws IOException, ProxyAuthenticationException {
+	return dao.addTags(image.getIdentifier(), tagId);
+    }
+
+    /**
+     * Search images from a string
+     * @param queryString the string
+     * @return images matching the string
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public List<Image> search(String queryString) throws IOException, ProxyAuthenticationException {
+	return dao.search(queryString);
+    }
+
+    /**
+     * Deletes the file extension
+     * @param path
+     * @return
+     */
+    private String getImageName(String path) {
+	File fichier = new File(path);
+	StringBuffer name = new StringBuffer(fichier.getName());
+	return (name.delete(name.lastIndexOf("."), name.length())).toString();
+
+    }
+
+    public ImageDao getDao() {
+	return dao;
+    }
+
+    public void setDao(ImageDao dao) {
+	this.dao = dao;
+    }
+
+}
Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/TagServiceImpl.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/TagServiceImpl.java	(revision 9919)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/impl/TagServiceImpl.java	(revision 9919)
@@ -0,0 +1,82 @@
+package fr.mael.jiwigo.service.impl;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fr.mael.jiwigo.dao.TagDao;
+import fr.mael.jiwigo.om.Image;
+import fr.mael.jiwigo.om.Tag;
+import fr.mael.jiwigo.service.TagService;
+import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
+
+/*
+ *  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.
+ */
+/**
+ *
+
+ * @author mael
+ *
+ */
+public class TagServiceImpl implements TagService {
+    /**
+     * Logger
+     */
+    private final Logger LOG = LoggerFactory.getLogger(TagServiceImpl.class);
+
+    private TagDao dao;
+
+    /**
+     * Lists all tags
+     * @return le list of tags
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public List<Tag> list() throws IOException, ProxyAuthenticationException {
+	return dao.list();
+    }
+
+    /**
+     * Creates a tag
+     * @param nom name of the tag
+     * @return true if the tag is created
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public boolean create(String nom) throws IOException, ProxyAuthenticationException {
+	Tag tag = new Tag();
+	tag.setName(nom);
+	return dao.create(tag);
+    }
+
+    /**
+     * Returns all the tag for an image
+     * @param image the image to check
+     * @return the list of tags
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public List<Tag> tagsForImage(Image image) throws IOException, ProxyAuthenticationException {
+	return dao.tagsForImage(image);
+    }
+
+    public TagDao getDao() {
+	return dao;
+    }
+
+    public void setDao(TagDao dao) {
+	this.dao = dao;
+    }
+
+}
Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/session/SessionManager.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/session/SessionManager.java	(revision 9902)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/session/SessionManager.java	(revision 9919)
@@ -2,117 +2,11 @@
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.List;
 
-import org.apache.commons.lang.StringUtils;
-import org.apache.http.HttpHost;
-import org.apache.http.HttpResponse;
-import org.apache.http.NameValuePair;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.entity.UrlEncodedFormEntity;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.conn.params.ConnRoutePNames;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
-import org.apache.http.message.BasicNameValuePair;
 import org.w3c.dom.Document;
 
-import fr.mael.jiwigo.transverse.enumeration.MethodsEnum;
 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
-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.
- */
-/**
-
- * @author mael
- * Gestionnaire de connexion
- */
-public class SessionManager {
-
-    /**
-     * Logger
-     */
-    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
-	    .getLog(SessionManager.class);
-    /**
-     * the entered login
-     */
-    private String login;
-    /**
-     * the entered password
-     */
-    private String password;
-    /**
-     * the url of the site
-     */
-    private String url;
-    /**
-     * the http client
-     */
-    private DefaultHttpClient client;
-
-    /**
-     * defines if the user uses a proxy
-     */
-    private boolean usesProxy;
-
-    /**
-     * url of the proxy
-     */
-    private String urlProxy;
-
-    /**
-     * port of the proxy
-     */
-    private int portProxy;
-
-    /**
-     * login for the proxy
-     */
-    private String loginProxy;
-
-    /**
-     * pass for the proxy
-     */
-    private String passProxy;
-
-    /**
-     * true : an error was found for the proxy
-     */
-    private boolean proxyError;
-
-    /**
-     * Constructor
-     * @param login the login
-     * @param password the password
-     * @param url the url of the site
-     */
-    public SessionManager(String login, String password, String url) {
-	this.login = login;
-	this.password = password;
-	this.url = url + "/ws.php";
-	//	MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
-	//	client = new HttpClient(connectionManager);
-	ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager();
-	client = new DefaultHttpClient(connectionManager);
-	//Using of a Linux user agent. cause... it's better 8)
-	client.getParams().setParameter("http.useragent",
-		"Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1");
-
-    }
-
+public interface SessionManager {
     /**
      * Connection method
@@ -122,37 +16,5 @@
      *
      */
-    public int processLogin() {
-	Document doc;
-	//configures the proxy
-	if (usesProxy) {
-	    //	    HostConfiguration config = client.getHostConfiguration();
-	    //	    config.setProxy(urlProxy, portProxy);
-	    if (!StringUtils.isEmpty(loginProxy) && !StringUtils.isEmpty(passProxy)) {
-		//		Credentials credentials = new UsernamePasswordCredentials(loginProxy, passProxy);
-		//		AuthScope authScope = new AuthScope(urlProxy, portProxy);
-		//		client.getState().setProxyCredentials(authScope, credentials);
-		HttpHost proxy = new HttpHost(urlProxy, portProxy);
-		client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
-		client.getCredentialsProvider().setCredentials(new AuthScope(urlProxy, portProxy),
-			new UsernamePasswordCredentials(loginProxy, passProxy));
-
-	    }
-	}
-	//	try {
-	try {
-	    doc = executeReturnDocument(MethodsEnum.LOGIN.getLabel(), "username", login, "password", password);
-	    return (Tools.checkOk(doc) ? 0 : 1);
-	} catch (IOException e) {
-	    LOG.debug(Tools.getStackTrace(e));
-	    return 1;
-	} catch (ProxyAuthenticationException e) {
-	    LOG.debug(Tools.getStackTrace(e));
-	    return 2;
-	} catch (Exception e) {
-	    LOG.debug(Tools.getStackTrace(e));
-	    return 1;
-	}
-
-    }
+    public int processLogin();
 
     /**
@@ -165,51 +27,5 @@
      */
     public String executeReturnString(String methode, String... parametres) throws UnsupportedEncodingException,
-	    ProxyAuthenticationException {
-	if (parametres.length % 2 != 0 && !(parametres == null)) {
-	    try {
-		throw new Exception("Le nombre de parametres doit etre pair");
-	    } catch (Exception e) {
-		LOG.error(Tools.getStackTrace(e));
-		return null;
-	    }
-	}
-	HttpPost method = new HttpPost(url);
-	List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
-	nameValuePairs.add(new BasicNameValuePair("method", methode));
-	for (int i = 0; i < parametres.length; i += 2) {
-	    nameValuePairs.add(new BasicNameValuePair(parametres[i], parametres[i + 1]));
-	}
-	method.setEntity(new UrlEncodedFormEntity(nameValuePairs));
-	//begin bug:0001833
-	method.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
-	//end
-	try {
-	    HttpResponse response = client.execute(method);
-	    if (response.getStatusLine().getStatusCode() == 407) {
-		throw new ProxyAuthenticationException("Error while trying to auth on the proxy");
-	    }
-	    InputStream inputStream = response.getEntity().getContent();
-	    StringBuffer buffer = new StringBuffer();
-	    byte[] data = new byte[512];
-	    int len = 0;
-	    try {
-		while (-1 != (len = inputStream.read(data))) {
-		    buffer.append(new String(data, 0, len));
-		}
-	    } catch (IOException e) {
-		e.printStackTrace();
-	    }
-	    try {
-		inputStream.close();
-	    } catch (IOException e) {
-		e.printStackTrace();
-	    }
-	    return buffer.toString();
-	} catch (IOException e) {
-
-	}
-	return null;
-
-    }
+	    ProxyAuthenticationException;
 
     /**
@@ -222,15 +38,5 @@
      */
     public Document executeReturnDocument(String methode, String... parametres) throws IOException,
-	    ProxyAuthenticationException {
-	try {
-	    String returnedString = executeReturnString(methode, parametres);
-	    return Tools.stringToDocument(returnedString);
-	} catch (Exception e) {
-	    // TODO Auto-generated catch block
-	    LOG.error(Tools.getStackTrace(e));
-	}
-	return null;
-
-    }
+	    ProxyAuthenticationException;
 
     /**
@@ -240,93 +46,70 @@
      * @throws ProxyAuthenticationException
      */
-    public Document executeReturnDocument(String methode) throws ProxyAuthenticationException {
-	try {
-	    return Tools.stringToDocument(executeReturnString(methode));
-	} catch (Exception e) {
-	    // TODO Auto-generated catch block
-	    LOG.error(Tools.getStackTrace(e));
-	}
-	return null;
-
-    }
+    public Document executeReturnDocument(String methode) throws ProxyAuthenticationException;
 
     /**
+     * Getter of the login
      * @return the login
      */
-    public String getLogin() {
-	return login;
-    }
+    public String getLogin();
 
     /**
-     * @param login the login to set
+     * Setter of the login
+     * @param login
      */
-    public void setLogin(String login) {
-	this.login = login;
-    }
+    public void setLogin(String login);
 
     /**
-     * @return the url
+     * Setter of the user agent
+     * @param userAgent
      */
-    public String getUrl() {
-	return url;
-    }
+    public void setUserAgent(String userAgent);
 
     /**
-     * @param url the url to set
+     * Setter of the password to access piwigo
+     * @param password
      */
-    public void setUrl(String url) {
-	this.url = url;
-    }
+    public void setPassword(String password);
 
     /**
-     * @param usesProxy the usesProxy to set
+     * Setter of the proxy login
+     * @param loginProxy
      */
-    public void setUsesProxy(boolean usesProxy) {
-	this.usesProxy = usesProxy;
-    }
+    public void setLoginProxy(String loginProxy);
 
     /**
-     * @param urlProxy the urlProxy to set
+     * Setter of the proxy port
+     * @param port
      */
-    public void setUrlProxy(String urlProxy) {
-	this.urlProxy = urlProxy;
-    }
+    public void setPortProxy(int port);
 
     /**
-     * @param portProxy the portProxy to set
+     * Setter of the proxy url
+     * @param urlProxy
      */
-    public void setPortProxy(int portProxy) {
-	this.portProxy = portProxy;
-    }
+    public void setUrlProxy(String urlProxy);
 
     /**
-     * @param loginProxy the loginProxy to set
+     * Setter of the proxy pass
+     * @param proxyPass
      */
-    public void setLoginProxy(String loginProxy) {
-	this.loginProxy = loginProxy;
-    }
+    public void setPassProxy(String proxyPass);
 
     /**
-     * @param passProxy the passProxy to set
+     * Setter of the proxy url
+     * @param url
      */
-    public void setPassProxy(String passProxy) {
-	this.passProxy = passProxy;
-    }
+    public void setUrl(String url);
 
-    public String getPassword() {
-	return password;
-    }
+    /**
+     * Setter of the boolean that tells to use a proxy or not
+     * @param usesProxy
+     */
+    public void setUsesProxy(boolean usesProxy);
 
-    public void setPassword(String password) {
-	this.password = password;
-    }
-
-    public boolean isProxyError() {
-	return proxyError;
-    }
-
-    public void setProxyError(boolean proxyError) {
-	this.proxyError = proxyError;
-    }
-
+    /**
+     * Function that returns true if there is a proxy error
+     * @return
+     */
+    public boolean isProxyError();
 }
Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/session/impl/SessionManagerImpl.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/session/impl/SessionManagerImpl.java	(revision 9919)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/session/impl/SessionManagerImpl.java	(revision 9919)
@@ -0,0 +1,329 @@
+package fr.mael.jiwigo.transverse.session.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.conn.params.ConnRoutePNames;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.message.BasicNameValuePair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+
+import fr.mael.jiwigo.transverse.enumeration.MethodsEnum;
+import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
+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.
+ */
+/**
+
+ * @author mael
+ * Gestionnaire de connexion
+ */
+public class SessionManagerImpl implements SessionManager {
+
+    /**
+     * Logger
+     */
+    private final Logger LOG = LoggerFactory.getLogger(SessionManagerImpl.class);
+    /**
+     * the entered login
+     */
+    private String login;
+    /**
+     * the entered password
+     */
+    private String password;
+    /**
+     * the url of the site
+     */
+    private String url;
+    /**
+     * the http client
+     */
+    private DefaultHttpClient client;
+
+    /**
+     * defines if the user uses a proxy
+     */
+    private boolean usesProxy;
+
+    /**
+     * url of the proxy
+     */
+    private String urlProxy;
+
+    /**
+     * port of the proxy
+     */
+    private int portProxy;
+
+    /**
+     * login for the proxy
+     */
+    private String loginProxy;
+
+    /**
+     * pass for the proxy
+     */
+    private String passProxy;
+
+    /**
+     * true : an error was found for the proxy
+     */
+    private boolean proxyError;
+
+    public SessionManagerImpl() {
+	client = new DefaultHttpClient();
+    }
+
+    /**
+     * Constructor
+     * @param login the login
+     * @param password the password
+     * @param url the url of the site
+     * @param userAgent the user agent to use
+     */
+    public SessionManagerImpl(String login, String password, String url, String userAgent) {
+	this.login = login;
+	this.password = password;
+	this.url = url + "/ws.php";
+	//	MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
+	//	client = new HttpClient(connectionManager);
+	//	ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(null, null);
+	client = new DefaultHttpClient();
+	//Using of a Linux user agent. cause... it's better 8)
+	client.getParams().setParameter("http.useragent", userAgent);
+
+    }
+
+    /**
+     * Fonction used to set the user agent of the http client
+     * @param userAgent
+     */
+    public void setUserAgent(String userAgent) {
+	client.getParams().setParameter("http.useragent", userAgent);
+    }
+
+    /**
+     * Connection method
+     *
+     * @return 0 if Ok, 1 if not Ok (reason not specified), 2 if proxy error
+     *
+     *
+     */
+    public int processLogin() {
+	Document doc;
+	//configures the proxy
+	if (usesProxy) {
+	    //	    HostConfiguration config = client.getHostConfiguration();
+	    //	    config.setProxy(urlProxy, portProxy);
+	    if (!StringUtils.isEmpty(loginProxy) && !StringUtils.isEmpty(passProxy)) {
+		//		Credentials credentials = new UsernamePasswordCredentials(loginProxy, passProxy);
+		//		AuthScope authScope = new AuthScope(urlProxy, portProxy);
+		//		client.getState().setProxyCredentials(authScope, credentials);
+		HttpHost proxy = new HttpHost(urlProxy, portProxy);
+		client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
+		client.getCredentialsProvider().setCredentials(new AuthScope(urlProxy, portProxy),
+			new UsernamePasswordCredentials(loginProxy, passProxy));
+
+	    }
+	}
+	//	try {
+	try {
+	    doc = executeReturnDocument(MethodsEnum.LOGIN.getLabel(), "username", login, "password", password);
+	    return (Tools.checkOk(doc) ? 0 : 1);
+	} catch (IOException e) {
+	    LOG.debug(Tools.getStackTrace(e));
+	    return 1;
+	} catch (ProxyAuthenticationException e) {
+	    LOG.debug(Tools.getStackTrace(e));
+	    return 2;
+	} catch (Exception e) {
+	    LOG.debug(Tools.getStackTrace(e));
+	    return 1;
+	}
+
+    }
+
+    /**
+     * Executes a method on the webservice and returns the result as a string
+     * @param methode the method to execute
+     * @param parametres the parameters of the method. Must be even : the name of the parameter followed by its value
+     * @return the result
+     * @throws UnsupportedEncodingException
+     * @throws ProxyAuthenticationException
+     */
+    public String executeReturnString(String methode, String... parametres) throws UnsupportedEncodingException,
+	    ProxyAuthenticationException {
+	if (parametres.length % 2 != 0 && !(parametres == null)) {
+	    try {
+		throw new Exception("Le nombre de parametres doit etre pair");
+	    } catch (Exception e) {
+		LOG.error(Tools.getStackTrace(e));
+		return null;
+	    }
+	}
+	HttpPost method = new HttpPost(url);
+	List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
+	nameValuePairs.add(new BasicNameValuePair("method", methode));
+	for (int i = 0; i < parametres.length; i += 2) {
+	    nameValuePairs.add(new BasicNameValuePair(parametres[i], parametres[i + 1]));
+	}
+	method.setEntity(new UrlEncodedFormEntity(nameValuePairs));
+	method.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
+	try {
+	    HttpResponse response = client.execute(method);
+	    if (response.getStatusLine().getStatusCode() == 407) {
+		throw new ProxyAuthenticationException("Error while trying to auth on the proxy");
+	    }
+	    InputStream inputStream = response.getEntity().getContent();
+	    String toReturn = Tools.readInputStreamAsString(inputStream);
+	    return toReturn;
+	} catch (IOException e) {
+
+	}
+	return null;
+
+    }
+
+    /**
+     * Executes a method on the webservice and returns the result as a Dom document
+     * @param methode the method to execute
+     * @param parametres the parameters of the method. Must be even : the name of the parameter followed by its value
+     * @return the result
+     * @throws IOException
+     * @throws ProxyAuthenticationException
+     */
+    public Document executeReturnDocument(String methode, String... parametres) throws IOException,
+	    ProxyAuthenticationException {
+	try {
+	    String returnedString = executeReturnString(methode, parametres);
+	    return Tools.stringToDocument(returnedString);
+	} catch (Exception e) {
+	    // TODO Auto-generated catch block
+	    LOG.error(Tools.getStackTrace(e));
+	}
+	return null;
+
+    }
+
+    /**
+     * Executes a method on the webservice and returns the result as a Dom document
+     * @param methode the method to execute
+     * @return the result
+     * @throws ProxyAuthenticationException
+     */
+    public Document executeReturnDocument(String methode) throws ProxyAuthenticationException {
+	try {
+	    return Tools.stringToDocument(executeReturnString(methode));
+	} catch (Exception e) {
+	    // TODO Auto-generated catch block
+	    LOG.error(Tools.getStackTrace(e));
+	}
+	return null;
+
+    }
+
+    /**
+     * @return the login
+     */
+    public String getLogin() {
+	return login;
+    }
+
+    /**
+     * @param login the login to set
+     */
+    public void setLogin(String login) {
+	this.login = login;
+    }
+
+    /**
+     * @return the url
+     */
+    public String getUrl() {
+	return url;
+    }
+
+    /**
+     * @param url the url to set
+     */
+    public void setUrl(String url) {
+	this.url = url;
+    }
+
+    /**
+     * @param usesProxy the usesProxy to set
+     */
+    public void setUsesProxy(boolean usesProxy) {
+	this.usesProxy = usesProxy;
+    }
+
+    /**
+     * @param urlProxy the urlProxy to set
+     */
+    public void setUrlProxy(String urlProxy) {
+	this.urlProxy = urlProxy;
+    }
+
+    /**
+     * @param portProxy the portProxy to set
+     */
+    public void setPortProxy(int portProxy) {
+	this.portProxy = portProxy;
+    }
+
+    /**
+     * @param loginProxy the loginProxy to set
+     */
+    public void setLoginProxy(String loginProxy) {
+	this.loginProxy = loginProxy;
+    }
+
+    /**
+     * @param passProxy the passProxy to set
+     */
+    public void setPassProxy(String passProxy) {
+	this.passProxy = passProxy;
+    }
+
+    public String getPassword() {
+	return password;
+    }
+
+    public void setPassword(String password) {
+	this.password = password;
+    }
+
+    public boolean isProxyError() {
+	return proxyError;
+    }
+
+    public void setProxyError(boolean proxyError) {
+	this.proxyError = proxyError;
+    }
+
+}
Index: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/util/Tools.java
===================================================================
--- extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/util/Tools.java	(revision 9902)
+++ extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/util/Tools.java	(revision 9919)
@@ -40,4 +40,6 @@
 import org.apache.sanselan.formats.jpeg.iptc.PhotoshopApp13Data;
 import org.apache.sanselan.formats.tiff.write.TiffOutputSet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -46,4 +48,5 @@
 import org.xml.sax.SAXException;
 
+import fr.mael.jiwigo.service.impl.CategoryServiceImpl;
 import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException;
 
@@ -68,5 +71,5 @@
      * Logger
      */
-    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(Tools.class);
+    private static final Logger LOG = LoggerFactory.getLogger(CategoryServiceImpl.class);
 
     /**
@@ -97,4 +100,5 @@
     public static Document stringToDocument(String xmlSource) throws SAXException, ParserConfigurationException,
 	    IOException {
+	LOG.debug(xmlSource);
 	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 	DocumentBuilder builder = factory.newDocumentBuilder();
@@ -327,7 +331,55 @@
     }
 
+    public static Document readFileAsDocument(String filePath) {
+	Document doc = null;
+	try {
+	    DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
+	    DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
+	    doc = docBuilder.parse(filePath);
+	} catch (Exception e) {
+	    LOG.error("Error converting file to Document : " + getStackTrace(e));
+	}
+	return doc;
+    }
+
+    /**
+     * Gets the value of a document node
+     * @param element
+     * @param tagName
+     * @return
+     */
     public static String getStringValueDom(Element element, String tagName) {
 	Element el = (Element) element.getElementsByTagName(tagName).item(0);
 	return el.getFirstChild().getNodeValue();
     }
+
+    /**
+     * Sets the value of a document node
+     * @param element
+     * @param tagName
+     * @param value
+     */
+    public static void setStringValueDom(Element element, String tagName, String value) {
+	Element el = (Element) element.getElementsByTagName(tagName).item(0);
+	el.setNodeValue(value);
+    }
+
+    /**
+     * Write an xml document to a file
+     * @param doc document to write
+     * @param filename file where to write the document
+     */
+    public static void writeXmlFile(Document doc, String filename) {
+	try {
+	    Source source = new DOMSource(doc);
+	    File file = new File(filename);
+	    Result result = new StreamResult(file);
+	    Transformer xformer = TransformerFactory.newInstance().newTransformer();
+	    xformer.transform(source, result);
+	} catch (TransformerConfigurationException e) {
+	    LOG.error(getStackTrace(e));
+	} catch (TransformerException e) {
+	    LOG.error(getStackTrace(e));
+	}
+    }
 }
