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