Salome HOME
Refactoring of Database, replacing SQL by DAOs calls. Methods for search by criteria...
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / UploadAction.java
1 package org.splat.simer;
2
3 import java.io.File;
4
5 import org.splat.kernel.Do;
6 import org.splat.service.technical.RepositoryService;
7 import org.splat.dal.dao.som.Database;
8
9
10 public class UploadAction extends Action {
11
12         private File    upload         = null;
13         private String  uploadMimeType = null;
14     private String  uploadFileName = null;
15
16     private ToDo    action;                  // Action to do
17     private String  next           = null;   // Action to which the uploaded file is passed
18         private String  index          = null;   // Depending on the next action, document index to which the action applies
19         /**
20          * Injected repository service.
21          */
22         private RepositoryService _repositoryService;
23
24         private static final long serialVersionUID = 6003880772275115923L;
25
26     private enum ToDo { cancel, upload };
27
28 //  ==============================================================================================================================
29 //  Action methods
30 //  ==============================================================================================================================
31
32     public String doInitialize () {
33 //  -----------------------------
34       return SUCCESS;
35     }
36
37     public String doUpload () {
38 //  -------------------------
39       if (action == ToDo.cancel) return "cancel";
40       try {
41         File    udir = getRepositoryService().getDownloadDirectory(getConnectedUser());
42         String  path = udir.getPath() + "/" + uploadFileName;
43         File    file = new File(path);
44
45         if (!udir.exists()) udir.mkdir();
46         if (file.exists())  file.delete();
47         Do.copy(upload, file);
48         logger.info("Uploading \"" + uploadFileName + "\" " + uploadMimeType + " file.");
49         return next;
50       }
51       catch (OutOfMemoryError error) {
52         return "outofmemory";
53       }
54       catch (Exception error) {
55         logger.error("Reason: ", error);
56         return ERROR;
57       }
58     }
59 //  ==============================================================================================================================
60 //  Getters and setters
61 //  ==============================================================================================================================
62
63     public String getIndex () {
64 //  -------------------------
65       return index;
66     }
67     public String getFileName () {
68 //  ----------------------------
69       return uploadFileName;
70     }
71     public String getNextAction () {
72 //  ------------------------------
73       return next;
74     }
75
76     public void setCancel (boolean back) {
77 //  ------------------------------------
78       this.action = ToDo.cancel;
79     }
80     public void setDoIt (boolean upload) {
81 //  --------------------------------
82       this.action = ToDo.upload;
83     }
84     public void setIndex (String index) {
85 //  -----------------------------------
86       this.index = index;
87     }
88     public void setNextAction (String next) {
89 //  ---------------------------------------
90       this.next = next;
91     }
92     public void setUpload (File upload) {
93 //  -----------------------------------
94       this.upload = upload;
95     }
96     public void setUploadFileName (String name) {
97 //  -------------------------------------------
98       this.uploadFileName = name;
99     }
100     public void setUploadContentType (String mime) {
101 //  ----------------------------------------------
102       this.uploadMimeType = mime;
103     }
104
105         /**
106          * Get the repositoryService.
107          * @return the repositoryService
108          */
109         public RepositoryService getRepositoryService() {
110                 return _repositoryService;
111         }
112
113         /**
114          * Set the repositoryService.
115          * @param repositoryService the repositoryService to set
116          */
117         public void setRepositoryService(RepositoryService repositoryService) {
118                 _repositoryService = repositoryService;
119         }
120 }