1 5 6 package com.raptus.owxv3.modules.filemgr; 7 8 import java.sql.SQLException ; 9 10 import javax.servlet.http.HttpServletRequest ; 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 51 public class EAFileMgrUploadAction extends VModuleRoleAction 53 { 54 61 62 public String dispatchVModuleElement(HttpServletRequest request, 63 String 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 87 String 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 96 String fname = "unknown"; 97 FormFile ff = uploadbean.getUploadfile(); 98 if(ff != null) 99 fname = ff.getFileName(); 100 101 104 FileMgrUploadObject filemanager=new FileMgrUploadObject(vm,uploadbean); 105 try 106 { 107 if( filemanager.isEnoughFreeSpace() ) 108 { 109 112 filemanager.saveToDisk(); 113 filemanager.saveAsGlobalResource(); 114 uploadbean.reset(); 115 116 LoggingManager.log("Sucessfully uploaded file " + fname, this); 117 } 118 else 119 { 120 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 e) { 132 LoggingManager.log("Error while saving file " + fname + " Message: " + e, this); 133 } 134 } 135 136 139 try 140 { 141 GlobalResources gres=new GlobalResources(); 142 AllFileSelector fileselector=new AllFileSelector(gres); 143 uploadbean.setFileSelector(fileselector); 144 } 145 catch(SQLException e) 146 { 147 LoggingManager.log("Error while instantiating the FileSelector object", this); 148 } 149 150 return Constants.SECTION_EADMIN + Constants.DEFAULT_SPACER + element; 151 } 153 return null; 154 } 155 156 } 157 158 | Popular Tags |