View Javadoc
1   /*
2    * Copyright (c) 2002-2025, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
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.portlet.PortletTypeHome;
38  import fr.paris.lutece.portal.business.right.Right;
39  import fr.paris.lutece.portal.business.right.RightHome;
40  import fr.paris.lutece.portal.business.style.Theme;
41  import fr.paris.lutece.portal.service.content.ContentService;
42  import fr.paris.lutece.portal.service.content.ContentServiceEntry;
43  import fr.paris.lutece.portal.service.content.XPageAppService;
44  import fr.paris.lutece.portal.service.daemon.AppDaemonService;
45  import fr.paris.lutece.portal.service.daemon.DaemonEntry;
46  import fr.paris.lutece.portal.service.dashboard.DashboardComponentEntry;
47  import fr.paris.lutece.portal.service.dashboard.DashboardService;
48  import fr.paris.lutece.portal.service.dashboard.admin.AdminDashboardService;
49  import fr.paris.lutece.portal.service.database.PluginConnectionService;
50  import fr.paris.lutece.portal.service.filter.FilterEntry;
51  import fr.paris.lutece.portal.service.filter.FilterService;
52  import fr.paris.lutece.portal.service.includes.PageIncludeEntry;
53  import fr.paris.lutece.portal.service.includes.PageIncludeService;
54  import fr.paris.lutece.portal.service.init.LuteceInitException;
55  import fr.paris.lutece.portal.service.insert.InsertService;
56  import fr.paris.lutece.portal.service.insert.InsertServiceManager;
57  import fr.paris.lutece.portal.service.portal.PortalService;
58  import fr.paris.lutece.portal.service.rbac.RBACResourceTypeEntry;
59  import fr.paris.lutece.portal.service.rbac.ResourceIdService;
60  import fr.paris.lutece.portal.service.search.IndexationService;
61  import fr.paris.lutece.portal.service.search.SearchIndexer;
62  import fr.paris.lutece.portal.service.search.SearchIndexerEntry;
63  import fr.paris.lutece.portal.service.servlet.ServletEntry;
64  import fr.paris.lutece.portal.service.servlet.ServletService;
65  import fr.paris.lutece.portal.service.sessionlistener.HttpSessionListenerEntry;
66  import fr.paris.lutece.portal.service.sessionlistener.HttpSessionListenerService;
67  import fr.paris.lutece.portal.service.util.AppPropertiesService;
68  import fr.paris.lutece.portal.web.xpages.XPageApplicationEntry;
69  
70  import java.util.ArrayList;
71  import java.util.Collections;
72  import java.util.Comparator;
73  import java.util.HashMap;
74  import java.util.List;
75  import java.util.Map;
76  
77  import javax.servlet.http.HttpServletRequest;
78  
79  import org.apache.commons.collections.CollectionUtils;
80  
81  /**
82   * This class is the general plugin element
83   */
84  public abstract class Plugin implements Comparable<Plugin>
85  {
86      // Constantes
87      public static final int PLUGIN_TYPE_FEATURE = 0x01;
88      public static final int PLUGIN_TYPE_PORTLET = 0x02;
89      public static final int PLUGIN_TYPE_APPLICATION = 0x04;
90      public static final int PLUGIN_TYPE_INSERTSERVICE = 0x08;
91      public static final int PLUGIN_TYPE_CONTENTSERVICE = 0x10;
92      public static final int PLUGIN_TYPE_DAEMON = 0x20;
93      private static final String PROPERTY_DEFAULT_ICON_URL = "plugin.image.defaultIconUrl";
94      private static final String SCOPE_PORTAL = "portal";
95      private static final String SCOPE_XPAGE = "xpage";
96  
97      // Variables
98      private String _strName;
99      private String _strVersion;
100     private String _strDescription;
101     private String _strProvider;
102     private String _strProviderUrl;
103     private String _strCopyright;
104     private String _strPluginClass;
105     private String _strDbPoolName;
106     private String _strIconUrl;
107     private String _strDocumentationUrl;
108     private String _strMinCoreVersion;
109     private String _strMaxCoreVersion;
110     private boolean _bIsInstalled;
111     private boolean _bDbPoolRequired;
112     private ContentService _contentService;
113     private String _strCssStylesheetsScope;
114     private String _strJavascriptFilesScope;
115 
116     // Lists of rights and portlets of the plugin
117     private List<XPageApplicationEntry> _listXPageApplications;
118     private List<FilterEntry> _listFilters;
119     private List<ServletEntry> _listServlets;
120     private List<HttpSessionListenerEntry> _listListeners;
121     private Map<Integer, List<String>> _listCssStyleSheets;
122     private Map<Integer, List<String>> _listJavascriptFiles;
123     private List<String> _listAdminCssStyleSheets;
124     private List<String> _listAdminJavascriptFiles;
125     private List<Right> _listRights;
126     private List<PortletType> _listPortletTypes;
127     private List<ContentServiceEntry> _listContentServices;
128     private List<SearchIndexerEntry> _listSearchIndexers;
129     private List<InsertService> _listInsertServices;
130     private List<PageIncludeEntry> _listPageIncludes;
131     private List<DashboardComponentEntry> _listDashboardComponents;
132     private List<DashboardComponentEntry> _listAdminDashboardComponents;
133     private List<RBACResourceTypeEntry> _listRBACResourceTypes;
134     private List<DaemonEntry> _listDaemons;
135     private List<String> _listFreemarkerAutoIncludes;
136     private Map<String,String> _mapFreemarkerAutoImports;
137 
138     // hashtable which contains all the params described in the xml plugin file
139     private Map<String, String> _mapParams = new HashMap<>( );
140     private PluginConnectionService _connectionService;
141 
142     /**
143      * Initializes the plugin at the first load
144      *
145      */
146     public abstract void init( );
147 
148     /**
149      * Load plugin's data from the plugin's xml file.
150      *
151      * @param pluginFile
152      *            The plugin file object
153      * @throws LuteceInitException
154      *             If an error occured
155      */
156     void load( PluginFile pluginFile ) throws LuteceInitException
157     {
158         try
159         {
160             _strName = pluginFile.getName( );
161             _strVersion = pluginFile.getVersion( );
162             _strDescription = pluginFile.getDescription( );
163             _strProvider = pluginFile.getProvider( );
164             _strProviderUrl = pluginFile.getProviderUrl( );
165 
166             String strDefaultIconUrl = AppPropertiesService.getProperty( PROPERTY_DEFAULT_ICON_URL );
167             _strIconUrl = pluginFile.getIconUrl( ).equals( "" ) ? strDefaultIconUrl : pluginFile.getIconUrl( );
168             _strDocumentationUrl = pluginFile.getDocumentationUrl( );
169             _strCopyright = pluginFile.getCopyright( );
170             _strPluginClass = pluginFile.getPluginClass( );
171             _strMinCoreVersion = pluginFile.getMinCoreVersion( );
172             _strMaxCoreVersion = pluginFile.getMaxCoreVersion( );
173             _listXPageApplications = pluginFile.getXPageApplications( );
174             _listFilters = pluginFile.getFilters( );
175             _listServlets = pluginFile.getServlets( );
176             _listListeners = pluginFile.getListeners( );
177             _listRights = pluginFile.getRights( );
178             _listPortletTypes = pluginFile.getPortletTypes( );
179             _listContentServices = pluginFile.getContentServices( );
180             _listInsertServices = pluginFile.getInsertServices( );
181             _listSearchIndexers = pluginFile.getSearchIndexers( );
182             _listPageIncludes = pluginFile.getPageIncludes( );
183             _listDashboardComponents = pluginFile.getDashboardComponents( );
184             _listAdminDashboardComponents = pluginFile.getAdminDashboardComponents( );
185             _listRBACResourceTypes = pluginFile.getRBACResourceTypes( );
186             _listDaemons = pluginFile.getDaemons( );
187             _mapParams = pluginFile.getParams( );
188             _bDbPoolRequired = pluginFile.isDbPoolRequired( );
189 
190             _listCssStyleSheets = pluginFile.getCssStyleSheetsForAllModes( );
191             _strCssStylesheetsScope = ( pluginFile.getCssStylesheetsScope( ) != null ) ? pluginFile.getCssStylesheetsScope( ) : SCOPE_XPAGE;
192             _listJavascriptFiles = pluginFile.getJavascriptFilesForAllModes( );
193             _strJavascriptFilesScope = ( pluginFile.getJavascriptFilesScope( ) != null ) ? pluginFile.getJavascriptFilesScope( ) : SCOPE_XPAGE;
194             _listFreemarkerAutoIncludes = pluginFile.getFreemarkerAutoIncludes( );
195             _mapFreemarkerAutoImports = pluginFile.getFreemarkerAutoImports( );
196             _listAdminCssStyleSheets = pluginFile.getAdminCssStyleSheets( );
197             _listAdminJavascriptFiles = pluginFile.getAdminJavascriptFiles( );
198             // Register plugin components
199             registerXPageApplications( );
200             registerFilters( );
201             registerServlets( );
202             registerListeners( );
203             registerContentServices( );
204             registerInsertServices( );
205             registerSearchIndexers( );
206             registerPageIncludes( );
207             registerDashboardComponents( );
208             registerAdminDashboardComponents( );
209             registerRBACResourceTypes( );
210             registerDaemons( );
211         }
212         catch( Exception e )
213         {
214             throw new LuteceInitException( "Error loading plugin : " + e.getMessage( ), e );
215         }
216     }
217 
218     /**
219      *
220      * @return the content service
221      */
222     public ContentService getContentService( )
223     {
224         return _contentService;
225     }
226 
227     /**
228      * Returns weither or not plugin has portlet.
229      *
230      * @return true if the plugin contains one or more portlet
231      */
232     public boolean hasPortlets( )
233     {
234         return CollectionUtils.isNotEmpty( _listPortletTypes );
235     }
236 
237     /**
238      * Returns weither or not plugin has daemon.
239      *
240      * @return true if the plugin contains one or more daemon
241      */
242     public boolean hasDaemons( )
243     {
244         return CollectionUtils.isNotEmpty( _listDaemons );
245     }
246 
247     /**
248      * Returns The daemons list of the plugin.
249      *
250      * @return The daemons list of the plugin
251      */
252     public List<DaemonEntry> getDaemons( )
253     {
254         return _listDaemons;
255     }
256 
257     /**
258      * Updates the plg file
259      */
260     protected void update( )
261     {
262         PluginService.updatePluginData( this );
263     }
264 
265     /**
266      * Modify the plugin status
267      *
268      * @param bStatus
269      *            true installed, false uninstalled
270      */
271     public void setStatus( boolean bStatus )
272     {
273         _bIsInstalled = bStatus;
274     }
275 
276     /**
277      * Updates a database connection pool associated to the plugin and stores it
278      * 
279      * @param strPoolName
280      *            the name of the pool
281      */
282     public void updatePoolName( String strPoolName )
283     {
284         _strDbPoolName = strPoolName;
285         _connectionService.setPool( strPoolName );
286         update( );
287 
288         notifyListeners( PluginEvent.PLUGIN_POOL_CHANGED );
289     }
290 
291     /**
292      * Updates a database connection pool associated to the plugin and stores it
293      * 
294      * @param strPoolName
295      *            The name of the pool
296      */
297     public void setPoolName( String strPoolName )
298     {
299         _strDbPoolName = strPoolName;
300     }
301 
302     /**
303      * Gets the current database connection pool associated to the plugin
304      * 
305      * @return The name of the database for the pool checked
306      */
307     public String getDbPoolName( )
308     {
309         return _strDbPoolName;
310     }
311 
312     /**
313      * Creates a new right in the rights set
314      */
315     protected void registerRights( )
316     {
317         for ( Right right : _listRights )
318         {
319             RightHome.remove( right.getId( ) );
320 
321             if ( !( right.getId( ).equals( "" ) ) )
322             {
323                 RightHome.create( right );
324             }
325         }
326     }
327 
328     /**
329      * Remove a right from the rights set.
330      */
331     protected void unregisterRights( )
332     {
333         for ( Right right : _listRights )
334         {
335             if ( ( right != null ) && ( !( right.getId( ).equals( "" ) ) ) )
336             {
337                 RightHome.remove( right.getId( ) );
338             }
339         }
340     }
341 
342     /**
343      * Creates a new portlet in the portlets type set
344      */
345     protected void registerPortlets( )
346     {
347         for ( PortletType portletType : _listPortletTypes )
348         {
349             PortletTypeHome.remove( portletType.getId( ) );
350 
351             if ( ( portletType.getHomeClass( ) != null ) && ( !( portletType.getHomeClass( ).equals( "" ) ) ) )
352             {
353                 PortletTypeHome.create( portletType );
354             }
355         }
356     }
357 
358     /**
359      * Remove a portlet from the portlets type set.
360      */
361     protected void unregisterPortlets( )
362     {
363         for ( PortletType portletType : _listPortletTypes )
364         {
365             PortletTypeHome.remove( portletType.getId( ) );
366         }
367     }
368 
369     /**
370      * Register XPage applications
371      * 
372      * @throws LuteceInitException
373      *             If an error occurs
374      */
375     protected void registerXPageApplications( ) throws LuteceInitException
376     {
377         for ( XPageApplicationEntry entry : _listXPageApplications )
378         {
379             entry.setPluginName( getName( ) );
380             XPageAppService.registerXPageApplication( entry );
381         }
382     }
383 
384     /**
385      * Register Filters
386      * 
387      * @throws LuteceInitException
388      *             If an error occurs
389      */
390     protected void registerFilters( ) throws LuteceInitException
391     {
392         for ( FilterEntry entry : _listFilters )
393         {
394             FilterService.getInstance( ).registerFilter( entry, this );
395         }
396     }
397 
398     /**
399      * Register Servlets
400      * 
401      * @throws LuteceInitException
402      *             If an error occurs
403      */
404     protected void registerServlets( ) throws LuteceInitException
405     {
406         for ( ServletEntry entry : _listServlets )
407         {
408             ServletService.getInstance( ).registerServlet( entry, this );
409         }
410     }
411 
412     /**
413      * Register listeners
414      * 
415      * @throws LuteceInitException
416      *             if an error occurs
417      */
418     protected void registerListeners( ) throws LuteceInitException
419     {
420         for ( HttpSessionListenerEntry entry : _listListeners )
421         {
422             HttpSessionListenerService.registerListener( entry );
423         }
424     }
425 
426     /**
427      * Register Content Services
428      * 
429      * @throws LuteceInitException
430      *             If an error occurs
431      */
432     protected void registerContentServices( ) throws LuteceInitException
433     {
434         for ( ContentServiceEntry entry : _listContentServices )
435         {
436             try
437             {
438                 ContentService./../../../../fr/paris/lutece/portal/service/content/ContentService.html#ContentService">ContentService cs = (ContentService) Class.forName( entry.getClassName( ) ).newInstance( );
439 
440                 cs.setPluginName( getName( ) );
441 
442                 PortalService.registerContentService( cs.getName( ), cs );
443             }
444             catch( InstantiationException | ClassNotFoundException | IllegalAccessException e )
445             {
446                 throw new LuteceInitException( e.getMessage( ), e );
447             }
448         }
449     }
450 
451     /**
452      * Register Insert Services
453      * 
454      * @throws LuteceInitException
455      *             If an error occurs
456      */
457     protected void registerInsertServices( ) throws LuteceInitException
458     {
459         for ( InsertService is : _listInsertServices )
460         {
461             is.setPluginName( getName( ) );
462             InsertServiceManager.registerInsertService( is );
463         }
464     }
465 
466     /**
467      * Register Search Indexers
468      * 
469      * @throws LuteceInitException
470      *             If an error occurs
471      */
472     protected void registerSearchIndexers( ) throws LuteceInitException
473     {
474         for ( SearchIndexerEntry entry : _listSearchIndexers )
475         {
476             try
477             {
478                 SearchIndexer/../../../fr/paris/lutece/portal/service/search/SearchIndexer.html#SearchIndexer">SearchIndexer indexer = (SearchIndexer) Class.forName( entry.getClassName( ) ).newInstance( );
479                 IndexationService.registerIndexer( indexer );
480             }
481             catch( IllegalAccessException | ClassNotFoundException | InstantiationException e )
482             {
483                 throw new LuteceInitException( e.getMessage( ), e );
484             }
485         }
486     }
487 
488     /**
489      * Register Page Includes
490      * 
491      * @throws LuteceInitException
492      *             If an error occured
493      */
494     protected void registerPageIncludes( ) throws LuteceInitException
495     {
496         for ( PageIncludeEntry entry : _listPageIncludes )
497         {
498             entry.setPluginName( getName( ) );
499             PageIncludeService.registerPageInclude( entry );
500         }
501     }
502 
503     /**
504      * Register Dashboard Components
505      * 
506      * @throws LuteceInitException
507      *             If an error occured
508      */
509     protected void registerDashboardComponents( ) throws LuteceInitException
510     {
511         for ( DashboardComponentEntry entry : _listDashboardComponents )
512         {
513             DashboardService.getInstance( ).registerDashboardComponent( entry, this );
514         }
515     }
516 
517     /**
518      * Register Admin Dashboard Components
519      * 
520      * @throws LuteceInitException
521      *             If an error occured
522      */
523     protected void registerAdminDashboardComponents( ) throws LuteceInitException
524     {
525         for ( DashboardComponentEntry entry : _listAdminDashboardComponents )
526         {
527             AdminDashboardService.getInstance( ).registerDashboardComponent( entry, this );
528         }
529     }
530 
531     /**
532      * Register RBAC Resource Types
533      * 
534      * @throws LuteceInitException
535      *             If an error occurs
536      */
537     protected void registerRBACResourceTypes( ) throws LuteceInitException
538     {
539         for ( RBACResourceTypeEntry entry : _listRBACResourceTypes )
540         {
541             ResourceIdService ris;
542 
543             try
544             {
545                 ris = (ResourceIdService) Class.forName( entry.getClassName( ) ).newInstance( );
546                 // Each resource id service should register itself and its permissions
547                 ris.register( );
548             }
549             catch( InstantiationException | ClassNotFoundException | IllegalAccessException e )
550             {
551                 throw new LuteceInitException( e.getMessage( ), e );
552             }
553         }
554     }
555 
556     /**
557      * Register Daemons
558      * 
559      * @throws LuteceInitException
560      *             If an error occurs
561      */
562     protected void registerDaemons( ) throws LuteceInitException
563     {
564         for ( DaemonEntry entry : _listDaemons )
565         {
566             entry.setPluginName( getName( ) );
567             AppDaemonService.registerDaemon( entry );
568         }
569     }
570 
571     /**
572      * Installs a Plugin
573      */
574     public void install( )
575     {
576         // Register a new right for the plugin
577         registerRights( );
578 
579         // Register a new portlets as plugin
580         registerPortlets( );
581 
582         _bIsInstalled = true;
583         update( );
584 
585         notifyListeners( PluginEvent.PLUGIN_INSTALLED );
586     }
587 
588     /**
589      * Uninstalls a Plugin
590      */
591     public void uninstall( )
592     {
593         // Unregister a new right for the plugin
594         unregisterRights( );
595 
596         // Unregister a new portlets as plugin
597         unregisterPortlets( );
598         _bIsInstalled = false;
599         update( );
600 
601         notifyListeners( PluginEvent.PLUGIN_UNINSTALLED );
602     }
603 
604     /**
605      * Notifiy Listener
606      * 
607      * @param nEventType
608      *            The event type
609      */
610     private void notifyListeners( int nEventType )
611     {
612         PluginEventvice/plugin/PluginEvent.html#PluginEvent">PluginEvent event = new PluginEvent( this, nEventType );
613         PluginService.notifyListeners( event );
614     }
615 
616     /**
617      * Returns the type of the plugin
618      *
619      * @return the plugin type as a int
620      */
621     public int getType( )
622     {
623         // Load the Type
624         int nPluginTypeFlags = 0;
625 
626         if ( CollectionUtils.isNotEmpty( _listXPageApplications ) )
627         {
628             nPluginTypeFlags |= PLUGIN_TYPE_APPLICATION;
629         }
630 
631         if ( CollectionUtils.isNotEmpty( _listPortletTypes ) )
632         {
633             nPluginTypeFlags |= PLUGIN_TYPE_PORTLET;
634         }
635 
636         if ( CollectionUtils.isNotEmpty( _listRights ) )
637         {
638             nPluginTypeFlags |= PLUGIN_TYPE_FEATURE;
639         }
640 
641         if ( CollectionUtils.isNotEmpty( _listInsertServices ) )
642         {
643             nPluginTypeFlags |= PLUGIN_TYPE_INSERTSERVICE;
644         }
645 
646         if ( CollectionUtils.isNotEmpty( _listContentServices ) )
647         {
648             nPluginTypeFlags |= PLUGIN_TYPE_CONTENTSERVICE;
649         }
650 
651         if ( CollectionUtils.isNotEmpty( _listDaemons ) )
652         {
653             nPluginTypeFlags |= PLUGIN_TYPE_DAEMON;
654         }
655 
656         return nPluginTypeFlags;
657     }
658 
659     /**
660      * Returns the list of insert services of the plugin
661      *
662      * @return the plugin list of ContentServiceEntry
663      */
664     public List<InsertService> getInsertServices( )
665     {
666         return _listInsertServices;
667     }
668 
669     /**
670      * Returns the list of Content services of the plugin
671      *
672      * @return the plugin list of ContentServiceEntry
673      */
674     public List<ContentServiceEntry> getContentServices( )
675     {
676         return _listContentServices;
677     }
678 
679     /**
680      * Returns the list of XPage Applications of the plugin
681      *
682      * @return the plugin list of XPageApplicationEntry
683      */
684     public List<XPageApplicationEntry> getApplications( )
685     {
686         return _listXPageApplications;
687     }
688 
689     /**
690      * Returns the list of portlet type of the plugin
691      *
692      * @return the plugin list of portlet type
693      */
694     public List<PortletType> getPortletTypes( )
695     {
696         return _listPortletTypes;
697     }
698 
699     /**
700      * Sets the list of portlet type
701      *
702      * @param listPortletTypes
703      *            The portlet type list
704      */
705     public void setPortletTypes( List<PortletType> listPortletTypes )
706     {
707         _listPortletTypes = listPortletTypes;
708     }
709 
710     /**
711      * Returns the list of portlet type of the plugin
712      *
713      * @return the plugin list of rights
714      */
715     public List<Right> getRights( )
716     {
717         return _listRights;
718     }
719 
720     /**
721      * Sets plugin rights list
722      *
723      * @param listRights
724      *            The rights list
725      */
726     public void setRights( List<Right> listRights )
727     {
728         _listRights = listRights;
729     }
730 
731     /**
732      * Returns the name of the plugin
733      *
734      * @return the plugin name as a String
735      */
736     public String getName( )
737     {
738         return _strName;
739     }
740 
741     /**
742      * Sets the name of the plugin
743      *
744      * @param strName
745      *            The plugin name
746      */
747     public void setName( String strName )
748     {
749         _strName = strName;
750     }
751 
752     /**
753      * Returns the version of the plugin
754      *
755      * @return the plugin version as a String
756      */
757     public String getVersion( )
758     {
759         return _strVersion;
760     }
761 
762     /**
763      * Sets the version plugin name
764      * 
765      * @param strVersion
766      *            The version
767      */
768     public void setVersion( String strVersion )
769     {
770         _strVersion = strVersion;
771     }
772 
773     /**
774      * Returns the description of the plugin
775      *
776      * @return the plugin description as a String
777      */
778     public String getDescription( )
779     {
780         return _strDescription;
781     }
782 
783     /**
784      * Sets the description of the plugin
785      *
786      * @param strDescription
787      *            The description
788      */
789     public void setDescription( String strDescription )
790     {
791         _strDescription = strDescription;
792     }
793 
794     /**
795      * Returns the Provider of the plugin
796      *
797      * @return the plugin Provider as a String
798      */
799     public String getProvider( )
800     {
801         return _strProvider;
802     }
803 
804     /**
805      * Sets the provider name
806      *
807      * @param strProvider
808      *            The provider name
809      */
810     public void setProvider( String strProvider )
811     {
812         _strProvider = strProvider;
813     }
814 
815     /**
816      * Returns the Provider's URL of the plugin
817      *
818      * @return the plugin Provider's URL as a String
819      */
820     public String getProviderUrl( )
821     {
822         return _strProviderUrl;
823     }
824 
825     /**
826      * Sets the provider url
827      *
828      * @param strProviderUrl
829      *            the name of the provider
830      */
831     public void setProviderUrl( String strProviderUrl )
832     {
833         _strProviderUrl = strProviderUrl;
834     }
835 
836     /**
837      * Returns the Icon's URL of the plugin
838      *
839      * @return the plugin Icon's URL as a String
840      */
841     public String getIconUrl( )
842     {
843         return _strIconUrl;
844     }
845 
846     /**
847      * Sets the url of the plugin's icon
848      *
849      * @param strIconUrl
850      *            The url of icon
851      */
852     public void setIconUrl( String strIconUrl )
853     {
854         _strIconUrl = strIconUrl;
855     }
856 
857     /**
858      * Returns the Documentation's URL of the plugin
859      *
860      * @return the plugin Documentation's URL as a String
861      */
862     public String getDocumentationUrl( )
863     {
864         return _strDocumentationUrl;
865     }
866 
867     /**
868      * Sets the url of the plugin's Documentation
869      *
870      * @param strDocumentationUrl
871      *            The documentation Url
872      */
873     public void setDocumentationUrl( String strDocumentationUrl )
874     {
875         _strDocumentationUrl = strDocumentationUrl;
876     }
877 
878     /**
879      * Returns the Copyright of the plugin
880      *
881      * @return the plugin Copyright as a String
882      */
883     public String getCopyright( )
884     {
885         return _strCopyright;
886     }
887 
888     /**
889      * Sets the copyright
890      *
891      * @param strCopyright
892      *            The copyright
893      */
894     public void setCopyright( String strCopyright )
895     {
896         _strCopyright = strCopyright;
897     }
898 
899     /**
900      * Returns the main Class of the plugin
901      *
902      * @return the Class as a String
903      */
904     public String getServiceClass( )
905     {
906         return _strPluginClass;
907     }
908 
909     /**
910      * Sets the class service of plugin
911      *
912      * @param strPluginClass
913      *            The plugin class
914      */
915     public void setServiceClass( String strPluginClass )
916     {
917         _strPluginClass = strPluginClass;
918     }
919 
920     /**
921      * Returns the installation status of the plugin
922      *
923      * @return the installation status as an int
924      */
925     public boolean isInstalled( )
926     {
927         return _bIsInstalled;
928     }
929 
930     /**
931      * Sets the boolean which shows if the plugin is installed
932      *
933      * @param bIsInstalled
934      *            The installed boolean
935      */
936     public void setIsInstalled( boolean bIsInstalled )
937     {
938         _bIsInstalled = bIsInstalled;
939     }
940 
941     /**
942      * Returns the min core version compatibility for the plugin
943      *
944      * @return the min core version as a String
945      */
946     public String getMinCoreVersion( )
947     {
948         return _strMinCoreVersion;
949     }
950 
951     /**
952      * Sets the the min core version compatibility for the plugin
953      *
954      * @param strMinCoreVersion
955      *            The min core version
956      */
957     public void setMinCoreVersion( String strMinCoreVersion )
958     {
959         _strMinCoreVersion = strMinCoreVersion;
960     }
961 
962     /**
963      * Returns the max core version compatibility for the plugin
964      *
965      * @return the max core version as a String
966      */
967     public String getMaxCoreVersion( )
968     {
969         return _strMaxCoreVersion;
970     }
971 
972     /**
973      * Sets the the max core version compatibility for the plugin
974      *
975      * @param strMaxCoreVersion
976      *            The max core version
977      */
978     public void setMaxCoreVersion( String strMaxCoreVersion )
979     {
980         _strMaxCoreVersion = strMaxCoreVersion;
981     }
982 
983     /**
984      * Returns if the plugin needs a database connection pool
985      *
986      * @return <b>true</b> if the plugin needs a database connection pool, otherwise <b>false</b>
987      */
988     public boolean isDbPoolRequired( )
989     {
990         return _bDbPoolRequired;
991     }
992 
993     /**
994      * Sets the boolean which shows if a pool is required
995      *
996      * @param bDbPoolRequired
997      *            The dbpool boolean
998      */
999     public void setIsDbPoolRequired( boolean bDbPoolRequired )
1000     {
1001         _bDbPoolRequired = bDbPoolRequired;
1002     }
1003 
1004     /**
1005      * Returns a Connection Service associated to the plugin
1006      * 
1007      * @return _connectionService The connection service
1008      */
1009     public PluginConnectionService getConnectionService( )
1010     {
1011         return _connectionService;
1012     }
1013 
1014     /**
1015      * Sets the connection service
1016      *
1017      * @param connectionService
1018      *            The connection Service object
1019      */
1020     public void setConnectionService( PluginConnectionService connectionService )
1021     {
1022         _connectionService = connectionService;
1023     }
1024 
1025     /**
1026      * Initializes the plugin's ConnectionService
1027      *
1028      * @param strPoolName
1029      *            The pool name
1030      */
1031     public void initConnectionService( String strPoolName )
1032     {
1033         _connectionService = new PluginConnectionService( strPoolName );
1034     }
1035 
1036     /**
1037      * Gets plugin's parameters
1038      * 
1039      * @return _mapParams The hastable of parameters
1040      */
1041     public Map<String, String> getParams( )
1042     {
1043         return _mapParams;
1044     }
1045 
1046     /**
1047      * Gets a parameter value for a given parameter name
1048      * 
1049      * @param strParamName
1050      *            The name of the parameter
1051      * @return null
1052      */
1053     public String getParamValue( String strParamName )
1054     {
1055         if ( !_mapParams.containsKey( strParamName ) )
1056         {
1057             return null;
1058         }
1059 
1060         return _mapParams.get( strParamName );
1061     }
1062 
1063     /**
1064      * Sets parameters values with an hashtable
1065      * 
1066      * @param mapParams
1067      *            The parameter map
1068      */
1069     public void setParams( Map<String, String> mapParams )
1070     {
1071         _mapParams = mapParams;
1072     }
1073 
1074     /**
1075      * Sets a parameter value for a given parameter name
1076      * 
1077      * @param strParamName
1078      *            The name of the parameter
1079      * @param strParamValue
1080      *            The value of the parameter
1081      */
1082     public void setParamValue( String strParamName, String strParamValue )
1083     {
1084         if ( _mapParams.containsKey( strParamName ) )
1085         {
1086             _mapParams.put( strParamName, strParamValue );
1087         }
1088     }
1089 
1090     /**
1091      * Implementation of the Comparable interface.
1092      * 
1093      * @param plugin
1094      *            A plugin Object
1095      * @return 1, 0 ou -1 according the plugin name
1096      */
1097     @Override
1098     public int compareTo( Plugin plugin )
1099     {
1100         Comparator<String> comparator = String.CASE_INSENSITIVE_ORDER;
1101 
1102         return comparator.compare( getName( ), plugin.getName( ) );
1103     }
1104 
1105     /**
1106      * {@inheritDoc}
1107      */
1108     @Override
1109     public boolean equals( Object o )
1110     {
1111         if ( !( o instanceof Plugin ) )
1112         {
1113             return false;
1114         }
1115 
1116         return compareTo( (Plugin) o ) == 0;
1117     }
1118 
1119     /**
1120      * Returns all CSS Style Sheets of the plugin with no mode associated
1121      * 
1122      * @return The list of CSS Style Sheets with no mode associated
1123      */
1124     public List<String> getCssStyleSheets( )
1125     {
1126         List<String> res = _listCssStyleSheets.get( null );
1127 
1128         if ( res == null )
1129         {
1130             return Collections.emptyList( );
1131         }
1132 
1133         return res;
1134     }
1135 
1136     /**
1137      * Returns all CSS Style Sheets of the plugin associated with a mode
1138      * 
1139      * @param mode
1140      *            the mode
1141      * @return The list of CSS Style Sheets associated with the mode
1142      * @since 5.1.0
1143      */
1144     public List<String> getCssStyleSheets( int mode )
1145     {
1146         List<String> res = _listCssStyleSheets.get( mode );
1147 
1148         if ( res == null )
1149         {
1150             return Collections.emptyList( );
1151         }
1152 
1153         return res;
1154     }
1155 
1156     /**
1157      * Returns the theme the plugin use for rendering a Xpage
1158      * 
1159      * @param request
1160      *            The HttpServletRequest
1161      * @return The theme
1162      */
1163     public Theme getXPageTheme( HttpServletRequest request )
1164     {
1165         return null;
1166     }
1167 
1168     /**
1169      * Add an Javascript File to the plugin definition, not associated with a mode
1170      * 
1171      * @param strJavascriptFile
1172      *            The Javascript File path
1173      */
1174     public void addJavascriptFile( String strJavascriptFile )
1175     {
1176         List<String> files = _listJavascriptFiles.computeIfAbsent( null, s -> new ArrayList<>( ) );
1177         files.add( strJavascriptFile );
1178     }
1179 
1180     /**
1181      * Returns all Javascript File of the plugin with no mode associated
1182      * 
1183      * @return The list of Javascript File with no mode associated
1184      */
1185     public List<String> getJavascriptFiles( )
1186     {
1187         List<String> res = _listJavascriptFiles.get( null );
1188 
1189         if ( res == null )
1190         {
1191             return Collections.emptyList( );
1192         }
1193 
1194         return res;
1195     }
1196 
1197     /**
1198      * Returns all Javascript File of the plugin associated with a mode
1199      * 
1200      * @param mode
1201      *            the mode
1202      * @return The list of Javascript File with associated with the mode
1203      * @since 5.1.0
1204      */
1205     public List<String> getJavascriptFiles( int mode )
1206     {
1207         List<String> res = _listJavascriptFiles.get( mode );
1208 
1209         if ( res == null )
1210         {
1211             return Collections.emptyList( );
1212         }
1213 
1214         return res;
1215     }
1216 
1217     /**
1218      * Give the scope of css stylesheets
1219      * 
1220      * @return true if scope is portal otherwise false
1221      */
1222     public boolean isCssStylesheetsScopePortal( )
1223     {
1224         return ( ( _strCssStylesheetsScope != null ) && _strCssStylesheetsScope.equalsIgnoreCase( SCOPE_PORTAL ) );
1225     }
1226 
1227     /**
1228      * Give the scope of css stylesheets
1229      * 
1230      * @return true if scope is portal otherwise false
1231      */
1232     public boolean isCssStylesheetsScopeXPage( )
1233     {
1234         return ( ( _strCssStylesheetsScope != null ) && _strCssStylesheetsScope.equalsIgnoreCase( SCOPE_XPAGE ) );
1235     }
1236 
1237     /**
1238      * Give the scope of javascripts
1239      * 
1240      * @return true if scope is portal otherwise false
1241      */
1242     public boolean isJavascriptFilesScopePortal( )
1243     {
1244         return ( ( _strJavascriptFilesScope != null ) && _strJavascriptFilesScope.equalsIgnoreCase( SCOPE_PORTAL ) );
1245     }
1246 
1247     /**
1248      * Give the scope of javascripts
1249      * 
1250      * @return true if scope is portal otherwise false
1251      */
1252     public boolean isJavascriptFilesScopeXPage( )
1253     {
1254         return ( ( _strJavascriptFilesScope != null ) && _strJavascriptFilesScope.equalsIgnoreCase( SCOPE_XPAGE ) );
1255     }
1256 
1257     /**
1258      * Return the list of stylesheets that should be used in the Back Office
1259      * 
1260      * @return the list of stylesheets that should be used in the Back Office
1261      * @since 5.1
1262      */
1263     public List<String> getAdminCssStyleSheets( )
1264     {
1265         return _listAdminCssStyleSheets;
1266     }
1267 
1268     /**
1269      * Return the list of Javascript Files that should be used in the Back Office
1270      * 
1271      * @return the list of Javascript Files that should be used in the Back Office
1272      * @since 5.1
1273      */
1274     public List<String> getAdminJavascriptFiles( )
1275     {
1276         return _listAdminJavascriptFiles;
1277     }
1278 
1279     /**
1280      * Adds a that file that will be autoincluded in freemarker templates
1281      * 
1282      * @param strMacroFileName
1283      *            the file name
1284      */
1285     @Deprecated
1286     public void addFreemarkerMacrosFile( String strMacroFileName )
1287     {
1288         _listFreemarkerAutoIncludes.add( strMacroFileName );
1289     }
1290 
1291     /**
1292      * Gets the free marker macros files.
1293      *
1294      * @return the free marker macros files
1295      */
1296     @Deprecated
1297     public List<String> getFreeMarkerMacrosFiles( )
1298     {
1299         return _listFreemarkerAutoIncludes;
1300     }
1301 
1302     /**
1303      * Adds a file that will be autoincluded in freemarker templates
1304      * 
1305      * @param strFileName
1306      *            the file name
1307      */
1308     public void addFreemarkerAutoInclude( String strFileName )
1309     {
1310         _listFreemarkerAutoIncludes.add( strFileName );
1311     }
1312 
1313     /**
1314      * Gets the freemarker auto-includes.
1315      *
1316      * @return the freemarker auto-includes
1317      */
1318     public List<String> getFreeMarkerAutoIncludes( )
1319     {
1320         return _listFreemarkerAutoIncludes;
1321     }
1322 
1323     /**
1324      * Adds a file that will be autoimported in freemarker templates
1325      * 
1326      * @param strNamespace
1327      *            The namespace corresponding to the import file
1328      * @param strFileName
1329      *            the file name
1330      */
1331     public void addFreemarkerAutoImport( String strNamespace, String strFileName )
1332     {
1333         _mapFreemarkerAutoImports.put( strNamespace, strFileName );
1334     }
1335 
1336     /**
1337      * Gets the freemarker auto-imports.
1338      *
1339      * @return the freemarker auto-imports
1340      */
1341     public Map<String,String> getFreeMarkerAutoImports( )
1342     {
1343         return _mapFreemarkerAutoImports;
1344     }
1345 
1346     /**
1347      * Useful for debugging
1348      *
1349      * @return The plugin object in String format
1350      */
1351     @Override
1352     public String toString( )
1353     {
1354         return getName( );
1355     }
1356 
1357     /**
1358      * {@inheritDoc}
1359      */
1360     @Override
1361     public int hashCode( )
1362     {
1363         if ( getName( ) == null )
1364         {
1365             return 0;
1366         }
1367 
1368         return getName( ).toLowerCase( ).hashCode( );
1369     }
1370 }