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 LOG.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 setErrorCode("message.error.outofmemory");
107 return "outofmemory";
109 catch (Exception error) {
110 LOG.error("Reason: ", error);
114 // ==============================================================================================================================
115 // Getters and setters
116 // ==============================================================================================================================
118 public String getIndex () {
119 // -------------------------
122 public String getFileName () {
123 // ----------------------------
124 return uploadFileName;
126 public String getNextAction () {
127 // ------------------------------
131 public void setCancel (final boolean back) {
132 // ------------------------------------
133 this.action = ToDo.cancel;
135 public void setDoIt (final boolean upload) {
136 // --------------------------------
137 this.action = ToDo.upload;
139 public void setIndex (final String index) {
140 // -----------------------------------
143 public void setNextAction (final String next) {
144 // ---------------------------------------
147 public void setUpload (final File upload) {
148 // -----------------------------------
149 this.upload = upload;
151 public void setUploadFileName (final String name) {
152 // -------------------------------------------
153 this.uploadFileName = name;
155 public void setUploadContentType (final String mime) {
156 // ----------------------------------------------
157 this.uploadMimeType = mime;
161 * Get the repositoryService.
162 * @return the repositoryService
164 public RepositoryService getRepositoryService() {
165 return _repositoryService;
169 * Set the repositoryService.
170 * @param repositoryService the repositoryService to set
172 public void setRepositoryService(final RepositoryService repositoryService) {
173 _repositoryService = repositoryService;
177 * Get the menuProperty.
178 * @return the menuProperty
180 public String getMenuProperty() {
181 return _menuProperty;
185 * Set the menuProperty.
186 * @param menuProperty the menuProperty to set
188 public void setMenuProperty(final String menuProperty) {
189 this._menuProperty = menuProperty;
193 * Get the _titleProperty.
194 * @return the _titleProperty
196 public String getTitleProperty() {
197 return _titleProperty;
201 * Set the _titleProperty.
202 * @param titleProperty the titleProperty to set
204 public void setTitleProperty(final String titleProperty) {
205 _titleProperty = titleProperty;
209 * Get the _editDisabledProperty.
210 * @return the _editDisabledProperty
212 public String getEditDisabledProperty() {
213 return _editDisabledProperty;
217 * Set the _editDisabledProperty.
218 * @param _editDisabledProperty the _editDisabledProperty to set
220 public void setEditDisabledProperty(final String _editDisabledProperty) {
221 this._editDisabledProperty = _editDisabledProperty;
225 * Get the toolProperty.
226 * @return the toolProperty
228 public String getToolProperty() {
229 return _toolProperty;
233 * Set the toolProperty.
234 * @param toolProperty the toolProperty to set
236 public void setToolProperty(final String toolProperty) {
237 _toolProperty = toolProperty;
241 * Get the leftMenuProperty.
242 * @return the leftMenuProperty
244 public String getLeftMenuProperty() {
245 return _leftMenuProperty;
249 * Set the leftMenuProperty.
250 * @param leftMenuProperty the leftMenuProperty to set
252 public void setLeftMenuProperty(final String leftMenuProperty) {
253 _leftMenuProperty = leftMenuProperty;