com.xpn.xwiki.plugin.skinx
Class AbstractDocumentSkinExtensionPlugin

java.lang.Object
  extended by com.xpn.xwiki.plugin.XWikiDefaultPlugin
      extended by com.xpn.xwiki.plugin.skinx.AbstractSkinExtensionPlugin
          extended by com.xpn.xwiki.plugin.skinx.AbstractDocumentSkinExtensionPlugin
All Implemented Interfaces:
com.xpn.xwiki.plugin.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: b475243e5f5328a7cb69d23e1f0d5c2103ed0074 $
See Also:
JsSkinExtensionPlugin, CssSkinExtensionPlugin

Field Summary
 
Fields inherited from class com.xpn.xwiki.plugin.skinx.AbstractSkinExtensionPlugin
contextKey, parametersContextKey
 
Constructor Summary
AbstractDocumentSkinExtensionPlugin(String name, String className, com.xpn.xwiki.XWikiContext context)
          XWiki plugin constructor.
 
Method Summary
 String endParsing(String content, com.xpn.xwiki.XWikiContext context)
          
 Set<String> getAlwaysUsedExtensions(com.xpn.xwiki.XWikiContext context)
          Returns the list of always used extensions of this type.
 List<org.xwiki.observation.event.Event> getEvents()
           
 com.xpn.xwiki.objects.classes.BaseClass getExtensionClass(com.xpn.xwiki.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(com.xpn.xwiki.XWikiContext context)
          Determines if the requested document contains on page skin extension objects of this type.
 void init(com.xpn.xwiki.XWikiContext context)
          
 void onEvent(org.xwiki.observation.event.Event event, Object source, Object data)
          
 void virtualInit(com.xpn.xwiki.XWikiContext context)
          
 
Methods inherited from class com.xpn.xwiki.plugin.skinx.AbstractSkinExtensionPlugin
getImportString, getLink, getParameter, getParametersForResource, getParametersMap, getPluginApi, getPulledResources, initializeRequestListIfNeeded, parametersAsQueryString, sanitize, use, use
 
Methods inherited from class com.xpn.xwiki.plugin.XWikiDefaultPlugin
beginParsing, beginRendering, commonTagsHandler, downloadAttachment, endRendering, endRenderingHandler, flushCache, flushCache, getClassName, getName, insidePREHandler, outsidePREHandler, setClassName, setName, startRenderingHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xwiki.observation.EventListener
getName
 

Constructor Detail

AbstractDocumentSkinExtensionPlugin

public AbstractDocumentSkinExtensionPlugin(String name,
                                           String className,
                                           com.xpn.xwiki.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.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.

init

public void init(com.xpn.xwiki.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 interface com.xpn.xwiki.plugin.XWikiPluginInterface
Overrides:
init in class com.xpn.xwiki.plugin.XWikiDefaultPlugin
See Also:
XWikiDefaultPlugin.init(com.xpn.xwiki.XWikiContext)

virtualInit

public void virtualInit(com.xpn.xwiki.XWikiContext context)

Create/update the XClass corresponding to this kind of extension in this virtual wiki.

Specified by:
virtualInit in interface com.xpn.xwiki.plugin.XWikiPluginInterface
Overrides:
virtualInit in class com.xpn.xwiki.plugin.XWikiDefaultPlugin
See Also:
XWikiDefaultPlugin.virtualInit(com.xpn.xwiki.XWikiContext)

getAlwaysUsedExtensions

public Set<String> getAlwaysUsedExtensions(com.xpn.xwiki.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)

hasPageExtensions

public boolean hasPageExtensions(com.xpn.xwiki.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

endParsing

public String endParsing(String content,
                         com.xpn.xwiki.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 interface com.xpn.xwiki.plugin.XWikiPluginInterface
Overrides:
endParsing in class AbstractSkinExtensionPlugin
See Also:
AbstractSkinExtensionPlugin.endParsing(String, XWikiContext)

getExtensionClass

public com.xpn.xwiki.objects.classes.BaseClass getExtensionClass(com.xpn.xwiki.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)


Copyright © 2004-2012 XWiki. All Rights Reserved.