Class PluginManager

java.lang.Object
com.jalios.jcms.plugin.PluginManager
All Implemented Interfaces:
PluginComponent, ReplicaMessageListener

public final class PluginManager extends Object implements ReplicaMessageListener
Singleton used to manage plugin's life cycle.
It also contains utility methods and constants for plugins.
  1. Initialization of PluginManager
  2. Loading Plugins
  3. Initialize dependencies
  4. Initializing deployed Plugins
  5. Setup deployed plugins
Since:
jcms-5.7.0
Author:
Jean-Philippe Encausse
  • Field Details

  • Method Details

    • getInstance

      public static PluginManager getInstance()
      Returns a PluginManager. Singleton method initalized by Channel (not synchronized)
      Returns:
      PluginManager the Pluginmanager
    • getPluginManager

      public static PluginManager getPluginManager()
    • init

      public void init(Channel channel)
      Inits the PluginManager.
      Parameters:
      channel - the Channel singleton instance
    • initPlugins

      public void initPlugins()
      Inits all plugins that have been correctly loaded. Called after Channelinitialized most important stuff.
    • initPlugins

      public void initPlugins(Collection<Plugin> collection)
      Inits all plugins that have been correctly loaded. Called juste after PluginManager Initialisation, Channel not completly initialised. Properties not loaded.
      Parameters:
      collection - a collection of Plugin
    • setupPlugins

      public void setupPlugins()
      Setup all plugins that have been correctly initialized. Channel properties have been loaded.
    • setupPlugins

      public void setupPlugins(Collection<Plugin> collection)
      Setup all plugins that have been correctly initialized. Channel properties have been loaded.
      Parameters:
      collection - a collection of Plugin
    • getMainPluginName

      public String getMainPluginName()
      Returns the name of the main plugin (or null if there is no main plugin)
      Returns:
      the name of the main plugin (or null if there is no main plugin)
      Since:
      jcms-8.0.1
    • getMainPlugin

      public Plugin getMainPlugin()
      Returns the main plugin (or null if there is no main plugin)
      Returns:
      the main plugin (or null if there is no main plugin)
      Since:
      jcms-8.0.1
    • isMainPluginDefined

      public boolean isMainPluginDefined()
      Returns true if the main plugin has been defined.
      Returns:
      true if the main plugin has been defined.
      Since:
      jcms-8.0.1
    • initMainPlugin

      public void initMainPlugin() throws IllegalStateException
      Initialize main plugin (reserved for JCMS internals).
      Throws:
      IllegalStateException - if the main plugin is not correctly started
      Since:
      jcms-8.0.1
    • loadMainPluginProperties

      public void loadMainPluginProperties(LangProperties properties, List<String> jcmsLangList)
      Loads all the properties of the main plugin.
      Parameters:
      properties - the properties where to load the main plugin properties
      jcmsLangList - the JCMS language list
      Since:
      jcms-8.0.1
    • getMainPluginCoreProperties

      public LangProperties getMainPluginCoreProperties()
      Returns the core properties the main plugin override.
      Returns:
      the core properties the main plugin override.
      Since:
      jcms-8.0.1
    • getAllPathSet

      public Set<String> getAllPathSet(boolean sources)
      Returns a Set of relative path to all plugins declared files
      Parameters:
      sources - also include .java sources
      Returns:
      Set of relative path
    • getAllPathSet

      public Set<String> getAllPathSet(boolean sources, boolean generated, boolean signature, boolean pkg, boolean jar, String prefix, boolean directory)
      Returns a Set of relative path to all plugins declared files
      Parameters:
      sources - also include .java sources
      generated - include generated content
      signature - add signature file
      pkg - add package file
      jar - add jar file
      prefix - add prefix to path
      directory - should resolve directory path
      Returns:
      Set of relative path
    • getPluginEntityResolver

      public EntityResolver getPluginEntityResolver()
    • getSAXBuilder

      public org.jdom.input.SAXBuilder getSAXBuilder()
    • register

      public void register(Plugin plugin)
      Register a loaded plugin in PluginManager
      Parameters:
      plugin - the loaded plugin
    • loadPluginXML

      public Plugin loadPluginXML(File file)
      Load a given Plugin Archive if it has not been already loadded
      Parameters:
      file - the folder that contains PLUGIN_XML
      Returns:
      Plugin or null if there is an error
    • loadArchive

      public Plugin loadArchive(File file)
      Load a given Plugin Archive if it has not been already loadded
      Parameters:
      file - the archive that ends with PLUGIN_EXTENSION
      Returns:
      Plugin or null if there is an error
    • orderPlugins

      public static Collection<Plugin> orderPlugins(Collection<Plugin> plugins, boolean useDefaultOnFailure)
      Computes a topological sort of all the plugins and inter-dependencies.
      • Plugin must be Comparable
      • Any cycle in the plugin dependencies will result in a naive sorting implementation being used
      Parameters:
      plugins - a collection of plugin, must not be null
      useDefaultOnFailure - true to use a naive sorting implementation if a cycle is detected, false to return null
      Returns:
      a sorted collection of plugins according to their dependencies, names and order
      Since:
      jcms-10.0.2 / JCMS-6901
    • deployPlugin

      public boolean deployPlugin(Plugin plugin, String archiveName)
      Deploy all files from a given archive to the current JCMS directory tree. If file already exists backup it to plugin backup directory.
      Parameters:
      plugin - the loaded Plugin
      archiveName - the archive to deploy
      Returns:
      boolean true if deployement has been correctly done
    • deletePluginFiles

      public boolean deletePluginFiles(Plugin plugin)
      Delete all deployed files of the given plugin.
      Parameters:
      plugin - the loaded Plugin
      Returns:
      boolean true if delete has been correctly done
    • performDeletePackage

      public boolean performDeletePackage(String packageName)
      Delete the given plugin package
      Parameters:
      packageName - the name of the package to delete
      Returns:
      boolean
      Since:
      jcms-5.7.1
    • registerTemplates

      public void registerTemplates()
      Iterates on plugin's collection and register types' template for initialized plugins.
    • registerTemplates

      public void registerTemplates(Collection<Plugin> collection)
      Iterates on plugin's collection and register types' template for initialized plugins
      Parameters:
      collection - a collection of Plugin
    • registerStoreListener

      public void registerStoreListener(boolean beforeStoreLoad)
      Iterates on plugin's collection and register StoreListener for initialized plugins.
      Parameters:
      beforeStoreLoad - boolean true before loading store
    • registerStoreListener

      public void registerStoreListener(Collection<Plugin> collection, boolean beforeStoreLoad)
      Iterates on plugin's collection and register StoreListener for initialized plugins
      Parameters:
      collection - a collection of Plugin
      beforeStoreLoad - boolean true before loading store
    • registerDBListener

      public void registerDBListener()
      Iterates on plugin's collection and register DBlistener for initialized plugins.
    • registerDBListener

      public void registerDBListener(Collection<Plugin> collection)
      Iterates on plugin's collection and register DBlistener for initialized plugins
      Parameters:
      collection - a collection of Plugin
    • registerJSyncListener

      public void registerJSyncListener()
      Iterates on plugin's collection and register JSyncListener for initialized plugins.
    • registerJSyncListener

      public void registerJSyncListener(Collection<Plugin> collection)
      Iterates on plugin's collection and register JSyncListener for initialized plugins
      Parameters:
      collection - a collection of Plugin
    • registerDataController

      public void registerDataController()
      Iterates on plugin's collection and register DataController for initialized plugins.
    • registerDataController

      public void registerDataController(Collection<Plugin> collection)
      Iterates on plugin's collection and register DataController for initialized plugins
      Parameters:
      collection - a collection of Plugin
    • registerAlarmListener

      public void registerAlarmListener()
      Iterates on plugin's collection and register AlarmListener for initialized plugins.
    • registerAlarmListener

      public void registerAlarmListener(Collection<Plugin> collection)
      Iterates on plugin's collection and register AlarmListener for initialized plugins
      Parameters:
      collection - a collection of Plugin
    • registerAlertChannel

      public void registerAlertChannel()
      Iterates on plugin's collection and register AlertChannel for initialized plugins.
    • registerAlertChannel

      public void registerAlertChannel(Collection<Plugin> collection)
      Iterates on plugin's collection and register AlertChannel for initialized plugins
      Parameters:
      collection - a collection of Plugin
    • registerRestResource

      public void registerRestResource()
      Iterates on plugin's collection and register RestResource for initialized plugins.
    • registerOpenApiResources

      public void registerOpenApiResources(Collection<Plugin> collection)
      Iterates on plugin's collection and register RestResource for initialized plugins
      Parameters:
      collection - a collection of Plugin
    • registerChannelListener

      public void registerChannelListener()
      Iterates on plugin's collection and register ChannelListener for initialized plugins.
    • registerChannelListener

      public void registerChannelListener(Collection<Plugin> collection)
      Iterates on plugin's collection and register ChannelListener for initialized plugins
      Parameters:
      collection - a collection of Plugin
    • registerQueryFilter

      public void registerQueryFilter()
      Iterates on plugin's collection and register QueryFilter for initialized plugins.
    • registerQueryFilter

      public void registerQueryFilter(Collection<Plugin> collection)
      Iterates on plugin's collection and register QueryFilter for initialized plugins
      Parameters:
      collection - a collection of Plugin
    • registerCleanFilter

      public void registerCleanFilter()
      Iterates on plugin's collection and register CleanFilter for initialized plugins.
    • registerCleanFilter

      public void registerCleanFilter(Collection<Plugin> collection)
      Iterates on plugin's collection and register CleanFilter for initialized plugins
      Parameters:
      collection - a collection of Plugin
    • registerPolicyFilter

      public void registerPolicyFilter()
      Iterates on plugin's collection and register PolicyFilter for initialized plugins.
    • registerPolicyFilter

      public void registerPolicyFilter(Collection<Plugin> collection)
      Iterates on plugin's collection and register PolicyFilter for initialized plugins
      Parameters:
      collection - a collection of Plugin
    • registerAuthenticationHandler

      public void registerAuthenticationHandler()
      Iterates on plugin's collection and register AuthenticationHandlers for initialized plugins.
    • registerAuthenticationHandler

      public void registerAuthenticationHandler(Collection<Plugin> collection)
      Iterates on plugin's collection and register AuthenticationHandlers for initialized plugins
      Parameters:
      collection - a collection of Plugin
    • registerHibernateMapping

      public void registerHibernateMapping()
      Iterates on plugin's collection and register Hibernate mappings for initialized plugins.
    • registerHibernateMapping

      public void registerHibernateMapping(Collection<Plugin> collection)
      Iterates on plugin's collection and register Hibernate mappings for initialized plugins
      Parameters:
      collection - a collection of Plugin
    • getCssFiles

      public void getCssFiles(Collection<File> cssPaths, FileFilter filter)
      Fill given cssPaths collection with plugins css path used for portals
      Parameters:
      cssPaths - Collection of css path
      filter - FileFilter for css
    • getCssFiles

      public void getCssFiles(Collection<File> cssPaths, Collection<Plugin> collection, FileFilter filter)
      Fill given cssPaths collection with plugins css path used for portals
      Parameters:
      cssPaths - Collection of css path
      collection - Collection of plugins
      filter - FileFilter for css
    • invalidateIncludeCache

      public void invalidateIncludeCache()
      Invalidate cache of plugin's JSP to include for given tags.
    • performInclude

      public void performInclude(String tag, javax.servlet.jsp.PageContext pageContext)
      Iterates on plugin's collection and retrieve Plugins' JSP to include for the given anchor. WARNING ! This method must be called from a jsp taglib
      Parameters:
      tag - the scope of include
      pageContext - the current Jsp's pageContext, required !
    • clearCachedInclude

      public void clearCachedInclude()
    • loadProperties

      public void loadProperties(LangProperties properties, List<String> jcmsLangList)
      Iterates on plugin's collection and load properties, including language properties for initialized plugins.
      Parameters:
      properties - the channel properties
      jcmsLangList - the lang list of JCMS
    • loadLanguageProperties

      public void loadLanguageProperties(LangProperties properties, List<String> jcmsLangList)
      Iterates on plugin's collection and load only languages properties for initialized plugins.
      Parameters:
      properties - the channel properties
      jcmsLangList - the lang list of JCMS
      Since:
      jcms-6.1.0
    • loadProperties

      public void loadProperties(LangProperties properties, List<String> jcmsLangList, Collection<Plugin> collection, boolean onlyLangProp)
      Iterates on plugin's collection and load properties for initialized plugins
      Parameters:
      properties - the channel properties
      jcmsLangList - the lang list of JCMS
      collection - a collection of Plugin
      onlyLangProp - only the language properties
    • getWorkflowsPath

      public Set<String> getWorkflowsPath()
      Returns a Set of relative Path to all webapp's workflow
      Returns:
      Set of relative path
    • getJarsPath

      public Set<String> getJarsPath()
      Returns a Set of relative Path to all webapp's jar
      Returns:
      Set of relative path
    • getPluginPath

      public Set<String> getPluginPath(boolean priv, String pluginName, Set<String> pluginSet)
      Returns a Set of relative Path to plugin public/private folder with all files stored on disk even if they are not declared in xml
      Parameters:
      priv - boolean true if private or false if public
      pluginName - the name og the plugin
      pluginSet - the set of known path to add
      Returns:
      Set of relative path
    • getPlugins

      public Collection<Plugin> getPlugins()
      Returns a Collection of plugins.
      Returns:
      Collenction the plugin's collection
    • getPlugin

      public Plugin getPlugin(String pluginName)
      Returns the plugin for the given name or null if it does not exists.
      Parameters:
      pluginName - the name of the plugin
      Returns:
      Plugin the plugin
    • isPluginEnabled

      public boolean isPluginEnabled(String pluginName)
      Returns true if this plugin is enabled.
      Parameters:
      pluginName - the name of the plugin
      Returns:
      true if this plugin is enabled.
      Since:
      jcms-10.0.2
    • isPluginActive

      public boolean isPluginActive(String pluginName)
      Returns true if this plugin is active.
      Parameters:
      pluginName - the name of the plugin
      Returns:
      true if this plugin is active.
      Since:
      jcms-10.0.2
    • enablePlugin

      public boolean enablePlugin(String pluginName)
      Enable the given plugin.
      Parameters:
      pluginName - the name of the plugin.
      Returns:
      true if the plugin has been successfully enabled.
      Since:
      jcms-10.0.0
    • enablePlugin

      public boolean enablePlugin(Plugin plugin)
      Enable the given plugin.
      Parameters:
      plugin - the plugin.
      Returns:
      true if the plugin has been successfully enabled.
      Since:
      jcms-10.0.0
    • disablePlugin

      public boolean disablePlugin(String pluginName)
      Disable the given plugin.
      Parameters:
      pluginName - the name of the plugin.
      Returns:
      true if the plugin has been successfully disabled.
      Since:
      jcms-10.0.0
    • disablePlugin

      public boolean disablePlugin(Plugin plugin)
      Disable the given plugin.
      Parameters:
      plugin - the plugin.
      Returns:
      true if the plugin has been successfully disabled.
      Since:
      jcms-10.0.0
    • findPluginProvidingType

      public Plugin findPluginProvidingType(String className)
      Return the plugin providing the given type.
      Parameters:
      className - the class name of the type
      Returns:
      the plugin providing the given type.
      Since:
      jcms-10.0.0
    • findPluginProvidingWorkflow

      public Plugin findPluginProvidingWorkflow(String wfId)
      Returns the plugin providing the given workflow.
      Parameters:
      wfId - the workflow ID
      Returns:
      the plugin providing the given workflow.
      Since:
      jcms-10.0.0
    • checkResourceAccess

      public boolean checkResourceAccess(String resource)
      Returns true if the given plugin's resource (JSP) is provided by an active plugin.
      Parameters:
      resource - the resource.
      Returns:
      true if the given plugin's resource (JSP) is provided by an active plugin.
      Since:
      jcms-10.0.0
    • isPluginSyncEnabled

      public boolean isPluginSyncEnabled()
    • initReplicaMessageListener

      public void initReplicaMessageListener()
    • processMessage

      public void processMessage(ReplicaMessage msg)
      Description copied from interface: ReplicaMessageListener
      Process the given ReplicaMessage.
      Specified by:
      processMessage in interface ReplicaMessageListener
      Parameters:
      msg - the ReplicaMessage to process