1 package org.splat.simer;
5 import org.splat.kernel.Do;
6 import org.splat.service.technical.RepositoryService;
7 import org.splat.wapp.Constants;
10 * Action for uploading a file into the user's download directory.
12 public class UploadAction extends Action {
15 * Serialization version id.
17 private static final long serialVersionUID = 6003880772275115923L;
22 private transient File _upload = null;
24 * Mime type of the uploaded file.
26 private transient String _uploadMimeType = null;
30 private transient String _uploadFileName = null;
35 private transient ToDo _action;
37 * Action to which the uploaded file is passed.
39 private String _nextAction = null;
41 * Depending on the next action, document index to which the action applies.
43 private String _index = null;
45 * Injected repository service.
47 private RepositoryService _repositoryService;
50 * Value of the menu property. It can be: none, create, open, study, knowledge, sysadmin, help.
52 private String _menuProperty;
55 * Value of the title bar property. It can be: study, knowledge.
57 private String _titleProperty;
60 * Value of the tool bar property. It can be: none, standard, study, back.
62 private String _toolProperty;
65 * Value of the left menu property. It can be: open, study, knowledge, scenario.
67 private String _leftMenuProperty;
70 * Property that indicates whether the current open study is editable or not. On the screen it looks like pen on the status icon, pop-up
71 * menu also can be called. It is necessary for correct building the title bar.
73 private String _editDisabledProperty = "false";
76 * Action modes enumeration.
80 * Cancel the operation.
89 // ==============================================================================================================================
91 // ==============================================================================================================================
94 * Prepare form for the upload action.
98 public String doInitialize() {
99 setMenuProperty(Constants.STUDY_MENU);
100 setToolProperty(Constants.NONE);
101 setLeftMenuProperty("open");
102 setTitleProperty(Constants.STUDY_MENU);
103 setEditDisabledProperty("true");
104 initializationFullScreenContext(_menuProperty, _titleProperty,
105 _editDisabledProperty, _toolProperty, _leftMenuProperty);
111 * Store uploaded file into the user's download directory.
113 * @return next action if ok, "cancel" if the operation is cancelled by user, "outofmemory" if there is no enough memory to upload the
114 * file or ERROR otherwise
116 public String doUpload() {
117 setMenuProperty(Constants.STUDY_MENU);
118 setTitleProperty(Constants.STUDY_MENU);
119 setEditDisabledProperty("true");
120 initializationScreenContext(_menuProperty, _titleProperty,
121 _editDisabledProperty);
124 if (_action == ToDo.cancel) {
128 File udir = getRepositoryService().getDownloadDirectory(
130 String path = udir.getPath() + "/" + _uploadFileName;
131 File file = new File(path);
133 if (!udir.exists()) {
139 Do.copy(_upload, file);
140 LOG.info("Uploading \"" + _uploadFileName + "\" "
141 + _uploadMimeType + " file.");
143 * if (next == null || next.isEmpty()) { next = "import"; }
147 } catch (OutOfMemoryError error) {
149 setMenuProperty(Constants.NONE);
150 setTitleProperty(Constants.STUDY_MENU);
151 setEditDisabledProperty("true");
152 setToolProperty(Constants.NONE);
153 setLeftMenuProperty(Constants.STUDY_MENU);
154 initializationFullScreenContext(_menuProperty, _titleProperty,
155 _editDisabledProperty, _toolProperty, _leftMenuProperty);
157 setErrorCode("message.error.outofmemory");
160 } catch (Exception error) {
161 LOG.error("Reason: ", error);
168 // ==============================================================================================================================
169 // Getters and setters
170 // ==============================================================================================================================
173 * Get the document index to which the action applies.
175 * @return the document index to which the action applies
177 public String getIndex() {
182 * Get the uploaded file name.
184 * @return the uploaded file name
186 public String getFileName() {
187 return _uploadFileName;
191 * Get the action to which the uploaded file is passed.
193 * @return the action to which the uploaded file is passed.
195 public String getNextAction() {
200 * Cancel the uploading.
204 public void setCancel(final boolean back) {
205 this._action = ToDo.cancel;
209 * Set the flag to perform uploading.
213 public void setDoIt(final boolean upload) {
214 this._action = ToDo.upload;
218 * Set the document index to which the action applies.
221 * the document index to which the action applies.
223 public void setIndex(final String index) {
228 * Set the action to which the uploaded file is passed.
231 * the action to which the uploaded file is passed.
233 public void setNextAction(final String next) {
234 this._nextAction = next;
238 * Set the uploaded file.
243 public void setUpload(final File upload) {
244 this._upload = upload;
248 * Set the uploaded file name.
251 * the uploaded file name
253 public void setUploadFileName(final String name) {
254 this._uploadFileName = name;
258 * Set the mime type of the uploaded file.
261 * the mime type of the uploaded file
263 public void setUploadContentType(final String mime) {
264 this._uploadMimeType = mime;
268 * Get the repositoryService.
270 * @return the repositoryService
272 public RepositoryService getRepositoryService() {
273 return _repositoryService;
277 * Set the repositoryService.
279 * @param repositoryService
280 * the repositoryService to set
282 public void setRepositoryService(final RepositoryService repositoryService) {
283 _repositoryService = repositoryService;
287 * Get the menuProperty.
289 * @return the menuProperty
291 public String getMenuProperty() {
292 return _menuProperty;
296 * Set the menuProperty.
298 * @param menuProperty
299 * the menuProperty to set
301 public void setMenuProperty(final String menuProperty) {
302 this._menuProperty = menuProperty;
306 * Get the _titleProperty.
308 * @return the _titleProperty
310 public String getTitleProperty() {
311 return _titleProperty;
315 * Set the _titleProperty.
317 * @param titleProperty
318 * the titleProperty to set
320 public void setTitleProperty(final String titleProperty) {
321 _titleProperty = titleProperty;
325 * Get the _editDisabledProperty.
327 * @return the _editDisabledProperty
329 public String getEditDisabledProperty() {
330 return _editDisabledProperty;
334 * Set the editDisabledProperty.
336 * @param editDisabledProperty
337 * the editDisabledProperty to set
339 public void setEditDisabledProperty(final String editDisabledProperty) {
340 this._editDisabledProperty = editDisabledProperty;
344 * Get the toolProperty.
346 * @return the toolProperty
348 public String getToolProperty() {
349 return _toolProperty;
353 * Set the toolProperty.
355 * @param toolProperty
356 * the toolProperty to set
358 public void setToolProperty(final String toolProperty) {
359 _toolProperty = toolProperty;
363 * Get the leftMenuProperty.
365 * @return the leftMenuProperty
367 public String getLeftMenuProperty() {
368 return _leftMenuProperty;
372 * Set the leftMenuProperty.
374 * @param leftMenuProperty
375 * the leftMenuProperty to set
377 public void setLeftMenuProperty(final String leftMenuProperty) {
378 _leftMenuProperty = leftMenuProperty;