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.XmlContent;
37 import fr.paris.lutece.portal.business.page.Page;
38 import fr.paris.lutece.portal.business.stylesheet.StyleSheet;
39 import fr.paris.lutece.util.xml.XmlUtil;
40
41 import java.sql.Timestamp;
42
43 import java.util.Map;
44
45 import javax.servlet.http.HttpServletRequest;
46
47
48
49
50
51
52
53 public abstract class Portlet implements XmlContent
54 {
55
56
57 public static final int STATUS_PUBLISHED = 0;
58 public static final int STATUS_UNPUBLISHED = 1;
59 public static final int FLAG_DISPLAY_ON_SMALL_DEVICE = 0x00000001;
60 public static final int FLAG_DISPLAY_ON_NORMAL_DEVICE = 0x00000010;
61 public static final int FLAG_DISPLAY_ON_LARGE_DEVICE = 0x00000100;
62 public static final int FLAG_DISPLAY_ON_XLARGE_DEVICE = 0x00001000;
63 private static final String VALUE_TRUE = "1";
64 private static final String VALUE_FALSE = "0";
65
66
67
68 private static final int MODE_NORMAL = 0;
69 private static final int MODE_ADMIN = 1;
70 private int _nId;
71 private int _nPageId;
72 private int _nStyleId;
73 private int _nColumn;
74 private int _nOrder;
75 private int _nStatus;
76 private int _nAcceptAlias;
77 private int _nDisplayPortletTitle;
78 private String _strName;
79 private String _strPortletTypeId;
80 private String _strPortletTypeName;
81 private String _strUrlCreation;
82 private String _strUrlUpdate;
83 private String _strPluginName;
84 private String _strHomeClassName;
85 private String _strRole;
86 private Timestamp _dateUpdate;
87 private int _nDeviceFlags;
88
89
90
91
92
93
94
95
96
97 public int getId( )
98 {
99 return _nId;
100 }
101
102
103
104
105
106
107 public void setId( int nId )
108 {
109 _nId = nId;
110 }
111
112
113
114
115
116
117 public int getStyleId( )
118 {
119 return _nStyleId;
120 }
121
122
123
124
125
126
127 public void setStyleId( int nStyleId )
128 {
129 _nStyleId = nStyleId;
130 }
131
132
133
134
135
136
137 public int getPageId( )
138 {
139 return _nPageId;
140 }
141
142
143
144
145
146
147 public void setPageId( int nPageId )
148 {
149 _nPageId = nPageId;
150 }
151
152
153
154
155
156
157 public int getStatus( )
158 {
159 return _nStatus;
160 }
161
162
163
164
165
166
167 public void setStatus( int nStatus )
168 {
169 _nStatus = nStatus;
170 }
171
172
173
174
175
176
177 public String getName( )
178 {
179 return _strName;
180 }
181
182
183
184
185
186
187 public void setName( String strName )
188 {
189 _strName = strName;
190 }
191
192
193
194
195
196
197
198 public String getPortletTypeId( )
199 {
200 return _strPortletTypeId;
201 }
202
203
204
205
206
207
208 public void setPortletTypeId( String strPortletTypeId )
209 {
210 _strPortletTypeId = strPortletTypeId;
211 }
212
213
214
215
216
217
218 public String getPortletTypeName( )
219 {
220 return _strPortletTypeName;
221 }
222
223
224
225
226
227
228 public void setPortletTypeName( String strPortletTypeName )
229 {
230 _strPortletTypeName = strPortletTypeName;
231 }
232
233
234
235
236
237
238 public String getUrlCreation( )
239 {
240 return _strUrlCreation;
241 }
242
243
244
245
246
247
248 public void setUrlCreation( String strUrlCreation )
249 {
250 _strUrlCreation = strUrlCreation;
251 }
252
253
254
255
256
257
258 public String getUrlUpdate( )
259 {
260 return _strUrlUpdate;
261 }
262
263
264
265
266
267
268 public void setUrlUpdate( String strUrlUpdate )
269 {
270 _strUrlUpdate = strUrlUpdate;
271 }
272
273
274
275
276
277
278 public Timestamp getDateUpdate( )
279 {
280 return _dateUpdate;
281 }
282
283
284
285
286
287
288 public void setDateUpdate( Timestamp dateUpdate )
289 {
290 _dateUpdate = dateUpdate;
291 }
292
293
294
295
296
297
298 public int getColumn( )
299 {
300 return _nColumn;
301 }
302
303
304
305
306
307
308
309 public void setColumn( int nColumn )
310 {
311 _nColumn = nColumn;
312 }
313
314
315
316
317
318
319 public int getOrder( )
320 {
321 return _nOrder;
322 }
323
324
325
326
327
328
329 public void setOrder( int nType )
330 {
331 _nOrder = nType;
332 }
333
334
335
336
337
338 public int getDeviceDisplayFlags( )
339 {
340 return _nDeviceFlags;
341 }
342
343
344
345
346
347
348 public boolean hasDeviceDisplayFlag( int nFlag )
349 {
350 return ( _nDeviceFlags & nFlag ) != 0;
351 }
352
353
354
355
356
357 public void setDeviceDisplayFlags( int nFlags )
358 {
359 _nDeviceFlags = nFlags;
360 }
361
362
363
364
365
366
367 public String getHomeClassName( )
368 {
369 return _strHomeClassName;
370 }
371
372
373
374
375
376
377
378 public void setHomeClassName( String strHomeClassName )
379 {
380 _strHomeClassName = strHomeClassName;
381 }
382
383
384
385
386
387
388 public int getAcceptAlias( )
389 {
390 return _nAcceptAlias;
391 }
392
393
394
395
396
397
398
399 public void setDisplayPortletTitle( int nDisplayPortletTitle )
400 {
401 _nDisplayPortletTitle = nDisplayPortletTitle;
402 }
403
404
405
406
407
408
409 public int getDisplayPortletTitle( )
410 {
411 return _nDisplayPortletTitle;
412 }
413
414
415
416
417
418
419 public void setAcceptAlias( int nAcceptAlias )
420 {
421 _nAcceptAlias = nAcceptAlias;
422 }
423
424
425
426
427
428
429 public String getPluginName( )
430 {
431 return _strPluginName;
432 }
433
434
435
436
437
438
439 public void setPluginName( String strPluginName )
440 {
441 _strPluginName = strPluginName;
442 }
443
444
445
446
447
448
449 public String getRole( )
450 {
451 _strRole = ( _strRole == null ) ? Page.ROLE_NONE : _strRole;
452
453 return _strRole;
454 }
455
456
457
458
459
460
461 public void setRole( String strRole )
462 {
463 _strRole = ( ( strRole == null ) || ( strRole.equals( "" ) ) ) ? Page.ROLE_NONE : strRole;
464 }
465
466
467
468
469
470
471
472
473
474 public void copy( Portlet portlet )
475 {
476 setId( portlet.getId( ) );
477 setPortletTypeId( portlet.getPortletTypeId( ) );
478 setPageId( portlet.getPageId( ) );
479 setStyleId( portlet.getStyleId( ) );
480 setName( portlet.getName( ) );
481 setPortletTypeName( portlet.getPortletTypeName( ) );
482 setUrlCreation( portlet.getUrlCreation( ) );
483 setUrlUpdate( portlet.getUrlUpdate( ) );
484 setDateUpdate( portlet.getDateUpdate( ) );
485 setColumn( portlet.getColumn( ) );
486 setOrder( portlet.getOrder( ) );
487 setAcceptAlias( portlet.getAcceptAlias( ) );
488 setPluginName( portlet.getPluginName( ) );
489 setDisplayPortletTitle( portlet.getDisplayPortletTitle( ) );
490 setDeviceDisplayFlags( portlet.getDeviceDisplayFlags( ) );
491 setStatus( portlet.getStatus( ) );
492 setRole( portlet.getRole( ) );
493 }
494
495
496
497
498
499
500
501
502 protected String addPortletTags( StringBuffer strPortlet )
503 {
504 StringBuffer strXml = new StringBuffer( );
505 XmlUtil.beginElement( strXml, TAG_PORTLET );
506 XmlUtil.addElementHtml( strXml, TAG_PORTLET_NAME, getName( ) );
507 XmlUtil.addElement( strXml, TAG_PORTLET_ID, getId( ) );
508 XmlUtil.addElement( strXml, TAG_PAGE_ID, getPageId( ) );
509 XmlUtil.addElement( strXml, TAG_PLUGIN_NAME, getPluginName( ) );
510 XmlUtil.addElement( strXml, TAG_DISPLAY_PORTLET_TITLE, getDisplayPortletTitle( ) );
511
512 String strDisplayOnSmallDevice = ( ( getDeviceDisplayFlags( ) & FLAG_DISPLAY_ON_SMALL_DEVICE ) != 0 )
513 ? VALUE_TRUE : VALUE_FALSE;
514 XmlUtil.addElement( strXml, TAG_DISPLAY_ON_SMALL_DEVICE, strDisplayOnSmallDevice );
515
516 String strDisplayOnNormalDevice = ( ( getDeviceDisplayFlags( ) & FLAG_DISPLAY_ON_NORMAL_DEVICE ) != 0 )
517 ? VALUE_TRUE : VALUE_FALSE;
518 XmlUtil.addElement( strXml, TAG_DISPLAY_ON_NORMAL_DEVICE, strDisplayOnNormalDevice );
519
520 String strDisplayOnLargeDevice = ( ( getDeviceDisplayFlags( ) & FLAG_DISPLAY_ON_LARGE_DEVICE ) != 0 )
521 ? VALUE_TRUE : VALUE_FALSE;
522 XmlUtil.addElement( strXml, TAG_DISPLAY_ON_LARGE_DEVICE, strDisplayOnLargeDevice );
523
524 String strDisplayOnXLargeDevice = ( ( getDeviceDisplayFlags( ) & FLAG_DISPLAY_ON_XLARGE_DEVICE ) != 0 )
525 ? VALUE_TRUE : VALUE_FALSE;
526 XmlUtil.addElement( strXml, TAG_DISPLAY_ON_XLARGE_DEVICE, strDisplayOnXLargeDevice );
527
528 strXml.append( strPortlet.toString( ) );
529 XmlUtil.endElement( strXml, TAG_PORTLET );
530
531 return strXml.toString( );
532 }
533
534
535
536
537
538
539
540 public String getXslFile( int nMode )
541 {
542 StyleSheet xsl;
543
544
545
546 switch ( nMode )
547 {
548 case MODE_NORMAL:
549 case MODE_ADMIN:
550 xsl = PortletHome.getXsl( getId( ), MODE_NORMAL );
551
552 break;
553
554 default:
555 xsl = PortletHome.getXsl( getId( ), nMode );
556
557 break;
558 }
559
560 return xsl.getFile( );
561 }
562
563
564
565
566
567
568
569 public byte[] getXslSource( int nMode )
570 {
571 StyleSheet xsl;
572
573
574
575 switch ( nMode )
576 {
577 case MODE_NORMAL:
578 case MODE_ADMIN:
579 xsl = PortletHome.getXsl( getId( ), MODE_NORMAL );
580
581 break;
582
583 default:
584 xsl = PortletHome.getXsl( getId( ), nMode );
585
586 break;
587 }
588
589 return xsl.getSource( );
590 }
591
592
593
594
595
596
597
598
599
600
601 public Map<String, String> getXslParams( )
602 {
603 return null;
604 }
605
606
607
608
609
610 public abstract void remove( );
611
612
613
614
615
616
617
618
619 public boolean isContentGeneratedByXmlAndXsl( )
620 {
621 return true;
622 }
623
624
625
626
627
628
629
630
631
632
633 public String getHtmlContent( HttpServletRequest request )
634 {
635 return null;
636 }
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653 public boolean canBeCachedForAnonymousUsers( )
654 {
655 return true;
656 }
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673 public boolean canBeCachedForConnectedUsers( )
674 {
675 return true;
676 }
677 }