1 | <%-- $Id: auto_install.jsp 3755 2007-09-19 12:36:00Z martin $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2007 Johan Enell, Nicklas Nordborg |
---|
4 | |
---|
5 | This file is part of BASE - BioArray Software Environment. |
---|
6 | Available at http://base.thep.lu.se/ |
---|
7 | |
---|
8 | BASE is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License |
---|
10 | as published by the Free Software Foundation; either version 2 |
---|
11 | of the License, or (at your option) any later version. |
---|
12 | |
---|
13 | BASE is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | GNU General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with this program; if not, write to the Free Software |
---|
20 | Foundation, Inc., 59 Temple Place - Suite 330, |
---|
21 | Boston, MA 02111-1307, USA. |
---|
22 | ------------------------------------------------------------------ |
---|
23 | |
---|
24 | |
---|
25 | @author Martin |
---|
26 | @version 2.5 |
---|
27 | --%> |
---|
28 | <%@ page session="false" |
---|
29 | |
---|
30 | import="net.sf.basedb.core.DbControl" |
---|
31 | import="net.sf.basedb.core.Item" |
---|
32 | import="net.sf.basedb.core.ItemContext" |
---|
33 | import="net.sf.basedb.core.ItemNotFoundException" |
---|
34 | import="net.sf.basedb.core.ItemQuery" |
---|
35 | import="net.sf.basedb.core.PluginDefinition" |
---|
36 | import="net.sf.basedb.core.PluginConfiguration" |
---|
37 | import="net.sf.basedb.core.SessionControl" |
---|
38 | import="net.sf.basedb.core.query.Hql" |
---|
39 | import="net.sf.basedb.core.query.Restrictions" |
---|
40 | import="net.sf.basedb.core.query.Expressions" |
---|
41 | import="net.sf.basedb.util.FileUtil" |
---|
42 | import="net.sf.basedb.util.JarClassLoader" |
---|
43 | import="net.sf.basedb.util.PluginInfo" |
---|
44 | import="net.sf.basedb.util.PluginConfigInfo" |
---|
45 | import="net.sf.basedb.util.Values" |
---|
46 | import="net.sf.basedb.clients.web.util.HTML" |
---|
47 | import="net.sf.basedb.clients.web.Base" |
---|
48 | |
---|
49 | import="java.util.Collections" |
---|
50 | import="java.util.List" |
---|
51 | import="java.util.ArrayList" |
---|
52 | import="java.util.Iterator" |
---|
53 | %> |
---|
54 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
55 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
56 | <%! |
---|
57 | private String getInfoMessage(PluginInfo info, int id) |
---|
58 | { |
---|
59 | StringBuilder message = new StringBuilder(); |
---|
60 | message.append("<div id=\"info."+id+"\" class=\"postit\" style=\"width:350px;display:none;\">"); |
---|
61 | |
---|
62 | message.append("<b>").append("Jar: ").append("</b>"); |
---|
63 | String jarpath = info.getJarPath(); |
---|
64 | message.append(jarpath.substring(jarpath.lastIndexOf('/')+1)).append("<br>"); |
---|
65 | |
---|
66 | message.append("<b>").append("Class: ").append("</b>"); |
---|
67 | message.append(HTML.encodeTags(info.getClassName())).append("<br>"); |
---|
68 | |
---|
69 | message.append("<b>").append("Version: ").append("</b>"); |
---|
70 | message.append(HTML.encodeTags(info.getAbout().getVersion())).append("<br>"); |
---|
71 | |
---|
72 | message.append("<b>").append("Works with: ").append("</b>"); |
---|
73 | message.append("BASE ").append(info.getMinBaseVersion()).append(" and higher").append("<br>"); |
---|
74 | |
---|
75 | message.append("<b>").append("Description: ").append("</b>"); |
---|
76 | message.append(HTML.encodeTags(info.getAbout().getDescription())).append("<br>"); |
---|
77 | message.append("</div>"); |
---|
78 | return message.toString(); |
---|
79 | } |
---|
80 | %> |
---|
81 | <% |
---|
82 | final Item itemType = Item.PLUGINDEFINITION; |
---|
83 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
84 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); |
---|
85 | final String ID = sc.getId(); |
---|
86 | final float scale = Base.getScale(sc); |
---|
87 | final DbControl dc = sc.newDbControl(); |
---|
88 | |
---|
89 | try |
---|
90 | { |
---|
91 | String title = "Plugin autoinstaller"; |
---|
92 | String tt = cc.getPropertyValue("trusted"); |
---|
93 | String up = cc.getPropertyValue("usePermissions"); |
---|
94 | String aie = cc.getPropertyValue("allowImmediateExection"); |
---|
95 | boolean isTrusted = tt == null ? true : Values.getBoolean(tt); |
---|
96 | boolean usePermissions = up == null ? false : Values.getBoolean(up); |
---|
97 | Boolean allowImmediateExecution = aie == null ? null : Values.getBoolean(aie); |
---|
98 | |
---|
99 | java.io.File pluginDir = new java.io.File(request.getParameter("plugin_path")); |
---|
100 | List<PluginInfo> pluginInfos = new ArrayList<PluginInfo>(); |
---|
101 | List<java.io.File> jarFiles = FileUtil.findFiles(pluginDir, null, "jar", true); |
---|
102 | |
---|
103 | for (java.io.File file : jarFiles) |
---|
104 | { |
---|
105 | pluginInfos.addAll(PluginInfo.loadFromJar(file)); |
---|
106 | } |
---|
107 | %> |
---|
108 | <base:page type="popup" title="<%=title%>"> |
---|
109 | <base:head scripts="tabcontrol.js" styles="tabcontrol.css"> |
---|
110 | <script language="JavaScript"> |
---|
111 | |
---|
112 | // Submit the form |
---|
113 | function saveSettings(install) |
---|
114 | { |
---|
115 | var frm = document.forms['autoinstall']; |
---|
116 | frm.submit(); |
---|
117 | } |
---|
118 | function toggle(grpId) |
---|
119 | { |
---|
120 | var grp = document.getElementById('grp.'+grpId); |
---|
121 | var grpIcon = document.getElementById('grp.'+grpId+'.icon'); |
---|
122 | var anchor = document.getElementById('a.'+grpId); |
---|
123 | var cnfId = 1; |
---|
124 | var cnf = document.getElementById('cnf.'+grpId+'.'+cnfId); |
---|
125 | if (cnf && cnf.style.display == 'none') |
---|
126 | { |
---|
127 | grpIcon.src = getRoot()+'images/joust/minustop.gif'; |
---|
128 | anchor.title='Collapse to hide configurations'; |
---|
129 | } |
---|
130 | else |
---|
131 | { |
---|
132 | grpIcon.src = getRoot()+'images/joust/plusonly.gif'; |
---|
133 | anchor.title='Expand to see configurations for this plugin'; |
---|
134 | } |
---|
135 | while (cnf) |
---|
136 | { |
---|
137 | Main.showHide(cnf.id); |
---|
138 | cnfId++; |
---|
139 | cnf = document.getElementById('cnf.'+grpId+'.'+cnfId); |
---|
140 | } |
---|
141 | } |
---|
142 | function setConfigsOnChange(pluginId, selectList, pluginExists) |
---|
143 | { |
---|
144 | var installoption = selectList[selectList.selectedIndex].value; |
---|
145 | if (installoption == 'plugin+confs') |
---|
146 | { |
---|
147 | var cnfId = 1; |
---|
148 | var cnf = document.getElementById('setconfig.'+pluginId+'.'+cnfId); |
---|
149 | while (cnf) |
---|
150 | { |
---|
151 | for (var i = 0; i < cnf.length; i++) |
---|
152 | { |
---|
153 | |
---|
154 | if (cnf[i].value == '1') |
---|
155 | { |
---|
156 | cnf.selectedIndex = i; |
---|
157 | i = cnf.length; |
---|
158 | } |
---|
159 | } |
---|
160 | cnfId++; |
---|
161 | cnf = document.getElementById('setconfig.'+pluginId+'.'+cnfId); |
---|
162 | } |
---|
163 | } |
---|
164 | else if (!pluginExists && installoption == '') |
---|
165 | { |
---|
166 | var cnfId = 1; |
---|
167 | var cnf = document.getElementById('setconfig.'+pluginId+'.'+cnfId); |
---|
168 | while (cnf) |
---|
169 | { |
---|
170 | for (var i = 0; i < cnf.length; i++) |
---|
171 | { |
---|
172 | |
---|
173 | if (cnf[i].value == '0') |
---|
174 | { |
---|
175 | cnf.selectedIndex = i; |
---|
176 | i = cnf.length; |
---|
177 | } |
---|
178 | } |
---|
179 | cnfId++; |
---|
180 | cnf = document.getElementById('setconfig.'+pluginId+'.'+cnfId); |
---|
181 | } |
---|
182 | } |
---|
183 | } |
---|
184 | function setPluginOnChange(pluginId, selectList, pluginExists) |
---|
185 | { |
---|
186 | var configOption = selectList[selectList.selectedIndex].value; |
---|
187 | var pluginList = document.getElementById('setplugin.' + pluginId); |
---|
188 | var pluginOption = pluginList[pluginList.selectedIndex].value; |
---|
189 | if ( (configOption == '1' && !pluginExists && pluginOption == '') || |
---|
190 | (configOption == '0' && pluginOption == 'plugin+confs') ) |
---|
191 | { |
---|
192 | for (var i=0; i<pluginList.length;i++) |
---|
193 | { |
---|
194 | if (pluginList[i].value == 'plugin') |
---|
195 | { |
---|
196 | pluginList.selectedIndex = i; |
---|
197 | i = pluginList.length; |
---|
198 | } |
---|
199 | } |
---|
200 | } |
---|
201 | } |
---|
202 | function toggleInformation(pluginId) |
---|
203 | { |
---|
204 | var infodiv = document.getElementById('info.'+pluginId); |
---|
205 | if (infodiv.style.display == 'block') |
---|
206 | { |
---|
207 | infodiv.style.display = 'none'; |
---|
208 | } |
---|
209 | else if (infodiv.style.display == 'none') |
---|
210 | { |
---|
211 | infodiv.style.display = 'block'; |
---|
212 | } |
---|
213 | } |
---|
214 | </script> |
---|
215 | </base:head> |
---|
216 | <base:body> |
---|
217 | <form name="autoinstall" action="index.jsp" method="post" onsubmit="return false;"> |
---|
218 | <input type="hidden" name="ID" value="<%=ID%>"> |
---|
219 | <input type="hidden" name="cmd" value="LoadPlugins"> |
---|
220 | <input type="hidden" name="plugin_path" value="<%=pluginDir%>"> |
---|
221 | |
---|
222 | <h3 class="docked"><%=title%> <base:help tabcontrol="plugins" /></h3> |
---|
223 | |
---|
224 | <t:tabcontrol id="plugins" contentstyle="<%="height: "+(int)(scale*260)+"px;"%>" |
---|
225 | position="bottom"> |
---|
226 | <t:tab id="plugins" title="Available plugins" validate="validatePlugins()" helpid="plugindefinition.autoinstaller"> |
---|
227 | <div align="left"> |
---|
228 | <table border="0" cellspacing="0" cellpadding="0"> |
---|
229 | <tr> |
---|
230 | <td width="45%"><b>Plugins</b></td> |
---|
231 | <td><b>Install</b></td> |
---|
232 | <td><b>Trusted</b></td> |
---|
233 | <td><b>Immediate execution</b></td> |
---|
234 | </tr> |
---|
235 | <% |
---|
236 | int plugin = 0; |
---|
237 | for (PluginInfo info : pluginInfos) |
---|
238 | { |
---|
239 | String name = info.getAbout().getName(); |
---|
240 | List<PluginConfigInfo> cnfInfos = info.getConfigurations(); |
---|
241 | ++plugin; |
---|
242 | int cnf = 0; |
---|
243 | boolean hasConfigs = cnfInfos != null && !cnfInfos.isEmpty(); |
---|
244 | boolean classExists = true; |
---|
245 | boolean jarExists = false; |
---|
246 | PluginDefinition pd = null; |
---|
247 | try |
---|
248 | { |
---|
249 | pd = PluginDefinition.getByClassName(dc, info.getClassName()); |
---|
250 | if (pd.getJarPath().equals(info.getJarPath())) |
---|
251 | { |
---|
252 | jarExists = true; |
---|
253 | } |
---|
254 | } |
---|
255 | catch(ItemNotFoundException ex) |
---|
256 | { |
---|
257 | classExists = false; |
---|
258 | jarExists = false; |
---|
259 | } |
---|
260 | %> |
---|
261 | <tr id="plugin.<%=plugin%>"> |
---|
262 | <td style="padding-top: 6px;"> |
---|
263 | <% |
---|
264 | if (hasConfigs) |
---|
265 | { |
---|
266 | %> |
---|
267 | <a href="javascript:toggle(<%=plugin%>)" id="<%="a."+plugin%>" title="Expand to see configurations for this plugin"> |
---|
268 | <base:icon id="<%="grp."+plugin+".icon"%>" image="joust/plusonly.gif" /> |
---|
269 | <a onmouseover="javascript:toggleInformation(<%=plugin%>)" |
---|
270 | onmouseout="javascript:toggleInformation(<%=plugin%>)" |
---|
271 | > |
---|
272 | <base:icon image="info.gif"/> |
---|
273 | </a> |
---|
274 | <%=getInfoMessage(info, plugin)%> |
---|
275 | <%=HTML.encodeTags(name)%></a> |
---|
276 | <% |
---|
277 | } |
---|
278 | else |
---|
279 | { |
---|
280 | %> |
---|
281 | <a onmouseover="javascript:toggleInformation(<%=plugin%>)" |
---|
282 | onmouseout="javascript:toggleInformation(<%=plugin%>)" |
---|
283 | > |
---|
284 | <base:icon image="info.gif"/> |
---|
285 | </a> |
---|
286 | <%=getInfoMessage(info, plugin)%> |
---|
287 | <%=HTML.encodeTags(name)%> |
---|
288 | <% |
---|
289 | } |
---|
290 | %> |
---|
291 | |
---|
292 | </td> |
---|
293 | <td> |
---|
294 | <select id="setplugin.<%=plugin%>" name="<%=info.getJarPath()%>.<%=info.getClassName()%>" |
---|
295 | style="width:90px" |
---|
296 | onchange="setConfigsOnChange(<%=plugin%>,this, <%=classExists%>)" |
---|
297 | <%=classExists&&jarExists ? "disabled" : "" %> |
---|
298 | > |
---|
299 | <option value="" title="Plugin will not be installed">no |
---|
300 | <option value="plugin" title="Plugin will be installed">plugin |
---|
301 | <% |
---|
302 | if (hasConfigs) |
---|
303 | { |
---|
304 | %> |
---|
305 | <option value="plugin+confs" |
---|
306 | title="Plugin and all configurations will be installed">with configs</option> |
---|
307 | <% |
---|
308 | } |
---|
309 | %> |
---|
310 | </select> |
---|
311 | <input type="hidden" name="<%=info.getClassName()%>.classExists" value="<%=classExists%>"> |
---|
312 | <input type="hidden" name="<%=info.getClassName()%>.jarExists" value="<%=jarExists%>"> |
---|
313 | <base:icon image="<%=classExists&&!jarExists ? "itemexists.gif" : "" %>" |
---|
314 | tooltip="The plugin is loaded from a different jar-file" |
---|
315 | /> |
---|
316 | <base:icon image="<%=classExists&&jarExists ? "hasvalues.gif" : "" %>" |
---|
317 | tooltip="Plugin with the same class name is already installed" |
---|
318 | /> |
---|
319 | </td> |
---|
320 | <td> |
---|
321 | |
---|
322 | <select name="<%=info.getClassName()%>.trusted" |
---|
323 | <%=classExists&&jarExists ? "disabled" : ""%> |
---|
324 | > |
---|
325 | <option value="0">no |
---|
326 | <option value="1">yes |
---|
327 | </select> |
---|
328 | |
---|
329 | </td> |
---|
330 | <td> |
---|
331 | |
---|
332 | <select name="<%=info.getClassName()%>.immediate_execution" |
---|
333 | <%=classExists&&jarExists ? "disabled" : ""%> |
---|
334 | > |
---|
335 | <option value="0">deny |
---|
336 | <option value="1">allow |
---|
337 | <% |
---|
338 | if (allowImmediateExecution == null) |
---|
339 | { |
---|
340 | %> |
---|
341 | <option value="" selected>auto |
---|
342 | <% |
---|
343 | } |
---|
344 | %> |
---|
345 | </select> |
---|
346 | </td> |
---|
347 | </tr> |
---|
348 | <% |
---|
349 | if (hasConfigs) |
---|
350 | { |
---|
351 | Iterator<PluginConfigInfo> cnfi = cnfInfos.iterator(); |
---|
352 | while (cnfi.hasNext()) |
---|
353 | { |
---|
354 | PluginConfigInfo cnfInfo = cnfi.next(); |
---|
355 | boolean isDublicate = false; |
---|
356 | if (classExists) |
---|
357 | { |
---|
358 | ItemQuery<PluginConfiguration> cnfQuery = pd.getPluginConfigurations(); |
---|
359 | cnfQuery.restrict(Restrictions.eq(Hql.property("name"), Expressions.string(cnfInfo.getName()))); |
---|
360 | Iterator<PluginConfiguration> it = cnfQuery.iterate(dc); |
---|
361 | isDublicate = it != null && it.hasNext(); |
---|
362 | } |
---|
363 | ++cnf; |
---|
364 | boolean hasNext = cnfi.hasNext(); |
---|
365 | %> |
---|
366 | <tr id="cnf.<%=plugin%>.<%=cnf%>" style="display: none;"> |
---|
367 | <td> |
---|
368 | <base:icon |
---|
369 | image="<%=hasNext ? "joust/big/join.gif" : "joust/big/joinbottom.gif"%>" |
---|
370 | /> |
---|
371 | <%=HTML.encodeTags(cnfInfo.getName())%> |
---|
372 | </td> |
---|
373 | <td> |
---|
374 | <select id="setconfig.<%=plugin%>.<%=cnf%>" name="<%=info.getClassName()%>.<%=cnfInfo.getName()%>" |
---|
375 | onChange="setPluginOnChange(<%=plugin%>, this, <%=classExists%>)"> |
---|
376 | <option value="0" title="Configuration will not be imported">no</option> |
---|
377 | <option value="1" title="Configuration will be imported">yes</option> |
---|
378 | </select> |
---|
379 | <base:icon image="<%=isDublicate ? "warning.gif" : ""%>" tooltip="Plugin already has a configuration with this name"/> |
---|
380 | </td> |
---|
381 | </tr> |
---|
382 | <% |
---|
383 | } |
---|
384 | } |
---|
385 | } |
---|
386 | %> |
---|
387 | </table> |
---|
388 | </div> |
---|
389 | <div align="right"> |
---|
390 | <i><base:icon image="warning.gif" /> = dublicate configuration</i><br> |
---|
391 | <i><base:icon image="hasvalues.gif" /> = plugin already installed</i><br> |
---|
392 | <i><base:icon image="itemexists.gif" /> = exists in a different jar-file,<br> |
---|
393 | installing will change the jar path.</i><br> |
---|
394 | </div> |
---|
395 | </t:tab> |
---|
396 | |
---|
397 | </t:tabcontrol> |
---|
398 | |
---|
399 | <table align="center"> |
---|
400 | <tr> |
---|
401 | <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td> |
---|
402 | <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td> |
---|
403 | </tr> |
---|
404 | </table> |
---|
405 | </base:body> |
---|
406 | </base:page> |
---|
407 | <% |
---|
408 | } |
---|
409 | finally |
---|
410 | { |
---|
411 | if (dc != null) dc.close(); |
---|
412 | } |
---|
413 | %> |
---|