5395 |
27 Aug 10 |
nicklas |
1 |
<%-- $Id$ |
5395 |
27 Aug 10 |
nicklas |
2 |
------------------------------------------------------------------ |
5395 |
27 Aug 10 |
nicklas |
Copyright (C) 2008 Nicklas Nordborg |
5395 |
27 Aug 10 |
nicklas |
4 |
|
5395 |
27 Aug 10 |
nicklas |
5 |
This file is part of BASE - BioArray Software Environment. |
5395 |
27 Aug 10 |
nicklas |
6 |
Available at http://base.thep.lu.se/ |
5395 |
27 Aug 10 |
nicklas |
7 |
|
5395 |
27 Aug 10 |
nicklas |
8 |
BASE is free software; you can redistribute it and/or |
5395 |
27 Aug 10 |
nicklas |
9 |
modify it under the terms of the GNU General Public License |
5395 |
27 Aug 10 |
nicklas |
10 |
as published by the Free Software Foundation; either version 3 |
5395 |
27 Aug 10 |
nicklas |
11 |
of the License, or (at your option) any later version. |
5395 |
27 Aug 10 |
nicklas |
12 |
|
5395 |
27 Aug 10 |
nicklas |
13 |
BASE is distributed in the hope that it will be useful, |
5395 |
27 Aug 10 |
nicklas |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5395 |
27 Aug 10 |
nicklas |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5395 |
27 Aug 10 |
nicklas |
16 |
GNU General Public License for more details. |
5395 |
27 Aug 10 |
nicklas |
17 |
|
5395 |
27 Aug 10 |
nicklas |
18 |
You should have received a copy of the GNU General Public License |
5395 |
27 Aug 10 |
nicklas |
19 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5395 |
27 Aug 10 |
nicklas |
20 |
------------------------------------------------------------------ |
5395 |
27 Aug 10 |
nicklas |
21 |
|
5395 |
27 Aug 10 |
nicklas |
22 |
@author Nicklas |
5395 |
27 Aug 10 |
nicklas |
23 |
--%> |
5554 |
27 Jan 11 |
nicklas |
24 |
<%@ page pageEncoding="UTF-8" session="false" contentType="application/json" |
5395 |
27 Aug 10 |
nicklas |
25 |
import="net.sf.basedb.core.SessionControl" |
7990 |
01 Jul 21 |
nicklas |
26 |
import="net.sf.basedb.core.DbControl" |
7990 |
01 Jul 21 |
nicklas |
27 |
import="net.sf.basedb.core.Path" |
7990 |
01 Jul 21 |
nicklas |
28 |
import="net.sf.basedb.core.ItemNotFoundException" |
7990 |
01 Jul 21 |
nicklas |
29 |
import="net.sf.basedb.core.File" |
5395 |
27 Aug 10 |
nicklas |
30 |
import="net.sf.basedb.core.SimpleAbsoluteProgressReporter" |
5395 |
27 Aug 10 |
nicklas |
31 |
import="net.sf.basedb.clients.web.Base" |
5395 |
27 Aug 10 |
nicklas |
32 |
import="net.sf.basedb.util.Values" |
5554 |
27 Jan 11 |
nicklas |
33 |
import="net.sf.basedb.util.error.ThrowableUtil" |
5395 |
27 Aug 10 |
nicklas |
34 |
import="net.sf.basedb.clients.web.WebException" |
5395 |
27 Aug 10 |
nicklas |
35 |
import="net.sf.basedb.clients.web.util.HTML" |
5395 |
27 Aug 10 |
nicklas |
36 |
import="net.sf.basedb.clients.web.fileupload.FileUploadProgress" |
5395 |
27 Aug 10 |
nicklas |
37 |
import="net.sf.basedb.clients.web.fileupload.UploadAbortedException" |
5554 |
27 Jan 11 |
nicklas |
38 |
import="org.json.simple.JSONObject" |
5395 |
27 Aug 10 |
nicklas |
39 |
%> |
5395 |
27 Aug 10 |
nicklas |
40 |
<% |
6124 |
13 Sep 12 |
nicklas |
41 |
response.setHeader("Cache-Control", "no-cache, max-age=0"); |
5395 |
27 Aug 10 |
nicklas |
42 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
7990 |
01 Jul 21 |
nicklas |
43 |
DbControl dc = null; |
5395 |
27 Aug 10 |
nicklas |
44 |
final String ID = sc.getId(); |
5395 |
27 Aug 10 |
nicklas |
45 |
final String cmd = request.getParameter("cmd"); |
5395 |
27 Aug 10 |
nicklas |
46 |
final String root = request.getContextPath()+"/"; |
5395 |
27 Aug 10 |
nicklas |
47 |
out.clear(); |
5554 |
27 Jan 11 |
nicklas |
48 |
JSONObject json = new JSONObject(); |
5554 |
27 Jan 11 |
nicklas |
49 |
json.put("status", "ok"); |
5395 |
27 Aug 10 |
nicklas |
50 |
try |
5395 |
27 Aug 10 |
nicklas |
51 |
{ |
5395 |
27 Aug 10 |
nicklas |
52 |
if ("GetProgress".equals(cmd)) |
5395 |
27 Aug 10 |
nicklas |
53 |
{ |
7605 |
26 Feb 19 |
nicklas |
54 |
final FileUploadProgress progress = sc.getSessionSetting("FileUploadProgress"); |
7605 |
26 Feb 19 |
nicklas |
55 |
final SimpleAbsoluteProgressReporter unpackProgress = sc.getSessionSetting("UnpackProgress"); |
5554 |
27 Jan 11 |
nicklas |
56 |
|
5395 |
27 Aug 10 |
nicklas |
57 |
if (unpackProgress != null) |
5395 |
27 Aug 10 |
nicklas |
58 |
{ |
5554 |
27 Jan 11 |
nicklas |
59 |
json.put("message", unpackProgress.getMessage()); |
5395 |
27 Aug 10 |
nicklas |
60 |
} |
5395 |
27 Aug 10 |
nicklas |
61 |
if (progress != null) |
5395 |
27 Aug 10 |
nicklas |
62 |
{ |
5554 |
27 Jan 11 |
nicklas |
63 |
json.put("file", progress.getCurrentFilename()); |
5554 |
27 Jan 11 |
nicklas |
64 |
json.put("totalBytes", progress.getTotalBytes()); |
5554 |
27 Jan 11 |
nicklas |
65 |
json.put("transferredBytes", progress.getTransferredBytes()); |
7985 |
22 Jun 21 |
nicklas |
66 |
json.put("timeInMillis", progress.getMillisecondsSinceStart()); |
5554 |
27 Jan 11 |
nicklas |
67 |
json.put("timeInSeconds", progress.getMillisecondsSinceStart() / 1000); |
7986 |
29 Jun 21 |
nicklas |
68 |
|
7986 |
29 Jun 21 |
nicklas |
69 |
Throwable t = progress.getException(); |
7986 |
29 Jun 21 |
nicklas |
70 |
if (t != null) |
7986 |
29 Jun 21 |
nicklas |
71 |
{ |
7986 |
29 Jun 21 |
nicklas |
72 |
sc.setSessionSetting("FileUploadProgress", null); |
7986 |
29 Jun 21 |
nicklas |
73 |
sc.setSessionSetting("UnpackProgress", null); |
7986 |
29 Jun 21 |
nicklas |
74 |
json.put("status", "error"); |
7986 |
29 Jun 21 |
nicklas |
75 |
json.put("message", t.getMessage()); |
7986 |
29 Jun 21 |
nicklas |
76 |
json.put("stacktrace", ThrowableUtil.stackTraceToString(t)); |
7986 |
29 Jun 21 |
nicklas |
77 |
if (t instanceof WebException) |
7986 |
29 Jun 21 |
nicklas |
78 |
{ |
7986 |
29 Jun 21 |
nicklas |
79 |
WebException we = (WebException)t; |
7986 |
29 Jun 21 |
nicklas |
80 |
json.put("title", we.getTitle()); |
7986 |
29 Jun 21 |
nicklas |
81 |
json.put("message", we.getDetail()); |
7986 |
29 Jun 21 |
nicklas |
82 |
} |
7986 |
29 Jun 21 |
nicklas |
83 |
else if (t instanceof UploadAbortedException) |
7986 |
29 Jun 21 |
nicklas |
84 |
{ |
7986 |
29 Jun 21 |
nicklas |
85 |
json.put("status", "abort"); |
7986 |
29 Jun 21 |
nicklas |
86 |
json.put("title", "Upload aborted"); |
7986 |
29 Jun 21 |
nicklas |
87 |
} |
7986 |
29 Jun 21 |
nicklas |
88 |
// Release the upload thread waiting in Upload.java |
7986 |
29 Jun 21 |
nicklas |
89 |
synchronized (t) |
7986 |
29 Jun 21 |
nicklas |
90 |
{ |
7986 |
29 Jun 21 |
nicklas |
91 |
t.notifyAll(); |
7986 |
29 Jun 21 |
nicklas |
92 |
} |
7986 |
29 Jun 21 |
nicklas |
93 |
} |
5395 |
27 Aug 10 |
nicklas |
94 |
} |
5395 |
27 Aug 10 |
nicklas |
95 |
} |
5395 |
27 Aug 10 |
nicklas |
96 |
else if ("Abort".equals(cmd)) |
5395 |
27 Aug 10 |
nicklas |
97 |
{ |
7605 |
26 Feb 19 |
nicklas |
98 |
final FileUploadProgress progress = sc.getSessionSetting("FileUploadProgress"); |
7991 |
01 Jul 21 |
nicklas |
99 |
if (progress != null) |
7991 |
01 Jul 21 |
nicklas |
100 |
{ |
7991 |
01 Jul 21 |
nicklas |
101 |
progress.setAbort(); |
7991 |
01 Jul 21 |
nicklas |
102 |
json.put("aborted", 1); |
7991 |
01 Jul 21 |
nicklas |
103 |
} |
7991 |
01 Jul 21 |
nicklas |
104 |
else |
7991 |
01 Jul 21 |
nicklas |
105 |
{ |
7991 |
01 Jul 21 |
nicklas |
106 |
json.put("aborted", 0); |
7991 |
01 Jul 21 |
nicklas |
107 |
} |
5395 |
27 Aug 10 |
nicklas |
108 |
} |
7990 |
01 Jul 21 |
nicklas |
109 |
else if ("CheckExistingFile".equals(cmd)) |
7990 |
01 Jul 21 |
nicklas |
110 |
{ |
7990 |
01 Jul 21 |
nicklas |
111 |
dc = sc.newDbControl(":Check if file exists"); |
7990 |
01 Jul 21 |
nicklas |
112 |
try |
7990 |
01 Jul 21 |
nicklas |
113 |
{ |
7990 |
01 Jul 21 |
nicklas |
114 |
Path path = new Path(request.getParameter("path"), Path.Type.FILE); |
7990 |
01 Jul 21 |
nicklas |
115 |
File f = File.getByPath(dc, path, false); |
7990 |
01 Jul 21 |
nicklas |
116 |
json.put("file", f.getName()); |
7990 |
01 Jul 21 |
nicklas |
117 |
json.put("fileExists", 1); |
7990 |
01 Jul 21 |
nicklas |
118 |
json.put("fileSize", f.getSize()); |
7990 |
01 Jul 21 |
nicklas |
119 |
} |
7990 |
01 Jul 21 |
nicklas |
120 |
catch (ItemNotFoundException ex) |
7990 |
01 Jul 21 |
nicklas |
121 |
{ |
7990 |
01 Jul 21 |
nicklas |
122 |
json.put("fileExists", 0); |
7990 |
01 Jul 21 |
nicklas |
123 |
} |
7990 |
01 Jul 21 |
nicklas |
124 |
} |
5395 |
27 Aug 10 |
nicklas |
125 |
else |
5395 |
27 Aug 10 |
nicklas |
126 |
{ |
5395 |
27 Aug 10 |
nicklas |
127 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
5395 |
27 Aug 10 |
nicklas |
128 |
} |
5395 |
27 Aug 10 |
nicklas |
129 |
} |
5554 |
27 Jan 11 |
nicklas |
130 |
catch (Throwable t) |
5554 |
27 Jan 11 |
nicklas |
131 |
{ |
5554 |
27 Jan 11 |
nicklas |
132 |
json.clear(); |
5554 |
27 Jan 11 |
nicklas |
133 |
json.put("status", "error"); |
5554 |
27 Jan 11 |
nicklas |
134 |
json.put("message", t.getMessage()); |
5554 |
27 Jan 11 |
nicklas |
135 |
json.put("stacktrace", ThrowableUtil.stackTraceToString(t)); |
5554 |
27 Jan 11 |
nicklas |
136 |
} |
5395 |
27 Aug 10 |
nicklas |
137 |
finally |
5395 |
27 Aug 10 |
nicklas |
138 |
{ |
7990 |
01 Jul 21 |
nicklas |
139 |
if (dc != null) dc.close(); |
5554 |
27 Jan 11 |
nicklas |
140 |
json.writeJSONString(out); |
5554 |
27 Jan 11 |
nicklas |
141 |
out.flush(); |
5395 |
27 Aug 10 |
nicklas |
142 |
} |
5395 |
27 Aug 10 |
nicklas |
143 |
%> |