1 package com.atlassian.plugin.servlet;
2
3 import com.atlassian.plugin.elements.ResourceLocation;
4 import org.apache.commons.lang.StringUtils;
5
6 import javax.servlet.ServletException;
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
9 import java.io.IOException;
10 import java.io.OutputStream;
11
12
13
14
15
16 public class ForwardableResource implements DownloadableResource
17 {
18 private ResourceLocation resourceLocation;
19
20 public ForwardableResource(ResourceLocation resourceLocation)
21 {
22 this.resourceLocation = resourceLocation;
23 }
24
25 public boolean isResourceModified(HttpServletRequest request, HttpServletResponse response)
26 {
27 return false;
28 }
29
30 public void serveResource(HttpServletRequest request, HttpServletResponse response) throws DownloadException
31 {
32 try
33 {
34 String type = getContentType();
35 if(StringUtils.isNotBlank(type))
36 {
37 response.setContentType(type);
38 }
39 request.getRequestDispatcher(getLocation()).forward(request, response);
40 }
41 catch(ServletException e)
42 {
43 throw new DownloadException(e.getMessage());
44 }
45 catch (IOException ioe)
46 {
47 throw new DownloadException(ioe.getMessage());
48 }
49 }
50
51
52
53
54 public void streamResource(OutputStream out)
55 {
56 return;
57 }
58
59 public String getContentType()
60 {
61 return resourceLocation.getContentType();
62 }
63
64 protected String getLocation()
65 {
66 return resourceLocation.getLocation();
67 }
68 }
69