source: trunk/www/admin/mimetypes/edit_mimetype.jsp @ 3719

Last change on this file since 3719 was 3719, checked in by Nicklas Nordborg, 14 years ago

References #411: Most of the basic functionality is now in place and has been documented
On major issue is that the Affymetrix Fusion SDK will not work with compressed files since
it expects direct access to the java.io.File object. I will try to solve this by modifying the
Affymetric Fusion SDK to work with InputStream:s instead. This would be better than to decompress
CEL and CDF files everytime they are needed. In most cases we only scan the headers anyway, so
it would be good if we can avoid copying the entire 40+ MB file(s) each time.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.6 KB
Line 
1<%-- $Id: edit_mimetype.jsp 3719 2007-09-12 13:02:59Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Hakkinen, Nicklas Nordborg, Martin Svensson
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 2
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330,
22  Boston, MA  02111-1307, USA.
23  ------------------------------------------------------------------
24
25
26  @author Nicklas
27  @version 2.0
28--%>
29<%@ page session="false"
30  import="net.sf.basedb.core.Application"
31  import="net.sf.basedb.core.SessionControl"
32  import="net.sf.basedb.core.DbControl"
33  import="net.sf.basedb.core.Item"
34  import="net.sf.basedb.core.ItemContext"
35  import="net.sf.basedb.core.Permission"
36  import="net.sf.basedb.core.MimeType"
37  import="net.sf.basedb.core.FileType"
38  import="net.sf.basedb.core.ItemQuery"
39  import="net.sf.basedb.core.ItemResultList"
40  import="net.sf.basedb.core.query.Hql"
41  import="net.sf.basedb.core.query.Orders"
42  import="net.sf.basedb.core.PermissionDeniedException"
43  import="net.sf.basedb.clients.web.Base"
44  import="net.sf.basedb.clients.web.util.HTML"
45  import="net.sf.basedb.util.Values"
46%>
47<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
48<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
49<%
50final Item itemType = Item.MIMETYPE;
51final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
52final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
53final int itemId = cc.getId();
54final String ID = sc.getId();
55final float scale = Base.getScale(sc);
56final DbControl dc = sc.newDbControl();
57try
58{
59  String title = null;
60  MimeType mimeType = null;
61  boolean readCurrentFileType = true;
62  int currentFileTypeId = 0;
63  boolean autoCompress = false;
64
65  if (itemId == 0)
66  {
67    title = "Create mime type";
68    cc.removeObject("item");
69    currentFileTypeId = Values.getInt(cc.getPropertyValue("fileType"), 0);
70    if (currentFileTypeId == 0)
71    {
72      currentFileTypeId = Values.getInt(cc.getRecent(Item.FILETYPE.name(), 0), 0);
73    }
74    autoCompress = Values.getBoolean(cc.getPropertyValue("autoCompress"), autoCompress);
75  }
76  else
77  {
78    mimeType = MimeType.getById(dc, itemId);
79    cc.setObject("item", mimeType);
80    title = "Edit MIME type -- " + HTML.encodeTags(mimeType.getName() + " (" + mimeType.getExtension() + ")");
81    autoCompress = mimeType.getAutoCompress();
82    try
83    {
84      FileType ft = mimeType.getFileType();
85      if (ft != null) currentFileTypeId = ft.getId();
86    }
87    catch (PermissionDeniedException ex)
88    {
89      readCurrentFileType = false;
90    }
91  }
92  if (mimeType != null) mimeType.checkPermission(Permission.WRITE);
93 
94  // Query to retrieve file types
95  final ItemQuery<FileType> fileTypeQuery = FileType.getQuery();
96  fileTypeQuery.order(Orders.asc(Hql.property("name")));
97  fileTypeQuery.setCacheResult(true);
98 
99  final String clazz = "class=\"text\"";
100  final String requiredClazz = "class=\"text required\"";
101  %>
102
103  <base:page type="popup" title="<%=title%>">
104  <base:head scripts="tabcontrol.js" styles="tabcontrol.css">
105    <script language="JavaScript">
106    // Validate the "MimeType" tab
107    function validateMimeType()
108    {
109      var frm = document.forms['mimeType'];
110      if (Main.trimString(frm.name.value) == '')
111      {
112        alert("You must enter a MIME type");
113        frm.name.focus();
114        return false;
115      }
116      if (Main.trimString(frm.extension.value) == '')
117      {
118        alert("You must enter a file extension");
119        frm.name.focus();
120        return false;
121      }
122      return true;
123    }
124
125    // Submit the form
126    function saveSettings()
127    {
128      var frm = document.forms['mimeType'];
129      if (TabControl.validateActiveTab('settings'))
130      {
131        frm.submit();
132      }
133    }
134   
135    function init()
136    {
137      <%
138      if (mimeType == null)
139      {
140        %>
141        var frm = document.forms['mimeType'];
142        frm.name.focus();
143        frm.name.select();
144        <%
145      }
146      %>
147    }
148    </script>
149  </base:head>
150  <base:body onload="init()">
151    <p>
152    <form action="index.jsp?ID=<%=ID%>" method="post" name="mimeType" onsubmit="return false;">
153    <input type="hidden" name="cmd" value="UpdateItem">
154
155    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
156    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*240)+"px;"%>" 
157      position="bottom" remember="<%=mimeType != null%>">
158    <t:tab id="info" title="MIME type" validate="validateMimeType()" helpid="mimetype.edit">
159      <table class="form" cellspacing=0>
160      <tr>
161        <td class="prompt">File extension</td>
162        <td><input <%=requiredClazz%> type="text" name="extension" 
163          value="<%=HTML.encodeTags(mimeType == null ? cc.getPropertyValue("extension") : mimeType.getExtension())%>" 
164          size="40" maxlength="<%=MimeType.MAX_NAME_LENGTH%>"></td>
165      </tr>
166      <tr>
167        <td class="prompt">MIME type</td>
168        <td><input <%=requiredClazz%> type="text" name="name" 
169          value="<%=HTML.encodeTags(mimeType == null ? Values.getString(cc.getPropertyValue("name"), "New MIME type") : mimeType.getName())%>" 
170          size="40" maxlength="<%=MimeType.MAX_NAME_LENGTH%>"></td>
171      </tr>
172      <tr valign="top">
173        <td class="prompt">File type</td>
174        <td colspan="2">
175          <select name="filetype_id" <%=!readCurrentFileType ? "disabled readonly class=\"disabled\"" : ""%>>
176          <%
177          if (!readCurrentFileType)
178          {
179            %>
180            <option value="-1">- denied -
181            <%
182          }
183          else
184          {
185            %>
186            <option value="0">- none -
187            <%
188            ItemResultList<FileType> fileTypes = fileTypeQuery.list(dc);
189            for (FileType fileType : fileTypes)
190            {
191              int id = fileType.getId();
192              %>
193              <option 
194                value="<%=mimeType != null && id == currentFileTypeId ? -id : id%>" 
195                <%=id == currentFileTypeId ? "selected" : ""%>
196                ><%=HTML.encodeTags(fileType.getName())%>
197              <%
198            }
199          }
200          %>
201          </select>
202        </td>
203      </tr>
204      <tr>
205        <td class="prompt">Auto compress</td>
206        <td>
207          <input type="radio" name="autoCompress" value="0" <%=!autoCompress ? "checked" : ""%>>no
208          <input type="radio" name="autoCompress" value="1" <%=autoCompress ? "checked" : ""%>>yes
209         
210          <%
211          if (Application.autoCompressionEnabled())
212          {
213            %>
214            <base:note type="info" style="background: #ffffcc;">
215              Auto-compression has been disabled in <code>base.config</code>
216            </base:note>
217            <%
218          }
219          %>
220        </td>
221      </tr> 
222      <tr valign=top>
223        <td class="prompt">Description</td>
224        <td nowrap>
225          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
226            ><%=HTML.encodeTags(mimeType == null ? cc.getPropertyValue("description") : mimeType.getDescription())%></textarea>
227          <a href="javascript:Main.zoom('Description', 'mimeType', 'description')"
228            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
229        </td>
230      </tr>
231      </table>
232      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
233    </t:tab>
234    </t:tabcontrol>
235
236    <table align="center">
237    <tr>
238      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
239      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
240    </tr>
241    </table>
242    </form>
243  </base:body>
244  </base:page>
245  <%
246}
247finally
248{
249  if (dc != null) dc.close();
250}
251%>
Note: See TracBrowser for help on using the repository browser.