4867 |
31 Mar 09 |
nicklas |
1 |
<%-- $Id$ |
4867 |
31 Mar 09 |
nicklas |
2 |
------------------------------------------------------------------ |
5425 |
23 Sep 10 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson |
4867 |
31 Mar 09 |
nicklas |
Copyright (C) 2007 Nicklas Nordborg |
4867 |
31 Mar 09 |
nicklas |
5 |
|
4867 |
31 Mar 09 |
nicklas |
6 |
This file is part of BASE - BioArray Software Environment. |
4867 |
31 Mar 09 |
nicklas |
7 |
Available at http://base.thep.lu.se/ |
4867 |
31 Mar 09 |
nicklas |
8 |
|
4867 |
31 Mar 09 |
nicklas |
9 |
BASE is free software; you can redistribute it and/or |
4867 |
31 Mar 09 |
nicklas |
10 |
modify it under the terms of the GNU General Public License |
4867 |
31 Mar 09 |
nicklas |
11 |
as published by the Free Software Foundation; either version 3 |
4867 |
31 Mar 09 |
nicklas |
12 |
of the License, or (at your option) any later version. |
4867 |
31 Mar 09 |
nicklas |
13 |
|
4867 |
31 Mar 09 |
nicklas |
14 |
BASE is distributed in the hope that it will be useful, |
4867 |
31 Mar 09 |
nicklas |
15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4867 |
31 Mar 09 |
nicklas |
16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4867 |
31 Mar 09 |
nicklas |
17 |
GNU General Public License for more details. |
4867 |
31 Mar 09 |
nicklas |
18 |
|
4867 |
31 Mar 09 |
nicklas |
19 |
You should have received a copy of the GNU General Public License |
4867 |
31 Mar 09 |
nicklas |
20 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
4867 |
31 Mar 09 |
nicklas |
21 |
------------------------------------------------------------------ |
4867 |
31 Mar 09 |
nicklas |
22 |
|
4867 |
31 Mar 09 |
nicklas |
23 |
@author Nicklas |
4867 |
31 Mar 09 |
nicklas |
24 |
@version 2.0 |
4867 |
31 Mar 09 |
nicklas |
25 |
--%> |
5426 |
24 Sep 10 |
nicklas |
26 |
<%@ page pageEncoding="UTF-8" session="false" |
4867 |
31 Mar 09 |
nicklas |
27 |
import="net.sf.basedb.core.SessionControl" |
4867 |
31 Mar 09 |
nicklas |
28 |
import="net.sf.basedb.core.DbControl" |
4867 |
31 Mar 09 |
nicklas |
29 |
import="net.sf.basedb.core.Item" |
4867 |
31 Mar 09 |
nicklas |
30 |
import="net.sf.basedb.core.SystemItems" |
4867 |
31 Mar 09 |
nicklas |
31 |
import="net.sf.basedb.core.ItemContext" |
4867 |
31 Mar 09 |
nicklas |
32 |
import="net.sf.basedb.core.Permission" |
4867 |
31 Mar 09 |
nicklas |
33 |
import="net.sf.basedb.core.Directory" |
4867 |
31 Mar 09 |
nicklas |
34 |
import="net.sf.basedb.core.File" |
4867 |
31 Mar 09 |
nicklas |
35 |
import="net.sf.basedb.core.Location" |
4867 |
31 Mar 09 |
nicklas |
36 |
import="net.sf.basedb.core.PermissionDeniedException" |
4867 |
31 Mar 09 |
nicklas |
37 |
import="net.sf.basedb.core.BaseException" |
4867 |
31 Mar 09 |
nicklas |
38 |
import="net.sf.basedb.clients.web.Base" |
4867 |
31 Mar 09 |
nicklas |
39 |
import="net.sf.basedb.clients.web.util.HTML" |
4867 |
31 Mar 09 |
nicklas |
40 |
import="net.sf.basedb.util.Values" |
7626 |
07 Mar 19 |
nicklas |
41 |
import="net.sf.basedb.core.Config" |
4867 |
31 Mar 09 |
nicklas |
42 |
import="java.util.List" |
4867 |
31 Mar 09 |
nicklas |
43 |
import="java.util.Set" |
4867 |
31 Mar 09 |
nicklas |
44 |
import="java.util.HashSet" |
7626 |
07 Mar 19 |
nicklas |
45 |
import="java.nio.charset.Charset" |
4867 |
31 Mar 09 |
nicklas |
46 |
%> |
4867 |
31 Mar 09 |
nicklas |
47 |
<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
4867 |
31 Mar 09 |
nicklas |
48 |
<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %> |
4867 |
31 Mar 09 |
nicklas |
49 |
<% |
4867 |
31 Mar 09 |
nicklas |
50 |
final Item itemType = Item.FILE; |
4867 |
31 Mar 09 |
nicklas |
51 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
4867 |
31 Mar 09 |
nicklas |
52 |
final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); |
4867 |
31 Mar 09 |
nicklas |
53 |
final int itemId = cc.getId(); |
4867 |
31 Mar 09 |
nicklas |
54 |
final String ID = sc.getId(); |
4867 |
31 Mar 09 |
nicklas |
55 |
final float scale = Base.getScale(sc); |
7954 |
12 May 21 |
nicklas |
56 |
final DbControl dc = sc.newDbControl(":Edit file data"); |
4867 |
31 Mar 09 |
nicklas |
57 |
try |
4867 |
31 Mar 09 |
nicklas |
58 |
{ |
4867 |
31 Mar 09 |
nicklas |
59 |
final File file = File.getById(dc, itemId); |
4867 |
31 Mar 09 |
nicklas |
60 |
final String mimeType = file.getMimeType(); |
4867 |
31 Mar 09 |
nicklas |
61 |
final boolean editable = file.hasPermission(Permission.WRITE) && !file.isWriteProtected() && |
4867 |
31 Mar 09 |
nicklas |
62 |
mimeType != null && mimeType.startsWith("text/") && |
4867 |
31 Mar 09 |
nicklas |
63 |
file.getSize() < 102400 && file.getLocation() == Location.PRIMARY; |
4867 |
31 Mar 09 |
nicklas |
64 |
|
4867 |
31 Mar 09 |
nicklas |
65 |
if (!editable) |
4867 |
31 Mar 09 |
nicklas |
66 |
{ |
5558 |
28 Jan 11 |
nicklas |
67 |
throw new PermissionDeniedException("Online editing of file is not allowed: " + file); |
4867 |
31 Mar 09 |
nicklas |
68 |
} |
4867 |
31 Mar 09 |
nicklas |
69 |
final String path = file.getPath().toString(); |
4867 |
31 Mar 09 |
nicklas |
70 |
final String title = "Edit file -- " + HTML.encodeTags(file.getName()); |
4867 |
31 Mar 09 |
nicklas |
71 |
%> |
4867 |
31 Mar 09 |
nicklas |
72 |
<base:page type="popup" title="<%=title%>"> |
6308 |
20 Aug 13 |
nicklas |
73 |
<base:head styles="toolbar.css" scripts="~edit_file_data.js"> |
4867 |
31 Mar 09 |
nicklas |
74 |
<style> |
5908 |
13 Dec 11 |
nicklas |
75 |
#linenumbers |
5908 |
13 Dec 11 |
nicklas |
76 |
{ |
5908 |
13 Dec 11 |
nicklas |
77 |
position: absolute; |
7626 |
07 Mar 19 |
nicklas |
78 |
top: 0; |
7626 |
07 Mar 19 |
nicklas |
79 |
left: 0; |
7626 |
07 Mar 19 |
nicklas |
80 |
bottom: 0; |
5908 |
13 Dec 11 |
nicklas |
81 |
width: 3.6em; |
7626 |
07 Mar 19 |
nicklas |
82 |
padding-top: 2px; |
5908 |
13 Dec 11 |
nicklas |
83 |
padding-right: 0.4em; |
4867 |
31 Mar 09 |
nicklas |
84 |
text-align: right; |
4867 |
31 Mar 09 |
nicklas |
85 |
overflow: hidden; |
5908 |
13 Dec 11 |
nicklas |
86 |
color: #224488; |
5908 |
13 Dec 11 |
nicklas |
87 |
background: #E8E8E8; |
6378 |
12 Dec 13 |
nicklas |
88 |
font-family: monospace,Courier New; |
5908 |
13 Dec 11 |
nicklas |
89 |
border-right: 2px solid #224488; |
4867 |
31 Mar 09 |
nicklas |
90 |
} |
5908 |
13 Dec 11 |
nicklas |
91 |
|
5908 |
13 Dec 11 |
nicklas |
92 |
#filecontainer |
5908 |
13 Dec 11 |
nicklas |
93 |
{ |
5908 |
13 Dec 11 |
nicklas |
94 |
position: absolute; |
7626 |
07 Mar 19 |
nicklas |
95 |
top: 2px; |
5908 |
13 Dec 11 |
nicklas |
96 |
left: 4em; |
7626 |
07 Mar 19 |
nicklas |
97 |
bottom: 0; |
7626 |
07 Mar 19 |
nicklas |
98 |
right: 0; |
5908 |
13 Dec 11 |
nicklas |
99 |
margin-left: 2px; |
5908 |
13 Dec 11 |
nicklas |
100 |
} |
5908 |
13 Dec 11 |
nicklas |
101 |
|
5908 |
13 Dec 11 |
nicklas |
102 |
#filedata |
5908 |
13 Dec 11 |
nicklas |
103 |
{ |
5908 |
13 Dec 11 |
nicklas |
104 |
width: 100%; |
5908 |
13 Dec 11 |
nicklas |
105 |
height: 100%; |
7626 |
07 Mar 19 |
nicklas |
106 |
border: 0; |
7626 |
07 Mar 19 |
nicklas |
107 |
margin: 0; |
7626 |
07 Mar 19 |
nicklas |
108 |
padding: 0; |
5908 |
13 Dec 11 |
nicklas |
109 |
} |
7626 |
07 Mar 19 |
nicklas |
110 |
|
7626 |
07 Mar 19 |
nicklas |
111 |
.bigger-notify |
7626 |
07 Mar 19 |
nicklas |
112 |
{ |
7626 |
07 Mar 19 |
nicklas |
113 |
width: 30em; |
7626 |
07 Mar 19 |
nicklas |
114 |
} |
7626 |
07 Mar 19 |
nicklas |
115 |
|
7626 |
07 Mar 19 |
nicklas |
116 |
#charsetSection |
7626 |
07 Mar 19 |
nicklas |
117 |
{ |
7626 |
07 Mar 19 |
nicklas |
118 |
top: auto; |
7626 |
07 Mar 19 |
nicklas |
119 |
bottom: 0; |
7626 |
07 Mar 19 |
nicklas |
120 |
height: 2.4em; |
7626 |
07 Mar 19 |
nicklas |
121 |
left: auto; |
7626 |
07 Mar 19 |
nicklas |
122 |
right: calc(50% + 7em); |
7626 |
07 Mar 19 |
nicklas |
123 |
z-index: 2; |
7626 |
07 Mar 19 |
nicklas |
124 |
} |
7626 |
07 Mar 19 |
nicklas |
125 |
|
7626 |
07 Mar 19 |
nicklas |
126 |
#nonUtf8Warning |
7626 |
07 Mar 19 |
nicklas |
127 |
{ |
7626 |
07 Mar 19 |
nicklas |
128 |
visibility: hidden; |
7626 |
07 Mar 19 |
nicklas |
129 |
} |
7626 |
07 Mar 19 |
nicklas |
130 |
|
7626 |
07 Mar 19 |
nicklas |
131 |
#charsetSection.utf8-warning #nonUtf8Warning |
7626 |
07 Mar 19 |
nicklas |
132 |
{ |
7626 |
07 Mar 19 |
nicklas |
133 |
visibility: visible; |
7626 |
07 Mar 19 |
nicklas |
134 |
} |
4867 |
31 Mar 09 |
nicklas |
135 |
</style> |
4867 |
31 Mar 09 |
nicklas |
136 |
</base:head> |
6308 |
20 Aug 13 |
nicklas |
137 |
<base:body> |
6308 |
20 Aug 13 |
nicklas |
138 |
<h1><%=title%> <span id="modified"></span> <base:help helpid="file.edit.data" /></h1> |
5908 |
13 Dec 11 |
nicklas |
139 |
|
6308 |
20 Aug 13 |
nicklas |
140 |
<div id="page-data" class="datacontainer" |
6308 |
20 Aug 13 |
nicklas |
141 |
data-path="<%=HTML.encodeTags(path) %>" |
6308 |
20 Aug 13 |
nicklas |
142 |
data-file-id="<%=itemId %>" |
6308 |
20 Aug 13 |
nicklas |
143 |
></div> |
6308 |
20 Aug 13 |
nicklas |
144 |
|
6162 |
10 Oct 12 |
nicklas |
145 |
<form action="index.jsp?ID=<%=ID%>" method="post" name="file"> |
4867 |
31 Mar 09 |
nicklas |
146 |
<input type="hidden" name="cmd" value="UpdateItem"> |
5908 |
13 Dec 11 |
nicklas |
147 |
|
5908 |
13 Dec 11 |
nicklas |
148 |
<div class="content bottomborder" style="overflow: hidden;"> |
5908 |
13 Dec 11 |
nicklas |
149 |
<div id="linenumbers"></div> |
5908 |
13 Dec 11 |
nicklas |
150 |
<div id="filecontainer"> |
5908 |
13 Dec 11 |
nicklas |
151 |
<textarea id="filedata" name="filedata" |
6308 |
20 Aug 13 |
nicklas |
152 |
wrap="off" style="overflow: auto;" |
4867 |
31 Mar 09 |
nicklas |
153 |
>Loading file; please wait...</textarea> |
5908 |
13 Dec 11 |
nicklas |
154 |
</div> |
5908 |
13 Dec 11 |
nicklas |
155 |
</div> |
7626 |
07 Mar 19 |
nicklas |
156 |
|
7626 |
07 Mar 19 |
nicklas |
157 |
<div id="charsetSection" class="absolutefull"> |
7626 |
07 Mar 19 |
nicklas |
158 |
<b>Character set</b> |
7626 |
07 Mar 19 |
nicklas |
159 |
<select name="charset" id="charset"> |
7626 |
07 Mar 19 |
nicklas |
160 |
<% |
7626 |
07 Mar 19 |
nicklas |
161 |
String currentCharset = Values.getString(file.getCharacterSet(), "UTF-8"); |
7626 |
07 Mar 19 |
nicklas |
162 |
int numCommon = Config.getCommonCharsets().size(); |
7626 |
07 Mar 19 |
nicklas |
163 |
int i = 0; |
7626 |
07 Mar 19 |
nicklas |
164 |
boolean hasSelected = false; |
7626 |
07 Mar 19 |
nicklas |
165 |
for (String charset : Config.getAllCharsets()) |
7626 |
07 Mar 19 |
nicklas |
166 |
{ |
7626 |
07 Mar 19 |
nicklas |
167 |
// The UTF-32 charset is not working well in browsers and we do not include non-encoding character sets |
7626 |
07 Mar 19 |
nicklas |
168 |
if (charset.startsWith("UTF-32") || !Charset.forName(charset).canEncode()) continue; |
7626 |
07 Mar 19 |
nicklas |
169 |
boolean selected = false; |
7626 |
07 Mar 19 |
nicklas |
170 |
if (!hasSelected) |
7626 |
07 Mar 19 |
nicklas |
171 |
{ |
7626 |
07 Mar 19 |
nicklas |
172 |
selected = charset.equalsIgnoreCase(currentCharset); |
7626 |
07 Mar 19 |
nicklas |
173 |
hasSelected |= selected; |
7626 |
07 Mar 19 |
nicklas |
174 |
} |
7626 |
07 Mar 19 |
nicklas |
175 |
%> |
7626 |
07 Mar 19 |
nicklas |
176 |
<option value="<%=charset%>" <%=selected ? "selected" : ""%> |
7626 |
07 Mar 19 |
nicklas |
177 |
<%=i==numCommon ? "style=\"border-top: 1px solid #666666;\"" : "" %>><%=charset%> |
7626 |
07 Mar 19 |
nicklas |
178 |
<% |
7626 |
07 Mar 19 |
nicklas |
179 |
i++; |
7626 |
07 Mar 19 |
nicklas |
180 |
} |
7626 |
07 Mar 19 |
nicklas |
181 |
if (!hasSelected && currentCharset != null) |
7626 |
07 Mar 19 |
nicklas |
182 |
{ |
7626 |
07 Mar 19 |
nicklas |
183 |
%> |
7626 |
07 Mar 19 |
nicklas |
184 |
<option value="<%=currentCharset%>" selected><%=currentCharset%> |
7626 |
07 Mar 19 |
nicklas |
185 |
<% |
7626 |
07 Mar 19 |
nicklas |
186 |
} |
7626 |
07 Mar 19 |
nicklas |
187 |
%> |
7626 |
07 Mar 19 |
nicklas |
188 |
</select> |
7626 |
07 Mar 19 |
nicklas |
189 |
<span id="nonUtf8Warning"><img src="../../images/warning.png" |
7626 |
07 Mar 19 |
nicklas |
190 |
title="The selected character set may not be able to encode all characters"></span> |
7626 |
07 Mar 19 |
nicklas |
191 |
</div> |
4867 |
31 Mar 09 |
nicklas |
192 |
</form> |
5908 |
13 Dec 11 |
nicklas |
193 |
|
5908 |
13 Dec 11 |
nicklas |
194 |
<base:buttongroup subclass="dialogbuttons"> |
6308 |
20 Aug 13 |
nicklas |
195 |
<base:button id="btnSave" title="Save" /> |
6308 |
20 Aug 13 |
nicklas |
196 |
<base:button id="close" title="Close" /> |
5908 |
13 Dec 11 |
nicklas |
197 |
</base:buttongroup> |
4867 |
31 Mar 09 |
nicklas |
198 |
</base:body> |
4867 |
31 Mar 09 |
nicklas |
199 |
</base:page> |
4867 |
31 Mar 09 |
nicklas |
200 |
<% |
4867 |
31 Mar 09 |
nicklas |
201 |
} |
4867 |
31 Mar 09 |
nicklas |
202 |
finally |
4867 |
31 Mar 09 |
nicklas |
203 |
{ |
4867 |
31 Mar 09 |
nicklas |
204 |
if (dc != null) dc.close(); |
4867 |
31 Mar 09 |
nicklas |
205 |
} |
4867 |
31 Mar 09 |
nicklas |
206 |
%> |