Salome HOME
Fix for uploading of files with names containing specific (accented, ampersand) chara...
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / UploadAction.java
index 4b9432bb8cb311bddbb00a3d3e873f3a85383e42..95b5b3874f74a086e691303a0277d101776271b2 100644 (file)
@@ -1,6 +1,8 @@
 package org.splat.simer;
 
 import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 
 import org.splat.kernel.Do;
 import org.splat.service.technical.RepositoryService;
@@ -46,32 +48,6 @@ public class UploadAction extends Action {
         */
        private RepositoryService _repositoryService;
 
-       /**
-        * Value of the menu property. It can be: none, create, open, study, knowledge, sysadmin, help.
-        */
-       private String _menuProperty;
-
-       /**
-        * Value of the title bar property. It can be: study, knowledge.
-        */
-       private String _titleProperty;
-
-       /**
-        * Value of the tool bar property. It can be: none, standard, study, back.
-        */
-       private String _toolProperty;
-
-       /**
-        * Value of the left menu property. It can be: open, study, knowledge, scenario.
-        */
-       private String _leftMenuProperty;
-
-       /**
-        * Property that indicates whether the current open study is editable or not. On the screen it looks like pen on the status icon, pop-up
-        * menu also can be called. It is necessary for correct building the title bar.
-        */
-       private String _editDisabledProperty = "false";
-
        /**
         * Action modes enumeration.
         */
@@ -91,16 +67,27 @@ public class UploadAction extends Action {
        // ==============================================================================================================================
 
        /**
-        * Prepare form for the upload action.
+        * Prepare form for the upload documents to study action.
         * 
         * @return SUCCESS
         */
-       public String doInitialize() {
-               setMenuProperty(Constants.STUDY_MENU);
-               setToolProperty(Constants.NONE);
-               setLeftMenuProperty("open");
-               initializationFullScreenContext(_menuProperty, _toolProperty,
-                               _leftMenuProperty);
+       public String doInitializeStudy() {
+               initializationFullScreenContext(Constants.STUDY_MENU,
+                               Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
+                               Constants.STUDY_MENU);
+
+               return SUCCESS;
+       }
+       
+       /**
+        * Prepare form for the upload users action.
+        * @return SUCCESS
+        */
+       public String doInitializeSysAdmin() {
+               initializationFullScreenContext(Constants.SYSADMIN_MENU,
+                               Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
+                               Constants.OPEN);
+               setSimanContext("#Database_Management.htm");
 
                return SUCCESS;
        }
@@ -112,11 +99,8 @@ public class UploadAction extends Action {
         *         file or ERROR otherwise
         */
        public String doUpload() {
-               setMenuProperty(Constants.STUDY_MENU);
-               setTitleProperty(Constants.STUDY_MENU);
-               setEditDisabledProperty("true");
-               initializationScreenContext(_menuProperty, _titleProperty,
-                               _editDisabledProperty);
+               initializationScreenContext(getMenuProperty(), Constants.STUDY_MENU,
+                               Constants.TRUE);
 
                String res;
                if (_action == ToDo.cancel) {
@@ -144,13 +128,9 @@ public class UploadAction extends Action {
                                res = _nextAction;
                        } catch (OutOfMemoryError error) {
 
-                               setMenuProperty(Constants.NONE);
-                               setTitleProperty(Constants.STUDY_MENU);
-                               setEditDisabledProperty("true");
-                               setToolProperty(Constants.NONE);
-                               setLeftMenuProperty(Constants.STUDY_MENU);
-                               initializationFullScreenContext(_menuProperty, _titleProperty,
-                                               _editDisabledProperty, _toolProperty, _leftMenuProperty);
+                               initializationFullScreenContext(Constants.NONE,
+                                               Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
+                                               Constants.STUDY_MENU);
 
                                setErrorCode("message.error.outofmemory");
 
@@ -185,6 +165,20 @@ public class UploadAction extends Action {
                return _uploadFileName;
        }
 
+       /**
+        * Get fileName with url special symbols canceled for usage in struts.xml.
+        * @return the encoded uploaded file name.
+        */
+       public String getCanceledFileName() {
+               String res = _uploadFileName;
+               try {
+                       res = URLEncoder.encode(res, "ISO-8859-1");
+               } catch (UnsupportedEncodingException e) {
+                       LOG.error("Reason: ", e);
+               }
+               return res;
+       }
+       
        /**
         * Get the action to which the uploaded file is passed.
         * 
@@ -280,99 +274,4 @@ public class UploadAction extends Action {
        public void setRepositoryService(final RepositoryService repositoryService) {
                _repositoryService = repositoryService;
        }
-
-       /**
-        * Get the menuProperty.
-        * 
-        * @return the menuProperty
-        */
-       public String getMenuProperty() {
-               return _menuProperty;
-       }
-
-       /**
-        * Set the menuProperty.
-        * 
-        * @param menuProperty
-        *            the menuProperty to set
-        */
-       public void setMenuProperty(final String menuProperty) {
-               this._menuProperty = menuProperty;
-       }
-
-       /**
-        * Get the _titleProperty.
-        * 
-        * @return the _titleProperty
-        */
-       public String getTitleProperty() {
-               return _titleProperty;
-       }
-
-       /**
-        * Set the _titleProperty.
-        * 
-        * @param titleProperty
-        *            the titleProperty to set
-        */
-       public void setTitleProperty(final String titleProperty) {
-               _titleProperty = titleProperty;
-       }
-
-       /**
-        * Get the _editDisabledProperty.
-        * 
-        * @return the _editDisabledProperty
-        */
-       public String getEditDisabledProperty() {
-               return _editDisabledProperty;
-       }
-
-       /**
-        * Set the editDisabledProperty.
-        * 
-        * @param editDisabledProperty
-        *            the editDisabledProperty to set
-        */
-       public void setEditDisabledProperty(final String editDisabledProperty) {
-               this._editDisabledProperty = editDisabledProperty;
-       }
-
-       /**
-        * Get the toolProperty.
-        * 
-        * @return the toolProperty
-        */
-       public String getToolProperty() {
-               return _toolProperty;
-       }
-
-       /**
-        * Set the toolProperty.
-        * 
-        * @param toolProperty
-        *            the toolProperty to set
-        */
-       public void setToolProperty(final String toolProperty) {
-               _toolProperty = toolProperty;
-       }
-
-       /**
-        * Get the leftMenuProperty.
-        * 
-        * @return the leftMenuProperty
-        */
-       public String getLeftMenuProperty() {
-               return _leftMenuProperty;
-       }
-
-       /**
-        * Set the leftMenuProperty.
-        * 
-        * @param leftMenuProperty
-        *            the leftMenuProperty to set
-        */
-       public void setLeftMenuProperty(final String leftMenuProperty) {
-               _leftMenuProperty = leftMenuProperty;
-       }
 }
\ No newline at end of file