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.service.plugin;
35
36 import fr.paris.lutece.portal.business.portlet.PortletType;
37 import fr.paris.lutece.portal.business.right.Right;
38 import fr.paris.lutece.portal.service.content.ContentServiceEntry;
39 import fr.paris.lutece.portal.service.daemon.DaemonEntry;
40 import fr.paris.lutece.portal.service.dashboard.DashboardComponentEntry;
41 import fr.paris.lutece.portal.service.filter.FilterEntry;
42 import fr.paris.lutece.portal.service.includes.PageIncludeEntry;
43 import fr.paris.lutece.portal.service.init.LuteceInitException;
44 import fr.paris.lutece.portal.service.insert.InsertService;
45 import fr.paris.lutece.portal.service.rbac.RBACResourceTypeEntry;
46 import fr.paris.lutece.portal.service.search.SearchIndexerEntry;
47 import fr.paris.lutece.portal.service.servlet.ServletEntry;
48 import fr.paris.lutece.portal.service.sessionlistener.HttpSessionListenerEntry;
49 import fr.paris.lutece.portal.service.util.AppPropertiesService;
50 import fr.paris.lutece.portal.web.xpages.XPageApplicationEntry;
51
52 import org.apache.commons.digester.Digester;
53 import org.apache.commons.digester.Substitutor;
54 import org.apache.commons.digester.substitution.MultiVariableExpander;
55 import org.apache.commons.digester.substitution.VariableSubstitutor;
56 import org.apache.commons.digester.xmlrules.DigesterLoader;
57
58 import org.xml.sax.SAXException;
59
60 import java.io.FileInputStream;
61 import java.io.FileNotFoundException;
62 import java.io.IOException;
63 import java.io.InputStream;
64
65 import java.net.URL;
66
67 import java.util.ArrayList;
68 import java.util.Collections;
69 import java.util.HashMap;
70 import java.util.List;
71 import java.util.Map;
72
73 import javax.validation.constraints.NotNull;
74
75
76
77
78
79 public class PluginFile
80 {
81 private static final String FILE_RULES = "/fr/paris/lutece/portal/service/plugin/plugin-digester-rules.xml";
82
83
84 private String _strName;
85 private String _strVersion;
86 private String _strDescription;
87 private String _strProvider;
88 private String _strProviderUrl;
89 private String _strCopyright;
90 private String _strPluginClass;
91 private String _strIconUrl;
92 private String _strDocumentationUrl;
93 private String _strMinCoreVersion;
94 private String _strMaxCoreVersion;
95 private boolean _bIsInstalled;
96 private boolean _bDbPoolRequired;
97 private Map<Integer, List<String>> _listCssStyleSheets = new HashMap<Integer, List<String>>( );
98 private Map<Integer, List<String>> _listJavascriptFiles = new HashMap<Integer, List<String>>( );
99 private List<String> _listAdminCssStyleSheets = new ArrayList<String>( );
100 private List<String> _listAdminJavascriptFiles = new ArrayList<String>( );
101 private List<String> _listFreemarkerMacrosFiles = new ArrayList<String>( );
102 private List<Right> _listRights = new ArrayList<Right>( );
103 private List<PortletType> _listPortletTypes = new ArrayList<PortletType>( );
104 private List<DaemonEntry> _listDaemons = new ArrayList<DaemonEntry>( );
105 private List<XPageApplicationEntry> _listApplications = new ArrayList<XPageApplicationEntry>( );
106 private List<FilterEntry> _listFilters = new ArrayList<FilterEntry>( );
107 private List<ServletEntry> _listServlets = new ArrayList<ServletEntry>( );
108 private List<HttpSessionListenerEntry> _listListeners = new ArrayList<HttpSessionListenerEntry>( );
109 private List<ContentServiceEntry> _listContentServices = new ArrayList<ContentServiceEntry>( );
110 private List<SearchIndexerEntry> _listSearchIndexers = new ArrayList<SearchIndexerEntry>( );
111 private List<InsertService> _listInsertServices = new ArrayList<InsertService>( );
112 private List<RBACResourceTypeEntry> _listRBACResourceTypes = new ArrayList<RBACResourceTypeEntry>( );
113 private List<PageIncludeEntry> _listPageIncludes = new ArrayList<PageIncludeEntry>( );
114 private List<DashboardComponentEntry> _listDashboardComponents = new ArrayList<DashboardComponentEntry>( );
115 private List<DashboardComponentEntry> _listAdminDashboardComponents = new ArrayList<DashboardComponentEntry>( );
116 private Map<String, String> _mapParams = new HashMap<String, String>( );
117 private String _strSearchIndexerClass;
118 private String _strCssStylesheetsScope;
119 private String _strJavascriptFilesScope;
120
121
122
123
124
125
126 public void load( String strFilename ) throws LuteceInitException
127 {
128
129 URL rules = getClass( ).getResource( FILE_RULES );
130 Digester digester = DigesterLoader.createDigester( rules );
131
132
133 MultiVariableExpander expander = new MultiVariableExpander( );
134 expander.addSource( "$", AppPropertiesService.getPropertiesAsMap( ) );
135
136 Substitutor substitutor = new VariableSubstitutor( expander );
137 digester.setSubstitutor( substitutor );
138
139
140 digester.push( this );
141 digester.setValidating( false );
142
143 try
144 {
145 InputStream input = new FileInputStream( strFilename );
146 digester.parse( input );
147 }
148 catch ( FileNotFoundException e )
149 {
150 throw new LuteceInitException( "Error loading plugin file : " + strFilename, e );
151 }
152 catch ( SAXException e )
153 {
154 throw new LuteceInitException( "Error loading plugin file : " + strFilename, e );
155 }
156 catch ( IllegalArgumentException e )
157 {
158 throw new LuteceInitException( "Error loading plugin file : " + strFilename, e );
159 }
160 catch ( IOException e )
161 {
162 throw new LuteceInitException( "Error loading plugin file : " + strFilename, e );
163 }
164 }
165
166
167
168
169
170
171 public String getName( )
172 {
173 return _strName;
174 }
175
176
177
178
179
180
181 public void setName( String strName )
182 {
183 _strName = strName;
184 }
185
186
187
188
189
190
191 public String getVersion( )
192 {
193 return _strVersion;
194 }
195
196
197
198
199
200
201 public void setVersion( String strVersion )
202 {
203 _strVersion = strVersion;
204 }
205
206
207
208
209
210
211 public String getDescription( )
212 {
213 return _strDescription;
214 }
215
216
217
218
219
220
221 public void setDescription( String strDescription )
222 {
223 _strDescription = strDescription;
224 }
225
226
227
228
229
230
231 public String getProvider( )
232 {
233 return _strProvider;
234 }
235
236
237
238
239
240
241 public void setProvider( String strProvider )
242 {
243 _strProvider = strProvider;
244 }
245
246
247
248
249
250
251 public String getProviderUrl( )
252 {
253 return _strProviderUrl;
254 }
255
256
257
258
259
260
261 public void setProviderUrl( String strProviderUrl )
262 {
263 _strProviderUrl = strProviderUrl;
264 }
265
266
267
268
269
270
271 public String getIconUrl( )
272 {
273 return _strIconUrl;
274 }
275
276
277
278
279
280
281 public void setIconUrl( String strIconUrl )
282 {
283 _strIconUrl = strIconUrl;
284 }
285
286
287
288
289
290
291 public String getDocumentationUrl( )
292 {
293 return _strDocumentationUrl;
294 }
295
296
297
298
299
300
301 public void setDocumentationUrl( String strDocumentationUrl )
302 {
303 _strDocumentationUrl = strDocumentationUrl;
304 }
305
306
307
308
309
310
311 public String getCopyright( )
312 {
313 return _strCopyright;
314 }
315
316
317
318
319
320
321 public void setCopyright( String strCopyright )
322 {
323 _strCopyright = strCopyright;
324 }
325
326
327
328
329
330
331 public String getPluginClass( )
332 {
333 return _strPluginClass;
334 }
335
336
337
338
339
340
341 public void setPluginClass( String strPluginClass )
342 {
343 _strPluginClass = strPluginClass;
344 }
345
346
347
348
349
350
351 public boolean isInstalled( )
352 {
353 return _bIsInstalled;
354 }
355
356
357
358
359
360
361 public void setIsInstalled( boolean bIsInstalled )
362 {
363 _bIsInstalled = bIsInstalled;
364 }
365
366
367
368
369
370
371 public String getMinCoreVersion( )
372 {
373 return _strMinCoreVersion;
374 }
375
376
377
378
379
380
381 public void setMinCoreVersion( String strMinCoreVersion )
382 {
383 _strMinCoreVersion = strMinCoreVersion;
384 }
385
386
387
388
389
390
391 public String getMaxCoreVersion( )
392 {
393 return _strMaxCoreVersion;
394 }
395
396
397
398
399
400
401 public void setMaxCoreVersion( String strMaxCoreVersion )
402 {
403 _strMaxCoreVersion = strMaxCoreVersion;
404 }
405
406
407
408
409
410
411 private Integer getMode( String mode )
412 {
413 Integer nMode = null;
414
415 if ( mode != null )
416 {
417 nMode = Integer.valueOf( mode );
418 }
419
420 return nMode;
421 }
422
423
424
425
426
427 public void addCssStyleSheet( String strStyleSheet )
428 {
429 addCssStyleSheet( strStyleSheet, null );
430 }
431
432
433
434
435
436
437 public void addCssStyleSheet( String strStyleSheet, String mode )
438 {
439 Integer nMode = getMode( mode );
440 List<String> cssStyleSheets = _listCssStyleSheets.get( nMode );
441
442 if ( cssStyleSheets == null )
443 {
444 cssStyleSheets = new ArrayList<String>( );
445 _listCssStyleSheets.put( nMode, cssStyleSheets );
446 }
447
448 cssStyleSheets.add( strStyleSheet );
449 }
450
451
452
453
454
455
456 public void addAdminCssStyleSheet( String strStyleSheet )
457 {
458 _listAdminCssStyleSheets.add( strStyleSheet );
459 }
460
461
462
463
464
465
466 public void addAdminJavascriptFile( String strJavascriptFile )
467 {
468 _listAdminJavascriptFiles.add( strJavascriptFile );
469 }
470
471
472
473
474
475 @NotNull
476 public List<String> getCssStyleSheets( )
477 {
478 List<String> res = _listCssStyleSheets.get( null );
479
480 if ( res == null )
481 {
482 return Collections.emptyList( );
483 }
484
485 return res;
486 }
487
488
489
490
491
492
493 @NotNull
494 public Map<Integer, List<String>> getCssStyleSheetsForAllModes( )
495 {
496 return _listCssStyleSheets;
497 }
498
499
500
501
502
503 public void addJavascriptFile( String strJavascriptFile )
504 {
505 addJavascriptFile( strJavascriptFile, null );
506 }
507
508
509
510
511
512
513 public void addJavascriptFile( String strJavascriptFile, String mode )
514 {
515 Integer nMode = getMode( mode );
516 List<String> javascriptFiles = _listJavascriptFiles.get( nMode );
517
518 if ( javascriptFiles == null )
519 {
520 javascriptFiles = new ArrayList<String>( );
521 _listJavascriptFiles.put( nMode, javascriptFiles );
522 }
523
524 javascriptFiles.add( strJavascriptFile );
525 }
526
527
528
529
530
531 @NotNull
532 public List<String> getJavascriptFiles( )
533 {
534 List<String> res = _listJavascriptFiles.get( null );
535
536 if ( res == null )
537 {
538 return Collections.emptyList( );
539 }
540
541 return res;
542 }
543
544
545
546
547
548
549 @NotNull
550 public Map<Integer, List<String>> getJavascriptFilesForAllModes( )
551 {
552 return _listJavascriptFiles;
553 }
554
555
556
557
558
559 public void addFreemarkerMacrosFile( String strFileName )
560 {
561 _listFreemarkerMacrosFiles.add( strFileName );
562 }
563
564
565
566
567
568
569 public List<String> getFreemarkerMacrosFiles( )
570 {
571 return _listFreemarkerMacrosFiles;
572 }
573
574
575
576
577
578 public void addRight( Right right )
579 {
580 _listRights.add( right );
581 }
582
583
584
585
586
587
588 public List<Right> getRights( )
589 {
590
591 for ( Right right : _listRights )
592 {
593 right.setPluginName( _strName );
594 }
595
596 return _listRights;
597 }
598
599
600
601
602
603 public void addXPageApplication( XPageApplicationEntry application )
604 {
605 _listApplications.add( application );
606 }
607
608
609
610
611
612
613 public List<XPageApplicationEntry> getXPageApplications( )
614 {
615 return _listApplications;
616 }
617
618
619
620
621
622 public void addFilter( FilterEntry entry )
623 {
624 _listFilters.add( entry );
625 }
626
627
628
629
630
631
632 public List<FilterEntry> getFilters( )
633 {
634 return _listFilters;
635 }
636
637
638
639
640
641 public void addServlet( ServletEntry entry )
642 {
643 _listServlets.add( entry );
644 }
645
646
647
648
649
650
651 public List<ServletEntry> getServlets( )
652 {
653 return _listServlets;
654 }
655
656
657
658
659
660 public void addListener( HttpSessionListenerEntry entry )
661 {
662 _listListeners.add( entry );
663 }
664
665
666
667
668
669 public List<HttpSessionListenerEntry> getListeners( )
670 {
671 return _listListeners;
672 }
673
674
675
676
677
678 public void addPortletType( PortletType portletType )
679 {
680 _listPortletTypes.add( portletType );
681 }
682
683
684
685
686
687 public List<PortletType> getPortletTypes( )
688 {
689
690 for ( PortletType portletType : _listPortletTypes )
691 {
692 portletType.setPluginName( _strName );
693 }
694
695 return _listPortletTypes;
696 }
697
698
699
700
701
702 public void addContentService( ContentServiceEntry entry )
703 {
704 _listContentServices.add( entry );
705 }
706
707
708
709
710
711 public List<ContentServiceEntry> getContentServices( )
712 {
713 return _listContentServices;
714 }
715
716
717
718
719
720 public void addInsertService( InsertService is )
721 {
722 _listInsertServices.add( is );
723 }
724
725
726
727
728
729 public List<InsertService> getInsertServices( )
730 {
731 return _listInsertServices;
732 }
733
734
735
736
737
738 public void addSearchIndexer( SearchIndexerEntry entry )
739 {
740 _listSearchIndexers.add( entry );
741 }
742
743
744
745
746
747 public List<SearchIndexerEntry> getSearchIndexers( )
748 {
749 return _listSearchIndexers;
750 }
751
752
753
754
755
756 public void addPageInclude( PageIncludeEntry entry )
757 {
758 _listPageIncludes.add( entry );
759 }
760
761
762
763
764
765 public List<PageIncludeEntry> getPageIncludes( )
766 {
767 return _listPageIncludes;
768 }
769
770
771
772
773
774 public void addDashboardComponent( DashboardComponentEntry entry )
775 {
776 _listDashboardComponents.add( entry );
777 }
778
779
780
781
782
783 public List<DashboardComponentEntry> getDashboardComponents( )
784 {
785 return _listDashboardComponents;
786 }
787
788
789
790
791
792 public void addAdminDashboardComponent( DashboardComponentEntry dashboardComponent )
793 {
794 _listAdminDashboardComponents.add( dashboardComponent );
795 }
796
797
798
799
800
801 public List<DashboardComponentEntry> getAdminDashboardComponents( )
802 {
803 return _listAdminDashboardComponents;
804 }
805
806
807
808
809
810 public void addRBACResourceType( RBACResourceTypeEntry entry )
811 {
812 _listRBACResourceTypes.add( entry );
813 }
814
815
816
817
818
819 public List<RBACResourceTypeEntry> getRBACResourceTypes( )
820 {
821 return _listRBACResourceTypes;
822 }
823
824
825
826
827
828 public void addDaemon( DaemonEntry daemonEntry )
829 {
830 _listDaemons.add( daemonEntry );
831 }
832
833
834
835
836
837 public List<DaemonEntry> getDaemons( )
838 {
839 return _listDaemons;
840 }
841
842
843
844
845
846
847 public boolean isDbPoolRequired( )
848 {
849 return _bDbPoolRequired;
850 }
851
852
853
854
855
856
857 public void setIsDbPoolRequired( boolean bDbPoolRequired )
858 {
859 _bDbPoolRequired = bDbPoolRequired;
860 }
861
862
863
864
865
866 public Map<String, String> getParams( )
867 {
868 return _mapParams;
869 }
870
871
872
873
874
875
876 public void addParameter( String strName, String strValue )
877 {
878 _mapParams.put( strName, strValue );
879 }
880
881
882
883
884
885
886
887 public String getSearchIndexerClass( )
888 {
889 return _strSearchIndexerClass;
890 }
891
892
893
894
895
896
897 public void setSearchIndexerClass( String strSearchIndexerClass )
898 {
899 _strSearchIndexerClass = strSearchIndexerClass;
900 }
901
902
903
904
905
906
907
908 public String getCssStylesheetsScope( )
909 {
910 return _strCssStylesheetsScope;
911 }
912
913
914
915
916
917
918 public void setCssStylesheetsScope( String strCssStylesheetScope )
919 {
920 _strCssStylesheetsScope = strCssStylesheetScope;
921 }
922
923
924
925
926
927
928
929 public String getJavascriptFilesScope( )
930 {
931 return _strJavascriptFilesScope;
932 }
933
934
935
936
937
938
939 public void setJavascriptFilesScope( String strJavascriptFilescope )
940 {
941 _strJavascriptFilesScope = strJavascriptFilescope;
942 }
943
944
945
946
947
948
949 public List<String> getAdminCssStyleSheets( )
950 {
951 return _listAdminCssStyleSheets;
952 }
953
954
955
956
957
958
959 public List<String> getAdminJavascriptFiles( )
960 {
961 return _listAdminJavascriptFiles;
962 }
963 }