Salome HOME
Tool bar is improved.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / StartAction.java
1 package org.splat.simer;
2
3 import java.util.Map;
4
5 import javax.servlet.ServletContext;
6 import javax.servlet.http.HttpServletRequest;
7
8 import org.apache.struts2.interceptor.ServletRequestAware;
9 import org.apache.struts2.util.ServletContextAware;
10 import org.hibernate.HibernateException;
11 import org.hibernate.Session;
12 import org.hibernate.Transaction;
13 import org.splat.som.ApplicationRights;
14 import org.splat.dal.dao.som.Database;
15 import org.splat.service.technical.ProjectSettingsService;
16
17
18
19 public class StartAction extends Action implements ServletRequestAware {
20
21     private HttpServletRequest  request = null;
22
23         private ProjectSettingsService _projectSettingsService;
24         private ApplicationSettings _ApplicationSettings;
25         
26         /**
27          * Value of the menu property. 
28          * It can be: none, create, open, study, knowledge, sysadmin, help.
29          */
30         private String _menuProperty;
31         
32         /**
33          * Value of the title bar property. 
34          * It can be: study, knowledge.
35          */
36         private String _titleProperty;
37         
38         /**
39          * Property that indicates whether the current open study is editable or not.
40          * On the screen it looks like pen on the status icon, pop-up menu also can be called.
41          * It is necessary for correct building the title bar.
42          */
43         private String _editDisabledProperty = "false";
44         
45         /**
46          * Value of the tool bar property. 
47          * It can be: none, standard, study, back.
48          */
49         private String _toolProperty;
50
51         /**
52          * Serial version ID.
53          */
54         private static final long   serialVersionUID = 5875058140682652964L;
55
56 //  ==============================================================================================================================
57 //  Action execution
58 //  ==============================================================================================================================
59
60         public String doInitialize () throws Exception {
61 //  -----------------------------
62 //      Session      connex  = Database.getSession();
63 //      Transaction  transax = connex.beginTransaction();                 
64           StringBuffer wappurl = request.getRequestURL();     // "http://{server}:{port}/{webapp}/", including the leading '/'
65
66       logger.info( new StringBuffer("Initializing ").append(wappurl).append("...").toString() );
67           try {
68                 ProjectSettingsService project = getProjectSettings();
69         ApplicationSettings wapp    = getApplicationSettings().init(wappurl.toString(), this.getLocale());
70         String              root    = wapp.getApplicationRootPath();
71         logger.debug("Application root: " + root);
72
73 //      Database configuration
74                 project.configure(root + wapp.getApplicationProperty("wapp.configuration"));
75
76 //      Application configuration
77             System.setProperty("java.security.auth.login.config", root + wapp.getApplicationProperty("wapp.login"));        
78             wapp.configure(root + wapp.getApplicationProperty("wapp.customization"));
79
80 //      Initialization of the user session
81                 Map<String, Object> session = getSession();
82
83         session.put("user.rights", new ApplicationRights(null) );      // No user connected yet
84                 session.put("study.filter",     wapp.getFilter("study"));
85                 session.put("knowledge.filter", wapp.getFilter("knowledge"));
86
87 //          transax.commit();
88             
89                 setMenuProperty("none");
90                 initializationScreenContext(_menuProperty);
91             
92             return SUCCESS;
93       }
94       catch (Exception error) {
95         logger.fatal("Reason:", error);
96         
97         setMenuProperty("study");
98         setTitleProperty("study");
99         setEditDisabledProperty("true");
100         setToolProperty("none");
101         initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
102         
103         return ERROR;
104       }
105         }
106
107 //  ==============================================================================================================================
108 //  Setter
109 //  ==============================================================================================================================
110
111         public void setServletRequest (HttpServletRequest request) {
112 //  ----------------------------------------------------------
113       this.request = request;
114         }
115     /**
116      * Get project settings.
117          * @return Project settings service
118          */
119         private ProjectSettingsService getProjectSettings() {
120                 return _projectSettingsService;
121         }
122
123         /**
124          * Set project settings service.
125          * @param projectSettingsService project settings service
126          */
127         public void setProjectSettings(
128                         ProjectSettingsService projectSettingsService) {
129                 _projectSettingsService = projectSettingsService;
130         }
131
132         /**
133          * Get the applicationSettings.
134          * @return the applicationSettings
135          */
136         public ApplicationSettings getApplicationSettings() {
137                 return _ApplicationSettings;
138         }
139
140         /**
141          * Set the applicationSettings.
142          * @param applicationSettings the applicationSettings to set
143          */
144         public void setApplicationSettings(ApplicationSettings applicationSettings) {
145                 _ApplicationSettings = applicationSettings;
146         }
147         
148         /**
149          * Get the menuProperty.
150          * @return the menuProperty
151          */
152         public String getMenuProperty() {
153                 return _menuProperty;
154         }
155
156         /**
157          * Set the menuProperty.
158          * @param menuProperty the menuProperty to set
159          */
160         public void setMenuProperty(String menuProperty) {
161                 this._menuProperty = menuProperty;
162         }
163         
164         /**
165          * Get the _titleProperty.
166          * @return the _titleProperty
167          */
168         public String getTitleProperty() {
169                 return _titleProperty;
170         }
171
172         /**
173          * Set the _titleProperty.
174          * @param _titleProperty the titleProperty to set
175          */
176         public void setTitleProperty(String titleProperty) {
177                 _titleProperty = titleProperty;
178         }
179
180         /**
181          * Get the editDisabledProperty.
182          * @return the editDisabledProperty
183          */
184         public final String getEditDisabledProperty() {
185                 return _editDisabledProperty;
186         }
187
188         /**
189          * Set the editDisabledProperty.
190          * @param editDisabledProperty the editDisabledProperty to set
191          */
192         public final void setEditDisabledProperty(String editDisabledProperty) {
193                 _editDisabledProperty = editDisabledProperty;
194         }
195
196         /**
197          * Get the toolProperty.
198          * @return the toolProperty
199          */
200         public String getToolProperty() {
201                 return _toolProperty;
202         }
203
204         /**
205          * Set the toolProperty.
206          * @param toolProperty the toolProperty to set
207          */
208         public void setToolProperty(final String toolProperty) {
209                 _toolProperty = toolProperty;
210         }
211 }