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