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 * Value of the tool bar property.
38 * It can be: none, standard, study, back.
40 private String _toolProperty;
42 * Property that indicates whether the current open study is editable or not.
43 * On the screen it looks like pen on the status icon, pop-up menu also can be called.
44 * It is necessary for correct building the title bar.
46 private String _editDisabledProperty = "false";
48 private static final long serialVersionUID = 6003880772275115923L;
50 private enum ToDo { cancel, upload };
52 // ==============================================================================================================================
54 // ==============================================================================================================================
56 public String doInitialize () {
57 // -----------------------------
58 setMenuProperty("study");
59 setToolProperty("none");
60 initializationScreenContext(_menuProperty, _toolProperty);
65 public String doUpload () {
66 // -------------------------
67 setMenuProperty("study");
68 setTitleProperty("study");
69 setEditDisabledProperty("true");
70 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
72 if (action == ToDo.cancel) return "cancel";
74 File udir = getRepositoryService().getDownloadDirectory(getConnectedUser());
75 String path = udir.getPath() + "/" + uploadFileName;
76 File file = new File(path);
78 if (!udir.exists()) udir.mkdir();
79 if (file.exists()) file.delete();
80 Do.copy(upload, file);
81 logger.info("Uploading \"" + uploadFileName + "\" " + uploadMimeType + " file.");
82 /*if (next == null || next.isEmpty()) {
86 logger.info("MKA next = " + next);
89 catch (OutOfMemoryError error) {
91 setMenuProperty("none");
92 setTitleProperty("study");
93 setEditDisabledProperty("true");
94 setToolProperty("none");
95 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
99 catch (Exception error) {
100 logger.error("Reason: ", error);
104 // ==============================================================================================================================
105 // Getters and setters
106 // ==============================================================================================================================
108 public String getIndex () {
109 // -------------------------
112 public String getFileName () {
113 // ----------------------------
114 return uploadFileName;
116 public String getNextAction () {
117 // ------------------------------
121 public void setCancel (boolean back) {
122 // ------------------------------------
123 this.action = ToDo.cancel;
125 public void setDoIt (boolean upload) {
126 // --------------------------------
127 this.action = ToDo.upload;
129 public void setIndex (String index) {
130 // -----------------------------------
133 public void setNextAction (String next) {
134 // ---------------------------------------
137 public void setUpload (File upload) {
138 // -----------------------------------
139 this.upload = upload;
141 public void setUploadFileName (String name) {
142 // -------------------------------------------
143 this.uploadFileName = name;
145 public void setUploadContentType (String mime) {
146 // ----------------------------------------------
147 this.uploadMimeType = mime;
151 * Get the repositoryService.
152 * @return the repositoryService
154 public RepositoryService getRepositoryService() {
155 return _repositoryService;
159 * Set the repositoryService.
160 * @param repositoryService the repositoryService to set
162 public void setRepositoryService(RepositoryService repositoryService) {
163 _repositoryService = repositoryService;
167 * Get the menuProperty.
168 * @return the menuProperty
170 public String getMenuProperty() {
171 return _menuProperty;
175 * Set the menuProperty.
176 * @param menuProperty the menuProperty to set
178 public void setMenuProperty(String menuProperty) {
179 this._menuProperty = menuProperty;
183 * Get the _titleProperty.
184 * @return the _titleProperty
186 public String getTitleProperty() {
187 return _titleProperty;
191 * Set the _titleProperty.
192 * @param _titleProperty the titleProperty to set
194 public void setTitleProperty(String titleProperty) {
195 _titleProperty = titleProperty;
199 * Get the _editDisabledProperty.
200 * @return the _editDisabledProperty
202 public String getEditDisabledProperty() {
203 return _editDisabledProperty;
207 * Set the _editDisabledProperty.
208 * @param _editDisabledProperty the _editDisabledProperty to set
210 public void setEditDisabledProperty(String _editDisabledProperty) {
211 this._editDisabledProperty = _editDisabledProperty;
215 * Get the toolProperty.
216 * @return the toolProperty
218 public String getToolProperty() {
219 return _toolProperty;
223 * Set the toolProperty.
224 * @param toolProperty the toolProperty to set
226 public void setToolProperty(final String toolProperty) {
227 _toolProperty = toolProperty;