Class CharSequenceDownloadableResource

java.lang.Object
com.atlassian.plugin.webresource.transformer.AbstractTransformedDownloadableResource
com.atlassian.plugin.webresource.transformer.CharSequenceDownloadableResource
All Implemented Interfaces:
com.atlassian.plugin.servlet.DownloadableResource

public abstract class CharSequenceDownloadableResource extends AbstractTransformedDownloadableResource
Abstract class that makes it easy to create transforms that go from string to string. Override encoding() 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 CharSequenceDownloadableResource(nextResource)
           {
               protected CharSequence transform(CharSequence originalContent)
               {
                   return "Prefix: "  + originalContent;
               }
           };
       }
    }
 
Since:
2.9.0
  • Constructor Details

    • CharSequenceDownloadableResource

      protected CharSequenceDownloadableResource(com.atlassian.plugin.servlet.DownloadableResource originalResource)
  • Method Details

    • streamResource

      public void streamResource(OutputStream out) throws com.atlassian.plugin.servlet.DownloadException
      Throws:
      com.atlassian.plugin.servlet.DownloadException
    • encoding

      protected Charset encoding()
    • transform

      protected abstract CharSequence transform(CharSequence originalContent)
      Override this method to transform the original content into a new format.
      Parameters:
      originalContent - The content from the original resource.
      Returns:
      transformed content