Salome HOME
Tiles is added
[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         /**
31          * Value of the title bar property. 
32          * It can be: study, knowledge.
33          */
34         private String _titleProperty;
35         
36         /**
37          * Value of the tool bar property. 
38          * It can be: none, standard, study, back.
39          */
40         private String _toolProperty;
41         
42         /**
43          * Value of the left menu property. 
44          * It can be: open, study, knowledge, scenario.
45          */
46         private String _leftMenuProperty;
47         
48         /**
49          * Property that indicates whether the current open study is editable or not.
50          * On the screen it looks like pen on the status icon, pop-up menu also can be called.
51          * It is necessary for correct building the title bar.
52          */
53         private String _editDisabledProperty = "false";
54
55         private static final long serialVersionUID = 6003880772275115923L;
56
57     private enum ToDo { cancel, upload };
58
59 //  ==============================================================================================================================
60 //  Action methods
61 //  ==============================================================================================================================
62
63     public String doInitialize () {
64 //  -----------------------------
65         setMenuProperty("study");
66         setToolProperty("none");
67         setLeftMenuProperty("open");
68                 initializationFullScreenContext(_menuProperty, _toolProperty, _leftMenuProperty);
69                 
70       return SUCCESS;
71     }
72
73     public String doUpload () {
74 //  -------------------------
75       setMenuProperty("study");
76       setTitleProperty("study");
77       setEditDisabledProperty("true");
78       initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
79       
80       if (action == ToDo.cancel) return "cancel";
81       try {
82         File    udir = getRepositoryService().getDownloadDirectory(getConnectedUser());
83         String  path = udir.getPath() + "/" + uploadFileName;
84         File    file = new File(path);
85
86         if (!udir.exists()) udir.mkdir();
87         if (file.exists())  file.delete();
88         Do.copy(upload, file);
89         LOG.info("Uploading \"" + uploadFileName + "\" " + uploadMimeType + " file.");
90         /*if (next == null || next.isEmpty()) {
91                 next = "import";
92         }*/
93         
94         return next;
95       }
96       catch (OutOfMemoryError error) {
97           
98         setMenuProperty("none");
99         setTitleProperty("study");
100         setEditDisabledProperty("true");
101         setToolProperty("none");
102         setLeftMenuProperty("study");
103         initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
104         
105         setErrorCode("message.error.outofmemory");
106                 
107         return "outofmemory";
108       }
109       catch (Exception error) {
110         LOG.error("Reason: ", error);
111         return ERROR;
112       }
113     }
114 //  ==============================================================================================================================
115 //  Getters and setters
116 //  ==============================================================================================================================
117
118     public String getIndex () {
119 //  -------------------------
120       return index;
121     }
122     public String getFileName () {
123 //  ----------------------------
124       return uploadFileName;
125     }
126     public String getNextAction () {
127 //  ------------------------------
128       return next;
129     }
130
131     public void setCancel (final boolean back) {
132 //  ------------------------------------
133       this.action = ToDo.cancel;
134     }
135     public void setDoIt (final boolean upload) {
136 //  --------------------------------
137       this.action = ToDo.upload;
138     }
139     public void setIndex (final String index) {
140 //  -----------------------------------
141       this.index = index;
142     }
143     public void setNextAction (final String next) {
144 //  ---------------------------------------
145       this.next = next;
146     }
147     public void setUpload (final File upload) {
148 //  -----------------------------------
149       this.upload = upload;
150     }
151     public void setUploadFileName (final String name) {
152 //  -------------------------------------------
153       this.uploadFileName = name;
154     }
155     public void setUploadContentType (final String mime) {
156 //  ----------------------------------------------
157       this.uploadMimeType = mime;
158     }
159
160         /**
161          * Get the repositoryService.
162          * @return the repositoryService
163          */
164         public RepositoryService getRepositoryService() {
165                 return _repositoryService;
166         }
167
168         /**
169          * Set the repositoryService.
170          * @param repositoryService the repositoryService to set
171          */
172         public void setRepositoryService(final RepositoryService repositoryService) {
173                 _repositoryService = repositoryService;
174         }
175         
176         /**
177          * Get the menuProperty.
178          * @return the menuProperty
179          */
180         public String getMenuProperty() {
181                 return _menuProperty;
182         }
183
184         /**
185          * Set the menuProperty.
186          * @param menuProperty the menuProperty to set
187          */
188         public void setMenuProperty(final String menuProperty) {
189                 this._menuProperty = menuProperty;
190         }
191         
192         /**
193          * Get the _titleProperty.
194          * @return the _titleProperty
195          */
196         public String getTitleProperty() {
197                 return _titleProperty;
198         }
199
200         /**
201          * Set the _titleProperty.
202          * @param titleProperty the titleProperty to set
203          */
204         public void setTitleProperty(final String titleProperty) {
205                 _titleProperty = titleProperty;
206         }
207
208         /**
209          * Get the _editDisabledProperty.
210          * @return the _editDisabledProperty
211          */
212         public String getEditDisabledProperty() {
213                 return _editDisabledProperty;
214         }
215
216         /**
217          * Set the _editDisabledProperty.
218          * @param _editDisabledProperty the _editDisabledProperty to set
219          */
220         public void setEditDisabledProperty(final String _editDisabledProperty) {
221                 this._editDisabledProperty = _editDisabledProperty;
222         }
223
224         /**
225          * Get the toolProperty.
226          * @return the toolProperty
227          */
228         public String getToolProperty() {
229                 return _toolProperty;
230         }
231
232         /**
233          * Set the toolProperty.
234          * @param toolProperty the toolProperty to set
235          */
236         public void setToolProperty(final String toolProperty) {
237                 _toolProperty = toolProperty;
238         }
239         
240         /**
241          * Get the leftMenuProperty.
242          * @return the leftMenuProperty
243          */
244         public String getLeftMenuProperty() {
245                 return _leftMenuProperty;
246         }
247
248         /**
249          * Set the leftMenuProperty.
250          * @param leftMenuProperty the leftMenuProperty to set
251          */
252         public void setLeftMenuProperty(final String leftMenuProperty) {
253                 _leftMenuProperty = leftMenuProperty;
254         }
255 }