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;
43 * Value of the left menu property.
44 * It can be: open, study, knowledge, scenario.
46 private String _leftMenuProperty;
49 * Property that indicates whether the current open study is editable or not.
50 * On the screen it looks like pen on the status icon, pop-up menu also can be called.
51 * It is necessary for correct building the title bar.
53 private String _editDisabledProperty = "false";
55 private static final long serialVersionUID = 6003880772275115923L;
57 private enum ToDo { cancel, upload };
59 // ==============================================================================================================================
61 // ==============================================================================================================================
63 public String doInitialize () {
64 // -----------------------------
65 setMenuProperty("study");
66 setToolProperty("none");
67 setLeftMenuProperty("open");
68 initializationFullScreenContext(_menuProperty, _toolProperty, _leftMenuProperty);
73 public String doUpload () {
74 // -------------------------
75 setMenuProperty("study");
76 setTitleProperty("study");
77 setEditDisabledProperty("true");
78 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
80 if (action == ToDo.cancel) return "cancel";
82 File udir = getRepositoryService().getDownloadDirectory(getConnectedUser());
83 String path = udir.getPath() + "/" + uploadFileName;
84 File file = new File(path);
86 if (!udir.exists()) udir.mkdir();
87 if (file.exists()) file.delete();
88 Do.copy(upload, file);
89 logger.info("Uploading \"" + uploadFileName + "\" " + uploadMimeType + " file.");
90 /*if (next == null || next.isEmpty()) {
96 catch (OutOfMemoryError error) {
98 setMenuProperty("none");
99 setTitleProperty("study");
100 setEditDisabledProperty("true");
101 setToolProperty("none");
102 setLeftMenuProperty("study");
103 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
105 return "outofmemory";
107 catch (Exception error) {
108 logger.error("Reason: ", error);
112 // ==============================================================================================================================
113 // Getters and setters
114 // ==============================================================================================================================
116 public String getIndex () {
117 // -------------------------
120 public String getFileName () {
121 // ----------------------------
122 return uploadFileName;
124 public String getNextAction () {
125 // ------------------------------
129 public void setCancel (boolean back) {
130 // ------------------------------------
131 this.action = ToDo.cancel;
133 public void setDoIt (boolean upload) {
134 // --------------------------------
135 this.action = ToDo.upload;
137 public void setIndex (String index) {
138 // -----------------------------------
141 public void setNextAction (String next) {
142 // ---------------------------------------
145 public void setUpload (File upload) {
146 // -----------------------------------
147 this.upload = upload;
149 public void setUploadFileName (String name) {
150 // -------------------------------------------
151 this.uploadFileName = name;
153 public void setUploadContentType (String mime) {
154 // ----------------------------------------------
155 this.uploadMimeType = mime;
159 * Get the repositoryService.
160 * @return the repositoryService
162 public RepositoryService getRepositoryService() {
163 return _repositoryService;
167 * Set the repositoryService.
168 * @param repositoryService the repositoryService to set
170 public void setRepositoryService(RepositoryService repositoryService) {
171 _repositoryService = repositoryService;
175 * Get the menuProperty.
176 * @return the menuProperty
178 public String getMenuProperty() {
179 return _menuProperty;
183 * Set the menuProperty.
184 * @param menuProperty the menuProperty to set
186 public void setMenuProperty(String menuProperty) {
187 this._menuProperty = menuProperty;
191 * Get the _titleProperty.
192 * @return the _titleProperty
194 public String getTitleProperty() {
195 return _titleProperty;
199 * Set the _titleProperty.
200 * @param _titleProperty the titleProperty to set
202 public void setTitleProperty(String titleProperty) {
203 _titleProperty = titleProperty;
207 * Get the _editDisabledProperty.
208 * @return the _editDisabledProperty
210 public String getEditDisabledProperty() {
211 return _editDisabledProperty;
215 * Set the _editDisabledProperty.
216 * @param _editDisabledProperty the _editDisabledProperty to set
218 public void setEditDisabledProperty(String _editDisabledProperty) {
219 this._editDisabledProperty = _editDisabledProperty;
223 * Get the toolProperty.
224 * @return the toolProperty
226 public String getToolProperty() {
227 return _toolProperty;
231 * Set the toolProperty.
232 * @param toolProperty the toolProperty to set
234 public void setToolProperty(final String toolProperty) {
235 _toolProperty = toolProperty;
239 * Get the leftMenuProperty.
240 * @return the leftMenuProperty
242 public String getLeftMenuProperty() {
243 return _leftMenuProperty;
247 * Set the leftMenuProperty.
248 * @param leftMenuProperty the leftMenuProperty to set
250 public void setLeftMenuProperty(final String leftMenuProperty) {
251 _leftMenuProperty = leftMenuProperty;