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
 
Fields inherited from interface com.atlassian.plugin.webresource.WebResourceManager
DELAYED_INCLUDE_MODE, INLINE_INCLUDE_MODE
 
Constructor Summary
WebResourceManagerImpl(WebResourceIntegration webResourceIntegration)
           
 
Method Summary
 java.lang.String getStaticPluginResource(ModuleDescriptor moduleDescriptor, java.lang.String resourceName)
          A helper method to return a url for 'plugin' resources.
 java.lang.String getStaticPluginResource(java.lang.String pluginModuleKey, java.lang.String resourceName)
           
 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)
          Include the resources that have already been specified by the request in the page.
 void requireResource(java.lang.String resourceName)
          Called by a component to indicate that a certain resource is required to be inserted into this page.
 void requireResource(java.lang.String resourceName, java.io.Writer writer)
          Called by a component to indicate that a certain resource is required to be inserted into this page.
 void setIncludeMode(WebResourceManager.IncludeMode includeMode)
          Whether resources should be included inline, or at the top of the page.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebResourceManagerImpl

public WebResourceManagerImpl(WebResourceIntegration webResourceIntegration)
Method Detail

requireResource

public void requireResource(java.lang.String resourceName)
Description copied from interface: WebResourceManager
Called by a component to indicate that a certain resource is required to be inserted into this page. Note that this will always include the resources as if we are in WebResourceManager.DELAYED_INCLUDE_MODE. Use this if you do not want to inline a resource.

Specified by:
requireResource in interface WebResourceManager
Parameters:
resourceName - The fully qualified plugin name to include (eg jira.webresources:scriptaculous)

requireResource

public void requireResource(java.lang.String resourceName,
                            java.io.Writer writer)
Description copied from interface: WebResourceManager
Called by a component to indicate that a certain resource is required to be inserted into this page.

Specified by:
requireResource in interface WebResourceManager
Parameters:
resourceName - The fully qualified plugin name to include (eg jira.webresources:scriptaculous)
writer - The writer to write the links to if the WebResourceManager.IncludeMode equals WebResourceManager.INLINE_INCLUDE_MODE

includeResources

public void includeResources(java.io.Writer writer)
Description copied from interface: WebResourceManager
Include the resources that have already been specified by the request in the page. This is done by including links to the resources that have been specified.

Example - if a 'javascript' resource has been specified, 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

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.

getStaticPluginResourcePrefix

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

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

Specified by:
getStaticPluginResource in interface WebResourceManager
Returns:
"{base url}/s/{build num}/{system counter}/{plugin version}/_/download/resources/{plugin.key:module.key}/{resource.name}"

getStaticPluginResource

public java.lang.String getStaticPluginResource(java.lang.String pluginModuleKey,
                                                java.lang.String resourceName)
Specified by:
getStaticPluginResource in interface WebResourceManager
Parameters:
pluginModuleKey - complete plugin module key
Returns:
returns the url of this plugin resource

setIncludeMode

public void setIncludeMode(WebResourceManager.IncludeMode includeMode)
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 © 2008 Atlassian Pty Ltd. All Rights Reserved.