1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.portal.business.theme;
35
36 import fr.paris.lutece.portal.business.datastore.DataEntity;
37 import fr.paris.lutece.portal.business.datastore.DataEntityDAO;
38 import fr.paris.lutece.portal.business.datastore.DataEntityHome;
39 import fr.paris.lutece.portal.business.style.Theme;
40 import fr.paris.lutece.util.ReferenceList;
41 import fr.paris.lutece.util.sql.DAOUtil;
42
43 import java.util.ArrayList;
44 import java.util.Collection;
45
46
47
48
49
50 public final class ThemeDAO implements IThemeDAO
51 {
52 private static final String SQL_QUERY_SELECT = " SELECT code_theme, theme_description, path_images, path_css, theme_author, " +
53 " theme_author_url, theme_version, theme_licence, path_js FROM core_theme WHERE code_theme = ?";
54 private static final String SQL_QUERY_SELECTALL = " SELECT code_theme, theme_description, path_images, path_css, theme_author, " +
55 " theme_author_url, theme_version, theme_licence, path_js FROM core_theme ORDER BY code_theme";
56 private static final String SQL_QUERY_SELECT_THEME = " SELECT code_theme, theme_description FROM core_theme";
57 private static final String SQL_QUERY_SELECT_GLOBAL_THEME = " SELECT tt.code_theme, tt.theme_description, tt.path_images, tt.path_css, " +
58 " tt.theme_author, tt.theme_author_url, tt.theme_version, tt.theme_licence, tt.path_js " +
59 " FROM core_theme tt WHERE tt.code_theme = ?";
60 private static final String SQL_QUERY_UPDATE_GLOBAL_THEME = " UPDATE core_datastore SET entity_value=? WHERE entity_key = 'theme.globalThemeCode' ";
61 private static final String SQL_QUERY_UPDATE_GLOBAL_THEME_VERSION = " UPDATE core_datastore SET entity_value=? WHERE entity_key = 'theme.globalThemeVersion' ";
62
63
64
65
66 public Theme load( String strCodeTheme )
67 {
68 Theme theme = null;
69 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT ) ) {
70 daoUtil.setString( 1, strCodeTheme );
71
72 daoUtil.executeQuery( );
73
74 if ( daoUtil.next( ) )
75 {
76 theme = new Theme( );
77 theme.setCodeTheme( daoUtil.getString( 1 ) );
78 theme.setThemeDescription( daoUtil.getString( 2 ) );
79 theme.setPathImages( daoUtil.getString( 3 ) );
80 theme.setPathCss( daoUtil.getString( 4 ) );
81 theme.setThemeAuthor( daoUtil.getString( 5 ) );
82 theme.setThemeAuthorUrl( daoUtil.getString( 6 ) );
83 theme.setThemeVersion( daoUtil.getString( 7 ) );
84 theme.setThemeLicence( daoUtil.getString( 8 ) );
85 theme.setPathJs( daoUtil.getString( 9 ) );
86 }
87 }
88 return theme;
89 }
90
91
92
93
94 public Collection<Theme> selectThemesList( )
95 {
96 Collection<Theme> themeList = new ArrayList<Theme>( );
97 try (DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL ) ) {
98 daoUtil.executeQuery( );
99
100 while ( daoUtil.next( ) )
101 {
102 Themeal/business/style/Theme.html#Theme">Theme theme = new Theme( );
103
104 theme.setCodeTheme( daoUtil.getString( 1 ) );
105 theme.setThemeDescription( daoUtil.getString( 2 ) );
106 theme.setPathImages( daoUtil.getString( 3 ) );
107 theme.setPathCss( daoUtil.getString( 4 ) );
108 theme.setThemeAuthor( daoUtil.getString( 5 ) );
109 theme.setThemeAuthorUrl( daoUtil.getString( 6 ) );
110 theme.setThemeVersion( daoUtil.getString( 7 ) );
111 theme.setThemeLicence( daoUtil.getString( 8 ) );
112 theme.setPathJs( daoUtil.getString( 9 ) );
113
114 themeList.add( theme );
115 }
116 }
117 return themeList;
118 }
119
120
121
122
123 public ReferenceList getThemesList( )
124 {
125 ReferenceListt.html#ReferenceList">ReferenceList themesList = new ReferenceList( );
126 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_THEME ) ) {
127 daoUtil.executeQuery( );
128
129 while ( daoUtil.next( ) )
130 {
131 themesList.addItem( daoUtil.getString( 1 ), daoUtil.getString( 2 ) );
132 }
133
134 }
135 return themesList;
136 }
137
138
139
140
141 public void setGlobalTheme( String strGlobalTheme, String strGlobalThemeVersion )
142 {
143 try (DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE_GLOBAL_THEME ) )
144 {
145 daoUtil.setString( 1, strGlobalTheme );
146 daoUtil.executeUpdate( );
147 }
148
149 try (DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE_GLOBAL_THEME_VERSION ) )
150 {
151 daoUtil.setString( 1, strGlobalThemeVersion );
152 daoUtil.executeUpdate( );
153 }
154 }
155
156
157
158
159 public Theme getGlobalTheme( )
160 {
161 Theme theme = null;
162 DataEntity globalTheme = DataEntityHome.findByPrimaryKey("theme.globalThemeCode");
163 try( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_GLOBAL_THEME ) )
164 {
165 daoUtil.setString( 1, globalTheme.getValue() );
166 daoUtil.executeQuery( );
167
168 if ( daoUtil.next( ) )
169 {
170 theme = new Theme( );
171 theme.setCodeTheme( daoUtil.getString( 1 ) );
172 theme.setThemeDescription( daoUtil.getString( 2 ) );
173 theme.setPathImages( daoUtil.getString( 3 ) );
174 theme.setPathCss( daoUtil.getString( 4 ) );
175 theme.setThemeAuthor( daoUtil.getString( 5 ) );
176 theme.setThemeAuthorUrl( daoUtil.getString( 6 ) );
177 theme.setThemeVersion( daoUtil.getString( 7 ) );
178 theme.setThemeLicence( daoUtil.getString( 8 ) );
179 theme.setPathJs( daoUtil.getString( 9 ) );
180 }
181
182 }
183
184 return theme;
185 }
186 }