Salome HOME
<jsp:param ... > parameters are removed from the title bar
[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          * Property that indicates whether the current open study is editable or not.
38          * On the screen it looks like pen on the status icon, pop-up menu also can be called.
39          * It is necessary for correct building the title bar.
40          */
41         private String _editDisabledProperty = "false";
42
43         private static final long serialVersionUID = 6003880772275115923L;
44
45     private enum ToDo { cancel, upload };
46
47 //  ==============================================================================================================================
48 //  Action methods
49 //  ==============================================================================================================================
50
51     public String doInitialize () {
52 //  -----------------------------
53         setMenuProperty("study");
54                 initializationScreenContext(_menuProperty);
55                 
56       return SUCCESS;
57     }
58
59     public String doUpload () {
60 //  -------------------------
61       setMenuProperty("study");
62       setTitleProperty("study");
63       setEditDisabledProperty("true");
64       initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
65       
66       if (action == ToDo.cancel) return "cancel";
67       try {
68         File    udir = getRepositoryService().getDownloadDirectory(getConnectedUser());
69         String  path = udir.getPath() + "/" + uploadFileName;
70         File    file = new File(path);
71
72         if (!udir.exists()) udir.mkdir();
73         if (file.exists())  file.delete();
74         Do.copy(upload, file);
75         logger.info("Uploading \"" + uploadFileName + "\" " + uploadMimeType + " file.");
76         /*if (next == null || next.isEmpty()) {
77                 next = "import";
78         }*/
79         
80         logger.info("MKA next = " + next);
81         return next;
82       }
83       catch (OutOfMemoryError error) {
84           
85         setMenuProperty("none");
86         setTitleProperty("study");
87         setEditDisabledProperty("true");
88         initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
89                 
90         return "outofmemory";
91       }
92       catch (Exception error) {
93         logger.error("Reason: ", error);
94         return ERROR;
95       }
96     }
97 //  ==============================================================================================================================
98 //  Getters and setters
99 //  ==============================================================================================================================
100
101     public String getIndex () {
102 //  -------------------------
103       return index;
104     }
105     public String getFileName () {
106 //  ----------------------------
107       return uploadFileName;
108     }
109     public String getNextAction () {
110 //  ------------------------------
111       return next;
112     }
113
114     public void setCancel (boolean back) {
115 //  ------------------------------------
116       this.action = ToDo.cancel;
117     }
118     public void setDoIt (boolean upload) {
119 //  --------------------------------
120       this.action = ToDo.upload;
121     }
122     public void setIndex (String index) {
123 //  -----------------------------------
124       this.index = index;
125     }
126     public void setNextAction (String next) {
127 //  ---------------------------------------
128       this.next = next;
129     }
130     public void setUpload (File upload) {
131 //  -----------------------------------
132       this.upload = upload;
133     }
134     public void setUploadFileName (String name) {
135 //  -------------------------------------------
136       this.uploadFileName = name;
137     }
138     public void setUploadContentType (String mime) {
139 //  ----------------------------------------------
140       this.uploadMimeType = mime;
141     }
142
143         /**
144          * Get the repositoryService.
145          * @return the repositoryService
146          */
147         public RepositoryService getRepositoryService() {
148                 return _repositoryService;
149         }
150
151         /**
152          * Set the repositoryService.
153          * @param repositoryService the repositoryService to set
154          */
155         public void setRepositoryService(RepositoryService repositoryService) {
156                 _repositoryService = repositoryService;
157         }
158         
159         /**
160          * Get the menuProperty.
161          * @return the menuProperty
162          */
163         public String getMenuProperty() {
164                 return _menuProperty;
165         }
166
167         /**
168          * Set the menuProperty.
169          * @param menuProperty the menuProperty to set
170          */
171         public void setMenuProperty(String menuProperty) {
172                 this._menuProperty = menuProperty;
173         }
174         
175         /**
176          * Get the _titleProperty.
177          * @return the _titleProperty
178          */
179         public String getTitleProperty() {
180                 return _titleProperty;
181         }
182
183         /**
184          * Set the _titleProperty.
185          * @param _titleProperty the titleProperty to set
186          */
187         public void setTitleProperty(String titleProperty) {
188                 _titleProperty = titleProperty;
189         }
190
191         /**
192          * Get the _editDisabledProperty.
193          * @return the _editDisabledProperty
194          */
195         public String getEditDisabledProperty() {
196                 return _editDisabledProperty;
197         }
198
199         /**
200          * Set the _editDisabledProperty.
201          * @param _editDisabledProperty the _editDisabledProperty to set
202          */
203         public void setEditDisabledProperty(String _editDisabledProperty) {
204                 this._editDisabledProperty = _editDisabledProperty;
205         }
206
207         
208 }