KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > contineo > actions > documan > util > DownloadAction


1 /*
2  * DownloadAction.java
3  *
4  * Created on 29. Oktober 2003, 00:05
5  */

6
7 package org.contineo.actions.documan.util;
8
9 import javax.servlet.http.HttpServletRequest JavaDoc;
10 import javax.servlet.http.HttpServletResponse JavaDoc;
11 import javax.servlet.http.HttpSession JavaDoc;
12
13 import org.apache.log4j.Level;
14 import org.apache.log4j.Logger;
15 import org.apache.struts.action.Action;
16 import org.apache.struts.action.ActionForm;
17 import org.apache.struts.action.ActionForward;
18 import org.apache.struts.action.ActionMapping;
19 import org.contineo.admin.dao.MenuDAO;
20 import org.contineo.core.LoggingManager;
21 import org.contineo.core.SessionManagement;
22
23 /**
24  * Sends the requested document to the client
25  * @author Michael Scholz
26  * @author Sebastian Stein
27  */

28 public class DownloadAction extends Action {
29
30     /**
31      * @uml.property name="logger"
32      * @uml.associationEnd
33      */

34     private Logger logger;
35
36     
37     /** Creates a new instance of DownloadAction */
38     public DownloadAction() {
39         logger = LoggingManager.getLogger(this.getClass());
40     }
41
42     /** sends the requested document to the client */
43     public ActionForward execute(ActionMapping mapping,
44                     ActionForm form, HttpServletRequest JavaDoc request,
45                     HttpServletResponse JavaDoc response) {
46         ActionForward actionForward = new ActionForward();
47         HttpSession JavaDoc session = request.getSession();
48         if (SessionManagement.isValid(session)) {
49             try {
50                 // check that we have all the necessary parameters
51
String JavaDoc menuIdStr = request.getParameter("menuid");
52                 if (menuIdStr == null || menuIdStr.equalsIgnoreCase(""))
53                     throw new Exception JavaDoc("menuid not set in session");
54                 String JavaDoc username = (String JavaDoc)session.getAttribute("authuser");
55                 if (username == null || username.equalsIgnoreCase(""))
56                     throw new Exception JavaDoc("username not set in session");
57
58                 // if we have access to the document, return it
59
MenuDAO mdao = new MenuDAO();
60                 int menuIdInt = Integer.parseInt(menuIdStr);
61                 if (mdao.isReadEnable(menuIdInt, username)) {
62                     DownloadDocUtil.downloadDocument(response, menuIdStr, null);
63
64                     // add the file to the recent files of the user
65
DownloadDocUtil.addToRecentFiles(username, menuIdInt);
66                     
67                     // we already send the document to the client, so no forward possible
68
actionForward = null;
69                 } else {
70                     actionForward = mapping.findForward("noaccess");
71                 }
72             } catch (Exception JavaDoc e) {
73                 if (logger.isEnabledFor(Level.ERROR))
74                     logger.error(e.getMessage());
75                 actionForward = mapping.findForward("error");
76             }
77         } else
78             actionForward = mapping.findForward("invalid");
79         
80         return actionForward;
81     }
82 }
Popular Tags