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

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

Bug correction :
bug:0001837 : there is now a default translation file (in english), so the application won't crash when a translation is not found
bug:0001833 : the accents are manage when creating a new category
bug:0001832 : on a right click on the categories list, the selection is now visible
bug:0001830 : there is no bug on refreshing the categories tree

Features :
feature:001828 : exif and iptc tags are kept after resizing an image
feature:001827 : pwg.images.addChunk is now fully used : images are split into chunks before being sent

Other features :

  • The user can manage his preferences :

-The web images size
-The chunks size

  • The user can save the login informations (url, login, password) /!\ in a plain text file !
File size: 3.7 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    /**
56     * Constructeur privé, afin que seule l'instance soit accessible
57     */
58    private CategoryDao() {
59
60    }
61
62    /**
63     * @return l'instance
64     */
65    public static CategoryDao getInstance() {
66        if (instance == null) {
67            instance = new CategoryDao();
68        }
69        return instance;
70    }
71
72    /**
73     * Lister les catégorie
74     * @param rafraichir permet de dire si on utilise les catégories présentes dans le cache ou pas
75     * @param recursive listing récursif des catégories
76     * @return la liste des catégories
77     * @throws IOException
78     */
79    public List<Category> lister(boolean recursive) throws IOException {
80        Document doc = Main.sessionManager.executerReturnDocument(MethodsEnum.LISTER_CATEGORIES.getLabel(),
81                "recursive", String.valueOf(recursive));
82        Element element = doc.getRootElement().getChild("categories");
83        List<Element> listElement = (List<Element>) element.getChildren("category");
84        ArrayList<Category> categories = new ArrayList<Category>();
85        for (Element cat : listElement) {
86            Category myCat = new Category(cat);
87            categories.add(myCat);
88        }
89        return categories;
90    }
91
92    /**
93     * Création d'une catégorie
94     * @param category la catégorie à créer
95     * @return true si la catégorie a bien été créée
96     */
97    public boolean creer(Category category) {
98        try {
99            return Outil.checkOk(Main.sessionManager.executerReturnDocument(MethodsEnum.AJOUTER_CATEGORIE.getLabel(),
100                    "name", category.getNom(), "parent", String.valueOf(category.getParentDirect())));
101        } catch (IOException e) {
102            LOG.error(Outil.getStackTrace(e));
103        }
104        return false;
105    }
106
107}
Note: See TracBrowser for help on using the repository browser.