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;
25 * Value of the menu property.
26 * It can be: none, create, open, study, knowledge, sysadmin, help.
28 private String _menuProperty;
30 private static final long serialVersionUID = 6003880772275115923L;
32 private enum ToDo { cancel, upload };
34 // ==============================================================================================================================
36 // ==============================================================================================================================
38 public String doInitialize () {
39 // -----------------------------
40 setMenuProperty("study");
41 initializationScreenContext(_menuProperty);
46 public String doUpload () {
47 // -------------------------
48 setMenuProperty("study");
49 initializationScreenContext(_menuProperty);
51 if (action == ToDo.cancel) return "cancel";
53 File udir = getRepositoryService().getDownloadDirectory(getConnectedUser());
54 String path = udir.getPath() + "/" + uploadFileName;
55 File file = new File(path);
57 if (!udir.exists()) udir.mkdir();
58 if (file.exists()) file.delete();
59 Do.copy(upload, file);
60 logger.info("Uploading \"" + uploadFileName + "\" " + uploadMimeType + " file.");
61 /*if (next == null || next.isEmpty()) {
65 logger.info("MKA next = " + next);
68 catch (OutOfMemoryError error) {
70 setMenuProperty("none");
71 initializationScreenContext(_menuProperty);
75 catch (Exception error) {
76 logger.error("Reason: ", error);
80 // ==============================================================================================================================
81 // Getters and setters
82 // ==============================================================================================================================
84 public String getIndex () {
85 // -------------------------
88 public String getFileName () {
89 // ----------------------------
90 return uploadFileName;
92 public String getNextAction () {
93 // ------------------------------
97 public void setCancel (boolean back) {
98 // ------------------------------------
99 this.action = ToDo.cancel;
101 public void setDoIt (boolean upload) {
102 // --------------------------------
103 this.action = ToDo.upload;
105 public void setIndex (String index) {
106 // -----------------------------------
109 public void setNextAction (String next) {
110 // ---------------------------------------
113 public void setUpload (File upload) {
114 // -----------------------------------
115 this.upload = upload;
117 public void setUploadFileName (String name) {
118 // -------------------------------------------
119 this.uploadFileName = name;
121 public void setUploadContentType (String mime) {
122 // ----------------------------------------------
123 this.uploadMimeType = mime;
127 * Get the repositoryService.
128 * @return the repositoryService
130 public RepositoryService getRepositoryService() {
131 return _repositoryService;
135 * Set the repositoryService.
136 * @param repositoryService the repositoryService to set
138 public void setRepositoryService(RepositoryService repositoryService) {
139 _repositoryService = repositoryService;
143 * Get the menuProperty.
144 * @return the menuProperty
146 public String getMenuProperty() {
147 return _menuProperty;
151 * Set the menuProperty.
152 * @param menuProperty the menuProperty to set
154 public void setMenuProperty(String menuProperty) {
155 this._menuProperty = menuProperty;