4798 |
03 Mar 09 |
nicklas |
1 |
<%-- $Id$ |
4798 |
03 Mar 09 |
nicklas |
2 |
------------------------------------------------------------------ |
4798 |
03 Mar 09 |
nicklas |
Copyright (C) 2009 Nicklas Nordborg |
4798 |
03 Mar 09 |
nicklas |
4 |
|
4798 |
03 Mar 09 |
nicklas |
5 |
This file is part of BASE - BioArray Software Environment. |
4798 |
03 Mar 09 |
nicklas |
6 |
Available at http://base.thep.lu.se/ |
4798 |
03 Mar 09 |
nicklas |
7 |
|
4798 |
03 Mar 09 |
nicklas |
8 |
BASE is free software; you can redistribute it and/or |
4798 |
03 Mar 09 |
nicklas |
9 |
modify it under the terms of the GNU General Public License |
4798 |
03 Mar 09 |
nicklas |
10 |
as published by the Free Software Foundation; either version 3 |
4798 |
03 Mar 09 |
nicklas |
11 |
of the License, or (at your option) any later version. |
4798 |
03 Mar 09 |
nicklas |
12 |
|
4798 |
03 Mar 09 |
nicklas |
13 |
BASE is distributed in the hope that it will be useful, |
4798 |
03 Mar 09 |
nicklas |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4798 |
03 Mar 09 |
nicklas |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4798 |
03 Mar 09 |
nicklas |
16 |
GNU General Public License for more details. |
4798 |
03 Mar 09 |
nicklas |
17 |
|
4798 |
03 Mar 09 |
nicklas |
18 |
You should have received a copy of the GNU General Public License |
4798 |
03 Mar 09 |
nicklas |
19 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
4798 |
03 Mar 09 |
nicklas |
20 |
------------------------------------------------------------------ |
4798 |
03 Mar 09 |
nicklas |
21 |
|
4798 |
03 Mar 09 |
nicklas |
22 |
@author Nicklas |
4798 |
03 Mar 09 |
nicklas |
23 |
--%> |
5555 |
27 Jan 11 |
nicklas |
24 |
<%@ page pageEncoding="UTF-8" session="false" contentType="application/json" |
4798 |
03 Mar 09 |
nicklas |
25 |
import="net.sf.basedb.core.SessionControl" |
4798 |
03 Mar 09 |
nicklas |
26 |
import="net.sf.basedb.core.DbControl" |
4798 |
03 Mar 09 |
nicklas |
27 |
import="net.sf.basedb.core.Include" |
4798 |
03 Mar 09 |
nicklas |
28 |
import="net.sf.basedb.core.Directory" |
4798 |
03 Mar 09 |
nicklas |
29 |
import="net.sf.basedb.core.ItemQuery" |
7983 |
22 Jun 21 |
nicklas |
30 |
import="net.sf.basedb.core.Item" |
7983 |
22 Jun 21 |
nicklas |
31 |
import="net.sf.basedb.core.Permission" |
4798 |
03 Mar 09 |
nicklas |
32 |
import="net.sf.basedb.core.query.Hql" |
4798 |
03 Mar 09 |
nicklas |
33 |
import="net.sf.basedb.core.query.Orders" |
4798 |
03 Mar 09 |
nicklas |
34 |
import="net.sf.basedb.util.Values" |
4964 |
09 Jun 09 |
nicklas |
35 |
import="net.sf.basedb.util.error.ThrowableUtil" |
4798 |
03 Mar 09 |
nicklas |
36 |
import="net.sf.basedb.clients.web.Base" |
6385 |
18 Dec 13 |
nicklas |
37 |
import="net.sf.basedb.clients.web.util.HTML" |
4798 |
03 Mar 09 |
nicklas |
38 |
import="net.sf.basedb.clients.web.WebException" |
5555 |
27 Jan 11 |
nicklas |
39 |
import="org.json.simple.JSONObject" |
5556 |
28 Jan 11 |
nicklas |
40 |
import="org.json.simple.JSONArray" |
4964 |
09 Jun 09 |
nicklas |
41 |
import="java.util.List" |
4798 |
03 Mar 09 |
nicklas |
42 |
%> |
4798 |
03 Mar 09 |
nicklas |
43 |
<% |
6124 |
13 Sep 12 |
nicklas |
44 |
response.setHeader("Cache-Control", "no-cache, max-age=0"); |
4798 |
03 Mar 09 |
nicklas |
45 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
4798 |
03 Mar 09 |
nicklas |
46 |
final String ID = sc.getId(); |
4798 |
03 Mar 09 |
nicklas |
47 |
final String cmd = request.getParameter("cmd"); |
4798 |
03 Mar 09 |
nicklas |
48 |
final String root = request.getContextPath()+"/"; |
4798 |
03 Mar 09 |
nicklas |
49 |
final int itemId = Values.getInt(request.getParameter("item_id")); |
4798 |
03 Mar 09 |
nicklas |
50 |
DbControl dc = null; |
4798 |
03 Mar 09 |
nicklas |
51 |
out.clear(); |
5555 |
27 Jan 11 |
nicklas |
52 |
JSONObject json = new JSONObject(); |
5555 |
27 Jan 11 |
nicklas |
53 |
json.put("status", "ok"); |
4798 |
03 Mar 09 |
nicklas |
54 |
try |
4798 |
03 Mar 09 |
nicklas |
55 |
{ |
4798 |
03 Mar 09 |
nicklas |
56 |
if ("GetSubdirectories".equals(cmd)) |
4798 |
03 Mar 09 |
nicklas |
57 |
{ |
7954 |
12 May 21 |
nicklas |
58 |
dc = sc.newDbControl(":Get subdirectories"); |
4798 |
03 Mar 09 |
nicklas |
59 |
Directory dir = Directory.getById(dc, itemId); |
7983 |
22 Jun 21 |
nicklas |
60 |
boolean createFilePermission = sc.hasPermission(Permission.CREATE, Item.FILE); |
4798 |
03 Mar 09 |
nicklas |
61 |
|
4798 |
03 Mar 09 |
nicklas |
62 |
ItemQuery<Directory> query = dir.getSubDirectories(); |
4798 |
03 Mar 09 |
nicklas |
63 |
query.include(Include.ALL); |
4798 |
03 Mar 09 |
nicklas |
64 |
query.order(Orders.asc(Hql.property("name"))); |
4964 |
09 Jun 09 |
nicklas |
65 |
List<Directory> subdirs = query.list(dc); |
5555 |
27 Jan 11 |
nicklas |
66 |
JSONArray jsonSubdirs = new JSONArray(); |
4964 |
09 Jun 09 |
nicklas |
67 |
for (Directory d : subdirs) |
4798 |
03 Mar 09 |
nicklas |
68 |
{ |
5555 |
27 Jan 11 |
nicklas |
69 |
JSONObject jsonDir = new JSONObject(); |
5555 |
27 Jan 11 |
nicklas |
70 |
jsonDir.put("id", d.getId()); |
6385 |
18 Dec 13 |
nicklas |
71 |
jsonDir.put("text", HTML.encodeTags(d.getName())); |
5555 |
27 Jan 11 |
nicklas |
72 |
jsonDir.put("path", d.getPath().toString()); |
6385 |
18 Dec 13 |
nicklas |
73 |
jsonDir.put("isLazy", 1); |
7983 |
22 Jun 21 |
nicklas |
74 |
jsonDir.put("allowUpload", createFilePermission && d.hasPermission(Permission.USE)); |
6385 |
18 Dec 13 |
nicklas |
75 |
|
6385 |
18 Dec 13 |
nicklas |
76 |
String folderIcon = "Folder"; |
6385 |
18 Dec 13 |
nicklas |
77 |
if (d.isHomeDirectory()) |
6385 |
18 Dec 13 |
nicklas |
78 |
{ |
6385 |
18 Dec 13 |
nicklas |
79 |
folderIcon = "UserHome"; |
6385 |
18 Dec 13 |
nicklas |
80 |
} |
6385 |
18 Dec 13 |
nicklas |
81 |
else if (d.isRemoved()) |
6385 |
18 Dec 13 |
nicklas |
82 |
{ |
6385 |
18 Dec 13 |
nicklas |
83 |
folderIcon = "FolderDeleted"; |
6385 |
18 Dec 13 |
nicklas |
84 |
} |
6385 |
18 Dec 13 |
nicklas |
85 |
else if (d.getAutoCompress()) |
6385 |
18 Dec 13 |
nicklas |
86 |
{ |
6385 |
18 Dec 13 |
nicklas |
87 |
folderIcon = "FolderCompressed"; |
6385 |
18 Dec 13 |
nicklas |
88 |
} |
6385 |
18 Dec 13 |
nicklas |
89 |
jsonDir.put("icon", folderIcon); |
5555 |
27 Jan 11 |
nicklas |
90 |
jsonSubdirs.add(jsonDir); |
4798 |
03 Mar 09 |
nicklas |
91 |
} |
4798 |
03 Mar 09 |
nicklas |
92 |
dc.commit(); |
5555 |
27 Jan 11 |
nicklas |
93 |
json.put("subdirs", jsonSubdirs); |
4798 |
03 Mar 09 |
nicklas |
94 |
} |
4798 |
03 Mar 09 |
nicklas |
95 |
else |
4798 |
03 Mar 09 |
nicklas |
96 |
{ |
4964 |
09 Jun 09 |
nicklas |
97 |
throw new RuntimeException("Invalid command. The command " + cmd + " is not recognised as a valid command."); |
4798 |
03 Mar 09 |
nicklas |
98 |
} |
4798 |
03 Mar 09 |
nicklas |
99 |
} |
4964 |
09 Jun 09 |
nicklas |
100 |
catch (Throwable t) |
4964 |
09 Jun 09 |
nicklas |
101 |
{ |
4964 |
09 Jun 09 |
nicklas |
102 |
t.printStackTrace(); |
5555 |
27 Jan 11 |
nicklas |
103 |
json.clear(); |
5555 |
27 Jan 11 |
nicklas |
104 |
json.put("status", "error"); |
5555 |
27 Jan 11 |
nicklas |
105 |
json.put("message", t.getMessage()); |
5555 |
27 Jan 11 |
nicklas |
106 |
json.put("stacktrace", ThrowableUtil.stackTraceToString(t)); |
4964 |
09 Jun 09 |
nicklas |
107 |
} |
4798 |
03 Mar 09 |
nicklas |
108 |
finally |
4798 |
03 Mar 09 |
nicklas |
109 |
{ |
5555 |
27 Jan 11 |
nicklas |
110 |
json.writeJSONString(out); |
5555 |
27 Jan 11 |
nicklas |
111 |
out.flush(); |
4798 |
03 Mar 09 |
nicklas |
112 |
if (dc != null) dc.close(); |
4798 |
03 Mar 09 |
nicklas |
113 |
} |
4798 |
03 Mar 09 |
nicklas |
114 |
%> |