Class AbstractDocumentSkinExtensionPlugin
- java.lang.Object
-
- com.xpn.xwiki.plugin.XWikiDefaultPlugin
-
- com.xpn.xwiki.plugin.skinx.AbstractSkinExtensionPlugin
-
- com.xpn.xwiki.plugin.skinx.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 Summary
Fields Modifier and Type Field Description protected static org.slf4j.Logger
LOGGER
Log helper for logging messages in this class.-
Fields inherited from class com.xpn.xwiki.plugin.skinx.AbstractSkinExtensionPlugin
contextKey, DEFER_DEFAULT_PARAM, parametersContextKey, QUERY_PARAMETER_DELIMITER
-
-
Constructor Summary
Constructors Constructor Description AbstractDocumentSkinExtensionPlugin(String name, String className, XWikiContext context)
XWiki plugin constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description String
endParsing(String content, XWikiContext context)
Set<org.xwiki.model.reference.DocumentReference>
getAlwaysUsedExtensions()
Returns the list of always used extensions of this type as a set of document references.Set<String>
getAlwaysUsedExtensions(XWikiContext context)
Returns the list of always used extensions of this type.protected String
getDocumentSkinExtensionURL(org.xwiki.model.reference.DocumentReference documentReference, String documentName, String pluginName, XWikiContext context)
Return the URL to a document skin extension.List<org.xwiki.observation.event.Event>
getEvents()
BaseClass
getExtensionClass(XWikiContext context)
Creates or updates the XClass used for this type of extension.protected abstract String
getExtensionClassName()
The name of the XClass which holds extensions of this type.protected abstract String
getExtensionName()
A user-friendly name for this type of resource, used in the auto-generated class document.boolean
hasPageExtensions(XWikiContext context)
Determines if the requested document contains on page skin extension objects of this type.void
init(XWikiContext context)
protected boolean
isAccessible(String documentName, XWikiContext context)
protected boolean
isAccessible(org.xwiki.model.reference.DocumentReference documentReference, XWikiContext context)
void
onEvent(org.xwiki.observation.event.Event event, Object source, Object data)
void
use(String resource, Map<String,Object> parameters, XWikiContext context)
Mark a skin extension document as used in the current result, together with some parameters.void
virtualInit(XWikiContext context)
-
Methods inherited from class com.xpn.xwiki.plugin.skinx.AbstractSkinExtensionPlugin
getCacheResources, getCurrentDocumentReferenceResolver, getDefaultEntityReferenceSerializer, getImportString, getLink, getLink, getParameter, getParametersForResource, getParametersMap, getPluginApi, getPulledResources, getSkinExtensionAsync, initializeRequestListIfNeeded, parametersAsQueryString, restoreCacheResources, sanitize, use
-
Methods inherited from class com.xpn.xwiki.plugin.XWikiDefaultPlugin
beginParsing, beginRendering, commonTagsHandler, downloadAttachment, endRendering, endRenderingHandler, flushCache, flushCache, getClassName, getLocalization, getName, insidePREHandler, localizePlainOrKey, outsidePREHandler, setClassName, setName, startRenderingHandler
-
-
-
-
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 interfaceorg.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 theSpace.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.
-
init
public void init(XWikiContext context)
Create/update the XClass corresponding to this kind of extension, and register the listeners that update the list of always used extensions.
- Specified by:
init
in interfaceXWikiPluginInterface
- Overrides:
init
in classXWikiDefaultPlugin
- See Also:
XWikiDefaultPlugin.init(com.xpn.xwiki.XWikiContext)
-
virtualInit
public void virtualInit(XWikiContext context)
Create/update the XClass corresponding to this kind of extension in this virtual wiki.
- Specified by:
virtualInit
in interfaceXWikiPluginInterface
- Overrides:
virtualInit
in classXWikiDefaultPlugin
- See Also:
XWikiDefaultPlugin.virtualInit(com.xpn.xwiki.XWikiContext)
-
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 valuealways
to declare that an extension should always be used.For this kind of resources, an XObject property (
use
) with the valuealways
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 classAbstractSkinExtensionPlugin
- 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 valuealways
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 thecurrentPage
value for theuse
property.- Specified by:
hasPageExtensions
in classAbstractSkinExtensionPlugin
- 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 classAbstractSkinExtensionPlugin
- 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)
-
endParsing
public String endParsing(String content, XWikiContext context)
At the end of the request, insert the links to the pulled resources in the response, in the place marked by an XML comment of the format
<!-- canonical.plugin.classname -->
.We must override this method since the plugin manager only calls it for classes that provide their own implementation, and not an inherited one.
- Specified by:
endParsing
in interfaceXWikiPluginInterface
- Overrides:
endParsing
in classAbstractSkinExtensionPlugin
- See Also:
AbstractSkinExtensionPlugin.endParsing(String, XWikiContext)
-
getExtensionClass
public BaseClass getExtensionClass(XWikiContext context)
Creates or updates the XClass used for this type of extension. Usually called oninit(XWikiContext)
andvirtualInit(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 interfaceorg.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 namecontext
- 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 referencecontext
- 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 referencedocumentName
- the Skin Extension's document namepluginName
- the name of the plugincontext
- the XWiki Context- Returns:
- the URL to the document skin extension.
- Since:
- 7.4.1
-
-