]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/UploadAction.java
Salome HOME
Menus are improved
[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         /**
25          * Value of the menu property. 
26          * It can be: none, create, open, study, knowledge, sysadmin, help.
27          */
28         private String _menuProperty;
29
30         private static final long serialVersionUID = 6003880772275115923L;
31
32     private enum ToDo { cancel, upload };
33
34 //  ==============================================================================================================================
35 //  Action methods
36 //  ==============================================================================================================================
37
38     public String doInitialize () {
39 //  -----------------------------
40         setMenuProperty("study");
41                 initializationScreenContext(_menuProperty);
42                 
43       return SUCCESS;
44     }
45
46     public String doUpload () {
47 //  -------------------------
48       setMenuProperty("study");
49       initializationScreenContext(_menuProperty);
50       
51       if (action == ToDo.cancel) return "cancel";
52       try {
53         File    udir = getRepositoryService().getDownloadDirectory(getConnectedUser());
54         String  path = udir.getPath() + "/" + uploadFileName;
55         File    file = new File(path);
56
57         if (!udir.exists()) udir.mkdir();
58         if (file.exists())  file.delete();
59         Do.copy(upload, file);
60         logger.info("Uploading \"" + uploadFileName + "\" " + uploadMimeType + " file.");
61         /*if (next == null || next.isEmpty()) {
62                 next = "import";
63         }*/
64         
65         logger.info("MKA next = " + next);
66         return next;
67       }
68       catch (OutOfMemoryError error) {
69           
70         setMenuProperty("none");
71                 initializationScreenContext(_menuProperty);
72                 
73         return "outofmemory";
74       }
75       catch (Exception error) {
76         logger.error("Reason: ", error);
77         return ERROR;
78       }
79     }
80 //  ==============================================================================================================================
81 //  Getters and setters
82 //  ==============================================================================================================================
83
84     public String getIndex () {
85 //  -------------------------
86       return index;
87     }
88     public String getFileName () {
89 //  ----------------------------
90       return uploadFileName;
91     }
92     public String getNextAction () {
93 //  ------------------------------
94       return next;
95     }
96
97     public void setCancel (boolean back) {
98 //  ------------------------------------
99       this.action = ToDo.cancel;
100     }
101     public void setDoIt (boolean upload) {
102 //  --------------------------------
103       this.action = ToDo.upload;
104     }
105     public void setIndex (String index) {
106 //  -----------------------------------
107       this.index = index;
108     }
109     public void setNextAction (String next) {
110 //  ---------------------------------------
111       this.next = next;
112     }
113     public void setUpload (File upload) {
114 //  -----------------------------------
115       this.upload = upload;
116     }
117     public void setUploadFileName (String name) {
118 //  -------------------------------------------
119       this.uploadFileName = name;
120     }
121     public void setUploadContentType (String mime) {
122 //  ----------------------------------------------
123       this.uploadMimeType = mime;
124     }
125
126         /**
127          * Get the repositoryService.
128          * @return the repositoryService
129          */
130         public RepositoryService getRepositoryService() {
131                 return _repositoryService;
132         }
133
134         /**
135          * Set the repositoryService.
136          * @param repositoryService the repositoryService to set
137          */
138         public void setRepositoryService(RepositoryService repositoryService) {
139                 _repositoryService = repositoryService;
140         }
141         
142         /**
143          * Get the menuProperty.
144          * @return the menuProperty
145          */
146         public String getMenuProperty() {
147                 return _menuProperty;
148         }
149
150         /**
151          * Set the menuProperty.
152          * @param menuProperty the menuProperty to set
153          */
154         public void setMenuProperty(String menuProperty) {
155                 this._menuProperty = menuProperty;
156         }
157 }