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 documents to study action.
72 public String doInitializeStudy() {
73 initializationFullScreenContext(Constants.STUDY_MENU,
74 Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
75 Constants.STUDY_MENU);
81 * Prepare form for the upload users action.
84 public String doInitializeSysAdmin() {
85 initializationFullScreenContext(Constants.SYSADMIN_MENU,
86 Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
93 * Store uploaded file into the user's download directory.
95 * @return next action if ok, "cancel" if the operation is cancelled by user, "outofmemory" if there is no enough memory to upload the
96 * file or ERROR otherwise
98 public String doUpload() {
99 initializationScreenContext(getMenuProperty(), Constants.STUDY_MENU,
103 if (_action == ToDo.cancel) {
107 File udir = getRepositoryService().getDownloadDirectory(
109 String path = udir.getPath() + "/" + _uploadFileName;
110 File file = new File(path);
112 if (!udir.exists()) {
118 Do.copy(_upload, file);
119 LOG.info("Uploading \"" + _uploadFileName + "\" "
120 + _uploadMimeType + " file.");
122 * if (next == null || next.isEmpty()) { next = "import"; }
126 } catch (OutOfMemoryError error) {
128 initializationFullScreenContext(Constants.NONE,
129 Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
130 Constants.STUDY_MENU);
132 setErrorCode("message.error.outofmemory");
135 } catch (Exception error) {
136 LOG.error("Reason: ", error);
143 // ==============================================================================================================================
144 // Getters and setters
145 // ==============================================================================================================================
148 * Get the document index to which the action applies.
150 * @return the document index to which the action applies
152 public String getIndex() {
157 * Get the uploaded file name.
159 * @return the uploaded file name
161 public String getFileName() {
162 return _uploadFileName;
166 * Get the action to which the uploaded file is passed.
168 * @return the action to which the uploaded file is passed.
170 public String getNextAction() {
175 * Cancel the uploading.
179 public void setCancel(final boolean back) {
180 this._action = ToDo.cancel;
184 * Set the flag to perform uploading.
188 public void setDoIt(final boolean upload) {
189 this._action = ToDo.upload;
193 * Set the document index to which the action applies.
196 * the document index to which the action applies.
198 public void setIndex(final String index) {
203 * Set the action to which the uploaded file is passed.
206 * the action to which the uploaded file is passed.
208 public void setNextAction(final String next) {
209 this._nextAction = next;
213 * Set the uploaded file.
218 public void setUpload(final File upload) {
219 this._upload = upload;
223 * Set the uploaded file name.
226 * the uploaded file name
228 public void setUploadFileName(final String name) {
229 this._uploadFileName = name;
233 * Set the mime type of the uploaded file.
236 * the mime type of the uploaded file
238 public void setUploadContentType(final String mime) {
239 this._uploadMimeType = mime;
243 * Get the repositoryService.
245 * @return the repositoryService
247 public RepositoryService getRepositoryService() {
248 return _repositoryService;
252 * Set the repositoryService.
254 * @param repositoryService
255 * the repositoryService to set
257 public void setRepositoryService(final RepositoryService repositoryService) {
258 _repositoryService = repositoryService;