Plugin.java

  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. import fr.paris.lutece.portal.business.portlet.PortletType;
  36. import fr.paris.lutece.portal.business.portlet.PortletTypeHome;
  37. import fr.paris.lutece.portal.business.right.Right;
  38. import fr.paris.lutece.portal.business.right.RightHome;
  39. import fr.paris.lutece.portal.business.style.Theme;
  40. import fr.paris.lutece.portal.service.content.ContentService;
  41. import fr.paris.lutece.portal.service.content.ContentServiceEntry;
  42. import fr.paris.lutece.portal.service.content.XPageAppService;
  43. import fr.paris.lutece.portal.service.daemon.AppDaemonService;
  44. import fr.paris.lutece.portal.service.daemon.DaemonEntry;
  45. import fr.paris.lutece.portal.service.dashboard.DashboardComponentEntry;
  46. import fr.paris.lutece.portal.service.dashboard.DashboardService;
  47. import fr.paris.lutece.portal.service.dashboard.admin.AdminDashboardService;
  48. import fr.paris.lutece.portal.service.database.PluginConnectionService;
  49. import fr.paris.lutece.portal.service.filter.FilterEntry;
  50. import fr.paris.lutece.portal.service.filter.FilterService;
  51. import fr.paris.lutece.portal.service.includes.PageIncludeEntry;
  52. import fr.paris.lutece.portal.service.includes.PageIncludeService;
  53. import fr.paris.lutece.portal.service.init.LuteceInitException;
  54. import fr.paris.lutece.portal.service.insert.InsertService;
  55. import fr.paris.lutece.portal.service.insert.InsertServiceManager;
  56. import fr.paris.lutece.portal.service.portal.PortalService;
  57. import fr.paris.lutece.portal.service.rbac.RBACResourceTypeEntry;
  58. import fr.paris.lutece.portal.service.rbac.ResourceIdService;
  59. import fr.paris.lutece.portal.service.search.IndexationService;
  60. import fr.paris.lutece.portal.service.search.SearchIndexer;
  61. import fr.paris.lutece.portal.service.search.SearchIndexerEntry;
  62. import fr.paris.lutece.portal.service.servlet.ServletEntry;
  63. import fr.paris.lutece.portal.service.servlet.ServletService;
  64. import fr.paris.lutece.portal.service.sessionlistener.HttpSessionListenerEntry;
  65. import fr.paris.lutece.portal.service.sessionlistener.HttpSessionListenerService;
  66. import fr.paris.lutece.portal.service.util.AppPropertiesService;
  67. import fr.paris.lutece.portal.web.xpages.XPageApplicationEntry;

  68. import java.util.ArrayList;
  69. import java.util.Collections;
  70. import java.util.Comparator;
  71. import java.util.HashMap;
  72. import java.util.List;
  73. import java.util.Map;

  74. import javax.servlet.http.HttpServletRequest;

  75. import org.apache.commons.collections.CollectionUtils;

  76. /**
  77.  * This class is the general plugin element
  78.  */
  79. public abstract class Plugin implements Comparable<Plugin>
  80. {
  81.     // Constantes
  82.     public static final int PLUGIN_TYPE_FEATURE = 0x01;
  83.     public static final int PLUGIN_TYPE_PORTLET = 0x02;
  84.     public static final int PLUGIN_TYPE_APPLICATION = 0x04;
  85.     public static final int PLUGIN_TYPE_INSERTSERVICE = 0x08;
  86.     public static final int PLUGIN_TYPE_CONTENTSERVICE = 0x10;
  87.     public static final int PLUGIN_TYPE_DAEMON = 0x20;
  88.     private static final String PROPERTY_DEFAULT_ICON_URL = "plugin.image.defaultIconUrl";
  89.     private static final String SCOPE_PORTAL = "portal";
  90.     private static final String SCOPE_XPAGE = "xpage";

  91.     // Variables
  92.     private String _strName;
  93.     private String _strVersion;
  94.     private String _strDescription;
  95.     private String _strProvider;
  96.     private String _strProviderUrl;
  97.     private String _strCopyright;
  98.     private String _strPluginClass;
  99.     private String _strDbPoolName;
  100.     private String _strIconUrl;
  101.     private String _strDocumentationUrl;
  102.     private String _strMinCoreVersion;
  103.     private String _strMaxCoreVersion;
  104.     private boolean _bIsInstalled;
  105.     private boolean _bDbPoolRequired;
  106.     private ContentService _contentService;
  107.     private String _strCssStylesheetsScope;
  108.     private String _strJavascriptFilesScope;

  109.     // Lists of rights and portlets of the plugin
  110.     private List<XPageApplicationEntry> _listXPageApplications;
  111.     private List<FilterEntry> _listFilters;
  112.     private List<ServletEntry> _listServlets;
  113.     private List<HttpSessionListenerEntry> _listListeners;
  114.     private Map<Integer, List<String>> _listCssStyleSheets;
  115.     private Map<Integer, List<String>> _listJavascriptFiles;
  116.     private List<String> _listAdminCssStyleSheets;
  117.     private List<String> _listAdminJavascriptFiles;
  118.     private List<Right> _listRights;
  119.     private List<PortletType> _listPortletTypes;
  120.     private List<ContentServiceEntry> _listContentServices;
  121.     private List<SearchIndexerEntry> _listSearchIndexers;
  122.     private List<InsertService> _listInsertServices;
  123.     private List<PageIncludeEntry> _listPageIncludes;
  124.     private List<DashboardComponentEntry> _listDashboardComponents;
  125.     private List<DashboardComponentEntry> _listAdminDashboardComponents;
  126.     private List<RBACResourceTypeEntry> _listRBACResourceTypes;
  127.     private List<DaemonEntry> _listDaemons;
  128.     private List<String> _listFreemarkerMacrosFiles;

  129.     // hashtable which contains all the params described in the xml plugin file
  130.     private Map<String, String> _mapParams = new HashMap<>( );
  131.     private PluginConnectionService _connectionService;

  132.     /**
  133.      * Initializes the plugin at the first load
  134.      *
  135.      */
  136.     public abstract void init( );

  137.     /**
  138.      * Load plugin's data from the plugin's xml file.
  139.      *
  140.      * @param pluginFile
  141.      *            The plugin file object
  142.      * @throws LuteceInitException
  143.      *             If an error occured
  144.      */
  145.     void load( PluginFile pluginFile ) throws LuteceInitException
  146.     {
  147.         try
  148.         {
  149.             _strName = pluginFile.getName( );
  150.             _strVersion = pluginFile.getVersion( );
  151.             _strDescription = pluginFile.getDescription( );
  152.             _strProvider = pluginFile.getProvider( );
  153.             _strProviderUrl = pluginFile.getProviderUrl( );

  154.             String strDefaultIconUrl = AppPropertiesService.getProperty( PROPERTY_DEFAULT_ICON_URL );
  155.             _strIconUrl = pluginFile.getIconUrl( ).equals( "" ) ? strDefaultIconUrl : pluginFile.getIconUrl( );
  156.             _strDocumentationUrl = pluginFile.getDocumentationUrl( );
  157.             _strCopyright = pluginFile.getCopyright( );
  158.             _strPluginClass = pluginFile.getPluginClass( );
  159.             _strMinCoreVersion = pluginFile.getMinCoreVersion( );
  160.             _strMaxCoreVersion = pluginFile.getMaxCoreVersion( );
  161.             _listXPageApplications = pluginFile.getXPageApplications( );
  162.             _listFilters = pluginFile.getFilters( );
  163.             _listServlets = pluginFile.getServlets( );
  164.             _listListeners = pluginFile.getListeners( );
  165.             _listRights = pluginFile.getRights( );
  166.             _listPortletTypes = pluginFile.getPortletTypes( );
  167.             _listContentServices = pluginFile.getContentServices( );
  168.             _listInsertServices = pluginFile.getInsertServices( );
  169.             _listSearchIndexers = pluginFile.getSearchIndexers( );
  170.             _listPageIncludes = pluginFile.getPageIncludes( );
  171.             _listDashboardComponents = pluginFile.getDashboardComponents( );
  172.             _listAdminDashboardComponents = pluginFile.getAdminDashboardComponents( );
  173.             _listRBACResourceTypes = pluginFile.getRBACResourceTypes( );
  174.             _listDaemons = pluginFile.getDaemons( );
  175.             _mapParams = pluginFile.getParams( );
  176.             _bDbPoolRequired = pluginFile.isDbPoolRequired( );

  177.             _listCssStyleSheets = pluginFile.getCssStyleSheetsForAllModes( );
  178.             _strCssStylesheetsScope = ( pluginFile.getCssStylesheetsScope( ) != null ) ? pluginFile.getCssStylesheetsScope( ) : SCOPE_XPAGE;
  179.             _listJavascriptFiles = pluginFile.getJavascriptFilesForAllModes( );
  180.             _strJavascriptFilesScope = ( pluginFile.getJavascriptFilesScope( ) != null ) ? pluginFile.getJavascriptFilesScope( ) : SCOPE_XPAGE;
  181.             _listFreemarkerMacrosFiles = pluginFile.getFreemarkerMacrosFiles( );
  182.             _listAdminCssStyleSheets = pluginFile.getAdminCssStyleSheets( );
  183.             _listAdminJavascriptFiles = pluginFile.getAdminJavascriptFiles( );
  184.             // Register plugin components
  185.             registerXPageApplications( );
  186.             registerFilters( );
  187.             registerServlets( );
  188.             registerListeners( );
  189.             registerContentServices( );
  190.             registerInsertServices( );
  191.             registerSearchIndexers( );
  192.             registerPageIncludes( );
  193.             registerDashboardComponents( );
  194.             registerAdminDashboardComponents( );
  195.             registerRBACResourceTypes( );
  196.             registerDaemons( );
  197.         }
  198.         catch( Exception e )
  199.         {
  200.             throw new LuteceInitException( "Error loading plugin : " + e.getMessage( ), e );
  201.         }
  202.     }

  203.     /**
  204.      *
  205.      * @return the content service
  206.      */
  207.     public ContentService getContentService( )
  208.     {
  209.         return _contentService;
  210.     }

  211.     /**
  212.      * Returns weither or not plugin has portlet.
  213.      *
  214.      * @return true if the plugin contains one or more portlet
  215.      */
  216.     public boolean hasPortlets( )
  217.     {
  218.         return CollectionUtils.isNotEmpty( _listPortletTypes );
  219.     }

  220.     /**
  221.      * Returns weither or not plugin has daemon.
  222.      *
  223.      * @return true if the plugin contains one or more daemon
  224.      */
  225.     public boolean hasDaemons( )
  226.     {
  227.         return CollectionUtils.isNotEmpty( _listDaemons );
  228.     }

  229.     /**
  230.      * Returns The daemons list of the plugin.
  231.      *
  232.      * @return The daemons list of the plugin
  233.      */
  234.     public List<DaemonEntry> getDaemons( )
  235.     {
  236.         return _listDaemons;
  237.     }

  238.     /**
  239.      * Updates the plg file
  240.      */
  241.     protected void update( )
  242.     {
  243.         PluginService.updatePluginData( this );
  244.     }

  245.     /**
  246.      * Modify the plugin status
  247.      *
  248.      * @param bStatus
  249.      *            true installed, false uninstalled
  250.      */
  251.     public void setStatus( boolean bStatus )
  252.     {
  253.         _bIsInstalled = bStatus;
  254.     }

  255.     /**
  256.      * Updates a database connection pool associated to the plugin and stores it
  257.      *
  258.      * @param strPoolName
  259.      *            the name of the pool
  260.      */
  261.     public void updatePoolName( String strPoolName )
  262.     {
  263.         _strDbPoolName = strPoolName;
  264.         _connectionService.setPool( strPoolName );
  265.         update( );

  266.         notifyListeners( PluginEvent.PLUGIN_POOL_CHANGED );
  267.     }

  268.     /**
  269.      * Updates a database connection pool associated to the plugin and stores it
  270.      *
  271.      * @param strPoolName
  272.      *            The name of the pool
  273.      */
  274.     public void setPoolName( String strPoolName )
  275.     {
  276.         _strDbPoolName = strPoolName;
  277.     }

  278.     /**
  279.      * Gets the current database connection pool associated to the plugin
  280.      *
  281.      * @return The name of the database for the pool checked
  282.      */
  283.     public String getDbPoolName( )
  284.     {
  285.         return _strDbPoolName;
  286.     }

  287.     /**
  288.      * Creates a new right in the rights set
  289.      */
  290.     protected void registerRights( )
  291.     {
  292.         for ( Right right : _listRights )
  293.         {
  294.             RightHome.remove( right.getId( ) );

  295.             if ( !( right.getId( ).equals( "" ) ) )
  296.             {
  297.                 RightHome.create( right );
  298.             }
  299.         }
  300.     }

  301.     /**
  302.      * Remove a right from the rights set.
  303.      */
  304.     protected void unregisterRights( )
  305.     {
  306.         for ( Right right : _listRights )
  307.         {
  308.             if ( ( right != null ) && ( !( right.getId( ).equals( "" ) ) ) )
  309.             {
  310.                 RightHome.remove( right.getId( ) );
  311.             }
  312.         }
  313.     }

  314.     /**
  315.      * Creates a new portlet in the portlets type set
  316.      */
  317.     protected void registerPortlets( )
  318.     {
  319.         for ( PortletType portletType : _listPortletTypes )
  320.         {
  321.             PortletTypeHome.remove( portletType.getId( ) );

  322.             if ( ( portletType.getHomeClass( ) != null ) && ( !( portletType.getHomeClass( ).equals( "" ) ) ) )
  323.             {
  324.                 PortletTypeHome.create( portletType );
  325.             }
  326.         }
  327.     }

  328.     /**
  329.      * Remove a portlet from the portlets type set.
  330.      */
  331.     protected void unregisterPortlets( )
  332.     {
  333.         for ( PortletType portletType : _listPortletTypes )
  334.         {
  335.             PortletTypeHome.remove( portletType.getId( ) );
  336.         }
  337.     }

  338.     /**
  339.      * Register XPage applications
  340.      *
  341.      * @throws LuteceInitException
  342.      *             If an error occurs
  343.      */
  344.     protected void registerXPageApplications( ) throws LuteceInitException
  345.     {
  346.         for ( XPageApplicationEntry entry : _listXPageApplications )
  347.         {
  348.             entry.setPluginName( getName( ) );
  349.             XPageAppService.registerXPageApplication( entry );
  350.         }
  351.     }

  352.     /**
  353.      * Register Filters
  354.      *
  355.      * @throws LuteceInitException
  356.      *             If an error occurs
  357.      */
  358.     protected void registerFilters( ) throws LuteceInitException
  359.     {
  360.         for ( FilterEntry entry : _listFilters )
  361.         {
  362.             FilterService.getInstance( ).registerFilter( entry, this );
  363.         }
  364.     }

  365.     /**
  366.      * Register Servlets
  367.      *
  368.      * @throws LuteceInitException
  369.      *             If an error occurs
  370.      */
  371.     protected void registerServlets( ) throws LuteceInitException
  372.     {
  373.         for ( ServletEntry entry : _listServlets )
  374.         {
  375.             ServletService.getInstance( ).registerServlet( entry, this );
  376.         }
  377.     }

  378.     /**
  379.      * Register listeners
  380.      *
  381.      * @throws LuteceInitException
  382.      *             if an error occurs
  383.      */
  384.     protected void registerListeners( ) throws LuteceInitException
  385.     {
  386.         for ( HttpSessionListenerEntry entry : _listListeners )
  387.         {
  388.             HttpSessionListenerService.registerListener( entry );
  389.         }
  390.     }

  391.     /**
  392.      * Register Content Services
  393.      *
  394.      * @throws LuteceInitException
  395.      *             If an error occurs
  396.      */
  397.     protected void registerContentServices( ) throws LuteceInitException
  398.     {
  399.         for ( ContentServiceEntry entry : _listContentServices )
  400.         {
  401.             try
  402.             {
  403.                 ContentService cs = (ContentService) Class.forName( entry.getClassName( ) ).newInstance( );

  404.                 cs.setPluginName( getName( ) );

  405.                 PortalService.registerContentService( cs.getName( ), cs );
  406.             }
  407.             catch( InstantiationException | ClassNotFoundException | IllegalAccessException e )
  408.             {
  409.                 throw new LuteceInitException( e.getMessage( ), e );
  410.             }
  411.         }
  412.     }

  413.     /**
  414.      * Register Insert Services
  415.      *
  416.      * @throws LuteceInitException
  417.      *             If an error occurs
  418.      */
  419.     protected void registerInsertServices( ) throws LuteceInitException
  420.     {
  421.         for ( InsertService is : _listInsertServices )
  422.         {
  423.             is.setPluginName( getName( ) );
  424.             InsertServiceManager.registerInsertService( is );
  425.         }
  426.     }

  427.     /**
  428.      * Register Search Indexers
  429.      *
  430.      * @throws LuteceInitException
  431.      *             If an error occurs
  432.      */
  433.     protected void registerSearchIndexers( ) throws LuteceInitException
  434.     {
  435.         for ( SearchIndexerEntry entry : _listSearchIndexers )
  436.         {
  437.             try
  438.             {
  439.                 SearchIndexer indexer = (SearchIndexer) Class.forName( entry.getClassName( ) ).newInstance( );
  440.                 IndexationService.registerIndexer( indexer );
  441.             }
  442.             catch( IllegalAccessException | ClassNotFoundException | InstantiationException e )
  443.             {
  444.                 throw new LuteceInitException( e.getMessage( ), e );
  445.             }
  446.         }
  447.     }

  448.     /**
  449.      * Register Page Includes
  450.      *
  451.      * @throws LuteceInitException
  452.      *             If an error occured
  453.      */
  454.     protected void registerPageIncludes( ) throws LuteceInitException
  455.     {
  456.         for ( PageIncludeEntry entry : _listPageIncludes )
  457.         {
  458.             entry.setPluginName( getName( ) );
  459.             PageIncludeService.registerPageInclude( entry );
  460.         }
  461.     }

  462.     /**
  463.      * Register Dashboard Components
  464.      *
  465.      * @throws LuteceInitException
  466.      *             If an error occured
  467.      */
  468.     protected void registerDashboardComponents( ) throws LuteceInitException
  469.     {
  470.         for ( DashboardComponentEntry entry : _listDashboardComponents )
  471.         {
  472.             DashboardService.getInstance( ).registerDashboardComponent( entry, this );
  473.         }
  474.     }

  475.     /**
  476.      * Register Admin Dashboard Components
  477.      *
  478.      * @throws LuteceInitException
  479.      *             If an error occured
  480.      */
  481.     protected void registerAdminDashboardComponents( ) throws LuteceInitException
  482.     {
  483.         for ( DashboardComponentEntry entry : _listAdminDashboardComponents )
  484.         {
  485.             AdminDashboardService.getInstance( ).registerDashboardComponent( entry, this );
  486.         }
  487.     }

  488.     /**
  489.      * Register RBAC Resource Types
  490.      *
  491.      * @throws LuteceInitException
  492.      *             If an error occurs
  493.      */
  494.     protected void registerRBACResourceTypes( ) throws LuteceInitException
  495.     {
  496.         for ( RBACResourceTypeEntry entry : _listRBACResourceTypes )
  497.         {
  498.             ResourceIdService ris;

  499.             try
  500.             {
  501.                 ris = (ResourceIdService) Class.forName( entry.getClassName( ) ).newInstance( );
  502.                 // Each resource id service should register itself and its permissions
  503.                 ris.register( );
  504.             }
  505.             catch( InstantiationException | ClassNotFoundException | IllegalAccessException e )
  506.             {
  507.                 throw new LuteceInitException( e.getMessage( ), e );
  508.             }
  509.         }
  510.     }

  511.     /**
  512.      * Register Daemons
  513.      *
  514.      * @throws LuteceInitException
  515.      *             If an error occurs
  516.      */
  517.     protected void registerDaemons( ) throws LuteceInitException
  518.     {
  519.         for ( DaemonEntry entry : _listDaemons )
  520.         {
  521.             entry.setPluginName( getName( ) );
  522.             AppDaemonService.registerDaemon( entry );
  523.         }
  524.     }

  525.     /**
  526.      * Installs a Plugin
  527.      */
  528.     public void install( )
  529.     {
  530.         // Register a new right for the plugin
  531.         registerRights( );

  532.         // Register a new portlets as plugin
  533.         registerPortlets( );

  534.         _bIsInstalled = true;
  535.         update( );

  536.         notifyListeners( PluginEvent.PLUGIN_INSTALLED );
  537.     }

  538.     /**
  539.      * Uninstalls a Plugin
  540.      */
  541.     public void uninstall( )
  542.     {
  543.         // Unregister a new right for the plugin
  544.         unregisterRights( );

  545.         // Unregister a new portlets as plugin
  546.         unregisterPortlets( );
  547.         _bIsInstalled = false;
  548.         update( );

  549.         notifyListeners( PluginEvent.PLUGIN_UNINSTALLED );
  550.     }

  551.     /**
  552.      * Notifiy Listener
  553.      *
  554.      * @param nEventType
  555.      *            The event type
  556.      */
  557.     private void notifyListeners( int nEventType )
  558.     {
  559.         PluginEvent event = new PluginEvent( this, nEventType );
  560.         PluginService.notifyListeners( event );
  561.     }

  562.     /**
  563.      * Returns the type of the plugin
  564.      *
  565.      * @return the plugin type as a int
  566.      */
  567.     public int getType( )
  568.     {
  569.         // Load the Type
  570.         int nPluginTypeFlags = 0;

  571.         if ( CollectionUtils.isNotEmpty( _listXPageApplications ) )
  572.         {
  573.             nPluginTypeFlags |= PLUGIN_TYPE_APPLICATION;
  574.         }

  575.         if ( CollectionUtils.isNotEmpty( _listPortletTypes ) )
  576.         {
  577.             nPluginTypeFlags |= PLUGIN_TYPE_PORTLET;
  578.         }

  579.         if ( CollectionUtils.isNotEmpty( _listRights ) )
  580.         {
  581.             nPluginTypeFlags |= PLUGIN_TYPE_FEATURE;
  582.         }

  583.         if ( CollectionUtils.isNotEmpty( _listInsertServices ) )
  584.         {
  585.             nPluginTypeFlags |= PLUGIN_TYPE_INSERTSERVICE;
  586.         }

  587.         if ( CollectionUtils.isNotEmpty( _listContentServices ) )
  588.         {
  589.             nPluginTypeFlags |= PLUGIN_TYPE_CONTENTSERVICE;
  590.         }

  591.         if ( CollectionUtils.isNotEmpty( _listDaemons ) )
  592.         {
  593.             nPluginTypeFlags |= PLUGIN_TYPE_DAEMON;
  594.         }

  595.         return nPluginTypeFlags;
  596.     }

  597.     /**
  598.      * Returns the list of insert services of the plugin
  599.      *
  600.      * @return the plugin list of ContentServiceEntry
  601.      */
  602.     public List<InsertService> getInsertServices( )
  603.     {
  604.         return _listInsertServices;
  605.     }

  606.     /**
  607.      * Returns the list of Content services of the plugin
  608.      *
  609.      * @return the plugin list of ContentServiceEntry
  610.      */
  611.     public List<ContentServiceEntry> getContentServices( )
  612.     {
  613.         return _listContentServices;
  614.     }

  615.     /**
  616.      * Returns the list of XPage Applications of the plugin
  617.      *
  618.      * @return the plugin list of XPageApplicationEntry
  619.      */
  620.     public List<XPageApplicationEntry> getApplications( )
  621.     {
  622.         return _listXPageApplications;
  623.     }

  624.     /**
  625.      * Returns the list of portlet type of the plugin
  626.      *
  627.      * @return the plugin list of portlet type
  628.      */
  629.     public List<PortletType> getPortletTypes( )
  630.     {
  631.         return _listPortletTypes;
  632.     }

  633.     /**
  634.      * Sets the list of portlet type
  635.      *
  636.      * @param listPortletTypes
  637.      *            The portlet type list
  638.      */
  639.     public void setPortletTypes( List<PortletType> listPortletTypes )
  640.     {
  641.         _listPortletTypes = listPortletTypes;
  642.     }

  643.     /**
  644.      * Returns the list of portlet type of the plugin
  645.      *
  646.      * @return the plugin list of rights
  647.      */
  648.     public List<Right> getRights( )
  649.     {
  650.         return _listRights;
  651.     }

  652.     /**
  653.      * Sets plugin rights list
  654.      *
  655.      * @param listRights
  656.      *            The rights list
  657.      */
  658.     public void setRights( List<Right> listRights )
  659.     {
  660.         _listRights = listRights;
  661.     }

  662.     /**
  663.      * Returns the name of the plugin
  664.      *
  665.      * @return the plugin name as a String
  666.      */
  667.     public String getName( )
  668.     {
  669.         return _strName;
  670.     }

  671.     /**
  672.      * Sets the name of the plugin
  673.      *
  674.      * @param strName
  675.      *            The plugin name
  676.      */
  677.     public void setName( String strName )
  678.     {
  679.         _strName = strName;
  680.     }

  681.     /**
  682.      * Returns the version of the plugin
  683.      *
  684.      * @return the plugin version as a String
  685.      */
  686.     public String getVersion( )
  687.     {
  688.         return _strVersion;
  689.     }

  690.     /**
  691.      * Sets the version plugin name
  692.      *
  693.      * @param strVersion
  694.      *            The version
  695.      */
  696.     public void setVersion( String strVersion )
  697.     {
  698.         _strVersion = strVersion;
  699.     }

  700.     /**
  701.      * Returns the description of the plugin
  702.      *
  703.      * @return the plugin description as a String
  704.      */
  705.     public String getDescription( )
  706.     {
  707.         return _strDescription;
  708.     }

  709.     /**
  710.      * Sets the description of the plugin
  711.      *
  712.      * @param strDescription
  713.      *            The description
  714.      */
  715.     public void setDescription( String strDescription )
  716.     {
  717.         _strDescription = strDescription;
  718.     }

  719.     /**
  720.      * Returns the Provider of the plugin
  721.      *
  722.      * @return the plugin Provider as a String
  723.      */
  724.     public String getProvider( )
  725.     {
  726.         return _strProvider;
  727.     }

  728.     /**
  729.      * Sets the provider name
  730.      *
  731.      * @param strProvider
  732.      *            The provider name
  733.      */
  734.     public void setProvider( String strProvider )
  735.     {
  736.         _strProvider = strProvider;
  737.     }

  738.     /**
  739.      * Returns the Provider's URL of the plugin
  740.      *
  741.      * @return the plugin Provider's URL as a String
  742.      */
  743.     public String getProviderUrl( )
  744.     {
  745.         return _strProviderUrl;
  746.     }

  747.     /**
  748.      * Sets the provider url
  749.      *
  750.      * @param strProviderUrl
  751.      *            the name of the provider
  752.      */
  753.     public void setProviderUrl( String strProviderUrl )
  754.     {
  755.         _strProviderUrl = strProviderUrl;
  756.     }

  757.     /**
  758.      * Returns the Icon's URL of the plugin
  759.      *
  760.      * @return the plugin Icon's URL as a String
  761.      */
  762.     public String getIconUrl( )
  763.     {
  764.         return _strIconUrl;
  765.     }

  766.     /**
  767.      * Sets the url of the plugin's icon
  768.      *
  769.      * @param strIconUrl
  770.      *            The url of icon
  771.      */
  772.     public void setIconUrl( String strIconUrl )
  773.     {
  774.         _strIconUrl = strIconUrl;
  775.     }

  776.     /**
  777.      * Returns the Documentation's URL of the plugin
  778.      *
  779.      * @return the plugin Documentation's URL as a String
  780.      */
  781.     public String getDocumentationUrl( )
  782.     {
  783.         return _strDocumentationUrl;
  784.     }

  785.     /**
  786.      * Sets the url of the plugin's Documentation
  787.      *
  788.      * @param strDocumentationUrl
  789.      *            The documentation Url
  790.      */
  791.     public void setDocumentationUrl( String strDocumentationUrl )
  792.     {
  793.         _strDocumentationUrl = strDocumentationUrl;
  794.     }

  795.     /**
  796.      * Returns the Copyright of the plugin
  797.      *
  798.      * @return the plugin Copyright as a String
  799.      */
  800.     public String getCopyright( )
  801.     {
  802.         return _strCopyright;
  803.     }

  804.     /**
  805.      * Sets the copyright
  806.      *
  807.      * @param strCopyright
  808.      *            The copyright
  809.      */
  810.     public void setCopyright( String strCopyright )
  811.     {
  812.         _strCopyright = strCopyright;
  813.     }

  814.     /**
  815.      * Returns the main Class of the plugin
  816.      *
  817.      * @return the Class as a String
  818.      */
  819.     public String getServiceClass( )
  820.     {
  821.         return _strPluginClass;
  822.     }

  823.     /**
  824.      * Sets the class service of plugin
  825.      *
  826.      * @param strPluginClass
  827.      *            The plugin class
  828.      */
  829.     public void setServiceClass( String strPluginClass )
  830.     {
  831.         _strPluginClass = strPluginClass;
  832.     }

  833.     /**
  834.      * Returns the installation status of the plugin
  835.      *
  836.      * @return the installation status as an int
  837.      */
  838.     public boolean isInstalled( )
  839.     {
  840.         return _bIsInstalled;
  841.     }

  842.     /**
  843.      * Sets the boolean which shows if the plugin is installed
  844.      *
  845.      * @param bIsInstalled
  846.      *            The installed boolean
  847.      */
  848.     public void setIsInstalled( boolean bIsInstalled )
  849.     {
  850.         _bIsInstalled = bIsInstalled;
  851.     }

  852.     /**
  853.      * Returns the min core version compatibility for the plugin
  854.      *
  855.      * @return the min core version as a String
  856.      */
  857.     public String getMinCoreVersion( )
  858.     {
  859.         return _strMinCoreVersion;
  860.     }

  861.     /**
  862.      * Sets the the min core version compatibility for the plugin
  863.      *
  864.      * @param strMinCoreVersion
  865.      *            The min core version
  866.      */
  867.     public void setMinCoreVersion( String strMinCoreVersion )
  868.     {
  869.         _strMinCoreVersion = strMinCoreVersion;
  870.     }

  871.     /**
  872.      * Returns the max core version compatibility for the plugin
  873.      *
  874.      * @return the max core version as a String
  875.      */
  876.     public String getMaxCoreVersion( )
  877.     {
  878.         return _strMaxCoreVersion;
  879.     }

  880.     /**
  881.      * Sets the the max core version compatibility for the plugin
  882.      *
  883.      * @param strMaxCoreVersion
  884.      *            The max core version
  885.      */
  886.     public void setMaxCoreVersion( String strMaxCoreVersion )
  887.     {
  888.         _strMaxCoreVersion = strMaxCoreVersion;
  889.     }

  890.     /**
  891.      * Returns if the plugin needs a database connection pool
  892.      *
  893.      * @return <b>true</b> if the plugin needs a database connection pool, otherwise <b>false</b>
  894.      */
  895.     public boolean isDbPoolRequired( )
  896.     {
  897.         return _bDbPoolRequired;
  898.     }

  899.     /**
  900.      * Sets the boolean which shows if a pool is required
  901.      *
  902.      * @param bDbPoolRequired
  903.      *            The dbpool boolean
  904.      */
  905.     public void setIsDbPoolRequired( boolean bDbPoolRequired )
  906.     {
  907.         _bDbPoolRequired = bDbPoolRequired;
  908.     }

  909.     /**
  910.      * Returns a Connection Service associated to the plugin
  911.      *
  912.      * @return _connectionService The connection service
  913.      */
  914.     public PluginConnectionService getConnectionService( )
  915.     {
  916.         return _connectionService;
  917.     }

  918.     /**
  919.      * Sets the connection service
  920.      *
  921.      * @param connectionService
  922.      *            The connection Service object
  923.      */
  924.     public void setConnectionService( PluginConnectionService connectionService )
  925.     {
  926.         _connectionService = connectionService;
  927.     }

  928.     /**
  929.      * Initializes the plugin's ConnectionService
  930.      *
  931.      * @param strPoolName
  932.      *            The pool name
  933.      */
  934.     public void initConnectionService( String strPoolName )
  935.     {
  936.         _connectionService = new PluginConnectionService( strPoolName );
  937.     }

  938.     /**
  939.      * Gets plugin's parameters
  940.      *
  941.      * @return _mapParams The hastable of parameters
  942.      */
  943.     public Map<String, String> getParams( )
  944.     {
  945.         return _mapParams;
  946.     }

  947.     /**
  948.      * Gets a parameter value for a given parameter name
  949.      *
  950.      * @param strParamName
  951.      *            The name of the parameter
  952.      * @return null
  953.      */
  954.     public String getParamValue( String strParamName )
  955.     {
  956.         if ( !_mapParams.containsKey( strParamName ) )
  957.         {
  958.             return null;
  959.         }

  960.         return _mapParams.get( strParamName );
  961.     }

  962.     /**
  963.      * Sets parameters values with an hashtable
  964.      *
  965.      * @param mapParams
  966.      *            The parameter map
  967.      */
  968.     public void setParams( Map<String, String> mapParams )
  969.     {
  970.         _mapParams = mapParams;
  971.     }

  972.     /**
  973.      * Sets a parameter value for a given parameter name
  974.      *
  975.      * @param strParamName
  976.      *            The name of the parameter
  977.      * @param strParamValue
  978.      *            The value of the parameter
  979.      */
  980.     public void setParamValue( String strParamName, String strParamValue )
  981.     {
  982.         if ( _mapParams.containsKey( strParamName ) )
  983.         {
  984.             _mapParams.put( strParamName, strParamValue );
  985.         }
  986.     }

  987.     /**
  988.      * Implementation of the Comparable interface.
  989.      *
  990.      * @param plugin
  991.      *            A plugin Object
  992.      * @return 1, 0 ou -1 according the plugin name
  993.      */
  994.     @Override
  995.     public int compareTo( Plugin plugin )
  996.     {
  997.         Comparator<String> comparator = String.CASE_INSENSITIVE_ORDER;

  998.         return comparator.compare( getName( ), plugin.getName( ) );
  999.     }

  1000.     /**
  1001.      * {@inheritDoc}
  1002.      */
  1003.     @Override
  1004.     public boolean equals( Object o )
  1005.     {
  1006.         if ( !( o instanceof Plugin ) )
  1007.         {
  1008.             return false;
  1009.         }

  1010.         return compareTo( (Plugin) o ) == 0;
  1011.     }

  1012.     /**
  1013.      * Returns all CSS Style Sheets of the plugin with no mode associated
  1014.      *
  1015.      * @return The list of CSS Style Sheets with no mode associated
  1016.      */
  1017.     public List<String> getCssStyleSheets( )
  1018.     {
  1019.         List<String> res = _listCssStyleSheets.get( null );

  1020.         if ( res == null )
  1021.         {
  1022.             return Collections.emptyList( );
  1023.         }

  1024.         return res;
  1025.     }

  1026.     /**
  1027.      * Returns all CSS Style Sheets of the plugin associated with a mode
  1028.      *
  1029.      * @param mode
  1030.      *            the mode
  1031.      * @return The list of CSS Style Sheets associated with the mode
  1032.      * @since 5.1.0
  1033.      */
  1034.     public List<String> getCssStyleSheets( int mode )
  1035.     {
  1036.         List<String> res = _listCssStyleSheets.get( mode );

  1037.         if ( res == null )
  1038.         {
  1039.             return Collections.emptyList( );
  1040.         }

  1041.         return res;
  1042.     }

  1043.     /**
  1044.      * Returns the theme the plugin use for rendering a Xpage
  1045.      *
  1046.      * @param request
  1047.      *            The HttpServletRequest
  1048.      * @return The theme
  1049.      */
  1050.     public Theme getXPageTheme( HttpServletRequest request )
  1051.     {
  1052.         return null;
  1053.     }

  1054.     /**
  1055.      * Add an Javascript File to the plugin definition, not associated with a mode
  1056.      *
  1057.      * @param strJavascriptFile
  1058.      *            The Javascript File path
  1059.      */
  1060.     public void addJavascriptFile( String strJavascriptFile )
  1061.     {
  1062.         List<String> files = _listJavascriptFiles.computeIfAbsent( null, s -> new ArrayList<>( ) );
  1063.         files.add( strJavascriptFile );
  1064.     }

  1065.     /**
  1066.      * Returns all Javascript File of the plugin with no mode associated
  1067.      *
  1068.      * @return The list of Javascript File with no mode associated
  1069.      */
  1070.     public List<String> getJavascriptFiles( )
  1071.     {
  1072.         List<String> res = _listJavascriptFiles.get( null );

  1073.         if ( res == null )
  1074.         {
  1075.             return Collections.emptyList( );
  1076.         }

  1077.         return res;
  1078.     }

  1079.     /**
  1080.      * Returns all Javascript File of the plugin associated with a mode
  1081.      *
  1082.      * @param mode
  1083.      *            the mode
  1084.      * @return The list of Javascript File with associated with the mode
  1085.      * @since 5.1.0
  1086.      */
  1087.     public List<String> getJavascriptFiles( int mode )
  1088.     {
  1089.         List<String> res = _listJavascriptFiles.get( mode );

  1090.         if ( res == null )
  1091.         {
  1092.             return Collections.emptyList( );
  1093.         }

  1094.         return res;
  1095.     }

  1096.     /**
  1097.      * Give the scope of css stylesheets
  1098.      *
  1099.      * @return true if scope is portal otherwise false
  1100.      */
  1101.     public boolean isCssStylesheetsScopePortal( )
  1102.     {
  1103.         return ( ( _strCssStylesheetsScope != null ) && _strCssStylesheetsScope.equalsIgnoreCase( SCOPE_PORTAL ) );
  1104.     }

  1105.     /**
  1106.      * Give the scope of css stylesheets
  1107.      *
  1108.      * @return true if scope is portal otherwise false
  1109.      */
  1110.     public boolean isCssStylesheetsScopeXPage( )
  1111.     {
  1112.         return ( ( _strCssStylesheetsScope != null ) && _strCssStylesheetsScope.equalsIgnoreCase( SCOPE_XPAGE ) );
  1113.     }

  1114.     /**
  1115.      * Give the scope of javascripts
  1116.      *
  1117.      * @return true if scope is portal otherwise false
  1118.      */
  1119.     public boolean isJavascriptFilesScopePortal( )
  1120.     {
  1121.         return ( ( _strJavascriptFilesScope != null ) && _strJavascriptFilesScope.equalsIgnoreCase( SCOPE_PORTAL ) );
  1122.     }

  1123.     /**
  1124.      * Give the scope of javascripts
  1125.      *
  1126.      * @return true if scope is portal otherwise false
  1127.      */
  1128.     public boolean isJavascriptFilesScopeXPage( )
  1129.     {
  1130.         return ( ( _strJavascriptFilesScope != null ) && _strJavascriptFilesScope.equalsIgnoreCase( SCOPE_XPAGE ) );
  1131.     }

  1132.     /**
  1133.      * Return the list of stylesheets that should be used in the Back Office
  1134.      *
  1135.      * @return the list of stylesheets that should be used in the Back Office
  1136.      * @since 5.1
  1137.      */
  1138.     public List<String> getAdminCssStyleSheets( )
  1139.     {
  1140.         return _listAdminCssStyleSheets;
  1141.     }

  1142.     /**
  1143.      * Return the list of Javascript Files that should be used in the Back Office
  1144.      *
  1145.      * @return the list of Javascript Files that should be used in the Back Office
  1146.      * @since 5.1
  1147.      */
  1148.     public List<String> getAdminJavascriptFiles( )
  1149.     {
  1150.         return _listAdminJavascriptFiles;
  1151.     }

  1152.     /**
  1153.      * Adds a that file that will be autoincluded in freemarker templates
  1154.      *
  1155.      * @param strMacroFileName
  1156.      *            the file name
  1157.      */
  1158.     public void addFreemarkerMacrosFile( String strMacroFileName )
  1159.     {
  1160.         _listFreemarkerMacrosFiles.add( strMacroFileName );
  1161.     }

  1162.     /**
  1163.      * Gets the free marker macros files.
  1164.      *
  1165.      * @return the free marker macros files
  1166.      */
  1167.     public List<String> getFreeMarkerMacrosFiles( )
  1168.     {
  1169.         return _listFreemarkerMacrosFiles;
  1170.     }

  1171.     /**
  1172.      * Useful for debugging
  1173.      *
  1174.      * @return The plugin object in String format
  1175.      */
  1176.     @Override
  1177.     public String toString( )
  1178.     {
  1179.         return getName( );
  1180.     }

  1181.     /**
  1182.      * {@inheritDoc}
  1183.      */
  1184.     @Override
  1185.     public int hashCode( )
  1186.     {
  1187.         if ( getName( ) == null )
  1188.         {
  1189.             return 0;
  1190.         }

  1191.         return getName( ).toLowerCase( ).hashCode( );
  1192.     }
  1193. }