Rev 1306 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
204 | jmachado | 1 | package pt.estgp.estgweb.web; |
2 | |||
3 | import jomm.utils.StreamsUtils; |
||
760 | jmachado | 4 | import org.apache.log4j.Logger; |
204 | jmachado | 5 | import pt.estgp.estgweb.services.data.IRepositoryFile; |
6 | import pt.estgp.estgweb.web.utils.RequestUtils; |
||
7 | import pt.utl.ist.berserk.logic.serviceManager.IServiceManager; |
||
8 | import pt.utl.ist.berserk.logic.serviceManager.ServiceManager; |
||
9 | import pt.utl.ist.berserk.logic.serviceManager.exceptions.FilterChainFailedException; |
||
10 | |||
760 | jmachado | 11 | import javax.servlet.ServletException; |
12 | import javax.servlet.http.HttpServlet; |
||
13 | import javax.servlet.http.HttpServletRequest; |
||
14 | import javax.servlet.http.HttpServletResponse; |
||
15 | import java.io.IOException; |
||
16 | |||
204 | jmachado | 17 | /** |
18 | * @author Fabio |
||
19 | * @date 4/Abr/2008 |
||
20 | * @time 11:03:00 |
||
21 | * @see pt.estgp.estgweb.web |
||
22 | */ |
||
760 | jmachado | 23 | public class RepositoryStreamVersion extends HttpServlet |
204 | jmachado | 24 | { |
25 | |||
760 | jmachado | 26 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(RepositoryStreamVersion.class); |
204 | jmachado | 27 | |
28 | |||
29 | public void doGet(HttpServletRequest request, HttpServletResponse response) |
||
30 | throws ServletException, 1.5.0/docs/api/java/io/IOException.html">IOException |
||
31 | { |
||
32 | |||
33 | 1.5.0/docs/api/java/lang/String.html">String objectRequired = request.getPathInfo(); |
||
34 | objectRequired = objectRequired.substring(1); |
||
35 | |||
36 | long id = 1.5.0/docs/api/java/lang/Long.html">Long.parseLong(objectRequired.trim()); |
||
37 | |||
38 | IServiceManager sm = null; |
||
39 | try |
||
40 | { |
||
41 | sm = ServiceManager.getInstance(); |
||
42 | } |
||
43 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
44 | { |
||
45 | logger.error(e,e); |
||
46 | response.sendError(500); |
||
47 | return; |
||
48 | } |
||
49 | |||
50 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"identifier"}; |
||
51 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{""+ id}; |
||
52 | try |
||
53 | { |
||
760 | jmachado | 54 | IRepositoryFile iRepositoryFile = (IRepositoryFile) sm.execute(RequestUtils.getRequester(request, response), "LoadRepositoryFileVersion", args, names); |
204 | jmachado | 55 | if(iRepositoryFile == null) |
56 | { |
||
57 | response.sendError(404); |
||
58 | return; |
||
59 | } |
||
60 | response.setContentLength(iRepositoryFile.getSize()); |
||
61 | response.setContentType(iRepositoryFile.getContentType()); |
||
357 | jmachado | 62 | response.setHeader("Content-disposition","inline; filename=" + iRepositoryFile.getName()); |
204 | jmachado | 63 | StreamsUtils.inputStream2OutputStream(iRepositoryFile.getInput(),response.getOutputStream()); |
64 | } |
||
65 | catch(FilterChainFailedException fail) |
||
66 | { |
||
67 | response.sendError(401); |
||
68 | } |
||
69 | catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
70 | { |
||
71 | logger.error(e,e); |
||
72 | response.sendError(500); |
||
73 | } |
||
74 | } |
||
75 | |||
76 | } |