Salome HOME
app.root property is removed.
[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          * Serial version ID.
47          */
48         private static final long   serialVersionUID = 5875058140682652964L;
49
50 //  ==============================================================================================================================
51 //  Action execution
52 //  ==============================================================================================================================
53
54         public String doInitialize () throws Exception {
55 //  -----------------------------
56 //      Session      connex  = Database.getSession();
57 //      Transaction  transax = connex.beginTransaction();                 
58           StringBuffer wappurl = request.getRequestURL();     // "http://{server}:{port}/{webapp}/", including the leading '/'
59
60       logger.info( new StringBuffer("Initializing ").append(wappurl).append("...").toString() );
61           try {
62                 ProjectSettingsService project = getProjectSettings();
63         ApplicationSettings wapp    = getApplicationSettings().init(wappurl.toString(), this.getLocale());
64         String              root    = wapp.getApplicationRootPath();
65         logger.debug("Application root: " + root);
66
67 //      Database configuration
68                 project.configure(root + wapp.getApplicationProperty("wapp.configuration"));
69
70 //      Application configuration
71             System.setProperty("java.security.auth.login.config", root + wapp.getApplicationProperty("wapp.login"));        
72             wapp.configure(root + wapp.getApplicationProperty("wapp.customization"));
73
74 //      Initialization of the user session
75                 Map<String, Object> session = getSession();
76
77         session.put("user.rights", new ApplicationRights(null) );      // No user connected yet
78                 session.put("study.filter",     wapp.getFilter("study"));
79                 session.put("knowledge.filter", wapp.getFilter("knowledge"));
80
81 //          transax.commit();
82             
83                 setMenuProperty("none");
84                 initializationScreenContext(_menuProperty);
85             
86             return SUCCESS;
87       }
88       catch (Exception error) {
89         logger.fatal("Reason:", error);
90         
91         setMenuProperty("study");
92         setTitleProperty("study");
93         setEditDisabledProperty("true");
94         initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
95         
96         return ERROR;
97       }
98         }
99
100 //  ==============================================================================================================================
101 //  Setter
102 //  ==============================================================================================================================
103
104         public void setServletRequest (HttpServletRequest request) {
105 //  ----------------------------------------------------------
106       this.request = request;
107         }
108     /**
109      * Get project settings.
110          * @return Project settings service
111          */
112         private ProjectSettingsService getProjectSettings() {
113                 return _projectSettingsService;
114         }
115
116         /**
117          * Set project settings service.
118          * @param projectSettingsService project settings service
119          */
120         public void setProjectSettings(
121                         ProjectSettingsService projectSettingsService) {
122                 _projectSettingsService = projectSettingsService;
123         }
124
125         /**
126          * Get the applicationSettings.
127          * @return the applicationSettings
128          */
129         public ApplicationSettings getApplicationSettings() {
130                 return _ApplicationSettings;
131         }
132
133         /**
134          * Set the applicationSettings.
135          * @param applicationSettings the applicationSettings to set
136          */
137         public void setApplicationSettings(ApplicationSettings applicationSettings) {
138                 _ApplicationSettings = applicationSettings;
139         }
140         
141         /**
142          * Get the menuProperty.
143          * @return the menuProperty
144          */
145         public String getMenuProperty() {
146                 return _menuProperty;
147         }
148
149         /**
150          * Set the menuProperty.
151          * @param menuProperty the menuProperty to set
152          */
153         public void setMenuProperty(String menuProperty) {
154                 this._menuProperty = menuProperty;
155         }
156         
157         /**
158          * Get the _titleProperty.
159          * @return the _titleProperty
160          */
161         public String getTitleProperty() {
162                 return _titleProperty;
163         }
164
165         /**
166          * Set the _titleProperty.
167          * @param _titleProperty the titleProperty to set
168          */
169         public void setTitleProperty(String titleProperty) {
170                 _titleProperty = titleProperty;
171         }
172
173         /**
174          * Get the editDisabledProperty.
175          * @return the editDisabledProperty
176          */
177         public final String getEditDisabledProperty() {
178                 return _editDisabledProperty;
179         }
180
181         /**
182          * Set the editDisabledProperty.
183          * @param editDisabledProperty the editDisabledProperty to set
184          */
185         public final void setEditDisabledProperty(String editDisabledProperty) {
186                 _editDisabledProperty = editDisabledProperty;
187         }
188 }