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 * Action modes enumeration.
54 * Cancel the operation.
63 // ==============================================================================================================================
65 // ==============================================================================================================================
68 * Prepare form for the upload action.
72 public String doInitialize() {
73 initializationFullScreenContext(Constants.STUDY_MENU,
74 Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
81 * Store uploaded file into the user's download directory.
83 * @return next action if ok, "cancel" if the operation is cancelled by user, "outofmemory" if there is no enough memory to upload the
84 * file or ERROR otherwise
86 public String doUpload() {
87 initializationScreenContext(Constants.STUDY_MENU, Constants.STUDY_MENU,
91 if (_action == ToDo.cancel) {
95 File udir = getRepositoryService().getDownloadDirectory(
97 String path = udir.getPath() + "/" + _uploadFileName;
98 File file = new File(path);
100 if (!udir.exists()) {
106 Do.copy(_upload, file);
107 LOG.info("Uploading \"" + _uploadFileName + "\" "
108 + _uploadMimeType + " file.");
110 * if (next == null || next.isEmpty()) { next = "import"; }
114 } catch (OutOfMemoryError error) {
116 initializationFullScreenContext(Constants.NONE,
117 Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
118 Constants.STUDY_MENU);
120 setErrorCode("message.error.outofmemory");
123 } catch (Exception error) {
124 LOG.error("Reason: ", error);
131 // ==============================================================================================================================
132 // Getters and setters
133 // ==============================================================================================================================
136 * Get the document index to which the action applies.
138 * @return the document index to which the action applies
140 public String getIndex() {
145 * Get the uploaded file name.
147 * @return the uploaded file name
149 public String getFileName() {
150 return _uploadFileName;
154 * Get the action to which the uploaded file is passed.
156 * @return the action to which the uploaded file is passed.
158 public String getNextAction() {
163 * Cancel the uploading.
167 public void setCancel(final boolean back) {
168 this._action = ToDo.cancel;
172 * Set the flag to perform uploading.
176 public void setDoIt(final boolean upload) {
177 this._action = ToDo.upload;
181 * Set the document index to which the action applies.
184 * the document index to which the action applies.
186 public void setIndex(final String index) {
191 * Set the action to which the uploaded file is passed.
194 * the action to which the uploaded file is passed.
196 public void setNextAction(final String next) {
197 this._nextAction = next;
201 * Set the uploaded file.
206 public void setUpload(final File upload) {
207 this._upload = upload;
211 * Set the uploaded file name.
214 * the uploaded file name
216 public void setUploadFileName(final String name) {
217 this._uploadFileName = name;
221 * Set the mime type of the uploaded file.
224 * the mime type of the uploaded file
226 public void setUploadContentType(final String mime) {
227 this._uploadMimeType = mime;
231 * Get the repositoryService.
233 * @return the repositoryService
235 public RepositoryService getRepositoryService() {
236 return _repositoryService;
240 * Set the repositoryService.
242 * @param repositoryService
243 * the repositoryService to set
245 public void setRepositoryService(final RepositoryService repositoryService) {
246 _repositoryService = repositoryService;