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;
31 * Value of the title bar property.
32 * It can be: study, knowledge.
34 private String _titleProperty;
37 * Property that indicates whether the current open study is editable or not.
38 * On the screen it looks like pen on the status icon, pop-up menu also can be called.
39 * It is necessary for correct building the title bar.
41 private String _editDisabledProperty = "false";
43 private static final long serialVersionUID = 6003880772275115923L;
45 private enum ToDo { cancel, upload };
47 // ==============================================================================================================================
49 // ==============================================================================================================================
51 public String doInitialize () {
52 // -----------------------------
53 setMenuProperty("study");
54 initializationScreenContext(_menuProperty);
59 public String doUpload () {
60 // -------------------------
61 setMenuProperty("study");
62 setTitleProperty("study");
63 setEditDisabledProperty("true");
64 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
66 if (action == ToDo.cancel) return "cancel";
68 File udir = getRepositoryService().getDownloadDirectory(getConnectedUser());
69 String path = udir.getPath() + "/" + uploadFileName;
70 File file = new File(path);
72 if (!udir.exists()) udir.mkdir();
73 if (file.exists()) file.delete();
74 Do.copy(upload, file);
75 logger.info("Uploading \"" + uploadFileName + "\" " + uploadMimeType + " file.");
76 /*if (next == null || next.isEmpty()) {
80 logger.info("MKA next = " + next);
83 catch (OutOfMemoryError error) {
85 setMenuProperty("none");
86 setTitleProperty("study");
87 setEditDisabledProperty("true");
88 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
92 catch (Exception error) {
93 logger.error("Reason: ", error);
97 // ==============================================================================================================================
98 // Getters and setters
99 // ==============================================================================================================================
101 public String getIndex () {
102 // -------------------------
105 public String getFileName () {
106 // ----------------------------
107 return uploadFileName;
109 public String getNextAction () {
110 // ------------------------------
114 public void setCancel (boolean back) {
115 // ------------------------------------
116 this.action = ToDo.cancel;
118 public void setDoIt (boolean upload) {
119 // --------------------------------
120 this.action = ToDo.upload;
122 public void setIndex (String index) {
123 // -----------------------------------
126 public void setNextAction (String next) {
127 // ---------------------------------------
130 public void setUpload (File upload) {
131 // -----------------------------------
132 this.upload = upload;
134 public void setUploadFileName (String name) {
135 // -------------------------------------------
136 this.uploadFileName = name;
138 public void setUploadContentType (String mime) {
139 // ----------------------------------------------
140 this.uploadMimeType = mime;
144 * Get the repositoryService.
145 * @return the repositoryService
147 public RepositoryService getRepositoryService() {
148 return _repositoryService;
152 * Set the repositoryService.
153 * @param repositoryService the repositoryService to set
155 public void setRepositoryService(RepositoryService repositoryService) {
156 _repositoryService = repositoryService;
160 * Get the menuProperty.
161 * @return the menuProperty
163 public String getMenuProperty() {
164 return _menuProperty;
168 * Set the menuProperty.
169 * @param menuProperty the menuProperty to set
171 public void setMenuProperty(String menuProperty) {
172 this._menuProperty = menuProperty;
176 * Get the _titleProperty.
177 * @return the _titleProperty
179 public String getTitleProperty() {
180 return _titleProperty;
184 * Set the _titleProperty.
185 * @param _titleProperty the titleProperty to set
187 public void setTitleProperty(String titleProperty) {
188 _titleProperty = titleProperty;
192 * Get the _editDisabledProperty.
193 * @return the _editDisabledProperty
195 public String getEditDisabledProperty() {
196 return _editDisabledProperty;
200 * Set the _editDisabledProperty.
201 * @param _editDisabledProperty the _editDisabledProperty to set
203 public void setEditDisabledProperty(String _editDisabledProperty) {
204 this._editDisabledProperty = _editDisabledProperty;