com.atlassian.plugin.webresource.transformer
Class AbstractStringTransformedDownloadableResource

java.lang.Object
  extended by com.atlassian.plugin.webresource.transformer.AbstractTransformedDownloadableResource
      extended by com.atlassian.plugin.webresource.transformer.AbstractStringTransformedDownloadableResource
All Implemented Interfaces:
DownloadableResource

public abstract class AbstractStringTransformedDownloadableResource
extends AbstractTransformedDownloadableResource

Abstract class that makes it easy to create transforms that go from string to string. Override getEncoding() to customize the character encoding of the underlying content and transformed content.

For example, here is a minimal transformer that prepends text to the underlying resource:

 public class PrefixTransformer implements WebResourceTransformer
   {
       public DownloadableResource transform(Element configElement, ResourceLocation location, String filePath, DownloadableResource nextResource)
       {
           return new AbstractStringTransformedDownloadableResource(nextResource)
           {
               protected String transform(String originalContent)
               {
                   return "Prefix: "  + originalContent;
               }
           };
       }
    }
 

Since:
2.5.0

Constructor Summary
AbstractStringTransformedDownloadableResource(DownloadableResource originalResource)
           
 
Method Summary
protected  String getEncoding()
           
 void streamResource(OutputStream out)
          Write the resource to the supplied OutputStream.
protected abstract  String transform(String originalContent)
          Override this method to transform the original content into a new format.
 
Methods inherited from class com.atlassian.plugin.webresource.transformer.AbstractTransformedDownloadableResource
getContentType, getOriginalResource, isResourceModified, serveResource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractStringTransformedDownloadableResource

public AbstractStringTransformedDownloadableResource(DownloadableResource originalResource)
Method Detail

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.

Parameters:
out - the stream to write to
Throws:
DownloadException - if there were errors writing to the response. Since 2.3.

getEncoding

protected String getEncoding()
Returns:
the encoding used to read the original resource and encode the transformed string

transform

protected abstract String transform(String originalContent)
Override this method to transform the original content into a new format.

Parameters:
originalContent - The original content from the original downloadable resource.
Returns:
The transformed content you want returned


Copyright © 2010 Atlassian. All Rights Reserved.