source: extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/dao/TagDao.java @ 6964

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

Tag management :
Add Service and dao for the tags management (adding and listing tags)

File size: 3.3 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.Tag;
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 TagDao {
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 TagDao instance;
54
55    /**
56     * Constructeur privé, afin que seule l'instance soit accessible
57     */
58    private TagDao() {
59
60    }
61
62    /**
63     * @return l'instance
64     */
65    public static TagDao getInstance() {
66        if (instance == null) {
67            instance = new TagDao();
68        }
69        return instance;
70    }
71
72    /**
73     * Lister les tag
74     * @return la liste des tags
75     * @throws IOException
76     */
77    public List<Tag> lister() throws IOException {
78        Document doc = Main.sessionManager.executerReturnDocument(MethodsEnum.LISTER_TAGS.getLabel());
79        //      System.out.println(Outil.documentToString(doc));
80        Element element = doc.getRootElement().getChild("tags");
81        List<Element> listElement = (List<Element>) element.getChildren("tag");
82        ArrayList<Tag> tags = new ArrayList<Tag>();
83        for (Element t : listElement) {
84            Tag tag = new Tag(t);
85            tags.add(tag);
86        }
87        return tags;
88    }
89
90    /**
91     * Création d'un tag
92     * @param tag le tag à créer
93     * @return true si le tag a bien été créé
94     */
95    public boolean creer(Tag tag) {
96        try {
97            return Outil.checkOk(Main.sessionManager.executerReturnDocument(MethodsEnum.ADD_TAG.getLabel(), "name", tag
98                    .getNom()));
99        } catch (IOException e) {
100            LOG.error(Outil.getStackTrace(e));
101        }
102        return false;
103    }
104
105}
Note: See TracBrowser for help on using the repository browser.