View Javadoc

1   package de.tivsource.page.admin.actions.maintenance.files;
2   
3   import java.io.File;
4   
5   import org.apache.logging.log4j.LogManager;
6   import org.apache.logging.log4j.Logger;
7   import org.apache.struts2.convention.annotation.Action;
8   import org.apache.struts2.convention.annotation.Actions;
9   import org.apache.struts2.convention.annotation.Result;
10  
11  import de.tivsource.page.admin.actions.EmptyAction;
12  
13  /**
14   * 
15   * @author Marc Michele
16   *
17   */
18  public class DeleteAction extends EmptyAction {
19  
20      /**
21       * Serial Version UID.
22       */
23      private static final long serialVersionUID = -2036755864820648448L;
24  
25      /**
26  	 * Statischer Logger der Klasse.
27  	 */
28      private static final Logger LOGGER = LogManager.getLogger(DeleteAction.class);
29  
30      private String file;
31  
32      public String getFile() {
33          return file;
34      }
35  
36      public void setFile(String file) {
37          this.file = file;
38      }
39  
40      @Override
41      @Actions({
42          @Action(
43          		value = "delete", 
44          		results = { 
45          				@Result(name = "success", type = "redirectAction", location = "index.html"),
46          				@Result(name = "input", type="tiles", location = "fileDeleteForm"),
47          				@Result(name = "error", type="tiles", location = "fileDeleteError")
48          				}
49          )
50      })
51      public String execute() throws Exception {
52      	LOGGER.info("execute() aufgerufen.");
53  
54      	if(file != null && file.length() > 0) {
55      	    String strPath = "/var/www/html/uploads/";
56      	    String deleteFile = strPath + file;
57      	    File delete = new File(deleteFile);
58      	    delete.delete();
59      	    return SUCCESS;
60      	}
61      	else {
62      		return ERROR;
63      	}
64      	
65      	
66      }// Ende execute()
67  	
68  }// Ende class