source: extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/dao/CategoryDao.java @ 6821

Last change on this file since 6821 was 6821, checked in by mlg, 14 years ago

Premier commit. Actuellement, l'application gère :
-Listing des catégories
-Affichage des miniatures
-Ajout de commentaires
-gestion d'un cache pour ne pas télécharger les images plusieurs fois
-gestion d'un zoom dans le navigateur d'images
-navigateur d'images complètement refait, je viens de tester sur un grand écran, à priori, c'est beaucoup mieux
-meilleure gestion des exceptions, avec affichage de messages d'erreurs
-ajout d'un "logger" qui enregistre toutes les exceptions dans un fichier de log
-possibilité de ne pas mettre le "http://" dans l'écran de connexion
-gestion de transformations d'images dans le navigateur d'images : "flip" horizontal et vertical, rotations
-menu dans le navigateur d'images, qui permet d'effectuer toutes les actions, avec en plus, la possibilité d'imprimer une image

en cours d'implémentation : gestion des préférences de l'utilisateur. Actuellement, le fichier xml permettant d'écrire les préférences est géré,
il reste à faire un écran de gestion des préférences, avec un maximum d'options, afin que l'appli soit configurable.

File size: 3.9 KB
Line 
1package fr.mael.jiwigo.dao;
2
3import java.io.IOException;
4import java.util.ArrayList;
5import java.util.List;
6
7import org.jdom.Document;
8import org.jdom.Element;
9
10import fr.mael.jiwigo.Main;
11import fr.mael.jiwigo.om.Category;
12import fr.mael.jiwigo.transverse.enumeration.MethodsEnum;
13import fr.mael.jiwigo.transverse.util.Outil;
14
15/**
16   Copyright (c) 2010, Mael
17   All rights reserved.
18
19   Redistribution and use in source and binary forms, with or without
20   modification, are permitted provided that the following conditions are met:
21    * Redistributions of source code must retain the above copyright
22      notice, this list of conditions and the following disclaimer.
23    * Redistributions in binary form must reproduce the above copyright
24      notice, this list of conditions and the following disclaimer in the
25      documentation and/or other materials provided with the distribution.
26    * Neither the name of jiwigo nor the
27      names of its contributors may be used to endorse or promote products
28      derived from this software without specific prior written permission.
29
30   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
31   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33   DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY
34   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40   
41 * Dao des catégories
42 * @author mael
43 *
44 */
45public class CategoryDao {
46    /**
47     * Logger
48     */
49    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(Main.class);
50    /**
51     * Instance, afin d'utiliser un singleton
52     */
53    private static CategoryDao instance;
54    /**
55     * Cache. non utilisé pour le moment
56     */
57    private List<Category> cache;
58
59    /**
60     * Constructeur privé, afin que seule l'instance soit accessible
61     */
62    private CategoryDao() {
63
64    }
65
66    /**
67     * @return l'instance
68     */
69    public static CategoryDao getInstance() {
70        if (instance == null) {
71            instance = new CategoryDao();
72        }
73        return instance;
74    }
75
76    /**
77     * Lister les catégorie
78     * @param rafraichir permet de dire si on utilise les catégories présentes dans le cache ou pas
79     * @param recursive listing récursif des catégories
80     * @return la liste des catégories
81     * @throws IOException
82     */
83    public List<Category> lister(boolean rafraichir, boolean recursive) throws IOException {
84        if (cache == null || rafraichir) {
85            Document doc = Main.sessionManager.executerReturnDocument(MethodsEnum.LISTER_CATEGORIES.getLabel(),
86                    "recursive", String.valueOf(recursive));
87            Element element = doc.getRootElement().getChild("categories");
88            List<Element> listElement = (List<Element>) element.getChildren("category");
89            ArrayList<Category> categories = new ArrayList<Category>();
90            for (Element cat : listElement) {
91                Category myCat = new Category(cat);
92                categories.add(myCat);
93            }
94            this.cache = categories;
95        }
96        return cache;
97    }
98
99    /**
100     * Création d'une catégorie
101     * @param category la catégorie à créer
102     * @return true si la catégorie a bien été créée
103     */
104    public boolean creer(Category category) {
105        try {
106            return Outil.checkOk(Main.sessionManager.executerReturnDocument(MethodsEnum.AJOUTER_CATEGORIE.getLabel(),
107                    "name", category.getNom(), "parent", String.valueOf(category.getParentDirect())));
108        } catch (IOException e) {
109            LOG.error(Outil.getStackTrace(e));
110        }
111        return false;
112    }
113
114}
Note: See TracBrowser for help on using the repository browser.