1 package org.jahia.engines.users; 2 3 import java.util.HashMap ; 4 5 import javax.servlet.http.HttpSession ; 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 22 23 public class EditUserPreferences_Engine implements JahiaEngine { 24 25 private static final String TEMPLATE_JSP = "edituserpreferences"; 26 private static final String CLOSE_JSP = "selectusers_close"; 27 private static EditUserPreferences_Engine instance = null; 28 public static final String ENGINE_NAME = "edituserpreferences"; 29 private EngineToolBox toolBox; 30 31 32 private static final org.apache.log4j.Logger logger = 33 org.apache.log4j.Logger.getLogger (EditUserPreferences_Engine.class); 34 35 38 private EditUserPreferences_Engine () { 39 logger.debug ("***** Starting " + EditUserPreferences_Engine.class.getName () + 40 " engine *****"); 41 toolBox = EngineToolBox.getInstance (); 42 } 43 44 49 public static synchronized EditUserPreferences_Engine getInstance () { 50 if (instance == null) { 51 instance = new EditUserPreferences_Engine (); 52 } 53 return instance; 54 } 55 56 63 public boolean authoriseRender (ParamBean jParams) { 64 return toolBox.authoriseRender (jParams); 65 } 66 67 77 public String renderLink (ParamBean jParams, Object theObj) 78 throws JahiaException { 79 String rightParams = (String ) theObj; 80 String params = EMPTY_STRING; 81 params += "?mode=display&screen=edit"; 82 params += rightParams; 83 return jParams.composeEngineUrl (ENGINE_NAME, params); 84 } 85 86 94 public boolean needsJahiaData (ParamBean jParams) { 95 return false; 96 } 97 98 108 public void handleActions (ParamBean jParams, JahiaData jData) 109 throws JahiaException, 110 JahiaSessionExpirationException { 111 HashMap engineMap = initEngineMap (jParams); 113 114 processLastScreen (jParams, engineMap); 115 processCurrentScreen (jParams, engineMap); 116 117 toolBox.displayScreen (jParams, engineMap); 119 120 } 121 122 127 public final String getName () { 128 return ENGINE_NAME; 129 } 130 131 139 public void processLastScreen (ParamBean jParams, HashMap engineMap) 140 throws JahiaException { 141 String theScreen = (String ) 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 162 public void processCurrentScreen (ParamBean jParams, HashMap engineMap) 163 throws JahiaException { 164 String theScreen = (String ) engineMap.get ("screen"); 165 166 jParams.getRequest ().setAttribute ("jahia_session_engineMap", engineMap); 167 168 } 169 170 181 private HashMap initEngineMap (ParamBean jParams) 182 throws JahiaException, 183 JahiaSessionExpirationException { 184 String theScreen = jParams.getRequest ().getParameter ("screen"); 185 186 HttpSession theSession = jParams.getSession (); 189 190 HashMap engineMap = (HashMap ) theSession.getAttribute ( 191 "jahia_session_engineMap"); 192 193 if (engineMap == null) { 194 theScreen = "edit"; 195 engineMap = new HashMap (); 197 } 198 engineMap.put (RENDER_TYPE_PARAM, new Integer (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 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 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 |