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