extensions/net.sf.basedb.reggie/trunk/resources/download-as-zip.jsp

Code
Comments
Other
Rev Date Author Line
6854 24 Oct 22 nicklas 1 <%@ page
6854 24 Oct 22 nicklas 2   pageEncoding="UTF-8"
6854 24 Oct 22 nicklas 3   session="false"
6854 24 Oct 22 nicklas 4   import="net.sf.basedb.core.Application"
6854 24 Oct 22 nicklas 5   import="net.sf.basedb.core.User"
6854 24 Oct 22 nicklas 6   import="net.sf.basedb.core.File"
6854 24 Oct 22 nicklas 7   import="net.sf.basedb.core.DbControl"
6854 24 Oct 22 nicklas 8   import="net.sf.basedb.core.SessionControl"
6856 25 Oct 22 nicklas 9   import="net.sf.basedb.core.Item"
6856 25 Oct 22 nicklas 10   import="net.sf.basedb.core.ItemQuery"
6856 25 Oct 22 nicklas 11   import="net.sf.basedb.core.Include"
6856 25 Oct 22 nicklas 12   import="net.sf.basedb.core.AnnotationType"
6856 25 Oct 22 nicklas 13   import="net.sf.basedb.core.AnnotationSet"
6856 25 Oct 22 nicklas 14   import="net.sf.basedb.core.Annotation"
6856 25 Oct 22 nicklas 15   import="net.sf.basedb.core.query.Restrictions"
6856 25 Oct 22 nicklas 16   import="net.sf.basedb.core.query.Hql"
6856 25 Oct 22 nicklas 17   import="net.sf.basedb.core.query.Expressions"
6854 24 Oct 22 nicklas 18   import="net.sf.basedb.clients.web.Base"
6854 24 Oct 22 nicklas 19   import="net.sf.basedb.clients.web.util.HTML"
6854 24 Oct 22 nicklas 20   import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
6854 24 Oct 22 nicklas 21   import="net.sf.basedb.util.Values"
6856 25 Oct 22 nicklas 22   import="java.util.List"
6854 24 Oct 22 nicklas 23 %>
6854 24 Oct 22 nicklas 24 <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
6854 24 Oct 22 nicklas 25 <%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
6854 24 Oct 22 nicklas 26 <%
6854 24 Oct 22 nicklas 27 final SessionControl sc = Base.getExistingSessionControl(request, "net.sf.basedb.reggie", true);
6854 24 Oct 22 nicklas 28 final String ID = sc.getId();
6854 24 Oct 22 nicklas 29 final float scale = Base.getScale(sc);
6854 24 Oct 22 nicklas 30 final String home = ExtensionsControl.getHomeUrl("net.sf.basedb.reggie");
6854 24 Oct 22 nicklas 31 DbControl dc = null;
6854 24 Oct 22 nicklas 32 try
6854 24 Oct 22 nicklas 33 {
6854 24 Oct 22 nicklas 34   dc = sc.newDbControl();
6854 24 Oct 22 nicklas 35   final User user = User.getById(dc, sc.getLoggedInUserId());
6854 24 Oct 22 nicklas 36   int fileId = Values.getInt(request.getParameter("fileId"));
6854 24 Oct 22 nicklas 37   File file = File.getById(dc, fileId);
6856 25 Oct 22 nicklas 38   String lastPassword = sc.getUserClientSetting("reggie.zip-password");
6856 25 Oct 22 nicklas 39   if (file.isAnnotated())
6856 25 Oct 22 nicklas 40   {
6856 25 Oct 22 nicklas 41     ItemQuery<AnnotationType> query = AnnotationType.getQuery(Item.FILE);
6856 25 Oct 22 nicklas 42     query.restrict(Restrictions.eq(Hql.property("name"), Expressions.string("ZipPassword")));
6856 25 Oct 22 nicklas 43     query.setIncludes(Include.ALL);
6856 25 Oct 22 nicklas 44     List<AnnotationType> result = query.list(dc);
6856 25 Oct 22 nicklas 45     if (result.size() == 1)
6856 25 Oct 22 nicklas 46     {
6856 25 Oct 22 nicklas 47       AnnotationType zipPwd = result.get(0);
6856 25 Oct 22 nicklas 48       AnnotationSet as = file.getAnnotationSet();
6856 25 Oct 22 nicklas 49       if (as.hasAnnotation(zipPwd, Annotation.Source.PRIMARY))
6856 25 Oct 22 nicklas 50       {
6856 25 Oct 22 nicklas 51         lastPassword = (String)as.getAnnotation(zipPwd).getValues().get(0);
6856 25 Oct 22 nicklas 52       }
6856 25 Oct 22 nicklas 53     }
6856 25 Oct 22 nicklas 54   }
6854 24 Oct 22 nicklas 55 %>
6855 25 Oct 22 nicklas 56 <base:page type="popup" title="Download as ZIP" id="password-dialog">
6854 24 Oct 22 nicklas 57 <base:head 
6855 25 Oct 22 nicklas 58   scripts="~download-as-zip.js,~reggie-2.js"
6855 25 Oct 22 nicklas 59   styles="~css/reggie-2.css"
6854 24 Oct 22 nicklas 60 />
6854 24 Oct 22 nicklas 61 <base:body>
6854 24 Oct 22 nicklas 62   <h1>Download as ZIP</h1>
6854 24 Oct 22 nicklas 63
6854 24 Oct 22 nicklas 64   <div id="page-data" class="datacontainer"
6854 24 Oct 22 nicklas 65     data-file-id="<%=fileId%>"
6854 24 Oct 22 nicklas 66   ></div>
6854 24 Oct 22 nicklas 67
6854 24 Oct 22 nicklas 68   <form name="options" id="wizard" class="wizard">
6854 24 Oct 22 nicklas 69   <div class="content bottomborder">
6854 24 Oct 22 nicklas 70   
6854 24 Oct 22 nicklas 71     <table class="fullform input100">
6854 24 Oct 22 nicklas 72     <tr>
6854 24 Oct 22 nicklas 73       <th>File</th>
6854 24 Oct 22 nicklas 74       <td>
6854 24 Oct 22 nicklas 75         <%=HTML.encodeTags(file.getName())%>
6854 24 Oct 22 nicklas 76       </td>
6854 24 Oct 22 nicklas 77     </tr>
6854 24 Oct 22 nicklas 78     <tr>
6854 24 Oct 22 nicklas 79       <th>Password</th>
6854 24 Oct 22 nicklas 80       <td>
6856 25 Oct 22 nicklas 81         <input class="text auto-init" data-auto-init="focus" style="width: calc(100% - 9em);"
6856 25 Oct 22 nicklas 82           type="text" name="password" id="password" maxlength="20" value="<%=HTML.encodeTags(lastPassword)%>">
6856 25 Oct 22 nicklas 83           <base:button id="generate" title="Generate" style="width: 6em;" />
6854 24 Oct 22 nicklas 84       </td>
6854 24 Oct 22 nicklas 85     </tr>
6854 24 Oct 22 nicklas 86     <tr>
6854 24 Oct 22 nicklas 87       <th class="subprompt"></th>
6856 25 Oct 22 nicklas 88       <td style="padding: 0.5em; font-style: italic;">
6856 25 Oct 22 nicklas 89         <ul style="padding-left: 1em;">
6856 25 Oct 22 nicklas 90         <li>Max 20 characters.
6856 25 Oct 22 nicklas 91         <li>If empty, the ZIP file is not password protected.
6856 25 Oct 22 nicklas 92         </ul>
6856 25 Oct 22 nicklas 93       </td>
6856 25 Oct 22 nicklas 94     </tr>
6856 25 Oct 22 nicklas 95     <tr>
6856 25 Oct 22 nicklas 96       <th></th>
6854 24 Oct 22 nicklas 97       <td>
6856 25 Oct 22 nicklas 98         <label><input type="checkbox" name="rememberPassword" id="rememberPassword"
6856 25 Oct 22 nicklas 99           <%=lastPassword != null ? "checked" : "" %>
6861 04 Nov 22 nicklas 100         >Remember password</label> - 
6861 04 Nov 22 nicklas 101         <i>the password is saved to the <code>ZipPassword</code> annotation on the file item.</i>
6854 24 Oct 22 nicklas 102       </td>
6854 24 Oct 22 nicklas 103     </tr>
6854 24 Oct 22 nicklas 104     <tr class="dynamic">
6854 24 Oct 22 nicklas 105       <th class="subprompt"></th>
6854 24 Oct 22 nicklas 106       <td>
6854 24 Oct 22 nicklas 107       </td>
6854 24 Oct 22 nicklas 108     </tr>
6854 24 Oct 22 nicklas 109     </table>
6854 24 Oct 22 nicklas 110   
6854 24 Oct 22 nicklas 111   </div>
6854 24 Oct 22 nicklas 112   </form>
6854 24 Oct 22 nicklas 113   
6854 24 Oct 22 nicklas 114   <base:buttongroup subclass="dialogbuttons" id="dialogbuttons">
6855 25 Oct 22 nicklas 115     <base:button id="btnDownload" title="Download" image="<%=home+"/images/download-as-zip.png"%>" />
6854 24 Oct 22 nicklas 116     <base:button id="close" title="Cancel" />
6854 24 Oct 22 nicklas 117   </base:buttongroup>
6854 24 Oct 22 nicklas 118 </base:body>
6854 24 Oct 22 nicklas 119 </base:page>
6854 24 Oct 22 nicklas 120 <%
6854 24 Oct 22 nicklas 121 }
6854 24 Oct 22 nicklas 122 finally
6854 24 Oct 22 nicklas 123 {
6854 24 Oct 22 nicklas 124   if (dc != null) dc.close();
6854 24 Oct 22 nicklas 125 }
6854 24 Oct 22 nicklas 126 %>