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.portlet;
35
36 import fr.paris.lutece.portal.business.stylesheet.StyleSheet;
37 import fr.paris.lutece.portal.service.portlet.PortletEvent;
38 import fr.paris.lutece.portal.service.portlet.PortletEventListener;
39 import fr.paris.lutece.portal.service.spring.SpringContextService;
40 import fr.paris.lutece.portal.service.util.AppLogService;
41 import fr.paris.lutece.portal.service.util.AppPropertiesService;
42 import fr.paris.lutece.util.ReferenceList;
43
44 import java.util.Collection;
45 import java.util.List;
46
47
48
49
50
51
52 public abstract class PortletHome implements PortletHomeInterface
53 {
54 private static final String PROPERTY_PORTLET_CREATION_STATUS = "lutece.portlet.creation.status";
55 private static final int CONSTANT_DEFAULT_STATUS = Portlet.STATUS_PUBLISHED;
56
57
58 private static IPortletDAO _dao = SpringContextService.getBean( "portletDAO" );
59
60
61
62
63
64
65
66
67
68
69 public static Portlet findByPrimaryKey( int nKey )
70 {
71 Portlet portlet = _dao.load( nKey );
72 String strHomeClass = portlet.getHomeClassName( );
73 Portlet p = null;
74
75 try
76 {
77 PortletHomeInterface home = (PortletHomeInterface) Class.forName( strHomeClass ).newInstance( );
78 p = home.getDAO( ).load( nKey );
79 p.copy( portlet );
80 }
81 catch ( InstantiationException e )
82 {
83 AppLogService.error( e.getMessage( ), e );
84 }
85 catch ( IllegalAccessException e )
86 {
87 AppLogService.error( e.getMessage( ), e );
88 }
89 catch ( ClassNotFoundException e )
90 {
91 AppLogService.error( e.getMessage( ), e );
92 }
93
94 return p;
95 }
96
97
98
99
100
101
102
103 public static List<Portlet> findByType( String strIdPortletType )
104 {
105 return _dao.selectPortletsByType( strIdPortletType );
106 }
107
108
109
110
111
112
113
114 public static Collection<PortletImpl> getPortletsListbyName( String strPortletName )
115 {
116 return _dao.selectPortletsListbyName( strPortletName );
117 }
118
119
120
121
122
123
124
125
126 static StyleSheet getXsl( int nIdPortlet, int nIdMode )
127 {
128 return _dao.selectXslFile( nIdPortlet, nIdMode );
129 }
130
131
132
133
134
135
136
137 public static ReferenceList getStylesList( String strIdPortletType )
138 {
139 return _dao.selectStylesList( strIdPortletType );
140 }
141
142
143
144
145
146
147 public static Collection<Portlet> getPortletsByRoleKey( String strRole )
148 {
149 return _dao.selectPortletsByRole( strRole );
150 }
151
152
153
154
155
156
157
158 public synchronized Portlet create( Portlet portlet )
159 {
160
161 int nIdPortlet = PortletHome.newPrimaryKey( );
162 portlet.setId( nIdPortlet );
163
164 portlet.setStatus( AppPropertiesService.getPropertyInt( PROPERTY_PORTLET_CREATION_STATUS,
165 CONSTANT_DEFAULT_STATUS ) );
166
167
168 getDAO( ).insert( portlet );
169
170
171 _dao.insert( portlet );
172
173
174 invalidate( portlet );
175
176 return portlet;
177 }
178
179
180
181
182
183
184 static int newPrimaryKey( )
185 {
186 return _dao.newPrimaryKey( );
187 }
188
189
190
191
192
193
194 public synchronized void remove( Portlet portlet )
195 {
196
197 getDAO( ).delete( portlet.getId( ) );
198
199
200 _dao.delete( portlet.getId( ) );
201
202
203 invalidate( portlet );
204 }
205
206
207
208
209
210
211 public void update( Portlet portlet )
212 {
213 getDAO( ).store( portlet );
214 _dao.store( portlet );
215
216
217 invalidate( portlet );
218 }
219
220
221
222
223
224
225
226 public static void invalidate( Portlet portlet )
227 {
228 PortletEvent event = new PortletEvent( PortletEvent.INVALIDATE, portlet.getId( ), portlet.getPageId( ) );
229 notifyListeners( event );
230
231
232 Collection<Portlet> listAliases = getAliasList( portlet.getId( ) );
233
234 for ( Portlet alias : listAliases )
235 {
236 PortletEvent eventAlias = new PortletEvent( PortletEvent.INVALIDATE, alias.getId( ), alias.getPageId( ) );
237 notifyListeners( eventAlias );
238 }
239 }
240
241
242
243
244
245
246 public static void invalidate( int nIdPortlet )
247 {
248 Portlet portlet = findByPrimaryKey( nIdPortlet );
249 invalidate( portlet );
250 }
251
252
253
254
255
256
257
258 public static boolean hasAlias( int nIdPortlet )
259 {
260 return _dao.hasAlias( nIdPortlet );
261 }
262
263
264
265
266
267
268
269 public static void updateStatus( Portlet portlet, int nStatus )
270 {
271
272 _dao.updateStatus( portlet, nStatus );
273
274
275 invalidate( portlet );
276 }
277
278
279
280
281
282
283
284
285 public static PortletType getPortletType( String strPortletTypeId )
286 {
287 return _dao.selectPortletType( strPortletTypeId );
288 }
289
290
291
292
293
294
295
296 public static Collection<PortletImpl> getPortletListByStyle( int nStyleId )
297 {
298 return _dao.selectPortletListByStyle( nStyleId );
299 }
300
301
302
303
304
305
306
307 public static Collection<Portlet> getAliasList( int nPortletId )
308 {
309 return _dao.selectAliasesForPortlet( nPortletId );
310 }
311
312
313
314
315
316 public static Portlet getLastModifiedPortlet( )
317 {
318 return _dao.loadLastModifiedPortlet( );
319 }
320
321
322
323
324
325 public static void notifyListeners( PortletEvent event )
326 {
327 for ( PortletEventListener listener : SpringContextService.getBeansOfType( PortletEventListener.class ) )
328 {
329 listener.processPortletEvent( event );
330 }
331 }
332
333
334
335
336
337
338
339 public static List<Integer> getUsedOrdersForColumns( int pageId, int columnId )
340 {
341 return _dao.getUsedOrdersForColumns( pageId, columnId );
342 }
343 }