1794 |
19 Jan 06 |
nicklas |
1 |
<%-- $Id$ |
1794 |
19 Jan 06 |
nicklas |
2 |
------------------------------------------------------------------ |
5425 |
23 Sep 10 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2007 Nicklas Nordborg |
1794 |
19 Jan 06 |
nicklas |
5 |
|
2304 |
22 May 06 |
jari |
6 |
This file is part of BASE - BioArray Software Environment. |
2304 |
22 May 06 |
jari |
7 |
Available at http://base.thep.lu.se/ |
1794 |
19 Jan 06 |
nicklas |
8 |
|
1794 |
19 Jan 06 |
nicklas |
9 |
BASE is free software; you can redistribute it and/or |
1794 |
19 Jan 06 |
nicklas |
10 |
modify it under the terms of the GNU General Public License |
4476 |
05 Sep 08 |
jari |
11 |
as published by the Free Software Foundation; either version 3 |
1794 |
19 Jan 06 |
nicklas |
12 |
of the License, or (at your option) any later version. |
1794 |
19 Jan 06 |
nicklas |
13 |
|
1794 |
19 Jan 06 |
nicklas |
14 |
BASE is distributed in the hope that it will be useful, |
1794 |
19 Jan 06 |
nicklas |
15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1794 |
19 Jan 06 |
nicklas |
16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1794 |
19 Jan 06 |
nicklas |
17 |
GNU General Public License for more details. |
1794 |
19 Jan 06 |
nicklas |
18 |
|
1794 |
19 Jan 06 |
nicklas |
19 |
You should have received a copy of the GNU General Public License |
4510 |
11 Sep 08 |
jari |
20 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
1794 |
19 Jan 06 |
nicklas |
21 |
------------------------------------------------------------------ |
1794 |
19 Jan 06 |
nicklas |
22 |
|
1794 |
19 Jan 06 |
nicklas |
23 |
@author Nicklas |
1794 |
19 Jan 06 |
nicklas |
24 |
@version 2.0 |
1794 |
19 Jan 06 |
nicklas |
25 |
--%> |
5426 |
24 Sep 10 |
nicklas |
26 |
<%@ page pageEncoding="UTF-8" session="false" |
1794 |
19 Jan 06 |
nicklas |
27 |
import="net.sf.basedb.core.SessionControl" |
1794 |
19 Jan 06 |
nicklas |
28 |
import="net.sf.basedb.core.DbControl" |
1794 |
19 Jan 06 |
nicklas |
29 |
import="net.sf.basedb.core.Item" |
1798 |
20 Jan 06 |
nicklas |
30 |
import="net.sf.basedb.core.Removable" |
1798 |
20 Jan 06 |
nicklas |
31 |
import="net.sf.basedb.core.SharedItem" |
4587 |
15 Oct 08 |
martin |
32 |
import="net.sf.basedb.core.OwnedItem" |
1794 |
19 Jan 06 |
nicklas |
33 |
import="net.sf.basedb.core.Include" |
1794 |
19 Jan 06 |
nicklas |
34 |
import="net.sf.basedb.core.Directory" |
1794 |
19 Jan 06 |
nicklas |
35 |
import="net.sf.basedb.core.File" |
5361 |
14 Jun 10 |
nicklas |
36 |
import="net.sf.basedb.core.FileServer" |
5630 |
13 May 11 |
nicklas |
37 |
import="net.sf.basedb.core.ItemSubtype" |
1798 |
20 Jan 06 |
nicklas |
38 |
import="net.sf.basedb.core.Location" |
1794 |
19 Jan 06 |
nicklas |
39 |
import="net.sf.basedb.core.ItemQuery" |
1794 |
19 Jan 06 |
nicklas |
40 |
import="net.sf.basedb.core.Permission" |
1794 |
19 Jan 06 |
nicklas |
41 |
import="net.sf.basedb.core.ItemContext" |
1794 |
19 Jan 06 |
nicklas |
42 |
import="net.sf.basedb.core.MultiPermissions" |
1794 |
19 Jan 06 |
nicklas |
43 |
import="net.sf.basedb.core.PermissionDeniedException" |
1794 |
19 Jan 06 |
nicklas |
44 |
import="net.sf.basedb.core.ItemAlreadyExistsException" |
6589 |
04 Nov 14 |
nicklas |
45 |
import="net.sf.basedb.core.query.Hql" |
6589 |
04 Nov 14 |
nicklas |
46 |
import="net.sf.basedb.core.query.Restrictions" |
6589 |
04 Nov 14 |
nicklas |
47 |
import="net.sf.basedb.core.query.Expressions" |
1794 |
19 Jan 06 |
nicklas |
48 |
import="net.sf.basedb.util.RemovableUtil" |
1794 |
19 Jan 06 |
nicklas |
49 |
import="net.sf.basedb.util.ShareableUtil" |
2918 |
15 Nov 06 |
nicklas |
50 |
import="net.sf.basedb.util.OwnableUtil" |
3719 |
12 Sep 07 |
nicklas |
51 |
import="net.sf.basedb.core.SimpleProgressReporter" |
1794 |
19 Jan 06 |
nicklas |
52 |
import="net.sf.basedb.clients.web.Base" |
1794 |
19 Jan 06 |
nicklas |
53 |
import="net.sf.basedb.clients.web.WebException" |
2753 |
20 Oct 06 |
nicklas |
54 |
import="net.sf.basedb.util.Values" |
1794 |
19 Jan 06 |
nicklas |
55 |
import="net.sf.basedb.clients.web.util.HTML" |
5501 |
18 Nov 10 |
nicklas |
56 |
import="net.sf.basedb.core.plugin.GuiContext" |
5501 |
18 Nov 10 |
nicklas |
57 |
import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
6587 |
03 Nov 14 |
nicklas |
58 |
import="net.sf.basedb.clients.web.plugins.PathLoader" |
5501 |
18 Nov 10 |
nicklas |
59 |
import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
5501 |
18 Nov 10 |
nicklas |
60 |
import="net.sf.basedb.clients.web.extensions.JspContext" |
5501 |
18 Nov 10 |
nicklas |
61 |
import="net.sf.basedb.clients.web.extensions.edit.EditUtil" |
7604 |
25 Feb 19 |
nicklas |
62 |
import="net.sf.basedb.clients.web.extensions.edit.OnSaveAction" |
5501 |
18 Nov 10 |
nicklas |
63 |
import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer" |
6040 |
30 Mar 12 |
nicklas |
64 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnExportRenderer" |
7604 |
25 Feb 19 |
nicklas |
65 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnAction" |
6040 |
30 Mar 12 |
nicklas |
66 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil" |
1794 |
19 Jan 06 |
nicklas |
67 |
import="java.util.Enumeration" |
1794 |
19 Jan 06 |
nicklas |
68 |
import="java.util.Set" |
1794 |
19 Jan 06 |
nicklas |
69 |
import="java.util.HashSet" |
1794 |
19 Jan 06 |
nicklas |
70 |
import="java.util.List" |
1794 |
19 Jan 06 |
nicklas |
71 |
import="java.util.ArrayList" |
1794 |
19 Jan 06 |
nicklas |
72 |
import="java.util.Collections" |
1794 |
19 Jan 06 |
nicklas |
73 |
%> |
1794 |
19 Jan 06 |
nicklas |
74 |
<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
1794 |
19 Jan 06 |
nicklas |
75 |
<%! |
5630 |
13 May 11 |
nicklas |
76 |
private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,size,itemSubtype,description,actions"); |
5179 |
04 Nov 09 |
nicklas |
77 |
private static final ItemContext searchContext = Base.createDefaultContext("name", "path,name,size,description,actions"); |
1794 |
19 Jan 06 |
nicklas |
78 |
private static final Item itemType = Item.FILE; |
6587 |
03 Nov 14 |
nicklas |
79 |
|
6587 |
03 Nov 14 |
nicklas |
80 |
private static void registerExportUtils(ItemContext cc) |
6587 |
03 Nov 14 |
nicklas |
81 |
{ |
6587 |
03 Nov 14 |
nicklas |
82 |
// Path |
6587 |
03 Nov 14 |
nicklas |
83 |
cc.setObject("export.dataloader.path", new PathLoader()); |
6587 |
03 Nov 14 |
nicklas |
84 |
} |
6587 |
03 Nov 14 |
nicklas |
85 |
|
1794 |
19 Jan 06 |
nicklas |
86 |
%> |
1794 |
19 Jan 06 |
nicklas |
87 |
<% |
1794 |
19 Jan 06 |
nicklas |
88 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
1794 |
19 Jan 06 |
nicklas |
89 |
final String ID = sc.getId(); |
1794 |
19 Jan 06 |
nicklas |
90 |
final String cmd = request.getParameter("cmd"); |
1794 |
19 Jan 06 |
nicklas |
91 |
final String root = request.getContextPath()+"/"; |
1794 |
19 Jan 06 |
nicklas |
92 |
final String mode = request.getParameter("mode"); |
1794 |
19 Jan 06 |
nicklas |
93 |
final String callback = request.getParameter("callback"); |
1794 |
19 Jan 06 |
nicklas |
94 |
final String itemId = request.getParameter("item_id"); |
5179 |
04 Nov 09 |
nicklas |
95 |
final String subcontext = Values.getString(request.getParameter("subcontext"), ""); |
6589 |
04 Nov 14 |
nicklas |
96 |
final boolean isSearch = "search".equals(subcontext); |
1803 |
23 Jan 06 |
nicklas |
97 |
final ItemContext dirContext = sc.getCurrentContext(Item.DIRECTORY); |
1803 |
23 Jan 06 |
nicklas |
98 |
final int directoryId = Values.getInt(request.getParameter("directory_id"), dirContext.getId()); |
1803 |
23 Jan 06 |
nicklas |
99 |
dirContext.setId(directoryId); |
1794 |
19 Jan 06 |
nicklas |
100 |
final String listPage = "list_files.jsp?ID="+ID+"&directory_id="+directoryId |
1794 |
19 Jan 06 |
nicklas |
101 |
+(mode == null ? "" : "&mode="+mode) |
1794 |
19 Jan 06 |
nicklas |
102 |
+(callback == null ? "" : "&callback="+callback) |
5179 |
04 Nov 09 |
nicklas |
103 |
+(itemId == null ? "" : "&item_id="+itemId) |
5179 |
04 Nov 09 |
nicklas |
104 |
+"&subcontext=" + subcontext; |
1794 |
19 Jan 06 |
nicklas |
105 |
final String viewPage = "view_file.jsp?ID="+ID; |
1794 |
19 Jan 06 |
nicklas |
106 |
final String editPage = "edit_file.jsp?ID="+ID; |
1794 |
19 Jan 06 |
nicklas |
107 |
|
1794 |
19 Jan 06 |
nicklas |
108 |
String forward = null; |
1794 |
19 Jan 06 |
nicklas |
109 |
String redirect = null; |
1794 |
19 Jan 06 |
nicklas |
110 |
String message = null; |
1794 |
19 Jan 06 |
nicklas |
111 |
DbControl dc = null; |
1794 |
19 Jan 06 |
nicklas |
112 |
|
1794 |
19 Jan 06 |
nicklas |
113 |
try |
1794 |
19 Jan 06 |
nicklas |
114 |
{ |
1794 |
19 Jan 06 |
nicklas |
115 |
if (cmd == null || "List".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
116 |
{ |
1794 |
19 Jan 06 |
nicklas |
117 |
// Display the list page without updating the current context |
5451 |
26 Oct 10 |
nicklas |
118 |
Base.getAndSetCurrentContext(sc, itemType, subcontext, (PageContext)null, defaultContext, false); |
1794 |
19 Jan 06 |
nicklas |
119 |
redirect = listPage; |
1794 |
19 Jan 06 |
nicklas |
120 |
} |
1794 |
19 Jan 06 |
nicklas |
121 |
else if ("UpdateContext".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
122 |
{ |
1794 |
19 Jan 06 |
nicklas |
123 |
// Display the list page after updating the current context from the request parameters |
5179 |
04 Nov 09 |
nicklas |
124 |
Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
1794 |
19 Jan 06 |
nicklas |
125 |
redirect = listPage; |
1794 |
19 Jan 06 |
nicklas |
126 |
} |
1794 |
19 Jan 06 |
nicklas |
127 |
else if ("LoadContext".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
128 |
{ |
1794 |
19 Jan 06 |
nicklas |
129 |
// Display the list page after loading a saved context |
1794 |
19 Jan 06 |
nicklas |
130 |
int contextId = Values.getInt(request.getParameter("context")); |
1794 |
19 Jan 06 |
nicklas |
131 |
Base.loadContext(sc, contextId, defaultContext); |
1794 |
19 Jan 06 |
nicklas |
132 |
redirect = listPage; |
1794 |
19 Jan 06 |
nicklas |
133 |
} |
1794 |
19 Jan 06 |
nicklas |
134 |
|
1794 |
19 Jan 06 |
nicklas |
135 |
else if ("ViewItem".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
136 |
{ |
1794 |
19 Jan 06 |
nicklas |
137 |
// Display the view page for a single item |
5179 |
04 Nov 09 |
nicklas |
138 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
1794 |
19 Jan 06 |
nicklas |
139 |
forward = viewPage; |
1794 |
19 Jan 06 |
nicklas |
140 |
} |
1794 |
19 Jan 06 |
nicklas |
141 |
else if ("EditItem".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
142 |
{ |
1794 |
19 Jan 06 |
nicklas |
143 |
// Display the edit page for a single item (should be opened in a popup) |
5179 |
04 Nov 09 |
nicklas |
144 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
1794 |
19 Jan 06 |
nicklas |
145 |
redirect = editPage; |
1794 |
19 Jan 06 |
nicklas |
146 |
} |
5568 |
10 Feb 11 |
nicklas |
147 |
else if ("EditMultiple".equals(cmd)) |
5568 |
10 Feb 11 |
nicklas |
148 |
{ |
5568 |
10 Feb 11 |
nicklas |
149 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
5568 |
10 Feb 11 |
nicklas |
150 |
if (cc.getSelected().size() == 1) |
5568 |
10 Feb 11 |
nicklas |
151 |
{ |
5568 |
10 Feb 11 |
nicklas |
152 |
cc.setId(cc.getSelected().iterator().next()); |
5568 |
10 Feb 11 |
nicklas |
153 |
redirect = editPage; |
5568 |
10 Feb 11 |
nicklas |
154 |
} |
5568 |
10 Feb 11 |
nicklas |
155 |
else |
5568 |
10 Feb 11 |
nicklas |
156 |
{ |
5568 |
10 Feb 11 |
nicklas |
157 |
redirect = "edit_multiple_file.jsp?ID="+ID; |
5568 |
10 Feb 11 |
nicklas |
158 |
} |
5568 |
10 Feb 11 |
nicklas |
159 |
} |
1794 |
19 Jan 06 |
nicklas |
160 |
else if ("NewItem".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
161 |
{ |
1794 |
19 Jan 06 |
nicklas |
162 |
// Display the edit page for a new item (should be opened in a popup) |
1794 |
19 Jan 06 |
nicklas |
163 |
if (!sc.hasPermission(Permission.CREATE, itemType)) |
1794 |
19 Jan 06 |
nicklas |
164 |
{ |
1794 |
19 Jan 06 |
nicklas |
165 |
throw new PermissionDeniedException(Permission.CREATE, itemType.toString()); |
1794 |
19 Jan 06 |
nicklas |
166 |
} |
5179 |
04 Nov 09 |
nicklas |
167 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
1794 |
19 Jan 06 |
nicklas |
168 |
cc.setId(0); |
5793 |
07 Oct 11 |
nicklas |
169 |
redirect = editPage+"&directory_id="+directoryId; |
1794 |
19 Jan 06 |
nicklas |
170 |
} |
1798 |
20 Jan 06 |
nicklas |
171 |
else if ("UploadNewFile".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
172 |
{ |
1794 |
19 Jan 06 |
nicklas |
173 |
// Display the upload page for a new item (should be opened in a popup) |
1794 |
19 Jan 06 |
nicklas |
174 |
if (!sc.hasPermission(Permission.CREATE, itemType)) |
1794 |
19 Jan 06 |
nicklas |
175 |
{ |
1794 |
19 Jan 06 |
nicklas |
176 |
throw new PermissionDeniedException(Permission.CREATE, itemType.toString()); |
1794 |
19 Jan 06 |
nicklas |
177 |
} |
5179 |
04 Nov 09 |
nicklas |
178 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
1794 |
19 Jan 06 |
nicklas |
179 |
cc.setId(0); |
1794 |
19 Jan 06 |
nicklas |
180 |
redirect = "../upload/index.jsp?ID="+ID+"&directory_id="+directoryId; |
1794 |
19 Jan 06 |
nicklas |
181 |
} |
1798 |
20 Jan 06 |
nicklas |
182 |
else if ("UploadFile".equals(cmd)) |
1798 |
20 Jan 06 |
nicklas |
183 |
{ |
1798 |
20 Jan 06 |
nicklas |
184 |
// Display the upload page for an existing item (should be opened in a popup) |
5179 |
04 Nov 09 |
nicklas |
185 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
6308 |
20 Aug 13 |
nicklas |
186 |
redirect = "../upload/index.jsp?ID="+ID+"&file_id=" +itemId; |
1798 |
20 Jan 06 |
nicklas |
187 |
} |
1794 |
19 Jan 06 |
nicklas |
188 |
else if ("UpdateItem".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
189 |
{ |
1794 |
19 Jan 06 |
nicklas |
190 |
// Update the properties on an item (will close the popup) |
5179 |
04 Nov 09 |
nicklas |
191 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, null, defaultContext); |
2597 |
25 Aug 06 |
nicklas |
192 |
final int maxRecent = Base.getMaxRecent(sc); |
7954 |
12 May 21 |
nicklas |
193 |
dc = sc.newDbControl(":Edit "+itemType); |
7605 |
26 Feb 19 |
nicklas |
194 |
File file = cc.getObject("item"); |
1794 |
19 Jan 06 |
nicklas |
195 |
if (file == null) |
1794 |
19 Jan 06 |
nicklas |
196 |
{ |
1794 |
19 Jan 06 |
nicklas |
197 |
file = File.getNew(dc, Directory.getById(dc, directoryId)); |
1794 |
19 Jan 06 |
nicklas |
198 |
message = "File created"; |
5326 |
29 Apr 10 |
nicklas |
199 |
file.setLocation(Location.EXTERNAL); |
1794 |
19 Jan 06 |
nicklas |
200 |
dc.saveItem(file); |
1794 |
19 Jan 06 |
nicklas |
201 |
} |
1794 |
19 Jan 06 |
nicklas |
202 |
else |
1794 |
19 Jan 06 |
nicklas |
203 |
{ |
5060 |
19 Aug 09 |
nicklas |
204 |
dc.reattachItem(file, false); |
1794 |
19 Jan 06 |
nicklas |
205 |
message = "File updated"; |
1794 |
19 Jan 06 |
nicklas |
206 |
} |
5501 |
18 Nov 10 |
nicklas |
207 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(Item.FILE), file); |
7604 |
25 Feb 19 |
nicklas |
208 |
ExtensionsInvoker<OnSaveAction> invoker = EditUtil.useOnSaveExtensions(jspContext); |
5501 |
18 Nov 10 |
nicklas |
209 |
try |
1794 |
19 Jan 06 |
nicklas |
210 |
{ |
5501 |
18 Nov 10 |
nicklas |
211 |
file.setName(Values.getStringOrNull(request.getParameter("name"))); |
5501 |
18 Nov 10 |
nicklas |
212 |
file.setMimeType(Values.getStringOrNull(request.getParameter("mime_type"))); |
5501 |
18 Nov 10 |
nicklas |
213 |
file.setCharacterSet(Values.getStringOrNull(request.getParameter("characterSet"))); |
5501 |
18 Nov 10 |
nicklas |
214 |
file.setWriteProtected(Values.getBoolean(request.getParameter("write_protected"), false)); |
5643 |
26 May 11 |
nicklas |
215 |
file.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
5643 |
26 May 11 |
nicklas |
216 |
|
5643 |
26 May 11 |
nicklas |
217 |
int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1); |
5643 |
26 May 11 |
nicklas |
218 |
if (subtypeId >= 0) // < 0 = denied or unchanged |
5361 |
14 Jun 10 |
nicklas |
219 |
{ |
5643 |
26 May 11 |
nicklas |
220 |
ItemSubtype subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId); |
5643 |
26 May 11 |
nicklas |
221 |
file.setItemSubtype(subtype); |
7703 |
11 Apr 19 |
nicklas |
222 |
cc.setRecent(Item.ITEMSUBTYPE, subtype, maxRecent); |
5361 |
14 Jun 10 |
nicklas |
223 |
} |
5643 |
26 May 11 |
nicklas |
224 |
|
5501 |
18 Nov 10 |
nicklas |
225 |
if (file.getLocation() == Location.EXTERNAL) |
5501 |
18 Nov 10 |
nicklas |
226 |
{ |
5501 |
18 Nov 10 |
nicklas |
227 |
boolean loadMetadata = Values.getBoolean(request.getParameter("loadMetadata")); |
5501 |
18 Nov 10 |
nicklas |
228 |
int serverId = Values.getInt(request.getParameter("server_id"), -1); |
5501 |
18 Nov 10 |
nicklas |
229 |
if (serverId >= 0) // < 0 = denied or unchanged |
5501 |
18 Nov 10 |
nicklas |
230 |
{ |
5501 |
18 Nov 10 |
nicklas |
231 |
FileServer server = serverId == 0 ? null : FileServer.getById(dc, serverId); |
5501 |
18 Nov 10 |
nicklas |
232 |
file.setFileServer(server); |
7703 |
11 Apr 19 |
nicklas |
233 |
cc.setRecent(Item.FILESERVER, server, maxRecent); |
5501 |
18 Nov 10 |
nicklas |
234 |
} |
5599 |
31 Mar 11 |
nicklas |
235 |
file.setUrl(Values.getStringOrNull(request.getParameter("url")), loadMetadata); |
5501 |
18 Nov 10 |
nicklas |
236 |
} |
5501 |
18 Nov 10 |
nicklas |
237 |
|
7857 |
20 Oct 20 |
nicklas |
238 |
// Annotations tab |
7857 |
20 Oct 20 |
nicklas |
239 |
Base.updateAnnotations(dc, file, file, request); |
7857 |
20 Oct 20 |
nicklas |
240 |
|
5501 |
18 Nov 10 |
nicklas |
241 |
// OnSave extensions |
5501 |
18 Nov 10 |
nicklas |
242 |
invoker.render(OnSaveRenderer.ON_SAVE); |
5501 |
18 Nov 10 |
nicklas |
243 |
dc.commit(); |
5501 |
18 Nov 10 |
nicklas |
244 |
invoker.render(OnSaveRenderer.ON_COMMIT); |
5332 |
30 Apr 10 |
nicklas |
245 |
} |
5501 |
18 Nov 10 |
nicklas |
246 |
catch (Exception ex) |
5501 |
18 Nov 10 |
nicklas |
247 |
{ |
5501 |
18 Nov 10 |
nicklas |
248 |
invoker.render(OnSaveRenderer.onRollback(ex)); |
5501 |
18 Nov 10 |
nicklas |
249 |
throw ex; |
5501 |
18 Nov 10 |
nicklas |
250 |
} |
5501 |
18 Nov 10 |
nicklas |
251 |
finally |
5501 |
18 Nov 10 |
nicklas |
252 |
{ |
5501 |
18 Nov 10 |
nicklas |
253 |
cc.removeObject("item"); |
5501 |
18 Nov 10 |
nicklas |
254 |
} |
1794 |
19 Jan 06 |
nicklas |
255 |
} |
5568 |
10 Feb 11 |
nicklas |
256 |
else if ("UpdateMultipleItems".equals(cmd)) |
5568 |
10 Feb 11 |
nicklas |
257 |
{ |
7954 |
12 May 21 |
nicklas |
258 |
dc = sc.newDbControl(":Edit multiple files"); |
5568 |
10 Feb 11 |
nicklas |
259 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, null, defaultContext); |
5568 |
10 Feb 11 |
nicklas |
260 |
boolean setWriteProtected = !"keep".equals(request.getParameter("write_protected")); |
5568 |
10 Feb 11 |
nicklas |
261 |
boolean writeProtected = Values.getBoolean(request.getParameter("write_protected")); |
5568 |
10 Feb 11 |
nicklas |
262 |
int fileTypeId = Values.getInt(request.getParameter("filetype_id"), -1); |
5568 |
10 Feb 11 |
nicklas |
263 |
boolean setFileType = fileTypeId >= 0; |
5630 |
13 May 11 |
nicklas |
264 |
ItemSubtype fileType = setFileType && fileTypeId > 0 ? ItemSubtype.getById(dc, fileTypeId) : null; |
5568 |
10 Feb 11 |
nicklas |
265 |
boolean setCharacterSet = !"keep".equals(request.getParameter("characterSet")); |
5568 |
10 Feb 11 |
nicklas |
266 |
String characterSet = Values.getStringOrNull(request.getParameter("characterSet")); |
5568 |
10 Feb 11 |
nicklas |
267 |
boolean setMimeType = !Values.getBoolean(request.getParameter("keepMimeType")); |
5568 |
10 Feb 11 |
nicklas |
268 |
String mimeType = Values.getStringOrNull(request.getParameter("mimeType")); |
5568 |
10 Feb 11 |
nicklas |
269 |
|
5568 |
10 Feb 11 |
nicklas |
270 |
int numSelected = cc.getSelected().size(); |
5568 |
10 Feb 11 |
nicklas |
271 |
int numUpdated = 0; |
5568 |
10 Feb 11 |
nicklas |
272 |
if (setWriteProtected || setFileType || setCharacterSet || setMimeType) |
5568 |
10 Feb 11 |
nicklas |
273 |
{ |
5568 |
10 Feb 11 |
nicklas |
274 |
for (int fileId : cc.getSelected()) |
5568 |
10 Feb 11 |
nicklas |
275 |
{ |
5568 |
10 Feb 11 |
nicklas |
276 |
File file = File.getById(dc, fileId); |
5568 |
10 Feb 11 |
nicklas |
277 |
if (file.hasPermission(Permission.WRITE)) |
5568 |
10 Feb 11 |
nicklas |
278 |
{ |
5568 |
10 Feb 11 |
nicklas |
279 |
if (setWriteProtected) file.setWriteProtected(writeProtected); |
5630 |
13 May 11 |
nicklas |
280 |
if (setFileType) file.setItemSubtype(fileType); |
5568 |
10 Feb 11 |
nicklas |
281 |
if (setCharacterSet) file.setCharacterSet(characterSet); |
5568 |
10 Feb 11 |
nicklas |
282 |
if (setMimeType) file.setMimeType(mimeType); |
5568 |
10 Feb 11 |
nicklas |
283 |
numUpdated++; |
5568 |
10 Feb 11 |
nicklas |
284 |
} |
5568 |
10 Feb 11 |
nicklas |
285 |
} |
5568 |
10 Feb 11 |
nicklas |
286 |
} |
5568 |
10 Feb 11 |
nicklas |
287 |
dc.commit(); |
5568 |
10 Feb 11 |
nicklas |
288 |
message = numUpdated + " of " + numSelected + " files updated"; |
5568 |
10 Feb 11 |
nicklas |
289 |
} |
1794 |
19 Jan 06 |
nicklas |
290 |
else if ("DeleteItem".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
291 |
{ |
1794 |
19 Jan 06 |
nicklas |
292 |
// Delete a single item and then return to the view page |
7954 |
12 May 21 |
nicklas |
293 |
dc = sc.newDbControl(":Delete "+itemType); |
5179 |
04 Nov 09 |
nicklas |
294 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
1794 |
19 Jan 06 |
nicklas |
295 |
RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true); |
1794 |
19 Jan 06 |
nicklas |
296 |
dc.commit(); |
1794 |
19 Jan 06 |
nicklas |
297 |
redirect = viewPage; |
1794 |
19 Jan 06 |
nicklas |
298 |
} |
1794 |
19 Jan 06 |
nicklas |
299 |
else if ("DeleteItems".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
300 |
{ |
1794 |
19 Jan 06 |
nicklas |
301 |
// Delete all selected items on the list page |
7954 |
12 May 21 |
nicklas |
302 |
dc = sc.newDbControl(":Delete "+itemType); |
5179 |
04 Nov 09 |
nicklas |
303 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
1798 |
20 Jan 06 |
nicklas |
304 |
int numTotal = cc.getSelected().size()+dirContext.getSelected().size(); |
2526 |
15 Aug 06 |
martin |
305 |
int[] numRemoved = RemovableUtil.removeRecursively(dc, Item.DIRECTORY, dirContext.getSelected(), true); |
2526 |
15 Aug 06 |
martin |
306 |
numRemoved[0] += RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true); |
2526 |
15 Aug 06 |
martin |
307 |
numTotal += numRemoved[1]; |
1794 |
19 Jan 06 |
nicklas |
308 |
dc.commit(); |
2526 |
15 Aug 06 |
martin |
309 |
if (numTotal != numRemoved[0]) |
1794 |
19 Jan 06 |
nicklas |
310 |
{ |
2526 |
15 Aug 06 |
martin |
311 |
message = (numRemoved[0] == 0 ? "No" : "Only "+numRemoved[0]+" of "+numTotal) + " items could be deleted, because you have no DELETE permission"; |
1794 |
19 Jan 06 |
nicklas |
312 |
} |
6192 |
31 Oct 12 |
nicklas |
313 |
redirect = listPage; |
1794 |
19 Jan 06 |
nicklas |
314 |
} |
1794 |
19 Jan 06 |
nicklas |
315 |
else if ("RestoreItem".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
316 |
{ |
1794 |
19 Jan 06 |
nicklas |
317 |
// Restore a single item and then return to the view page |
7954 |
12 May 21 |
nicklas |
318 |
dc = sc.newDbControl(":Restore "+itemType); |
5179 |
04 Nov 09 |
nicklas |
319 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
3004 |
06 Dec 06 |
martin |
320 |
RemovableUtil.removeRecursively(dc, itemType, Collections.singleton(cc.getId()), false); |
1794 |
19 Jan 06 |
nicklas |
321 |
dc.commit(); |
1794 |
19 Jan 06 |
nicklas |
322 |
redirect = viewPage; |
1794 |
19 Jan 06 |
nicklas |
323 |
} |
1794 |
19 Jan 06 |
nicklas |
324 |
else if ("RestoreItems".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
325 |
{ |
1794 |
19 Jan 06 |
nicklas |
326 |
// Restore all selected items on the list page |
7954 |
12 May 21 |
nicklas |
327 |
dc = sc.newDbControl(":Restore "+itemType); |
5179 |
04 Nov 09 |
nicklas |
328 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
1798 |
20 Jan 06 |
nicklas |
329 |
int numTotal = cc.getSelected().size()+dirContext.getSelected().size(); |
3004 |
06 Dec 06 |
martin |
330 |
int numRemoved = 0; |
3004 |
06 Dec 06 |
martin |
331 |
int[] numDirRemoved = RemovableUtil.removeRecursively(dc, Item.DIRECTORY, dirContext.getSelected(), false); |
3004 |
06 Dec 06 |
martin |
332 |
int[] numFileRemoved = RemovableUtil.removeRecursively(dc, itemType, cc.getSelected(), false); |
3004 |
06 Dec 06 |
martin |
333 |
numTotal += numDirRemoved[1] + numFileRemoved[1]; |
3004 |
06 Dec 06 |
martin |
334 |
numRemoved = numDirRemoved[0] + numFileRemoved[0]; |
3004 |
06 Dec 06 |
martin |
335 |
|
1794 |
19 Jan 06 |
nicklas |
336 |
dc.commit(); |
3004 |
06 Dec 06 |
martin |
337 |
if (numTotal != numRemoved) |
1794 |
19 Jan 06 |
nicklas |
338 |
{ |
3004 |
06 Dec 06 |
martin |
339 |
message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission"; |
1794 |
19 Jan 06 |
nicklas |
340 |
} |
6192 |
31 Oct 12 |
nicklas |
341 |
redirect = listPage; |
1794 |
19 Jan 06 |
nicklas |
342 |
} |
1794 |
19 Jan 06 |
nicklas |
343 |
else if ("ShareItem".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
344 |
{ |
1794 |
19 Jan 06 |
nicklas |
345 |
// Display a popup window for sharing a single item |
7954 |
12 May 21 |
nicklas |
346 |
dc = sc.newDbControl(":Share "+itemType); |
5179 |
04 Nov 09 |
nicklas |
347 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
2388 |
16 Jun 06 |
nicklas |
348 |
MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId())); |
1794 |
19 Jan 06 |
nicklas |
349 |
dc.close(); |
1794 |
19 Jan 06 |
nicklas |
350 |
cc.setObject("MultiPermissions", permissions); |
5179 |
04 Nov 09 |
nicklas |
351 |
redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name()+"&subcontext="+subcontext; |
1794 |
19 Jan 06 |
nicklas |
352 |
} |
1794 |
19 Jan 06 |
nicklas |
353 |
else if ("ShareItems".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
354 |
{ |
1794 |
19 Jan 06 |
nicklas |
355 |
// Display a popup window for sharing all selected items on the list page |
7954 |
12 May 21 |
nicklas |
356 |
dc = sc.newDbControl(":Share "+itemType); |
5179 |
04 Nov 09 |
nicklas |
357 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
1798 |
20 Jan 06 |
nicklas |
358 |
|
1798 |
20 Jan 06 |
nicklas |
359 |
Set<SharedItem> items = new HashSet<SharedItem>(); |
1798 |
20 Jan 06 |
nicklas |
360 |
for (Integer id : cc.getSelected()) |
1798 |
20 Jan 06 |
nicklas |
361 |
{ |
1798 |
20 Jan 06 |
nicklas |
362 |
if (id != null) items.add(File.getById(dc, id)); |
1798 |
20 Jan 06 |
nicklas |
363 |
} |
1798 |
20 Jan 06 |
nicklas |
364 |
for (Integer id : dirContext.getSelected()) |
1798 |
20 Jan 06 |
nicklas |
365 |
{ |
1798 |
20 Jan 06 |
nicklas |
366 |
if (id != null) items.add(Directory.getById(dc, id)); |
1798 |
20 Jan 06 |
nicklas |
367 |
} |
1798 |
20 Jan 06 |
nicklas |
368 |
|
1798 |
20 Jan 06 |
nicklas |
369 |
MultiPermissions permissions = new MultiPermissions(items); |
1794 |
19 Jan 06 |
nicklas |
370 |
dc.close(); |
1794 |
19 Jan 06 |
nicklas |
371 |
cc.setObject("MultiPermissions", permissions); |
5179 |
04 Nov 09 |
nicklas |
372 |
redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name()+"&subcontext="+subcontext; |
1794 |
19 Jan 06 |
nicklas |
373 |
} |
4587 |
15 Oct 08 |
martin |
374 |
else if ("SetOwnerOfItems".equals(cmd)) |
2918 |
15 Nov 06 |
nicklas |
375 |
{ |
4587 |
15 Oct 08 |
martin |
376 |
// Change owner of items selected on a list page |
7954 |
12 May 21 |
nicklas |
377 |
dc = sc.newDbControl(":Set owner of "+itemType); |
5179 |
04 Nov 09 |
nicklas |
378 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
4587 |
15 Oct 08 |
martin |
379 |
Set<OwnedItem> items = new HashSet<OwnedItem>(); |
4587 |
15 Oct 08 |
martin |
380 |
for (Integer id : cc.getSelected()) |
4587 |
15 Oct 08 |
martin |
381 |
{ |
4587 |
15 Oct 08 |
martin |
382 |
if (id != null) items.add(File.getById(dc, id)); |
4587 |
15 Oct 08 |
martin |
383 |
} |
4587 |
15 Oct 08 |
martin |
384 |
for (Integer id : dirContext.getSelected()) |
4587 |
15 Oct 08 |
martin |
385 |
{ |
4587 |
15 Oct 08 |
martin |
386 |
if (id != null) items.add(Directory.getById(dc, id)); |
4587 |
15 Oct 08 |
martin |
387 |
} |
4587 |
15 Oct 08 |
martin |
388 |
dc.close(); |
4587 |
15 Oct 08 |
martin |
389 |
cc.setObject("OwnedItems", items); |
5179 |
04 Nov 09 |
nicklas |
390 |
redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name()+"&subcontext="+subcontext; |
2918 |
15 Nov 06 |
nicklas |
391 |
} |
4587 |
15 Oct 08 |
martin |
392 |
else if ("SetOwnerOfItem".equals(cmd)) |
2918 |
15 Nov 06 |
nicklas |
393 |
{ |
4587 |
15 Oct 08 |
martin |
394 |
// Change owner of items selected on a list page |
7954 |
12 May 21 |
nicklas |
395 |
dc = sc.newDbControl(":Set owner of "+itemType); |
5179 |
04 Nov 09 |
nicklas |
396 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
4587 |
15 Oct 08 |
martin |
397 |
OwnedItem item = (OwnedItem)itemType.getById(dc, cc.getId()); |
4587 |
15 Oct 08 |
martin |
398 |
cc.setObject("OwnedItems", Collections.singleton(item)); |
4587 |
15 Oct 08 |
martin |
399 |
dc.close(); |
5179 |
04 Nov 09 |
nicklas |
400 |
redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name()+"&subcontext="+subcontext; |
2918 |
15 Nov 06 |
nicklas |
401 |
} |
1794 |
19 Jan 06 |
nicklas |
402 |
else if ("ExportItems".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
403 |
{ |
1794 |
19 Jan 06 |
nicklas |
404 |
// Run an export plugin in a list context |
5179 |
04 Nov 09 |
nicklas |
405 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
1794 |
19 Jan 06 |
nicklas |
406 |
final ItemQuery<File> query = File.getQuery(); |
7954 |
12 May 21 |
nicklas |
407 |
dc = sc.newDbControl(":Export "+itemType); |
7914 |
23 Feb 21 |
nicklas |
408 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
409 |
cc.configureQuery(dc, query, jspContext, true); |
6589 |
04 Nov 14 |
nicklas |
410 |
if (!isSearch) |
6589 |
04 Nov 14 |
nicklas |
411 |
{ |
6589 |
04 Nov 14 |
nicklas |
412 |
query.restrict(Restrictions.eq(Hql.property("directory"), Expressions.integer(directoryId))); |
6589 |
04 Nov 14 |
nicklas |
413 |
query.setFirstResult(0); |
6589 |
04 Nov 14 |
nicklas |
414 |
query.setMaxResults(-1); |
6589 |
04 Nov 14 |
nicklas |
415 |
} |
6589 |
04 Nov 14 |
nicklas |
416 |
|
6587 |
03 Nov 14 |
nicklas |
417 |
registerExportUtils(cc); |
6040 |
30 Mar 12 |
nicklas |
418 |
cc.setQuery(query); |
7604 |
25 Feb 19 |
nicklas |
419 |
ExtensionsInvoker<ListColumnAction<File,?>> listInvoker = ListColumnUtil.useExtensions(jspContext); |
7604 |
25 Feb 19 |
nicklas |
420 |
listInvoker.render(new ListColumnExportRenderer<File>(cc)); |
5590 |
16 Mar 11 |
nicklas |
421 |
dc.close(); |
6308 |
20 Aug 13 |
nicklas |
422 |
redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&subcontext="+subcontext+"&context_type=LIST&title=Export+files"; |
1794 |
19 Jan 06 |
nicklas |
423 |
} |
1794 |
19 Jan 06 |
nicklas |
424 |
else if ("ExportItem".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
425 |
{ |
1794 |
19 Jan 06 |
nicklas |
426 |
// Run an export plugin in single-item context |
5179 |
04 Nov 09 |
nicklas |
427 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
6587 |
03 Nov 14 |
nicklas |
428 |
registerExportUtils(cc); |
6308 |
20 Aug 13 |
nicklas |
429 |
redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&subcontext="+subcontext+"&context_type=ITEM&title=Export+file"; |
1794 |
19 Jan 06 |
nicklas |
430 |
} |
1794 |
19 Jan 06 |
nicklas |
431 |
else if ("ImportItems".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
432 |
{ |
1794 |
19 Jan 06 |
nicklas |
433 |
// Run an import plugin in a list context |
5179 |
04 Nov 09 |
nicklas |
434 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
1794 |
19 Jan 06 |
nicklas |
435 |
final ItemQuery<File> query = File.getQuery(); |
7954 |
12 May 21 |
nicklas |
436 |
dc = sc.newDbControl(":Import "+itemType); |
7914 |
23 Feb 21 |
nicklas |
437 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
438 |
cc.configureQuery(dc, query, jspContext, true); |
6589 |
04 Nov 14 |
nicklas |
439 |
if (!isSearch) |
6589 |
04 Nov 14 |
nicklas |
440 |
{ |
6589 |
04 Nov 14 |
nicklas |
441 |
query.restrict(Restrictions.eq(Hql.property("directory"), Expressions.integer(directoryId))); |
6589 |
04 Nov 14 |
nicklas |
442 |
query.setFirstResult(0); |
6589 |
04 Nov 14 |
nicklas |
443 |
query.setMaxResults(-1); |
6589 |
04 Nov 14 |
nicklas |
444 |
} |
5590 |
16 Mar 11 |
nicklas |
445 |
dc.close(); |
1794 |
19 Jan 06 |
nicklas |
446 |
cc.setQuery(query); |
6308 |
20 Aug 13 |
nicklas |
447 |
redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&subcontext="+subcontext+"&context_type=LIST&title=Import+files"; |
1794 |
19 Jan 06 |
nicklas |
448 |
} |
1794 |
19 Jan 06 |
nicklas |
449 |
else if ("ImportItem".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
450 |
{ |
1794 |
19 Jan 06 |
nicklas |
451 |
// Run an import plugin in single-item context |
5179 |
04 Nov 09 |
nicklas |
452 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
6308 |
20 Aug 13 |
nicklas |
453 |
redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&subcontext="+subcontext+"&context_type=ITEM&title=Import+file"; |
1794 |
19 Jan 06 |
nicklas |
454 |
} |
1794 |
19 Jan 06 |
nicklas |
455 |
else if ("RunListPlugin".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
456 |
{ |
1794 |
19 Jan 06 |
nicklas |
457 |
// Run another plugin in a list context |
5179 |
04 Nov 09 |
nicklas |
458 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
1794 |
19 Jan 06 |
nicklas |
459 |
final ItemQuery<File> query = File.getQuery(); |
7954 |
12 May 21 |
nicklas |
460 |
dc = sc.newDbControl(":Run plugin "+itemType); |
7914 |
23 Feb 21 |
nicklas |
461 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
462 |
cc.configureQuery(dc, query, jspContext, true); |
6589 |
04 Nov 14 |
nicklas |
463 |
if (!isSearch) |
6589 |
04 Nov 14 |
nicklas |
464 |
{ |
6589 |
04 Nov 14 |
nicklas |
465 |
query.restrict(Restrictions.eq(Hql.property("directory"), Expressions.integer(directoryId))); |
6589 |
04 Nov 14 |
nicklas |
466 |
query.setFirstResult(0); |
6589 |
04 Nov 14 |
nicklas |
467 |
query.setMaxResults(-1); |
6589 |
04 Nov 14 |
nicklas |
468 |
} |
5590 |
16 Mar 11 |
nicklas |
469 |
dc.close(); |
1794 |
19 Jan 06 |
nicklas |
470 |
cc.setQuery(query); |
5179 |
04 Nov 09 |
nicklas |
471 |
redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&subcontext="+subcontext+"&context_type=LIST&main_type=OTHER&title=Run+plugin"; |
1794 |
19 Jan 06 |
nicklas |
472 |
} |
1794 |
19 Jan 06 |
nicklas |
473 |
else if ("RunPlugin".equals(cmd)) |
1794 |
19 Jan 06 |
nicklas |
474 |
{ |
1794 |
19 Jan 06 |
nicklas |
475 |
// Run another plugin in single-item context |
5179 |
04 Nov 09 |
nicklas |
476 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
5179 |
04 Nov 09 |
nicklas |
477 |
redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&subcontext="+subcontext+"&context_type=ITEM&main_type=OTHER&title=Run+plugin"; |
1794 |
19 Jan 06 |
nicklas |
478 |
} |
1798 |
20 Jan 06 |
nicklas |
479 |
else if ("MoveItems".equals(cmd)) |
1798 |
20 Jan 06 |
nicklas |
480 |
{ |
5179 |
04 Nov 09 |
nicklas |
481 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
1798 |
20 Jan 06 |
nicklas |
482 |
int numMoved = 0; |
1798 |
20 Jan 06 |
nicklas |
483 |
int numTotal = cc.getSelected().size(); |
6308 |
20 Aug 13 |
nicklas |
484 |
Location moveTo = Location.valueOf(request.getParameter("move")); |
6308 |
20 Aug 13 |
nicklas |
485 |
|
7954 |
12 May 21 |
nicklas |
486 |
dc = sc.newDbControl(":Move files"); |
6308 |
20 Aug 13 |
nicklas |
487 |
for (Integer id : cc.getSelected()) |
1798 |
20 Jan 06 |
nicklas |
488 |
{ |
6308 |
20 Aug 13 |
nicklas |
489 |
File f = File.getById(dc, id); |
6308 |
20 Aug 13 |
nicklas |
490 |
Location current = f.getLocation(); |
6308 |
20 Aug 13 |
nicklas |
491 |
try |
1798 |
20 Jan 06 |
nicklas |
492 |
{ |
6308 |
20 Aug 13 |
nicklas |
493 |
if (moveTo == Location.OFFLINE && current != Location.OFFLINE) |
1798 |
20 Jan 06 |
nicklas |
494 |
{ |
6308 |
20 Aug 13 |
nicklas |
495 |
// 0 = move offline |
6308 |
20 Aug 13 |
nicklas |
496 |
f.setLocation(Location.OFFLINE); |
6308 |
20 Aug 13 |
nicklas |
497 |
numMoved++; |
1798 |
20 Jan 06 |
nicklas |
498 |
} |
1798 |
20 Jan 06 |
nicklas |
499 |
} |
6308 |
20 Aug 13 |
nicklas |
500 |
catch (PermissionDeniedException ex) |
6308 |
20 Aug 13 |
nicklas |
501 |
{} |
1798 |
20 Jan 06 |
nicklas |
502 |
dc.commit(); |
1798 |
20 Jan 06 |
nicklas |
503 |
} |
1798 |
20 Jan 06 |
nicklas |
504 |
if (numTotal != numMoved) |
1798 |
20 Jan 06 |
nicklas |
505 |
{ |
1798 |
20 Jan 06 |
nicklas |
506 |
message = (numMoved == 0 ? "No" : "Only "+numMoved+" of "+numTotal) + " items could be move, because you have no WRITE permission"; |
1798 |
20 Jan 06 |
nicklas |
507 |
} |
6192 |
31 Oct 12 |
nicklas |
508 |
redirect = listPage; |
1798 |
20 Jan 06 |
nicklas |
509 |
} |
1798 |
20 Jan 06 |
nicklas |
510 |
else if ("MoveItem".equals(cmd)) |
1798 |
20 Jan 06 |
nicklas |
511 |
{ |
5179 |
04 Nov 09 |
nicklas |
512 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
6308 |
20 Aug 13 |
nicklas |
513 |
Location moveTo = Location.valueOf(request.getParameter("move")); |
6308 |
20 Aug 13 |
nicklas |
514 |
|
7954 |
12 May 21 |
nicklas |
515 |
dc = sc.newDbControl(":Move files"); |
6308 |
20 Aug 13 |
nicklas |
516 |
File f = File.getById(dc, cc.getId()); |
6308 |
20 Aug 13 |
nicklas |
517 |
Location current = f.getLocation(); |
6308 |
20 Aug 13 |
nicklas |
518 |
if (moveTo == Location.OFFLINE && current != Location.OFFLINE) |
1798 |
20 Jan 06 |
nicklas |
519 |
{ |
6308 |
20 Aug 13 |
nicklas |
520 |
// 0 = move offline |
6308 |
20 Aug 13 |
nicklas |
521 |
f.setLocation(Location.OFFLINE); |
1798 |
20 Jan 06 |
nicklas |
522 |
} |
6308 |
20 Aug 13 |
nicklas |
523 |
dc.commit(); |
1798 |
20 Jan 06 |
nicklas |
524 |
redirect = viewPage; |
1798 |
20 Jan 06 |
nicklas |
525 |
} |
1798 |
20 Jan 06 |
nicklas |
526 |
else if ("MoveToDirectory".equals(cmd)) |
1798 |
20 Jan 06 |
nicklas |
527 |
{ |
5179 |
04 Nov 09 |
nicklas |
528 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
1798 |
20 Jan 06 |
nicklas |
529 |
int numMoved = 0; |
1798 |
20 Jan 06 |
nicklas |
530 |
int numTotal = cc.getSelected().size()+dirContext.getSelected().size(); |
1798 |
20 Jan 06 |
nicklas |
531 |
int newDirectoryId = Values.getInt(request.getParameter("newdirectory_id")); |
1798 |
20 Jan 06 |
nicklas |
532 |
|
7954 |
12 May 21 |
nicklas |
533 |
dc = sc.newDbControl(":Move files"); |
1798 |
20 Jan 06 |
nicklas |
534 |
Directory newDirectory = Directory.getById(dc, newDirectoryId); |
1798 |
20 Jan 06 |
nicklas |
535 |
for (Integer id : cc.getSelected()) |
1798 |
20 Jan 06 |
nicklas |
536 |
{ |
1798 |
20 Jan 06 |
nicklas |
537 |
try |
1798 |
20 Jan 06 |
nicklas |
538 |
{ |
1798 |
20 Jan 06 |
nicklas |
539 |
File f = File.getById(dc, id); |
4019 |
29 Nov 07 |
nicklas |
540 |
if (File.exists(dc, newDirectory, f.getName())) |
4019 |
29 Nov 07 |
nicklas |
541 |
{ |
4019 |
29 Nov 07 |
nicklas |
542 |
throw new ItemAlreadyExistsException("Directory '" + newDirectory.getName() + "' already contains file: " + f.getName()); |
4019 |
29 Nov 07 |
nicklas |
543 |
} |
1798 |
20 Jan 06 |
nicklas |
544 |
f.setDirectory(newDirectory); |
1798 |
20 Jan 06 |
nicklas |
545 |
numMoved++; |
1798 |
20 Jan 06 |
nicklas |
546 |
} |
1798 |
20 Jan 06 |
nicklas |
547 |
catch (PermissionDeniedException ex) |
1798 |
20 Jan 06 |
nicklas |
548 |
{} |
1798 |
20 Jan 06 |
nicklas |
549 |
} |
1798 |
20 Jan 06 |
nicklas |
550 |
|
1798 |
20 Jan 06 |
nicklas |
551 |
for (Integer id : dirContext.getSelected()) |
1798 |
20 Jan 06 |
nicklas |
552 |
{ |
1798 |
20 Jan 06 |
nicklas |
553 |
try |
1798 |
20 Jan 06 |
nicklas |
554 |
{ |
1798 |
20 Jan 06 |
nicklas |
555 |
Directory d = Directory.getById(dc, id); |
4019 |
29 Nov 07 |
nicklas |
556 |
if (Directory.exists(dc, newDirectory, d.getName())) |
4019 |
29 Nov 07 |
nicklas |
557 |
{ |
4019 |
29 Nov 07 |
nicklas |
558 |
throw new ItemAlreadyExistsException("Directory '" + newDirectory.getName() + "' already contains subdirectoy: " + d.getName()); |
4019 |
29 Nov 07 |
nicklas |
559 |
} |
1798 |
20 Jan 06 |
nicklas |
560 |
d.setParent(newDirectory); |
1798 |
20 Jan 06 |
nicklas |
561 |
numMoved++; |
1798 |
20 Jan 06 |
nicklas |
562 |
} |
1798 |
20 Jan 06 |
nicklas |
563 |
catch (PermissionDeniedException ex) |
1798 |
20 Jan 06 |
nicklas |
564 |
{} |
1798 |
20 Jan 06 |
nicklas |
565 |
} |
1798 |
20 Jan 06 |
nicklas |
566 |
dc.commit(); |
1798 |
20 Jan 06 |
nicklas |
567 |
if (numTotal != numMoved) |
1798 |
20 Jan 06 |
nicklas |
568 |
{ |
1798 |
20 Jan 06 |
nicklas |
569 |
message = (numMoved == 0 ? "No" : "Only "+numMoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission"; |
1798 |
20 Jan 06 |
nicklas |
570 |
} |
6192 |
31 Oct 12 |
nicklas |
571 |
redirect = listPage; |
1798 |
20 Jan 06 |
nicklas |
572 |
} |
2384 |
15 Jun 06 |
nicklas |
573 |
else if ("ViewFile".equals(cmd)) |
2384 |
15 Jun 06 |
nicklas |
574 |
{ |
2384 |
15 Jun 06 |
nicklas |
575 |
// View the file contents of a file |
5179 |
04 Nov 09 |
nicklas |
576 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
7954 |
12 May 21 |
nicklas |
577 |
dc = sc.newDbControl(":View file"); |
2384 |
15 Jun 06 |
nicklas |
578 |
File f = File.getById(dc, cc.getId()); |
4951 |
27 May 09 |
nicklas |
579 |
redirect = root + "filemanager/files/view/-"+ID+"-"+ f.getPath().toURLString("UTF-8"); |
2384 |
15 Jun 06 |
nicklas |
580 |
dc.close(); |
2384 |
15 Jun 06 |
nicklas |
581 |
} |
2384 |
15 Jun 06 |
nicklas |
582 |
else if ("DownloadFile".equals(cmd)) |
2384 |
15 Jun 06 |
nicklas |
583 |
{ |
2384 |
15 Jun 06 |
nicklas |
584 |
// Download the file contents of a file |
5179 |
04 Nov 09 |
nicklas |
585 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
6308 |
20 Aug 13 |
nicklas |
586 |
forward = "download_file.jsp?ID="+ID; |
2384 |
15 Jun 06 |
nicklas |
587 |
} |
3719 |
12 Sep 07 |
nicklas |
588 |
else if ("CompressItem".equals(cmd)) |
3719 |
12 Sep 07 |
nicklas |
589 |
{ |
3719 |
12 Sep 07 |
nicklas |
590 |
// Compress a single item and then return to the view page |
3719 |
12 Sep 07 |
nicklas |
591 |
SimpleProgressReporter progress = new SimpleProgressReporter(null); |
3719 |
12 Sep 07 |
nicklas |
592 |
sc.setSessionSetting("progress.compress", progress); |
7954 |
12 May 21 |
nicklas |
593 |
dc = sc.newDbControl(":Compress file"); |
5179 |
04 Nov 09 |
nicklas |
594 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
3719 |
12 Sep 07 |
nicklas |
595 |
File f = File.getById(dc, cc.getId()); |
3719 |
12 Sep 07 |
nicklas |
596 |
f.compress(progress); |
3719 |
12 Sep 07 |
nicklas |
597 |
dc.commit(); |
3719 |
12 Sep 07 |
nicklas |
598 |
redirect = viewPage; |
3719 |
12 Sep 07 |
nicklas |
599 |
} |
3719 |
12 Sep 07 |
nicklas |
600 |
else if ("DecompressItem".equals(cmd)) |
3719 |
12 Sep 07 |
nicklas |
601 |
{ |
3719 |
12 Sep 07 |
nicklas |
602 |
// Compress a single item and then return to the view page |
3719 |
12 Sep 07 |
nicklas |
603 |
SimpleProgressReporter progress = new SimpleProgressReporter(null); |
3719 |
12 Sep 07 |
nicklas |
604 |
sc.setSessionSetting("progress.decompress", progress); |
7954 |
12 May 21 |
nicklas |
605 |
dc = sc.newDbControl(":De-compress file"); |
5179 |
04 Nov 09 |
nicklas |
606 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
3719 |
12 Sep 07 |
nicklas |
607 |
File f = File.getById(dc, cc.getId()); |
3719 |
12 Sep 07 |
nicklas |
608 |
f.decompress(progress); |
3719 |
12 Sep 07 |
nicklas |
609 |
dc.commit(); |
3719 |
12 Sep 07 |
nicklas |
610 |
redirect = viewPage; |
3719 |
12 Sep 07 |
nicklas |
611 |
} |
4867 |
31 Mar 09 |
nicklas |
612 |
else if ("EditFileData".equals(cmd)) |
4867 |
31 Mar 09 |
nicklas |
613 |
{ |
4867 |
31 Mar 09 |
nicklas |
614 |
// Display the edit page for a single item (should be opened in a popup) |
5179 |
04 Nov 09 |
nicklas |
615 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subcontext, pageContext, defaultContext); |
4867 |
31 Mar 09 |
nicklas |
616 |
redirect = "edit_file_data.jsp?ID=" + ID; |
4867 |
31 Mar 09 |
nicklas |
617 |
} |
5179 |
04 Nov 09 |
nicklas |
618 |
else if ("Search".equals(cmd)) |
5179 |
04 Nov 09 |
nicklas |
619 |
{ |
5179 |
04 Nov 09 |
nicklas |
620 |
// Display the list page after updating the current context from the request parameters |
5179 |
04 Nov 09 |
nicklas |
621 |
Base.getAndSetCurrentContext(sc, itemType, "search", pageContext, searchContext); |
5179 |
04 Nov 09 |
nicklas |
622 |
redirect = listPage; |
5179 |
04 Nov 09 |
nicklas |
623 |
} |
1794 |
19 Jan 06 |
nicklas |
624 |
else |
1794 |
19 Jan 06 |
nicklas |
625 |
{ |
1794 |
19 Jan 06 |
nicklas |
626 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
1794 |
19 Jan 06 |
nicklas |
627 |
} |
1794 |
19 Jan 06 |
nicklas |
628 |
} |
1794 |
19 Jan 06 |
nicklas |
629 |
finally |
1794 |
19 Jan 06 |
nicklas |
630 |
{ |
1794 |
19 Jan 06 |
nicklas |
631 |
if (dc != null) dc.close(); |
1794 |
19 Jan 06 |
nicklas |
632 |
} |
1794 |
19 Jan 06 |
nicklas |
633 |
|
1794 |
19 Jan 06 |
nicklas |
634 |
if (forward != null) |
1794 |
19 Jan 06 |
nicklas |
635 |
{ |
6192 |
31 Oct 12 |
nicklas |
636 |
sc.setSessionSetting("alert-message", message); |
1794 |
19 Jan 06 |
nicklas |
637 |
pageContext.forward(forward); |
1794 |
19 Jan 06 |
nicklas |
638 |
} |
1794 |
19 Jan 06 |
nicklas |
639 |
else if (redirect != null) |
1794 |
19 Jan 06 |
nicklas |
640 |
{ |
6192 |
31 Oct 12 |
nicklas |
641 |
sc.setSessionSetting("alert-message", message); |
1794 |
19 Jan 06 |
nicklas |
642 |
response.sendRedirect(redirect); |
1794 |
19 Jan 06 |
nicklas |
643 |
} |
1794 |
19 Jan 06 |
nicklas |
644 |
else if (message == null) |
1794 |
19 Jan 06 |
nicklas |
645 |
{ |
1794 |
19 Jan 06 |
nicklas |
646 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
1794 |
19 Jan 06 |
nicklas |
647 |
} |
1794 |
19 Jan 06 |
nicklas |
648 |
else |
1794 |
19 Jan 06 |
nicklas |
649 |
{ |
1794 |
19 Jan 06 |
nicklas |
650 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
1794 |
19 Jan 06 |
nicklas |
651 |
} |
1794 |
19 Jan 06 |
nicklas |
652 |
%> |
1794 |
19 Jan 06 |
nicklas |
653 |
|