KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > modules > filemgr > EAFileMgrUploadAction


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5
6 package com.raptus.owxv3.modules.filemgr;
7
8 import java.sql.SQLException JavaDoc;
9
10 import javax.servlet.http.HttpServletRequest JavaDoc;
11
12 import org.apache.struts.action.*;
13 import org.apache.struts.upload.FormFile;
14
15 import com.raptus.owxv3.*;
16 import com.raptus.owxv3.api.*;
17
18
19 /**
20  *
21  * <hr>
22  * <table width="100%" border="0">
23  * <tr>
24  * <td width="24%"><b>Filename</b></td><td width="76%">EAFileMgrUploadAction.java</td>
25  * </tr>
26  * <tr>
27  * <td width="24%"><b>Author</b></td><td width="76%">REEA</td>
28  * </tr>
29  * <tr>
30  * <td width="24%"><b>Date</b></td><td width="76%">25th of September 2001</td>
31  * </tr>
32  * </table>
33  * <hr>
34  * <table width="100%" border="0">
35  * <tr>
36  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
37  * </tr>
38  * </table>
39  * <hr>
40  * </table>
41  * <hr>
42  * <table width="100%" border="0">
43  * <tr>
44  * <td>
45  * This class is called when displaying the "File upload" screen
46  * </td>
47  * </tr>
48  * </table>
49  * <hr>
50  */

51 //public class EAFileMgrUploadAction extends VModuleAuthAction
52
public class EAFileMgrUploadAction extends VModuleRoleAction
53 {
54     /**
55      *
56      * Method overwritten from <code>VModuleAuthAction</code>
57      * This Action can be envoked to:
58      * <p>To display the upload screen
59      *<p> To save the file provided with upload
60      */

61
62     public String JavaDoc dispatchVModuleElement(HttpServletRequest JavaDoc request,
63                                          String JavaDoc element,
64                                          org.apache.struts.action.ActionForm form,
65                                          VModule vm,
66                                          com.raptus.owxv3.api.usermgr.User user)
67     {
68
69         if(element.compareToIgnoreCase(FileMgrConstants.ELEMENT_UPLOAD) == 0)
70         {
71             EAFileMgrUploadBean uploadbean=(EAFileMgrUploadBean)form;
72             ActionErrors acterrors=uploadbean.validate(request);
73
74             if(acterrors!=null)
75             {
76                 if(acterrors.size()>0)
77                 {
78                     saveErrors(request,acterrors);
79                     LoggingManager.log("Upload is not accepted due to errors. " + acterrors, this);
80                     return Constants.SECTION_EADMIN + Constants.DEFAULT_SPACER + element;
81                 }
82             }
83             
84             /**
85              *Checking what kind of action should perform
86              */

87             String JavaDoc action="";
88             if(request.getParameter(FileMgrConstants.HTTPGET_PARAM_ACTION)!=null)
89                 action=request.getParameter(FileMgrConstants.HTTPGET_PARAM_ACTION);
90
91             if(action.compareToIgnoreCase(FileMgrConstants.VMODULE_ACTION_SAVE)==0)
92             {
93                 /**
94                  *recieving new file for uploading
95                  */

96                 String JavaDoc fname = "unknown";
97                 FormFile ff = uploadbean.getUploadfile();
98                 if(ff != null)
99                     fname = ff.getFileName();
100
101                 /**
102                  *creating a FileMgrUploadObject that will save the file if we have enough disk space.
103                  */

104                 FileMgrUploadObject filemanager=new FileMgrUploadObject(vm,uploadbean);
105                 try
106                 {
107                     if( filemanager.isEnoughFreeSpace() )
108                     {
109                         /**
110                          *the file can be saved, it is enough disk space
111                          */

112                         filemanager.saveToDisk();
113                         filemanager.saveAsGlobalResource();
114                         uploadbean.reset();
115                         
116                         LoggingManager.log("Sucessfully uploaded file " + fname, this);
117                     }
118                     else
119                     {
120                         /**
121                          *the file CAN NOT be saved due to the lack of space configured.
122                          *We create an ActionErrors object to inform the user that there is no more disk space
123                          *in his acount.
124                          */

125
126                         ActionErrors errors=new ActionErrors();
127                         errors.add(ActionErrors.GLOBAL_ERROR,new ActionError(FileMgrConstants.VMODULE_UPLOAD_ERROR_NODISKSPACE));
128                         saveErrors(request,errors);
129                         LoggingManager.log("Not enough disk space to save the uploaded file! " + fname, this);
130                     }
131                 } catch(Exception JavaDoc e) {
132                     LoggingManager.log("Error while saving file " + fname + " Message: " + e, this);
133                 }
134             }
135
136             /*
137              *Allways reload the list of categories
138              */

139             try
140              {
141                  GlobalResources gres=new GlobalResources();
142                  AllFileSelector fileselector=new AllFileSelector(gres);
143                  uploadbean.setFileSelector(fileselector);
144              }
145              catch(SQLException JavaDoc e)
146              {
147                  LoggingManager.log("Error while instantiating the FileSelector object", this);
148              }
149
150             return Constants.SECTION_EADMIN + Constants.DEFAULT_SPACER + element;
151         }//end big if
152

153         return null;
154     }
155
156 }
157
158 // eof
159
Popular Tags