com.atlassian.plugin.webresource
Class WebResourceManagerImpl

java.lang.Object
  extended by com.atlassian.plugin.webresource.WebResourceManagerImpl
All Implemented Interfaces:
WebResourceManager

public class WebResourceManagerImpl
extends java.lang.Object
implements WebResourceManager

A handy super-class that handles most of the resource management.

To use this manager, you need to have the following UrlRewriteFilter code:

 <rule>
 <from>^/s/(.*)/_/(.*)</from>
 <run class="com.atlassian.plugin.servlet.ResourceDownloadUtils" method="addCachingHeaders" />
 <to type="forward">/$2</to>
 </rule>
 

Sub-classes should implement the abstract methods


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.atlassian.plugin.webresource.WebResourceManager
WebResourceManager.IncludeMode
 
Field Summary
protected  ResourceBatchingConfiguration batchingConfiguration
           
protected  com.atlassian.plugin.webresource.ResourceDependencyResolver dependencyResolver
           
protected  PluginResourceLocator pluginResourceLocator
           
protected static java.util.List<com.atlassian.plugin.webresource.WebResourceFormatter> webResourceFormatters
           
protected  WebResourceIntegration webResourceIntegration
           
 
Fields inherited from interface com.atlassian.plugin.webresource.WebResourceManager
DELAYED_INCLUDE_MODE, INLINE_INCLUDE_MODE
 
Constructor Summary
WebResourceManagerImpl(PluginResourceLocator pluginResourceLocator, WebResourceIntegration webResourceIntegration)
           
WebResourceManagerImpl(PluginResourceLocator pluginResourceLocator, WebResourceIntegration webResourceIntegration, ResourceBatchingConfiguration batchingConfiguration)
           
WebResourceManagerImpl(PluginResourceLocator pluginResourceLocator, WebResourceIntegration webResourceIntegration, ResourceBatchingConfiguration batchingConfiguration, com.atlassian.plugin.webresource.ResourceDependencyResolver dependencyResolver)
           
 
Method Summary
 java.lang.String getRequiredResources()
          This is the equivalent of calling getRequiredResources(UrlMode, WebResourceFilter) with UrlMode.AUTO and a DefaultWebResourceFilter.
 java.lang.String getRequiredResources(UrlMode urlMode)
          This is the equivalent of calling getRequiredResources(UrlMode, WebResourceFilter) with the given url mode and a DefaultWebResourceFilter.
 java.lang.String getRequiredResources(UrlMode urlMode, WebResourceFilter webResourceFilter)
          Returns a String of the resources tags to the previously required resources called via requireResource methods for the specified url mode and resource filter.
 java.lang.String getResourceTags(java.lang.String moduleCompleteKey)
          Returns the resource tags of the specified resource.
 java.lang.String getResourceTags(java.lang.String moduleCompleteKey, UrlMode urlMode)
          Returns the resource tags of the specified resource.
 java.lang.String getStaticPluginResource(ModuleDescriptor moduleDescriptor, java.lang.String resourceName)
          A helper method to return a url for 'plugin' resources.
 java.lang.String getStaticPluginResource(ModuleDescriptor moduleDescriptor, java.lang.String resourceName, UrlMode urlMode)
          A helper method to return a url for 'plugin' resources.
 java.lang.String getStaticPluginResource(java.lang.String moduleCompleteKey, java.lang.String resourceName)
          A helper method to return a url for 'plugin' resources.
 java.lang.String getStaticPluginResource(java.lang.String moduleCompleteKey, java.lang.String resourceName, UrlMode urlMode)
          A helper method to return a url for 'plugin' resources.
 java.lang.String getStaticPluginResourcePrefix(ModuleDescriptor moduleDescriptor, java.lang.String resourceName)
          Deprecated. Use getStaticPluginResource(com.atlassian.plugin.ModuleDescriptor, String) instead
 java.lang.String getStaticResourcePrefix()
          A helper method to return a prefix for 'system' static resources.
 java.lang.String getStaticResourcePrefix(java.lang.String resourceCounter)
          A helper method to return a prefix for 'system' static resources.
 java.lang.String getStaticResourcePrefix(java.lang.String resourceCounter, UrlMode urlMode)
          A helper method to return a prefix for 'system' static resources.
 java.lang.String getStaticResourcePrefix(UrlMode urlMode)
          A helper method to return a prefix for 'system' static resources.
 void includeResources(java.lang.Iterable<java.lang.String> moduleCompleteKeys, java.io.Writer writer, UrlMode urlMode)
          Writes out the resource tags for a specified set of required resources and their dependencies.
 void includeResources(java.io.Writer writer)
          This is the equivalent of of calling includeResources(Writer, UrlMode, WebResourceFilter) with UrlMode.AUTO and a DefaultWebResourceFilter.
 void includeResources(java.io.Writer writer, UrlMode urlMode)
          This is the equivalent of of calling includeResources(Writer, UrlMode, WebResourceFilter) with the given url mode and a DefaultWebResourceFilter.
 void includeResources(java.io.Writer writer, UrlMode urlMode, WebResourceFilter webResourceFilter)
          Writes out the resource tags to the previously required resources called via requireResource methods for the specified url mode and resource filter.
 void requireResource(java.lang.String moduleCompleteKey)
          Indicates that a given plugin web resource is required.
 void requireResource(java.lang.String moduleCompleteKey, java.io.Writer writer)
          Writes the resource tags of the specified resource to the writer.
 void requireResource(java.lang.String moduleCompleteKey, java.io.Writer writer, UrlMode urlMode)
          Writes the resource tags of the specified resource to the writer.
 void requireResourcesForContext(java.lang.String context)
          Writes the resource tags of all resources that have the given context specified in their descriptor.
 void setIncludeMode(WebResourceManager.IncludeMode includeMode)
          Deprecated. Since 2.2.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

webResourceIntegration

protected final WebResourceIntegration webResourceIntegration

pluginResourceLocator

protected final PluginResourceLocator pluginResourceLocator

batchingConfiguration

protected final ResourceBatchingConfiguration batchingConfiguration

dependencyResolver

protected final com.atlassian.plugin.webresource.ResourceDependencyResolver dependencyResolver

webResourceFormatters

protected static final java.util.List<com.atlassian.plugin.webresource.WebResourceFormatter> webResourceFormatters
Constructor Detail

WebResourceManagerImpl

public WebResourceManagerImpl(PluginResourceLocator pluginResourceLocator,
                              WebResourceIntegration webResourceIntegration)

WebResourceManagerImpl

public WebResourceManagerImpl(PluginResourceLocator pluginResourceLocator,
                              WebResourceIntegration webResourceIntegration,
                              ResourceBatchingConfiguration batchingConfiguration)

WebResourceManagerImpl

public WebResourceManagerImpl(PluginResourceLocator pluginResourceLocator,
                              WebResourceIntegration webResourceIntegration,
                              ResourceBatchingConfiguration batchingConfiguration,
                              com.atlassian.plugin.webresource.ResourceDependencyResolver dependencyResolver)
Method Detail

requireResource

public void requireResource(java.lang.String moduleCompleteKey)
Description copied from interface: WebResourceManager
Indicates that a given plugin web resource is required. All resources called via this method must be included when WebResourceManager.includeResources(Writer) is called.

Specified by:
requireResource in interface WebResourceManager
Parameters:
moduleCompleteKey - The fully qualified plugin web resource module (eg jira.webresources:scriptaculous)
See Also:
WebResourceManager.includeResources(Writer, UrlMode)

requireResourcesForContext

public void requireResourcesForContext(java.lang.String context)
Description copied from interface: WebResourceManager
Writes the resource tags of all resources that have the given context specified in their descriptor.

Specified by:
requireResourcesForContext in interface WebResourceManager
Parameters:
context - The name of the context for which you want to require resources (eg "atl.admin")

includeResources

public void includeResources(java.io.Writer writer)
This is the equivalent of of calling includeResources(Writer, UrlMode, WebResourceFilter) with UrlMode.AUTO and a DefaultWebResourceFilter.

Specified by:
includeResources in interface WebResourceManager
Parameters:
writer - The writer to write the links to
See Also:
includeResources(Writer, UrlMode, WebResourceFilter)

includeResources

public void includeResources(java.lang.Iterable<java.lang.String> moduleCompleteKeys,
                             java.io.Writer writer,
                             UrlMode urlMode)
Description copied from interface: WebResourceManager
Writes out the resource tags for a specified set of required resources and their dependencies. Does not write out tags for resources specified in calls to WebResourceManager.requireResource(String).

Specified by:
includeResources in interface WebResourceManager
Parameters:
moduleCompleteKeys - The set of web resource modules to include
writer - the writer to write the links to
urlMode - specifies whether to use absolute URLs, relative URLs, or allow the concrete implementation to decide

includeResources

public void includeResources(java.io.Writer writer,
                             UrlMode urlMode)
This is the equivalent of of calling includeResources(Writer, UrlMode, WebResourceFilter) with the given url mode and a DefaultWebResourceFilter.

Specified by:
includeResources in interface WebResourceManager
See Also:
includeResources(Writer, UrlMode, WebResourceFilter)

includeResources

public void includeResources(java.io.Writer writer,
                             UrlMode urlMode,
                             WebResourceFilter webResourceFilter)
Writes out the resource tags to the previously required resources called via requireResource methods for the specified url mode and resource filter. Note that this method will clear the list of previously required resources.

Specified by:
includeResources in interface WebResourceManager
Parameters:
writer - the writer to write the links to
urlMode - the url mode to write resource url links in
webResourceFilter - the resource filter to filter resources on
Since:
2.4

getRequiredResources

public java.lang.String getRequiredResources()
This is the equivalent of calling getRequiredResources(UrlMode, WebResourceFilter) with UrlMode.AUTO and a DefaultWebResourceFilter.

Specified by:
getRequiredResources in interface WebResourceManager
Returns:
the resource tags for all resources previously required
See Also:
getRequiredResources(UrlMode, WebResourceFilter)

getRequiredResources

public java.lang.String getRequiredResources(UrlMode urlMode)
This is the equivalent of calling getRequiredResources(UrlMode, WebResourceFilter) with the given url mode and a DefaultWebResourceFilter.

Specified by:
getRequiredResources in interface WebResourceManager
Returns:
the resource tags for all resources previously required
See Also:
getRequiredResources(UrlMode, WebResourceFilter)

getRequiredResources

public java.lang.String getRequiredResources(UrlMode urlMode,
                                             WebResourceFilter webResourceFilter)
Returns a String of the resources tags to the previously required resources called via requireResource methods for the specified url mode and resource filter. Note that this method will NOT clear the list of previously required resources.

Specified by:
getRequiredResources in interface WebResourceManager
Parameters:
urlMode - the url mode to write out the resource tags
webResourceFilter - the web resource filter to filter resources on
Returns:
a String of the resource tags
Since:
2.4
See Also:
WebResourceManager.includeResources(Writer, UrlMode, WebResourceFilter)

requireResource

public void requireResource(java.lang.String moduleCompleteKey,
                            java.io.Writer writer)
Description copied from interface: WebResourceManager
Writes the resource tags of the specified resource to the writer. If you need it as a String to embed the tags in a template, use WebResourceManager.getResourceTags(String).

In general, the behavior of this method should be equivalent to calling WebResourceManager.requireResource(String, Writer, UrlMode) with a urlMode value of UrlMode.AUTO.

Specified by:
requireResource in interface WebResourceManager
Parameters:
moduleCompleteKey - The fully qualified plugin web resource module (eg jira.webresources:scriptaculous)
writer - The writer to write the resource tags to.

requireResource

public void requireResource(java.lang.String moduleCompleteKey,
                            java.io.Writer writer,
                            UrlMode urlMode)
Description copied from interface: WebResourceManager
Writes the resource tags of the specified resource to the writer. If you need it as a String to embed the tags in a template, use WebResourceManager.getResourceTags(String, UrlMode).

This method formats resource URLs in either relative or absolute format, depending on the value of urlMode. See UrlMode for details of the different options for URL format.

Specified by:
requireResource in interface WebResourceManager
Parameters:
moduleCompleteKey - The fully qualified plugin web resource module (eg jira.webresources:scriptaculous)
writer - The writer to write the resource tags to.
urlMode - specifies whether to use absolute URLs, relative URLs, or allow the concrete implementation to decide

getResourceTags

public java.lang.String getResourceTags(java.lang.String moduleCompleteKey)
Description copied from interface: WebResourceManager
Returns the resource tags of the specified resource. If you are outputting the value to a Writer, use WebResourceManager.requireResource(String, java.io.Writer).

In general, the behavior of this method should be equivalent to calling WebResourceManager.getResourceTags(String, UrlMode) with a urlMode value of UrlMode.AUTO.

Specified by:
getResourceTags in interface WebResourceManager
Parameters:
moduleCompleteKey - The fully qualified plugin web resource module (eg jira.webresources:scriptaculous)
Returns:
the resource tags for the specified resource
See Also:
WebResourceManager.requireResource(String, Writer)

getResourceTags

public java.lang.String getResourceTags(java.lang.String moduleCompleteKey,
                                        UrlMode urlMode)
Description copied from interface: WebResourceManager
Returns the resource tags of the specified resource. If you are outputting the value to a Writer, use WebResourceManager.requireResource(String, java.io.Writer, UrlMode).

This method formats resource URLs in either relative or absolute format, depending on the value of urlMode. See UrlMode for details of the different options for URL format.

Specified by:
getResourceTags in interface WebResourceManager
Parameters:
moduleCompleteKey - The fully qualified plugin web resource module (eg jira.webresources:scriptaculous)
urlMode - specifies whether to use absolute URLs, relative URLs, or allow the concrete implementation to decide
Returns:
the resource tags for the specified resource
See Also:
WebResourceManager.requireResource(String, Writer, UrlMode)

getStaticResourcePrefix

public java.lang.String getStaticResourcePrefix()
Description copied from interface: WebResourceManager
A helper method to return a prefix for 'system' static resources. Generally the implementation will return

/s/{build num}/{system counter}/_

Note that the servlet context is prepended, and there is no trailing slash.

Typical usage is to replace:

<%= request.getContextPath() %>/styles/global.css with <%= webResourceManager.getStaticResourcePrefix() %>/styles/global.css

In general, the behavior of this method should be equivalent to calling WebResourceManager.getStaticResourcePrefix(UrlMode) with a urlMode value of UrlMode.AUTO.

Specified by:
getStaticResourcePrefix in interface WebResourceManager
Returns:
A prefix that can be used to prefix 'static system' resources.

getStaticResourcePrefix

public java.lang.String getStaticResourcePrefix(UrlMode urlMode)
Description copied from interface: WebResourceManager
A helper method to return a prefix for 'system' static resources. Generally the implementation will return

/s/{build num}/{system counter}/_

Note that the servlet context is prepended, and there is no trailing slash.

Typical usage is to replace:

<%= request.getContextPath() %>/styles/global.css with <%= webResourceManager.getStaticResourcePrefix() %>/styles/global.css

This method returns a URL in either a relative or an absolute format, depending on the value of urlMode. See UrlMode for details of the different options for URL format.

Specified by:
getStaticResourcePrefix in interface WebResourceManager
Parameters:
urlMode - specifies whether to use absolute URLs, relative URLs, or allow the concrete implementation to decide
Returns:
A prefix that can be used to prefix 'static system' resources.

getStaticResourcePrefix

public java.lang.String getStaticResourcePrefix(java.lang.String resourceCounter)
Description copied from interface: WebResourceManager
A helper method to return a prefix for 'system' static resources. This method should be used for resources that change more frequently than system resources, and therefore have their own resource counter.

Generally the implementation will return

/s/{build num}/{system counter}/{resource counter}/_

Note that the servlet context is prepended, and there is no trailing slash.

Typical usage is to replace:

<%= request.getContextPath() %>/styles/global.css with <%= webResourceManager.getStaticResourcePrefix(resourceCounter) %>/styles/global.css

In general, the behavior of this method should be equivalent to calling WebResourceManager.getStaticResourcePrefix(String, UrlMode) with a urlMode value of UrlMode.AUTO.

Specified by:
getStaticResourcePrefix in interface WebResourceManager
Parameters:
resourceCounter - A number that represents the unique version of the resource you require. Every time this resource changes, you need to increment the resource counter
Returns:
A prefix that can be used to prefix 'static system' resources.

getStaticResourcePrefix

public java.lang.String getStaticResourcePrefix(java.lang.String resourceCounter,
                                                UrlMode urlMode)
Description copied from interface: WebResourceManager
A helper method to return a prefix for 'system' static resources. This method should be used for resources that change more frequently than system resources, and therefore have their own resource counter.

Generally the implementation will return

/s/{build num}/{system counter}/{resource counter}/_

Note that the servlet context is prepended, and there is no trailing slash.

Typical usage is to replace:

<%= request.getContextPath() %>/styles/global.css with <%= webResourceManager.getStaticResourcePrefix(resourceCounter) %>/styles/global.css

This method returns a URL in either a relative or an absolute format, depending on the value of urlMode. See UrlMode for details of the different options for URL format.

Specified by:
getStaticResourcePrefix in interface WebResourceManager
Parameters:
resourceCounter - A number that represents the unique version of the resource you require. Every time this resource changes, you need to increment the resource counter
urlMode - specifies whether to use absolute URLs, relative URLs, or allow the concrete implementation to decide
Returns:
A prefix that can be used to prefix 'static system' resources.

getStaticPluginResource

public java.lang.String getStaticPluginResource(java.lang.String moduleCompleteKey,
                                                java.lang.String resourceName)
Description copied from interface: WebResourceManager
A helper method to return a url for 'plugin' resources. Generally the implementation will return

/s/{build num}/{system counter}/{plugin version}/_/download/resources/plugin.key:module.key/resource.name

Note that the servlet context is prepended, and there is no trailing slash.

Typical usage is to replace:

<%= request.getContextPath() %>/download/resources/plugin.key:module.key/resource.name with <%= webResourceManager.getStaticPluginResource(descriptor, resourceName) %>

In general, the behavior of this method should be equivalent to calling WebResourceManager.getStaticPluginResource(String, String, UrlMode) with a urlMode value of UrlMode.AUTO.

Specified by:
getStaticPluginResource in interface WebResourceManager
Parameters:
moduleCompleteKey - complete plugin module key
resourceName - the name of the resource as defined in the plugin manifest
Returns:
A url that can be used to request 'plugin' resources.

getStaticPluginResource

public java.lang.String getStaticPluginResource(java.lang.String moduleCompleteKey,
                                                java.lang.String resourceName,
                                                UrlMode urlMode)
Description copied from interface: WebResourceManager
A helper method to return a url for 'plugin' resources. Generally the implementation will return

/s/{build num}/{system counter}/{plugin version}/_/download/resources/plugin.key:module.key/resource.name

Note that the servlet context is prepended, and there is no trailing slash.

Typical usage is to replace:

<%= request.getContextPath() %>/download/resources/plugin.key:module.key/resource.name with <%= webResourceManager.getStaticPluginResource(descriptor, resourceName) %>

This method returns a URL in either a relative or an absolute format, depending on the value of urlMode. See UrlMode for details of the different options for URL format.

Specified by:
getStaticPluginResource in interface WebResourceManager
Parameters:
moduleCompleteKey - complete plugin module key
resourceName - the name of the resource as defined in the plugin manifest
urlMode - specifies whether to use absolute URLs, relative URLs, or allow the concrete implementation to decide
Returns:
A url that can be used to request 'plugin' resources.

getStaticPluginResource

public java.lang.String getStaticPluginResource(ModuleDescriptor moduleDescriptor,
                                                java.lang.String resourceName)
Description copied from interface: WebResourceManager
A helper method to return a url for 'plugin' resources. Generally the implementation will return

/s/{build num}/{system counter}/{plugin version}/_/download/resources/plugin.key:module.key/resource.name

Note that the servlet context is prepended, and there is no trailing slash.

Typical usage is to replace:

<%= request.getContextPath() %>/download/resources/plugin.key:module.key/resource.name with <%= webResourceManager.getStaticPluginResource(descriptor, resourceName) %>

In general, the behavior of this method should be equivalent to calling WebResourceManager.getStaticPluginResource(ModuleDescriptor, String, UrlMode) with a urlMode value of UrlMode.AUTO.

Specified by:
getStaticPluginResource in interface WebResourceManager
Parameters:
moduleDescriptor - plugin module descriptor that contains the resource
resourceName - the name of the resource as defined in the plugin manifest
Returns:
"{base url}/s/{build num}/{system counter}/{plugin version}/_/download/resources/{plugin.key:module.key}/{resource.name}"
See Also:
WebResourceManager.getStaticPluginResource(String, String)

getStaticPluginResource

public java.lang.String getStaticPluginResource(ModuleDescriptor moduleDescriptor,
                                                java.lang.String resourceName,
                                                UrlMode urlMode)
Description copied from interface: WebResourceManager
A helper method to return a url for 'plugin' resources. Generally the implementation will return

/s/{build num}/{system counter}/{plugin version}/_/download/resources/plugin.key:module.key/resource.name

Note that the servlet context is prepended, and there is no trailing slash.

Typical usage is to replace:

<%= request.getContextPath() %>/download/resources/plugin.key:module.key/resource.name with <%= webResourceManager.getStaticPluginResource(descriptor, resourceName) %>

This method returns a URL in either a relative or an absolute format, depending on the value of urlMode. See UrlMode for details of the different options for URL format.

Specified by:
getStaticPluginResource in interface WebResourceManager
Parameters:
moduleDescriptor - plugin module descriptor that contains the resource
resourceName - the name of the resource as defined in the plugin manifest
urlMode - specifies whether to use absolute URLs, relative URLs, or allow the concrete implementation to decide
Returns:
returns the url of this plugin resource
See Also:
WebResourceManager.getStaticPluginResource(String, String, UrlMode)

getStaticPluginResourcePrefix

@Deprecated
public java.lang.String getStaticPluginResourcePrefix(ModuleDescriptor moduleDescriptor,
                                                                 java.lang.String resourceName)
Deprecated. Use getStaticPluginResource(com.atlassian.plugin.ModuleDescriptor, String) instead

Specified by:
getStaticPluginResourcePrefix in interface WebResourceManager

setIncludeMode

@Deprecated
public void setIncludeMode(WebResourceManager.IncludeMode includeMode)
Deprecated. Since 2.2.

Description copied from interface: WebResourceManager
Whether resources should be included inline, or at the top of the page. In most cases, you want to leave this as the default. However, for pages that don't have a decorator, you will not be able to 'delay' including the resources (css, javascript), and therefore need to include them directly inline.

Specified by:
setIncludeMode in interface WebResourceManager
Parameters:
includeMode - If there is no decorator for this request, set this to be WebResourceManager.INLINE_INCLUDE_MODE
See Also:
WebResourceManager.DELAYED_INCLUDE_MODE, WebResourceManager.INLINE_INCLUDE_MODE


Copyright © 2010 Atlassian. All Rights Reserved.