KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > communicator > applications > webtalk > controller > DeleteFileAction


1 /*
2  * DeleteFileAction.java
3  *
4  * Created on June 13, 2003, 8:57 AM
5  */

6
7 package com.quikj.application.communicator.applications.webtalk.controller;
8
9 import java.io.*;
10 import java.sql.*;
11 import java.util.*;
12 import javax.servlet.*;
13 import javax.servlet.http.*;
14 import org.apache.struts.action.*;
15 import com.quikj.application.communicator.admin.model.*;
16 import com.quikj.application.communicator.admin.controller.*;
17
18 /**
19  *
20  * @author Vinod Batra
21  */

22 public final class DeleteFileAction extends Action{
23     
24     /** Creates a new instance of DeleteFileAction */
25     public DeleteFileAction() {
26     }
27     public ActionForward execute(ActionMapping mapping,
28     ActionForm form,
29     HttpServletRequest request,
30     HttpServletResponse response)
31     throws IOException, ServletException {
32         
33         Locale locale = getLocale(request);
34         ActionErrors errors = new ActionErrors();
35         
36         // first check if the user has a connection
37
Connection c = (Connection)request.getSession().getAttribute("connection");
38         if (c == null) {
39             errors.add(ActionErrors.GLOBAL_ERROR,
40             new ActionError("error.not.logged.in"));
41             saveErrors(request, errors);
42             return mapping.findForward("logon");
43         }
44         
45         AccountElement element = (AccountElement)request.getSession().getAttribute("userInfo");
46         if ((element.isAdminLevel() == false) && (element.isCustomerLevel() == false))
47         {
48             errors.add(ActionErrors.GLOBAL_ERROR,
49             new ActionError("error.insufficient.privilege"));
50             saveErrors(request, errors);
51             
52             return mapping.findForward("main_menu");
53         }
54         
55         DeleteFileForm deleteForm = (DeleteFileForm) form;
56         
57         String JavaDoc name = deleteForm.getFileName();
58
59         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(request.getSession().getServletContext().getRealPath(""));
60         
61         buffer.append(File.separator);
62         buffer.append(UploadFileAction.APP_PATH);
63         
64         buffer.append(File.separator);
65         buffer.append(UploadFileAction.DATA_PATH);
66         
67         buffer.append(File.separator);
68         buffer.append(UploadFileAction.HTML_PATH);
69         
70         buffer.append(File.separator);
71         buffer.append(element.getDomain());
72         
73         File directory = new File(buffer.toString());
74         
75         File file = new File(directory,name);
76         if (!file.exists()) {
77             errors.add("fileName", new ActionError("file.no.exists"));
78             saveErrors(request, errors);
79             return (new ActionForward(mapping.getInput()));
80             
81         }
82         
83         if (!file.canWrite()) {
84             errors.add("fileName", new ActionError("file.no.permission.write"));
85             saveErrors(request, errors);
86             return (new ActionForward(mapping.getInput()));
87         }
88         
89         boolean result = file.delete();
90         if (result == false) {
91             errors.add("fileName", new ActionError("file.no.delete"));
92             saveErrors(request, errors);
93             return (new ActionForward(mapping.getInput()));
94             
95         }
96         
97         String JavaDoc fileSuccess = "deletion";
98         request.getSession().setAttribute("fileSuccess", fileSuccess);
99         
100         WebTalkRelatedTasks menu = new WebTalkRelatedTasks();
101         menu.addLink(new LinkAttribute("Upload File", "upload_file_input"));
102         menu.addLink(new LinkAttribute("Rename File", "rename_file_input"));
103         return (mapping.findForward("file_success"));
104         
105     }
106 }
107
Popular Tags