1 package org.splat.simer;
5 import org.splat.kernel.Do;
6 import org.splat.service.technical.RepositoryService;
7 import org.splat.dal.dao.som.Database;
10 public class UploadAction extends Action {
12 private File upload = null;
13 private String uploadMimeType = null;
14 private String uploadFileName = null;
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
20 * Injected repository service.
22 private RepositoryService _repositoryService;
24 private static final long serialVersionUID = 6003880772275115923L;
26 private enum ToDo { cancel, upload };
28 // ==============================================================================================================================
30 // ==============================================================================================================================
32 public String doInitialize () {
33 // -----------------------------
37 public String doUpload () {
38 // -------------------------
39 if (action == ToDo.cancel) return "cancel";
41 File udir = getRepositoryService().getDownloadDirectory(getConnectedUser());
42 String path = udir.getPath() + "/" + uploadFileName;
43 File file = new File(path);
45 if (!udir.exists()) udir.mkdir();
46 if (file.exists()) file.delete();
47 Do.copy(upload, file);
48 logger.info("Uploading \"" + uploadFileName + "\" " + uploadMimeType + " file.");
51 catch (OutOfMemoryError error) {
54 catch (Exception error) {
55 logger.error("Reason: ", error);
59 // ==============================================================================================================================
60 // Getters and setters
61 // ==============================================================================================================================
63 public String getIndex () {
64 // -------------------------
67 public String getFileName () {
68 // ----------------------------
69 return uploadFileName;
71 public String getNextAction () {
72 // ------------------------------
76 public void setCancel (boolean back) {
77 // ------------------------------------
78 this.action = ToDo.cancel;
80 public void setDoIt (boolean upload) {
81 // --------------------------------
82 this.action = ToDo.upload;
84 public void setIndex (String index) {
85 // -----------------------------------
88 public void setNextAction (String next) {
89 // ---------------------------------------
92 public void setUpload (File upload) {
93 // -----------------------------------
96 public void setUploadFileName (String name) {
97 // -------------------------------------------
98 this.uploadFileName = name;
100 public void setUploadContentType (String mime) {
101 // ----------------------------------------------
102 this.uploadMimeType = mime;
106 * Get the repositoryService.
107 * @return the repositoryService
109 public RepositoryService getRepositoryService() {
110 return _repositoryService;
114 * Set the repositoryService.
115 * @param repositoryService the repositoryService to set
117 public void setRepositoryService(RepositoryService repositoryService) {
118 _repositoryService = repositoryService;