KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > vfs > actions > ShowUploadAction


1 package com.sslexplorer.vfs.actions;
2
3 import javax.servlet.http.HttpServletRequest JavaDoc;
4 import javax.servlet.http.HttpServletResponse JavaDoc;
5
6 import org.apache.struts.action.ActionForm;
7 import org.apache.struts.action.ActionForward;
8 import org.apache.struts.action.ActionMapping;
9
10 import com.sslexplorer.core.CoreUtil;
11 import com.sslexplorer.core.actions.AuthenticatedDispatchAction;
12 import com.sslexplorer.security.Constants;
13 import com.sslexplorer.security.SessionInfo;
14 import com.sslexplorer.vfs.UploadDetails;
15 import com.sslexplorer.vfs.forms.ShowUploadForm;
16
17 /**
18  * <p>
19  * This is the action which performes the upload of a given file to the location
20  * in the {@link com.sslexplorer.vfs.UploadDetails}.
21  *
22  * @author James D Robinson
23  *
24  * @author James D Robinson <a HREF="mailto:
25  * james@3sp.com">&lt;james@3sp.com&gt;</a>
26  */

27 public class ShowUploadAction extends AuthenticatedDispatchAction {
28
29     /*
30      * (non-Javadoc)
31      *
32      * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping,
33      * org.apache.struts.action.ActionForm,
34      * javax.servlet.http.HttpServletRequest,
35      * javax.servlet.http.HttpServletResponse)
36      */

37     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
38         return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT | SessionInfo.USER_CONSOLE_CONTEXT;
39     }
40
41     /* (non-Javadoc)
42      * @see org.apache.struts.actions.DispatchAction#unspecified(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
43      */

44     public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request,
45                                      HttpServletResponse JavaDoc response) throws Exception JavaDoc {
46         return upload(mapping, form, request, response);
47     }
48
49     /**
50      * Display the upload page.
51      *
52      * @param mapping mapping
53      * @param form form
54      * @param request request
55      * @param response response
56      * @return forward
57      * @throws Exception on any error
58      */

59     public ActionForward upload(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
60                     throws Exception JavaDoc {
61         Integer JavaDoc i = (Integer JavaDoc) request.getAttribute(Constants.REQ_ATTR_UPLOAD_DETAILS);
62         if (i == null) {
63             throw new Exception JavaDoc("No upload id.");
64         }
65         UploadDetails upload = CoreUtil.getUpload(request.getSession(), i.intValue());
66         if (upload == null) {
67             throw new Exception JavaDoc("No file upload details configured for upload id " + i + ".");
68         }
69         ((ShowUploadForm) form).initialise(i.intValue(), upload);
70         CoreUtil.addRequiredFieldMessage(this, request);
71         return mapping.findForward("display");
72     }
73
74     /**
75      * Uploading is complete. Clean up.
76      *
77      * @param mapping mapping
78      * @param form form
79      * @param request request
80      * @param response response
81      * @return forward
82      * @throws Exception on any error
83      */

84     public ActionForward uploadDone(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
85                     throws Exception JavaDoc {
86         UploadDetails upload = CoreUtil.removeUpload(request.getSession(), ((ShowUploadForm) form).getUploadId());
87         return upload.getDoneForward();
88     }
89
90     /**
91      * Uploading is complete. Clean up.
92      *
93      * @param mapping mapping
94      * @param form form
95      * @param request request
96      * @param response response
97      * @return forward
98      * @throws Exception on any error
99      */

100     public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
101                     throws Exception JavaDoc {
102         UploadDetails upload = CoreUtil.removeUpload(request.getSession(), ((ShowUploadForm) form).getUploadId());
103         return upload.getCancelForward();
104     }
105
106 }
107
Popular Tags