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