KickJava   Java API By Example, From Geeks To Geeks.

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


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
14 import com.raptus.owxv3.*;
15 import com.raptus.owxv3.api.*;
16
17
18 /**
19  *
20  * <hr>
21  * <table width="100%" border="0">
22  * <tr>
23  * <td width="24%"><b>Filename</b></td><td width="76%">EAFileMgrListAction.java</td>
24  * </tr>
25  * <tr>
26  * <td width="24%"><b>Author</b></td><td width="76%">REEA</td>
27  * </tr>
28  * <tr>
29  * <td width="24%"><b>Date</b></td><td width="76%">25th of September 2001</td>
30  * </tr>
31  * </table>
32  * <hr>
33  * <table width="100%" border="0">
34  * <tr>
35  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
36  * </tr>
37  * </table>
38  * <hr>
39  * <table width="100%" border="0">
40  * <tr>
41  * <td>
42  * This class is called when displaying the "All file list" screen.
43  * </td>
44  * </tr>
45  * </table>
46  * <hr>
47  */

48 //public class EAFileMgrListAction extends VModuleAuthAction
49
public class EAFileMgrListAction extends VModuleRoleAction
50 {
51     /**
52      * Method overwritten from <code>VModuleAuthAction</code>
53      * This Action can be envoked to:
54      * <p>list the files currently uploaded
55      *<p> to delete a file
56      */

57
58     public String JavaDoc dispatchVModuleElement(HttpServletRequest JavaDoc request,
59                                          String JavaDoc element,
60                                          org.apache.struts.action.ActionForm form,
61                                          VModule vm,
62                                          com.raptus.owxv3.api.usermgr.User user)
63     {
64
65         if(element.compareToIgnoreCase(FileMgrConstants.ELEMENT_LIST) == 0)
66         {
67             EAFileMgrListBean listbean=(EAFileMgrListBean)form;
68             
69
70             /**
71              *Checking what kind of action should perform: list or delete
72              */

73
74             String JavaDoc action=request.getParameter(FileMgrConstants.HTTPGET_PARAM_ACTION);
75
76             /**
77              *The default action is list
78              */

79             if (action==null) action=FileMgrConstants.VMODULE_ACTION_LIST;
80             
81             /**
82              *Checking parameter filter
83              */

84             String JavaDoc filter=listbean.getFilter();
85             if(filter==null) filter="";
86
87             if(action.compareToIgnoreCase(FileMgrConstants.VMODULE_ACTION_DELETE)==0){
88                 /**
89                  *we are at action delete
90                  */

91
92                 int fileid=0;
93                 try
94                 {
95                     /**
96                      *We need the fileid of the file that should be deleted
97                      */

98                    if(request.getParameter(FileMgrConstants.HTTPGET_PARAM_FILEID)!=null)
99                        fileid=Integer.parseInt( request.getParameter(FileMgrConstants.HTTPGET_PARAM_FILEID) );
100
101                    if(fileid!=0){
102                        GlobalResources gres=new GlobalResources();
103                        /**
104                         *Creating a <code>FileMgrDeleteObject</code> that will delete
105                         *the file
106                         */

107                        FileMgrDeleteObject delobj=new FileMgrDeleteObject(vm,gres);
108                        if(! delobj.deleteFile(fileid) )
109                        {
110                            /**
111                             *the delete was not succesful, probabily usageCount>0
112                             */

113                            ActionErrors errors=new ActionErrors();
114                            errors.add( ActionErrors.GLOBAL_ERROR, new ActionError(FileMgrConstants.VMODULE_LIST_ERROR_INVALIDDELETE) );
115                            saveErrors(request,errors);
116                        }
117                    }
118                 }catch(NumberFormatException JavaDoc nfe)
119                 {
120                     LoggingManager.log("Wrong number supplied as fileid for deleting:"+nfe.getMessage(), this);
121                 }catch(SQLException JavaDoc sqle){
122                     LoggingManager.log("Could not delete file from database"+sqle.getMessage(), this);
123                 }catch(Exception JavaDoc e){
124                     LoggingManager.log("Could not delete file from disk"+e.getMessage(), this);
125                 }
126
127             }//end action==delete
128

129            
130             
131
132             /**
133              *Checking if the <code>EAFileMgrListBean</code> has a valid list of files,<br>
134              *if not we will provide the list using the <code>loadFiles()</code> of GlobalResources
135              */

136
137             //since the bean is in request there is no way that the list to be loaded
138

139             //if ( ! listbean.isListLoaded() ){
140
try{
141                    GlobalResources gres=new GlobalResources();
142                    listbean.setList(gres.loadFiles(filter));
143
144                 }catch(SQLException JavaDoc e){LoggingManager.log("Error while calling loadFiles() from GlobalResources"+e.getMessage(), this);}
145             //}//end if
146

147             return Constants.SECTION_EADMIN + Constants.DEFAULT_SPACER + element;
148         }//end bigif
149

150         return null;
151     }
152
153 }
154
155 // eof
156
Popular Tags