View Javadoc

1   package com.atlassian.plugin.servlet;
2   
3   import java.io.OutputStream;
4   
5   import javax.servlet.http.HttpServletRequest;
6   import javax.servlet.http.HttpServletResponse;
7   
8   /**
9    * Represents a plugin resource that can be downloaded.
10   *
11   * It is up to the calling class to check if the resource is modified before calling
12   * {@link #serveResource(HttpServletRequest, HttpServletResponse)} to serve the resource.
13   */
14  public interface DownloadableResource
15  {
16      /**
17       * Returns true if the plugin resource has been modified. The implementing class is responsible for
18       * setting any appropriate response codes or headers on the response.
19       *
20       * If the resource has been modified, the resource shouldn't be served. 
21       */
22      boolean isResourceModified(HttpServletRequest request, HttpServletResponse response);
23  
24      /**
25       * Writes the resource content out into the response.
26       * @throws DownloadException if there were errors writing to the response.
27       * @since 2.2
28       */
29      void serveResource(HttpServletRequest request, HttpServletResponse response) throws DownloadException;
30  
31      /**
32       * Write the resource to the supplied OutputStream. Note that the OutputStream will not be closed by this method.
33       * 
34       * @param out the stream to write to
35       * @throws DownloadException if there were errors writing to the response. Since 2.3.
36       * @since 2.2
37       */
38      void streamResource(OutputStream out) throws DownloadException;
39  
40      /**
41       * Returns the content type for the resource. May return null if it cannot resolve its own content type.
42       * 
43       * @since 2.2
44       */
45      String getContentType();
46  }