1 package org.splat.simer;
5 import org.splat.kernel.Do;
6 import org.splat.dal.dao.som.Database;
9 public class UploadAction extends Action {
11 private File upload = null;
12 private String uploadMimeType = null;
13 private String uploadFileName = null;
15 private ToDo action; // Action to do
16 private String next = null; // Action to which the uploaded file is passed
17 private String index = null; // Depending on the next action, document index to which the action applies
19 private static final long serialVersionUID = 6003880772275115923L;
21 private enum ToDo { cancel, upload };
23 // ==============================================================================================================================
25 // ==============================================================================================================================
27 public String doInitialize () {
28 // -----------------------------
32 public String doUpload () {
33 // -------------------------
34 if (action == ToDo.cancel) return "cancel";
36 File udir = Database.getDownloadDirectory(getConnectedUser());
37 String path = udir.getPath() + "/" + uploadFileName;
38 File file = new File(path);
40 if (!udir.exists()) udir.mkdir();
41 if (file.exists()) file.delete();
42 Do.copy(upload, file);
43 logger.info("Uploading \"" + uploadFileName + "\" " + uploadMimeType + " file.");
46 catch (OutOfMemoryError error) {
49 catch (Exception error) {
50 logger.error("Reason: ", error);
54 // ==============================================================================================================================
55 // Getters and setters
56 // ==============================================================================================================================
58 public String getIndex () {
59 // -------------------------
62 public String getFileName () {
63 // ----------------------------
64 return uploadFileName;
66 public String getNextAction () {
67 // ------------------------------
71 public void setCancel (boolean back) {
72 // ------------------------------------
73 this.action = ToDo.cancel;
75 public void setDoIt (boolean upload) {
76 // --------------------------------
77 this.action = ToDo.upload;
79 public void setIndex (String index) {
80 // -----------------------------------
83 public void setNextAction (String next) {
84 // ---------------------------------------
87 public void setUpload (File upload) {
88 // -----------------------------------
91 public void setUploadFileName (String name) {
92 // -------------------------------------------
93 this.uploadFileName = name;
95 public void setUploadContentType (String mime) {
96 // ----------------------------------------------
97 this.uploadMimeType = mime;