Class AbstractDocumentSkinExtensionPlugin

  • All Implemented Interfaces:
    com.xpn.xwiki.internal.cache.rendering.RenderingCacheAware, XWikiPluginInterface, org.xwiki.observation.EventListener
    Direct Known Subclasses:
    CssSkinExtensionPlugin, JsSkinExtensionPlugin

    public abstract class AbstractDocumentSkinExtensionPlugin
    extends AbstractSkinExtensionPlugin
    implements org.xwiki.observation.EventListener
    Abstract SX plugin for wiki-document-based extensions (Extensions written as object of a XWiki Extension class). Provides a generic method to initialize the XWiki class upon plugin initialization if needed. Provide a notification mechanism for extensions marked as "use-always".
    Since:
    1.4
    Version:
    $Id: 5456db6ea2d6aefc53d6d817a282ae88c1ae11be $
    See Also:
    JsSkinExtensionPlugin, CssSkinExtensionPlugin
    • Field Detail

      • LOGGER

        protected static final org.slf4j.Logger LOGGER
        Log helper for logging messages in this class.
    • Constructor Detail

      • AbstractDocumentSkinExtensionPlugin

        public AbstractDocumentSkinExtensionPlugin​(String name,
                                                   String className,
                                                   XWikiContext context)
        XWiki plugin constructor.
        Parameters:
        name - The name of the plugin, which can be used for retrieving the plugin API from velocity. Unused.
        className - The canonical classname of the plugin. Unused.
        context - The current request context.
        See Also:
        XWikiDefaultPlugin(String,String,com.xpn.xwiki.XWikiContext)
    • Method Detail

      • getEvents

        public List<org.xwiki.observation.event.Event> getEvents()
        Specified by:
        getEvents in interface org.xwiki.observation.EventListener
      • getExtensionClassName

        protected abstract String getExtensionClassName()
        The name of the XClass which holds extensions of this type.
        Returns:
        A String representation of the XClass name, in the Space.Document format.
      • getExtensionName

        protected abstract String getExtensionName()
        A user-friendly name for this type of resource, used in the auto-generated class document.
        Returns:
        The user-friendly name for this type of resource.
      • getAlwaysUsedExtensions

        public Set<String> getAlwaysUsedExtensions​(XWikiContext context)
        Returns the list of always used extensions of this type. Which resources are always used depends on the type of resource, for example document based StyleSheet extensions have a property in the object, use, which can have the value always to declare that an extension should always be used.

        For this kind of resources, an XObject property (use) with the value always indicates always used extensions. The list of extensions for each wiki is lazily placed in a cache: if the extension set for the context wiki is null, then they will be looked up in the database and added to it. The cache is invalidated using the notification mechanism.

        Specified by:
        getAlwaysUsedExtensions in class AbstractSkinExtensionPlugin
        Parameters:
        context - The current request context.
        Returns:
        A set of resource names that should be pulled in the current response. Note that this method is called for each request, as the list might change in time, and it can be different for each wiki in a farm.
        See Also:
        AbstractSkinExtensionPlugin.getAlwaysUsedExtensions(XWikiContext)
      • getAlwaysUsedExtensions

        public Set<org.xwiki.model.reference.DocumentReference> getAlwaysUsedExtensions()
        Returns the list of always used extensions of this type as a set of document references. For this kind of resources, an XObject property (use) with the value always indicates always used extensions. The list of extensions for each wiki is lazily placed in a cache: if the extension set for the context wiki is null, then they will be looked up in the database and added to it. The cache is invalidated using the notification mechanism. Note that this method is called for each request, as the list might change in time, and it can be different for each wiki in a farm.
        Returns:
        a set of document references that should be pulled in the current response
      • hasPageExtensions

        public boolean hasPageExtensions​(XWikiContext context)
        Description copied from class: AbstractSkinExtensionPlugin
        Determines if the requested document contains on page skin extension objects of this type. True if at least one of the extension objects has the currentPage value for the use property.
        Specified by:
        hasPageExtensions in class AbstractSkinExtensionPlugin
        Parameters:
        context - the current request context
        Returns:
        a boolean specifying if the current document contains on page skin extensions
      • use

        public void use​(String resource,
                        Map<String,​Object> parameters,
                        XWikiContext context)
        Description copied from class: AbstractSkinExtensionPlugin
        Mark a skin extension document as used in the current result, together with some parameters. How the parameters are used, depends on the type of resource being pulled. For example, JS and CSS extensions use the parameters in the resulting URL, while Link extensions use the parameters as attributes of the link tag. A resource is registered only once per request, further calls will not result in additional links, even if it is pulled with different parameters. If more than one calls per request are made, the parameters used are the ones from the last call (or none, if the last call did not specify any parameters).
        Overrides:
        use in class AbstractSkinExtensionPlugin
        Parameters:
        resource - The name of the resource to pull.
        parameters - The parameters for this resource.
        context - The current request context.
        See Also:
        AbstractSkinExtensionPlugin.use(String, XWikiContext)
      • getExtensionClass

        public BaseClass getExtensionClass​(XWikiContext context)
        Creates or updates the XClass used for this type of extension. Usually called on init(XWikiContext) and virtualInit(XWikiContext).
        Parameters:
        context - The current request context, which gives access to the wiki.
        Returns:
        The XClass for this extension.
      • onEvent

        public void onEvent​(org.xwiki.observation.event.Event event,
                            Object source,
                            Object data)

        Make sure to keep the alwaysUsedExtensions map consistent when the database changes.

        Specified by:
        onEvent in interface org.xwiki.observation.EventListener
        See Also:
        EventListener.onEvent(org.xwiki.observation.event.Event, java.lang.Object, java.lang.Object)
      • isAccessible

        protected boolean isAccessible​(String documentName,
                                       XWikiContext context)
        Parameters:
        documentName - the Skin Extension's document name
        context - the XWiki Context
        Returns:
        true if the specified document is accessible (i.e. has view rights) by the current user; false otherwise
      • isAccessible

        protected boolean isAccessible​(org.xwiki.model.reference.DocumentReference documentReference,
                                       XWikiContext context)
        Parameters:
        documentReference - the Skin Extension's document reference
        context - the XWiki Context
        Returns:
        true if the specified document is accessible (i.e. has view rights) by the current user; false otherwise
        Since:
        7.4.1
      • getDocumentSkinExtensionURL

        protected String getDocumentSkinExtensionURL​(org.xwiki.model.reference.DocumentReference documentReference,
                                                     String documentName,
                                                     String pluginName,
                                                     XWikiContext context)
        Return the URL to a document skin extension.
        Parameters:
        documentReference - the Skin Extension's document reference
        documentName - the Skin Extension's document name
        pluginName - the name of the plugin
        context - the XWiki Context
        Returns:
        the URL to the document skin extension.
        Since:
        7.4.1