View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.portal.business.style;
35  
36  import fr.paris.lutece.util.ReferenceList;
37  import fr.paris.lutece.util.sql.DAOUtil;
38  
39  import java.util.ArrayList;
40  import java.util.Collection;
41  
42  
43  /**
44   * This class provides Data Access methods for Theme objects
45   * @deprecated Use the plugin-theme instead
46   */
47  public final class ThemeDAO implements IThemeDAO
48  {
49      private static final String SQL_QUERY_SELECT = " SELECT code_theme, theme_description, path_images, path_css, theme_author, " +
50          " theme_author_url, theme_version, theme_licence, path_js FROM core_theme WHERE code_theme = ?";
51      private static final String SQL_QUERY_INSERT = " INSERT INTO core_theme ( code_theme, theme_description, path_images, path_css," +
52          " theme_author, theme_author_url, theme_version, theme_licence, path_js ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? )";
53      private static final String SQL_QUERY_DELETE = " DELETE FROM core_theme WHERE code_theme = ?";
54      private static final String SQL_QUERY_UPDATE = " UPDATE core_theme SET theme_description = ?, path_images = ?, " +
55          " path_css = ? , theme_author = ?, theme_author_url = ?, theme_version = ?, " +
56          " theme_licence = ?, path_js = ? WHERE code_theme = ?";
57      private static final String SQL_QUERY_SELECTALL = " SELECT code_theme, theme_description, path_images, path_css, theme_author, " +
58          " theme_author_url, theme_version, theme_licence, path_js FROM core_theme ORDER BY code_theme";
59      private static final String SQL_QUERY_SELECT_THEME = " SELECT code_theme, theme_description FROM core_theme";
60      private static final String SQL_QUERY_SELECT_GLOBAL_THEME = " SELECT global_theme_code FROM core_theme_global ";
61      private static final String SQL_QUERY_UPDATE_GLOBAL_THEME = " UPDATE core_theme_global SET global_theme_code = ? ";
62  
63      /**
64       * {@inheritDoc}
65       */
66      public synchronized void insert( Theme theme )
67      {
68          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT );
69  
70          daoUtil.setString( 1, theme.getCodeTheme(  ) );
71          daoUtil.setString( 2, theme.getThemeDescription(  ) );
72          daoUtil.setString( 3, theme.getPathImages(  ) );
73          daoUtil.setString( 4, theme.getPathCss(  ) );
74          daoUtil.setString( 5, theme.getThemeAuthor(  ) );
75          daoUtil.setString( 6, theme.getThemeAuthorUrl(  ) );
76          daoUtil.setString( 7, theme.getThemeVersion(  ) );
77          daoUtil.setString( 8, theme.getThemeLicence(  ) );
78          daoUtil.setString( 9, theme.getPathJs(  ) );
79  
80          daoUtil.executeUpdate(  );
81          daoUtil.free(  );
82      }
83  
84      /**
85       * {@inheritDoc}
86       */
87      public Theme load( String strCodeTheme )
88      {
89          Theme theme = null;
90          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT );
91          daoUtil.setString( 1, strCodeTheme );
92  
93          daoUtil.executeQuery(  );
94  
95          if ( daoUtil.next(  ) )
96          {
97              theme = new Theme(  );
98              theme.setCodeTheme( daoUtil.getString( 1 ) );
99              theme.setThemeDescription( daoUtil.getString( 2 ) );
100             theme.setPathImages( daoUtil.getString( 3 ) );
101             theme.setPathCss( daoUtil.getString( 4 ) );
102             theme.setThemeAuthor( daoUtil.getString( 5 ) );
103             theme.setThemeAuthorUrl( daoUtil.getString( 6 ) );
104             theme.setThemeVersion( daoUtil.getString( 7 ) );
105             theme.setThemeLicence( daoUtil.getString( 8 ) );
106             theme.setPathJs( daoUtil.getString( 9 ) );
107         }
108 
109         daoUtil.free(  );
110 
111         return theme;
112     }
113 
114     /**
115      * {@inheritDoc}
116      */
117     public void delete( String strCodeTheme )
118     {
119         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE );
120         daoUtil.setString( 1, strCodeTheme );
121         daoUtil.executeUpdate(  );
122         daoUtil.free(  );
123     }
124 
125     /**
126      * {@inheritDoc}
127      */
128     public void store( Theme theme )
129     {
130         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE );
131 
132         daoUtil.setString( 1, theme.getThemeDescription(  ) );
133         daoUtil.setString( 2, theme.getPathImages(  ) );
134         daoUtil.setString( 3, theme.getPathCss(  ) );
135         daoUtil.setString( 4, theme.getThemeAuthor(  ) );
136         daoUtil.setString( 5, theme.getThemeAuthorUrl(  ) );
137         daoUtil.setString( 6, theme.getThemeVersion(  ) );
138         daoUtil.setString( 7, theme.getThemeLicence(  ) );
139         daoUtil.setString( 8, theme.getPathJs(  ) );
140         daoUtil.setString( 9, theme.getCodeTheme(  ) );
141 
142         daoUtil.executeUpdate(  );
143         daoUtil.free(  );
144     }
145 
146     /**
147      * {@inheritDoc}
148      */
149     public Collection<Theme> selectThemesList(  )
150     {
151         Collection<Theme> themeList = new ArrayList<Theme>(  );
152         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL );
153         daoUtil.executeQuery(  );
154 
155         while ( daoUtil.next(  ) )
156         {
157             Theme theme = new Theme(  );
158 
159             theme.setCodeTheme( daoUtil.getString( 1 ) );
160             theme.setThemeDescription( daoUtil.getString( 2 ) );
161             theme.setPathImages( daoUtil.getString( 3 ) );
162             theme.setPathCss( daoUtil.getString( 4 ) );
163             theme.setThemeAuthor( daoUtil.getString( 5 ) );
164             theme.setThemeAuthorUrl( daoUtil.getString( 6 ) );
165             theme.setThemeVersion( daoUtil.getString( 7 ) );
166             theme.setThemeLicence( daoUtil.getString( 8 ) );
167             theme.setPathJs( daoUtil.getString( 9 ) );
168 
169             themeList.add( theme );
170         }
171 
172         daoUtil.free(  );
173 
174         return themeList;
175     }
176 
177     /**
178      * {@inheritDoc}
179      */
180     public ReferenceList getThemesList(  )
181     {
182         ReferenceList themesList = new ReferenceList(  );
183         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_THEME );
184 
185         daoUtil.executeQuery(  );
186 
187         while ( daoUtil.next(  ) )
188         {
189             themesList.addItem( daoUtil.getString( 1 ), daoUtil.getString( 2 ) );
190         }
191 
192         daoUtil.free(  );
193 
194         return themesList;
195     }
196 
197     /**
198      * {@inheritDoc }
199      */
200     public void setGlobalTheme( String strGlobalTheme )
201     {
202         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE_GLOBAL_THEME );
203 
204         daoUtil.setString( 1, strGlobalTheme );
205 
206         daoUtil.executeUpdate(  );
207         daoUtil.free(  );
208     }
209 
210     /**
211      * {@inheritDoc }
212      */
213     public String getGlobalTheme(  )
214     {
215         String strGlobalTheme = null;
216         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_GLOBAL_THEME );
217 
218         daoUtil.executeQuery(  );
219 
220         if ( daoUtil.next(  ) )
221         {
222             strGlobalTheme = daoUtil.getString( 1 );
223         }
224 
225         daoUtil.free(  );
226 
227         return strGlobalTheme;
228     }
229 }