com.atlassian.plugin.webresource
Class BatchPluginResource

java.lang.Object
  extended by com.atlassian.plugin.webresource.BatchPluginResource
All Implemented Interfaces:
DownloadableResource, BatchResource, PluginResource

public class BatchPluginResource
extends Object
implements DownloadableResource, PluginResource, BatchResource

Represents a batch of plugin resources.

It provides methods to parse and generate urls to locate a batch of plugin resources.

Note BatchPluginResource is also a type of DownloadableResource. The underlying implementation simply keeps a list of DownloadableResource of which this batch represents and delegates method calls.

Since:
2.2

Constructor Summary
BatchPluginResource(String moduleCompleteKey, String type, Map<String,String> params)
          A constructor that creates a default resource name for the batch in the format: moduleCompleteKey.type For example: test.plugin:resources.js

Note that name of the batch does not identify what the batch includes and could have been static e.g.

BatchPluginResource(String moduleCompleteKey, String type, Map<String,String> params, Iterable<DownloadableResource> resources)
          A constructor that creates a default resource name for the batch in the format: moduleCompleteKey.type For example: test.plugin:resources.js

This constructor includes the resources that are contained in the batch, and so is primarily for use when serving the resource.

 
Method Summary
protected  void addParamsToUrl(StringBuilder sb, Map<String,String> params)
           
 boolean equals(Object o)
           
 String getContentType()
          Returns the content type for the resource.
 String getModuleCompleteKey()
           
 Map<String,String> getParams()
           
 String getResourceName()
           
 String getType()
           
 String getUrl()
          Returns a url string in the format: /download/batch/MODULE_COMPLETE_KEY/resourceName?PARAMS e.g.
 String getVersion(WebResourceIntegration integration)
           
 int hashCode()
           
 boolean isCacheSupported()
           
 boolean isEmpty()
           
 boolean isResourceModified(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Returns true if the plugin resource has been modified.
 void serveResource(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Writes the resource content out into the response.
 void streamResource(OutputStream out)
          Write the resource to the supplied OutputStream.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BatchPluginResource

public BatchPluginResource(String moduleCompleteKey,
                           String type,
                           Map<String,String> params)
A constructor that creates a default resource name for the batch in the format: moduleCompleteKey.type For example: test.plugin:resources.js

Note that name of the batch does not identify what the batch includes and could have been static e.g. batch.js

Parameters:
moduleCompleteKey - - the key of the plugin module
type - - the type of resource (CSS/JS)
params - - the parameters of the resource (ieonly, media, etc)

BatchPluginResource

public BatchPluginResource(String moduleCompleteKey,
                           String type,
                           Map<String,String> params,
                           Iterable<DownloadableResource> resources)
A constructor that creates a default resource name for the batch in the format: moduleCompleteKey.type For example: test.plugin:resources.js

This constructor includes the resources that are contained in the batch, and so is primarily for use when serving the resource.

Parameters:
moduleCompleteKey - - the key of the plugin module
type - - the type of resource (CSS/JS)
params - - the parameters of the resource (ieonly, media, etc)
resources - - the resources included in the batch.
Method Detail

isEmpty

public boolean isEmpty()
Returns:
true if there are no resources included in this batch

isResourceModified

public boolean isResourceModified(javax.servlet.http.HttpServletRequest request,
                                  javax.servlet.http.HttpServletResponse response)
Description copied from interface: DownloadableResource
Returns true if the plugin resource has been modified. The implementing class is responsible for setting any appropriate response codes or headers on the response. If the resource has been modified, the resource shouldn't be served.

Specified by:
isResourceModified in interface DownloadableResource

serveResource

public void serveResource(javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response)
                   throws DownloadException
Description copied from interface: DownloadableResource
Writes the resource content out into the response.

Specified by:
serveResource in interface DownloadableResource
Throws:
DownloadException - if there were errors writing to the response.

streamResource

public void streamResource(OutputStream out)
                    throws DownloadException
Description copied from interface: DownloadableResource
Write the resource to the supplied OutputStream. Note that the OutputStream will not be closed by this method.

Specified by:
streamResource in interface DownloadableResource
Parameters:
out - the stream to write to
Throws:
DownloadException - if there were errors writing to the response. Since 2.3.

getContentType

public String getContentType()
Description copied from interface: DownloadableResource
Returns the content type for the resource. May return null if it cannot resolve its own content type.

Specified by:
getContentType in interface DownloadableResource

getUrl

public String getUrl()
Returns a url string in the format: /download/batch/MODULE_COMPLETE_KEY/resourceName?PARAMS e.g. /download/batch/example.plugin:webresources/example.plugin:webresources.css?ie=true

It is important for the url structure to be: 1. the same number of sectioned paths as the SinglePluginResource 2. include the module completey key in the path before the resource name This is due to css resources referencing other resources such as images in relative path forms.

Specified by:
getUrl in interface PluginResource
Returns:
the url for this plugin resource.

addParamsToUrl

protected void addParamsToUrl(StringBuilder sb,
                              Map<String,String> params)

getResourceName

public String getResourceName()
Specified by:
getResourceName in interface PluginResource
Returns:
the resource name for the plugin resource.

getParams

public Map<String,String> getParams()
Specified by:
getParams in interface BatchResource
Specified by:
getParams in interface PluginResource
Returns:
a map of parameter key and value pairs for this resource.

getVersion

public String getVersion(WebResourceIntegration integration)
Specified by:
getVersion in interface PluginResource
Returns:
the version prefix string for a cached resource

getModuleCompleteKey

public String getModuleCompleteKey()
Specified by:
getModuleCompleteKey in interface PluginResource
Returns:
the plugin module's complete key for which this resource belongs to.

isCacheSupported

public boolean isCacheSupported()
Specified by:
isCacheSupported in interface PluginResource
Returns:
true if caching for this resource is supported. Use this check to append a static caching url prefix to this resource's url.

getType

public String getType()
Specified by:
getType in interface BatchResource

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011 Atlassian. All Rights Reserved.