1 package org
.argeo
.slc
.web
.ajaxplorer
.svn
;
3 import javax
.servlet
.ServletOutputStream
;
4 import javax
.servlet
.http
.HttpServletRequest
;
5 import javax
.servlet
.http
.HttpServletResponse
;
7 import org
.apache
.commons
.io
.IOUtils
;
8 import org
.argeo
.slc
.web
.ajaxplorer
.AjxpAction
;
9 import org
.argeo
.slc
.web
.ajaxplorer
.AjxpAnswer
;
10 import org
.argeo
.slc
.web
.ajaxplorer
.AjxpDriverException
;
11 import org
.argeo
.slc
.web
.ajaxplorer
.file
.FileDownloadAction
;
12 import org
.tmatesoft
.svn
.core
.io
.SVNRepository
;
14 public class SvnDownloadAction
implements AjxpAction
<SvnDriver
> {
16 public AjxpAnswer
execute(SvnDriver driver
, HttpServletRequest request
) {
17 String path
= request
.getParameter("file");
18 if (path
.charAt(path
.length() - 1) == '/') {
19 // probably a directory
20 return AjxpAnswer
.DO_NOTHING
;
23 String revStr
= request
.getParameter("rev");
24 Long rev
= Long
.parseLong(revStr
);
25 return new SvnDownloadAnswer(driver
, path
, rev
);
28 public class SvnDownloadAnswer
implements AjxpAnswer
{
29 private final SvnDriver driver
;
30 private final String path
;
31 private final Long rev
;
33 public SvnDownloadAnswer(SvnDriver driver
, String path
, Long rev
) {
39 public void updateResponse(HttpServletResponse response
) {
40 ServletOutputStream out
= null;
42 FileDownloadAction
.setDefaultDownloadHeaders(response
,
44 response
.setHeader("AjaXplorer-SvnFileName", getFileName());
46 SVNRepository repository
= driver
.getRepository();
47 out
= response
.getOutputStream();
48 repository
.getFile(path
, rev
, null, out
);
49 } catch (Exception e
) {
50 throw new AjxpDriverException("Cannot download revision " + rev
51 + " of path " + path
, e
);
53 IOUtils
.closeQuietly(out
);
57 protected String
getFileName() {
58 int lastIndexSlash
= path
.lastIndexOf('/');
59 final String origFileName
;
60 if (lastIndexSlash
!= -1) {
61 origFileName
= path
.substring(lastIndexSlash
+ 1);
66 int lastIndexPoint
= origFileName
.lastIndexOf('.');
67 String prefix
= origFileName
.substring(0, lastIndexPoint
);
68 String ext
= origFileName
.substring(lastIndexPoint
);
69 return prefix
+ "-" + rev
+ ext
;