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  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)
           
 
Method Summary
 java.lang.String getRequiredResources()
           
 java.lang.String getResourceTags(java.lang.String moduleCompleteKey)
           
 java.lang.String getStaticPluginResource(ModuleDescriptor moduleDescriptor, java.lang.String resourceName)
           
 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 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.
 void includeResources(java.io.Writer writer)
          Writes out the resource tags to the previously required resources called via WebResourceManager.requireResource(String).
 void requireResource(java.lang.String moduleCompleteKey)
          Indicates to 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 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

webResourceFormatters

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

WebResourceManagerImpl

public WebResourceManagerImpl(PluginResourceLocator pluginResourceLocator,
                              WebResourceIntegration webResourceIntegration)
Method Detail

requireResource

public void requireResource(java.lang.String moduleCompleteKey)
Description copied from interface: WebResourceManager
Indicates to 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)

includeResources

public void includeResources(java.io.Writer writer)
Description copied from interface: WebResourceManager
Writes out the resource tags to the previously required resources called via WebResourceManager.requireResource(String). If you need it as a String to embed the tags in a template, use WebResourceManager.getRequiredResources().

Example - if a 'javascript' resource has been required earlier with requireResource(), this method should output:


  <script type="text/javascript" src="$contextPath/scripts/javascript.js"></script>
 
Similarly for other supported resources

Specified by:
includeResources in interface WebResourceManager
Parameters:
writer - The writer to write the links to

getRequiredResources

public java.lang.String getRequiredResources()
Specified by:
getRequiredResources in interface WebResourceManager
See Also:
#includeResources(Writer)}

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.getRequiredResources().

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.

getResourceTags

public java.lang.String getResourceTags(java.lang.String moduleCompleteKey)
Specified by:
getResourceTags in interface WebResourceManager
See Also:
#requireResource(String, Writer)}

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

Specified by:
getStaticResourcePrefix in interface WebResourceManager
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

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.

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) %>

Specified by:
getStaticPluginResource in interface WebResourceManager
Parameters:
moduleCompleteKey - complete plugin module key
Returns:
A url that can be used to request 'plugin' resources.

getStaticPluginResource

public java.lang.String getStaticPluginResource(ModuleDescriptor moduleDescriptor,
                                                java.lang.String resourceName)
Specified by:
getStaticPluginResource in interface WebResourceManager
Returns:
"{base url}/s/{build num}/{system counter}/{plugin version}/_/download/resources/{plugin.key:module.key}/{resource.name}"
See Also:
#getStaticPluginResource(String, String)}

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 © 2009 Atlassian Pty Ltd. All Rights Reserved.