KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > engines > users > EditUserPreferences_Engine


1 package org.jahia.engines.users;
2
3 import java.util.HashMap JavaDoc;
4
5 import javax.servlet.http.HttpSession JavaDoc;
6
7 import org.jahia.data.JahiaData;
8 import org.jahia.engines.EngineToolBox;
9 import org.jahia.engines.JahiaEngine;
10 import org.jahia.exceptions.JahiaException;
11 import org.jahia.exceptions.JahiaSessionExpirationException;
12 import org.jahia.params.ParamBean;
13
14 /**
15  * <p>Title: User preference edition engine</p> <p>Description: This engine allows the edition
16  * of the user preferences such as the user's personal settings, password and also language
17  * preferences </p> <p>Copyright: Copyright (c) 2002</p> <p>Company: Jahia Ltd</p>
18  *
19  * @author Serge Huber
20  * @version 1.0
21  */

22
23 public class EditUserPreferences_Engine implements JahiaEngine {
24
25     private static final String JavaDoc TEMPLATE_JSP = "edituserpreferences";
26     private static final String JavaDoc CLOSE_JSP = "selectusers_close";
27     private static EditUserPreferences_Engine instance = null;
28     public static final String JavaDoc ENGINE_NAME = "edituserpreferences";
29     private EngineToolBox toolBox;
30
31     /** logging */
32     private static final org.apache.log4j.Logger logger =
33             org.apache.log4j.Logger.getLogger (EditUserPreferences_Engine.class);
34
35     /**
36      * Private constructor for singleton pattern
37      */

38     private EditUserPreferences_Engine () {
39         logger.debug ("***** Starting " + EditUserPreferences_Engine.class.getName () +
40                 " engine *****");
41         toolBox = EngineToolBox.getInstance ();
42     }
43
44     /**
45      * Returns the singleton instance
46      *
47      * @return EditUserPreferences_Engine the singleton object instance.
48      */

49     public static synchronized EditUserPreferences_Engine getInstance () {
50         if (instance == null) {
51             instance = new EditUserPreferences_Engine ();
52         }
53         return instance;
54     }
55
56     /**
57      * Check if we have the rights to view this engine
58      *
59      * @param jParams ParamBean object
60      *
61      * @return boolean if we are allowed to render this engine, false otherwise
62      */

63     public boolean authoriseRender (ParamBean jParams) {
64         return toolBox.authoriseRender (jParams);
65     }
66
67     /**
68      * Renders a link to this engine.
69      *
70      * @param jParams ParamBean object to be used to generate URL.
71      * @param theObj the target object on which we want to process this engine
72      *
73      * @return a String containing an URL to this engine
74      *
75      * @throws JahiaException
76      */

77     public String JavaDoc renderLink (ParamBean jParams, Object JavaDoc theObj)
78             throws JahiaException {
79         String JavaDoc rightParams = (String JavaDoc) theObj;
80         String JavaDoc params = EMPTY_STRING;
81         params += "?mode=display&screen=edit";
82         params += rightParams;
83         return jParams.composeEngineUrl (ENGINE_NAME, params);
84     }
85
86     /**
87      * needsJahiaData
88      *
89      * @param jParams the current ParamBean
90      *
91      * @return true if the engine requires a JahiaData object to be constructed before
92      * dispatching to it.
93      */

94     public boolean needsJahiaData (ParamBean jParams) {
95         return false;
96     }
97
98     /**
99      * handles the engine actions
100      *
101      * @param jParams a ParamBean object
102      * @param jData a JahiaData object (not mandatory)
103      *
104      * @throws JahiaException if there is an error processing input parameters
105      * @throws JahiaSessionExpirationException
106      * if the session has expired while processing input actions
107      */

108     public void handleActions (ParamBean jParams, JahiaData jData)
109             throws JahiaException,
110             JahiaSessionExpirationException {
111         // initalizes the hashmap
112
HashMap JavaDoc engineMap = initEngineMap (jParams);
113
114         processLastScreen (jParams, engineMap);
115         processCurrentScreen (jParams, engineMap);
116
117         // displays the screen
118
toolBox.displayScreen (jParams, engineMap);
119
120     }
121
122     /**
123      * Retrieve the engine name.
124      *
125      * @return the engine name.
126      */

127     public final String JavaDoc getName () {
128         return ENGINE_NAME;
129     }
130
131     /**
132      * processes the last screen sent by the user
133      *
134      * @param jParams a ParamBean object
135      * @param engineMap the engineMap object containing the current engine state
136      *
137      * @throws JahiaException if there is an error processing input parameters
138      */

139     public void processLastScreen (ParamBean jParams, HashMap JavaDoc engineMap)
140             throws JahiaException {
141         // gets engineMap values
142
String JavaDoc theScreen = (String JavaDoc) engineMap.get ("screen");
143         if (theScreen == null) {
144             throw new JahiaException ("EditUserPreferences_Engine.processLastScreen",
145                     "Error in parameters",
146                     JahiaException.PARAMETER_ERROR,
147                     JahiaException.CRITICAL_SEVERITY);
148         }
149         if (theScreen.equals ("edit")) {
150         } else if (theScreen.equals ("save")) {
151         }
152     }
153
154     /**
155      * prepares the screen requested by the user
156      *
157      * @param jParams a ParamBean object
158      * @param engineMap the engineMap object containing the current engine state
159      *
160      * @throws JahiaException if there is an error processing input parameters
161      */

162     public void processCurrentScreen (ParamBean jParams, HashMap JavaDoc engineMap)
163             throws JahiaException {
164         String JavaDoc theScreen = (String JavaDoc) engineMap.get ("screen");
165
166         jParams.getRequest ().setAttribute ("jahia_session_engineMap", engineMap);
167
168     }
169
170     /**
171      * inits the engine map
172      *
173      * @param jParams a ParamBean object (with request and response)
174      *
175      * @return a HashMap object containing all the basic values needed by an engine
176      *
177      * @throws JahiaException if there is an error building the current engineMap
178      * @throws JahiaSessionExpirationException
179      * if the session has expired while processing input actions
180      */

181     private HashMap JavaDoc initEngineMap (ParamBean jParams)
182             throws JahiaException,
183             JahiaSessionExpirationException {
184         String JavaDoc theScreen = jParams.getRequest ().getParameter ("screen");
185
186         // gets session values
187
//HttpSession theSession = jParams.getRequest().getSession (true);
188
HttpSession JavaDoc theSession = jParams.getSession ();
189
190         HashMap JavaDoc engineMap = (HashMap JavaDoc) theSession.getAttribute (
191                 "jahia_session_engineMap");
192
193         if (engineMap == null) {
194             theScreen = "edit";
195             // init engine map
196
engineMap = new HashMap JavaDoc ();
197         }
198         engineMap.put (RENDER_TYPE_PARAM, new Integer JavaDoc (JahiaEngine.RENDERTYPE_FORWARD));
199         engineMap.put (ENGINE_NAME_PARAM, ENGINE_NAME);
200         engineMap.put (ENGINE_URL_PARAM, jParams.composeEngineUrl (ENGINE_NAME));
201         engineMap.put ("selectUGEngine", "selectGroups");
202         theSession.setAttribute ("jahia_session_engineMap", engineMap);
203
204         if (theScreen == null) {
205             theScreen = "edit";
206         }
207
208         // sets screen
209
engineMap.put ("screen", theScreen);
210         if (theScreen.equals ("cancel")) {
211             engineMap.put ("jspSource", CLOSE_JSP);
212         } else if (theScreen.equals ("save")) {
213             engineMap.put ("jspSource", CLOSE_JSP);
214         } else {
215             engineMap.put ("jspSource", TEMPLATE_JSP);
216         }
217
218         // sets engineMap for JSPs
219
jParams.getRequest ().setAttribute ("engineTitle", "Edit user preferences");
220         jParams.getRequest ().setAttribute ("org.jahia.engines.EngineHashMap",
221                 engineMap);
222
223         return engineMap;
224     }
225
226 }
227
Popular Tags