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 initializationFullScreenContext(_menuProperty, _toolProperty,
109 * Store uploaded file into the user's download directory.
111 * @return next action if ok, "cancel" if the operation is cancelled by user, "outofmemory" if there is no enough memory to upload the
112 * file or ERROR otherwise
114 public String doUpload() {
115 setMenuProperty(Constants.STUDY_MENU);
116 setTitleProperty(Constants.STUDY_MENU);
117 setEditDisabledProperty("true");
118 initializationScreenContext(_menuProperty, _titleProperty,
119 _editDisabledProperty);
122 if (_action == ToDo.cancel) {
126 File udir = getRepositoryService().getDownloadDirectory(
128 String path = udir.getPath() + "/" + _uploadFileName;
129 File file = new File(path);
131 if (!udir.exists()) {
137 Do.copy(_upload, file);
138 LOG.info("Uploading \"" + _uploadFileName + "\" "
139 + _uploadMimeType + " file.");
141 * if (next == null || next.isEmpty()) { next = "import"; }
145 } catch (OutOfMemoryError error) {
147 setMenuProperty(Constants.NONE);
148 setTitleProperty(Constants.STUDY_MENU);
149 setEditDisabledProperty("true");
150 setToolProperty(Constants.NONE);
151 setLeftMenuProperty(Constants.STUDY_MENU);
152 initializationFullScreenContext(_menuProperty, _titleProperty,
153 _editDisabledProperty, _toolProperty, _leftMenuProperty);
155 setErrorCode("message.error.outofmemory");
158 } catch (Exception error) {
159 LOG.error("Reason: ", error);
166 // ==============================================================================================================================
167 // Getters and setters
168 // ==============================================================================================================================
171 * Get the document index to which the action applies.
173 * @return the document index to which the action applies
175 public String getIndex() {
180 * Get the uploaded file name.
182 * @return the uploaded file name
184 public String getFileName() {
185 return _uploadFileName;
189 * Get the action to which the uploaded file is passed.
191 * @return the action to which the uploaded file is passed.
193 public String getNextAction() {
198 * Cancel the uploading.
202 public void setCancel(final boolean back) {
203 this._action = ToDo.cancel;
207 * Set the flag to perform uploading.
211 public void setDoIt(final boolean upload) {
212 this._action = ToDo.upload;
216 * Set the document index to which the action applies.
219 * the document index to which the action applies.
221 public void setIndex(final String index) {
226 * Set the action to which the uploaded file is passed.
229 * the action to which the uploaded file is passed.
231 public void setNextAction(final String next) {
232 this._nextAction = next;
236 * Set the uploaded file.
241 public void setUpload(final File upload) {
242 this._upload = upload;
246 * Set the uploaded file name.
249 * the uploaded file name
251 public void setUploadFileName(final String name) {
252 this._uploadFileName = name;
256 * Set the mime type of the uploaded file.
259 * the mime type of the uploaded file
261 public void setUploadContentType(final String mime) {
262 this._uploadMimeType = mime;
266 * Get the repositoryService.
268 * @return the repositoryService
270 public RepositoryService getRepositoryService() {
271 return _repositoryService;
275 * Set the repositoryService.
277 * @param repositoryService
278 * the repositoryService to set
280 public void setRepositoryService(final RepositoryService repositoryService) {
281 _repositoryService = repositoryService;
285 * Get the menuProperty.
287 * @return the menuProperty
289 public String getMenuProperty() {
290 return _menuProperty;
294 * Set the menuProperty.
296 * @param menuProperty
297 * the menuProperty to set
299 public void setMenuProperty(final String menuProperty) {
300 this._menuProperty = menuProperty;
304 * Get the _titleProperty.
306 * @return the _titleProperty
308 public String getTitleProperty() {
309 return _titleProperty;
313 * Set the _titleProperty.
315 * @param titleProperty
316 * the titleProperty to set
318 public void setTitleProperty(final String titleProperty) {
319 _titleProperty = titleProperty;
323 * Get the _editDisabledProperty.
325 * @return the _editDisabledProperty
327 public String getEditDisabledProperty() {
328 return _editDisabledProperty;
332 * Set the editDisabledProperty.
334 * @param editDisabledProperty
335 * the editDisabledProperty to set
337 public void setEditDisabledProperty(final String editDisabledProperty) {
338 this._editDisabledProperty = editDisabledProperty;
342 * Get the toolProperty.
344 * @return the toolProperty
346 public String getToolProperty() {
347 return _toolProperty;
351 * Set the toolProperty.
353 * @param toolProperty
354 * the toolProperty to set
356 public void setToolProperty(final String toolProperty) {
357 _toolProperty = toolProperty;
361 * Get the leftMenuProperty.
363 * @return the leftMenuProperty
365 public String getLeftMenuProperty() {
366 return _leftMenuProperty;
370 * Set the leftMenuProperty.
372 * @param leftMenuProperty
373 * the leftMenuProperty to set
375 public void setLeftMenuProperty(final String leftMenuProperty) {
376 _leftMenuProperty = leftMenuProperty;