1 package com.atlassian.plugin.servlet;
2
3 import javax.servlet.http.HttpServletRequest;
4 import javax.servlet.http.HttpServletResponse;
5 import java.io.OutputStream;
6
7 /**
8 * Represents a plugin resource that can be downloaded.
9 *
10 * It is up to the calling class to check if the resource is modified before calling
11 * {@link #serveResource(HttpServletRequest, HttpServletResponse)} to serve the resource.
12 */
13 public interface DownloadableResource {
14
15 /**
16 * Returns true if the plugin resource has been modified. The implementing class is responsible for
17 * setting any appropriate response codes or headers on the response.
18 *
19 * If the resource has not been modified, the resource shouldn't be served.
20 */
21 boolean isResourceModified(HttpServletRequest request, HttpServletResponse response);
22
23 /**
24 * Writes the resource content out into the response.
25 *
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 }