public class

WebResourceManagerImpl

extends Object
implements WebResourceManager
java.lang.Object
   ↳ com.atlassian.plugin.webresource.WebResourceManagerImpl

Class Overview

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

Summary

Fields
protected final ResourceBatchingConfiguration batchingConfiguration
protected final ResourceDependencyResolver dependencyResolver
protected final PluginResourceLocator pluginResourceLocator
protected static final List<WebResourceFormatter> webResourceFormatters
protected final WebResourceIntegration webResourceIntegration
[Expand]
Inherited Fields
From interface com.atlassian.plugin.webresource.WebResourceManager
Public Constructors
WebResourceManagerImpl(PluginResourceLocator pluginResourceLocator, WebResourceIntegration webResourceIntegration)
WebResourceManagerImpl(PluginResourceLocator pluginResourceLocator, WebResourceIntegration webResourceIntegration, ResourceBatchingConfiguration batchingConfiguration)
WebResourceManagerImpl(PluginResourceLocator pluginResourceLocator, WebResourceIntegration webResourceIntegration, ResourceBatchingConfiguration batchingConfiguration, ResourceDependencyResolver dependencyResolver)
Public Methods
String getRequiredResources(UrlMode urlMode)
This is the equivalent of calling getRequiredResources(UrlMode, WebResourceFilter) with the given url mode and a DefaultWebResourceFilter.
String getRequiredResources()
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.
String getResourceTags(String moduleCompleteKey, UrlMode urlMode)
Returns the resource tags of the specified resource.
String getResourceTags(String moduleCompleteKey)
Returns the resource tags of the specified resource.
String getStaticPluginResource(String moduleCompleteKey, String resourceName)
A helper method to return a url for 'plugin' resources.
String getStaticPluginResource(ModuleDescriptor moduleDescriptor, String resourceName)
String getStaticPluginResource(ModuleDescriptor moduleDescriptor, String resourceName, UrlMode urlMode)
String getStaticPluginResource(String moduleCompleteKey, String resourceName, UrlMode urlMode)
A helper method to return a url for 'plugin' resources.
String getStaticPluginResourcePrefix(ModuleDescriptor moduleDescriptor, String resourceName)
String getStaticResourcePrefix(String resourceCounter, UrlMode urlMode)
A helper method to return a prefix for 'system' static resources.
String getStaticResourcePrefix(String resourceCounter)
A helper method to return a prefix for 'system' static resources.
String getStaticResourcePrefix(UrlMode urlMode)
A helper method to return a prefix for 'system' static resources.
String getStaticResourcePrefix()
A helper method to return a prefix for 'system' static resources.
void includeResources(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(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 includeResources(Iterable<String> moduleCompleteKeys, Writer writer, UrlMode urlMode)
Writes out the resource tags for a specified set of required resources and their dependencies.
void includeResources(Writer writer)
void requireResource(String moduleCompleteKey, Writer writer)
Writes the resource tags of the specified resource to the writer.
void requireResource(String moduleCompleteKey)
Indicates that a given plugin web resource is required.
void requireResource(String moduleCompleteKey, Writer writer, UrlMode urlMode)
Writes the resource tags of the specified resource to the writer.
void requireResourcesForContext(String context)
Writes the resource tags of all resources that have the given context specified in their descriptor.
void setIncludeMode(WebResourceManager.IncludeMode includeMode)
This method is deprecated. Since 2.2.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.atlassian.plugin.webresource.WebResourceManager

Fields

protected final ResourceBatchingConfiguration batchingConfiguration

protected final ResourceDependencyResolver dependencyResolver

protected final PluginResourceLocator pluginResourceLocator

protected static final List<WebResourceFormatter> webResourceFormatters

protected final WebResourceIntegration webResourceIntegration

Public Constructors

public WebResourceManagerImpl (PluginResourceLocator pluginResourceLocator, WebResourceIntegration webResourceIntegration)

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

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

Public Methods

public String getRequiredResources (UrlMode urlMode)

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

Returns
  • the resource tags for all resources previously required

public String getRequiredResources ()

Returns
  • the resource tags for all resources previously required

public 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.

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

public String getResourceTags (String moduleCompleteKey, UrlMode urlMode)

Returns the resource tags of the specified resource. If you are outputting the value to a Writer, use 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.
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

public String getResourceTags (String moduleCompleteKey)

Returns the resource tags of the specified resource. If you are outputting the value to a Writer, use requireResource(String, java.io.Writer).

In general, the behavior of this method should be equivalent to calling getResourceTags(String, UrlMode) with a urlMode value of AUTO.
Parameters
moduleCompleteKey The fully qualified plugin web resource module (eg jira.webresources:scriptaculous)
Returns
  • the resource tags for the specified resource

public String getStaticPluginResource (String moduleCompleteKey, String resourceName)

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 getStaticPluginResource(String, String, UrlMode) with a urlMode value of AUTO.
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.

public String getStaticPluginResource (ModuleDescriptor moduleDescriptor, String resourceName)

Returns
  • "{base url}/s/{build num}/{system counter}/{plugin version}/_/download/resources/{plugin.key:module.key}/{resource.name}"

public String getStaticPluginResource (ModuleDescriptor moduleDescriptor, String resourceName, UrlMode urlMode)

public String getStaticPluginResource (String moduleCompleteKey, String resourceName, UrlMode urlMode)

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.
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.

public String getStaticPluginResourcePrefix (ModuleDescriptor moduleDescriptor, String resourceName)

public String getStaticResourcePrefix (String resourceCounter, UrlMode urlMode)

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.
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.

public String getStaticResourcePrefix (String resourceCounter)

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 getStaticResourcePrefix(String, UrlMode) with a urlMode value of AUTO.
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.

public String getStaticResourcePrefix (UrlMode urlMode)

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.
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.

public String getStaticResourcePrefix ()

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 getStaticResourcePrefix(UrlMode) with a urlMode value of AUTO.
Returns
  • A prefix that can be used to prefix 'static system' resources.

public void includeResources (Writer writer, UrlMode urlMode)

public void includeResources (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.

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

public void includeResources (Iterable<String> moduleCompleteKeys, Writer writer, UrlMode urlMode)

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 requireResource(String).

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

public void includeResources (Writer writer)

Parameters
writer The writer to write the links to

public void requireResource (String moduleCompleteKey, Writer writer)

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 getResourceTags(String).

In general, the behavior of this method should be equivalent to calling requireResource(String, Writer, UrlMode) with a urlMode value of AUTO.
Parameters
moduleCompleteKey The fully qualified plugin web resource module (eg jira.webresources:scriptaculous)
writer The writer to write the resource tags to.

public void requireResource (String moduleCompleteKey)

Indicates that a given plugin web resource is required. All resources called via this method must be included when includeResources(Writer) is called.

Parameters
moduleCompleteKey The fully qualified plugin web resource module (eg jira.webresources:scriptaculous)

public void requireResource (String moduleCompleteKey, Writer writer, UrlMode urlMode)

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 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.
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

public void requireResourcesForContext (String context)

Writes the resource tags of all resources that have the given context specified in their descriptor.

Parameters
context The name of the context for which you want to require resources (eg "atl.admin")

public void setIncludeMode (WebResourceManager.IncludeMode includeMode)

This method is deprecated.
Since 2.2.

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.

Parameters
includeMode If there is no decorator for this request, set this to be INLINE_INCLUDE_MODE