KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > za > org > coefficient > modules > fileUpload > MostRecentFileUploads


1 /*
2  * Coefficient - facilitates project based collaboration
3  * Copyright (C) 2003, Dylan Etkin, CSIR icomtek
4  * PO Box 395
5  * Pretoria 0001, RSA
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package za.org.coefficient.modules.fileUpload;
21
22 import za.org.coefficient.interfaces.CoefficientContext;
23 import za.org.coefficient.modules.BaseModule;
24 import za.org.coefficient.util.common.HibernatePager;
25 import za.org.coefficient.util.ejb.VelocityScreenUtil;
26 import za.org.coefficient.util.ejb.SecurityUtil;
27
28 import java.util.HashMap JavaDoc;
29
30 /**
31  * @pojo2ejb.class
32  * name="MostRecentFileUploads"
33  * jndi-prefix="za/org/coefficient/orphan/"
34  * interface-extends="za.org.coefficient.interfaces.Module"
35  * interface-local-extends="za.org.coefficient.interfaces.ModuleLocal"
36  *
37  * @web.resource-env-ref
38  * name="za/org/coefficient/orphan/MostRecentFileUploads"
39  * type="za.org.coefficient.modules.fileUpload.MostRecentFileUploads"
40  * @web.resource-env-ref
41  * name="MostRecentFileUploads"
42  * type="za.org.coefficient.modules.fileUpload.MostRecentFileUploads"
43  */

44 public class MostRecentFileUploads extends BaseModule {
45     //~ Methods ================================================================
46

47     public String JavaDoc getMainMethod() {
48         return "view";
49     }
50
51     public String JavaDoc getModuleDescription() {
52         return "Shows the most recently created file uploads";
53     }
54
55     public String JavaDoc getModuleDisplayName() {
56         return "Most Recent File Uploads" ;
57     }
58
59     public CoefficientContext view(CoefficientContext ctx) throws Exception JavaDoc {
60         HashMap JavaDoc searchParams = new HashMap JavaDoc();
61         searchParams.put("active", new Boolean JavaDoc(true));
62         String JavaDoc query = "select upload from " + ProjectUpload.class.getName()
63             + " as upload where upload.folderItem.currentVersion = upload.id and upload.folderItem.maxReadRole.id = ? order by upload.timestamp";
64         HibernatePager hp =
65             new HibernatePager(query, new Object JavaDoc[]{SecurityUtil.getRoleForDescription(SecurityUtil.GUEST_ROLE_DESC).getId()});
66         if (hp.currentPage().size() > 0) {
67             HashMap JavaDoc map = new HashMap JavaDoc();
68             map.put("pager", hp);
69             StringBuffer JavaDoc sb =
70                 VelocityScreenUtil.getProcessedScreen("view-uploads.vm", map);
71
72             // Set the html into the context
73
ctx.setModuleContent(sb.toString(), getModuleDisplayName());
74         }
75         return ctx;
76     }
77 }
78
Popular Tags