1 25 package org.ofbiz.webapp.control; 26 27 import java.io.Serializable ; 28 import java.net.URL ; 29 import java.util.Collection ; 30 import java.util.Map ; 31 import java.util.List ; 32 import java.util.LinkedList ; 33 import javax.servlet.ServletContext ; 34 35 import org.ofbiz.base.util.Debug; 36 import org.ofbiz.base.util.UtilValidate; 37 38 45 public class RequestManager implements Serializable { 46 47 public static final String module = RequestManager.class.getName(); 48 public static final int VIEW_HANDLER_KEY = 1; 49 public static final int EVENT_HANDLER_KEY = 0; 50 51 private URL configFileUrl; 52 53 public RequestManager(ServletContext context) { 54 55 56 try { 57 configFileUrl = context.getResource("/WEB-INF/controller.xml"); 58 } catch (Exception e) { 59 Debug.logError(e, "[RequestManager.constructor] Error Finding XML Config File: " + 60 "/WEB-INF/controller.xml", module); 61 } 62 ConfigXMLReader.getConfigMap(configFileUrl); 64 ConfigXMLReader.getHandlerMap(configFileUrl); 65 ConfigXMLReader.getRequestMap(configFileUrl); 66 ConfigXMLReader.getViewMap(configFileUrl); 67 } 68 69 70 public Map getHandlerMap() { 71 return (Map ) ConfigXMLReader.getHandlerMap(configFileUrl); 72 } 73 74 75 public String getHandlerClass(String name, int type) { 76 Map map = getHandlerMap(); 77 Map hMap = null; 78 79 if (type == 1) { 80 hMap = (Map ) map.get("view"); 81 } else { 82 hMap = (Map ) map.get("event"); 83 } 84 85 if (!hMap.containsKey(name)) { 86 return null; 87 } else { 88 return (String ) hMap.get(name); 89 } 90 } 91 92 public List getHandlerKeys(int type) { 93 Map map = getHandlerMap(); 94 Map hMap = null; 95 96 if (type == 1) { 97 hMap = (Map ) map.get("view"); 98 } else { 99 hMap = (Map ) map.get("event"); 100 } 101 102 if (hMap != null) { 103 return new LinkedList (hMap.keySet()); 104 } else { 105 return null; 106 } 107 } 108 109 public Map getRequestMapMap(String uriStr) { 110 if (UtilValidate.isNotEmpty(uriStr)) { 111 return (Map ) ConfigXMLReader.getRequestMap(configFileUrl).get(uriStr); 112 } else { 113 return null; 114 } 115 } 116 117 public String getRequestAttribute(String uriStr, String attribute) { 118 Map uri = getRequestMapMap(uriStr); 119 120 if (uri != null && attribute != null) { 121 return (String ) uri.get(attribute); 122 } else { 123 Debug.logInfo("[RequestManager.getRequestAttribute] Value for attribute \"" + attribute + 124 "\" of uri \"" + uriStr + "\" not found", module); 125 return null; 126 } 127 } 128 129 130 public String getEventPath(String uriStr) { 131 Map uri = getRequestMapMap(uriStr); 132 133 if (uri != null) 134 return (String ) uri.get(ConfigXMLReader.EVENT_PATH); 135 else { 136 Debug.logWarning("[RequestManager.getEventPath] Path of event for request \"" + uriStr + 137 "\" not found", module); 138 return null; 139 } 140 } 141 142 143 public String getEventType(String uriStr) { 144 Map uri = getRequestMapMap(uriStr); 145 146 if (uri != null) 147 return (String ) uri.get(ConfigXMLReader.EVENT_TYPE); 148 else { 149 Debug.logWarning("[RequestManager.getEventType] Type of event for request \"" + uriStr + 150 "\" not found", module); 151 return null; 152 } 153 } 154 155 156 public String getEventMethod(String uriStr) { 157 Map uri = getRequestMapMap(uriStr); 158 159 if (uri != null) { 160 return (String ) uri.get(ConfigXMLReader.EVENT_METHOD); 161 } else { 162 Debug.logWarning("[RequestManager.getEventMethod] Method of event for request \"" + 163 uriStr + "\" not found", module); 164 return null; 165 } 166 } 167 168 169 public boolean getEventGlobalTransaction(String uriStr) { 170 Map uri = getRequestMapMap(uriStr); 171 172 if (uri != null) { 173 return new Boolean ((String ) uri.get(ConfigXMLReader.EVENT_GLOBAL_TRANSACTION)).booleanValue(); 174 } else { 175 if (Debug.verboseOn()) { 176 Debug.logWarning("[RequestManager.getEventGlobalTransaction] Global-transaction of event for request \"" + 177 uriStr + "\" not found, defaulting to true", module); 178 } 179 return false; 180 } 181 } 182 183 184 public String getViewName(String uriStr) { 185 Map uri = getRequestMapMap(uriStr); 186 187 if (uri != null) 188 return (String ) uri.get(ConfigXMLReader.NEXT_PAGE); 189 else { 190 Debug.logWarning("[RequestManager.getViewName] View name for uri \"" + uriStr + "\" not found", module); 191 return null; 192 } 193 } 194 195 196 public String getViewPage(String viewStr) { 197 if (viewStr != null && viewStr.startsWith("view:")) viewStr = viewStr.substring(viewStr.indexOf(':') + 1); 198 Map page = (Map ) ConfigXMLReader.getViewMap(configFileUrl).get(viewStr); 199 200 if (page != null) { 201 return (String ) page.get(ConfigXMLReader.VIEW_PAGE); 202 } else { 203 Debug.logWarning("[RequestManager.getViewPage] View with name \"" + viewStr + "\" not found", module); 204 return null; 205 } 206 } 207 208 209 public String getViewType(String viewStr) { 210 Map view = (Map ) ConfigXMLReader.getViewMap(configFileUrl).get(viewStr); 211 212 if (view != null) { 213 return (String ) view.get(ConfigXMLReader.VIEW_TYPE); 214 } else { 215 Debug.logWarning("[RequestManager.getViewType] View with name \"" + viewStr + "\" not found", module); 216 return null; 217 } 218 } 219 220 221 public String getViewInfo(String viewStr) { 222 Map view = (Map ) ConfigXMLReader.getViewMap(configFileUrl).get(viewStr); 223 224 if (view != null) { 225 return (String ) view.get(ConfigXMLReader.VIEW_INFO); 226 } else { 227 Debug.logWarning("[RequestManager.getViewInfo] View with name \"" + viewStr + "\" not found", module); 228 return null; 229 } 230 } 231 232 233 public String getViewContentType(String viewStr) { 234 Map view = (Map ) ConfigXMLReader.getViewMap(configFileUrl).get(viewStr); 235 236 if (view != null) { 237 return (String ) view.get(ConfigXMLReader.VIEW_CONTENT_TYPE); 238 } else { 239 Debug.logWarning("[RequestManager.getViewInfo] View with name \"" + viewStr + "\" not found", module); 240 return null; 241 } 242 } 243 244 245 public String getViewEncoding(String viewStr) { 246 Map view = (Map ) ConfigXMLReader.getViewMap(configFileUrl).get(viewStr); 247 248 if (view != null) { 249 return (String ) view.get(ConfigXMLReader.VIEW_ENCODING); 250 } else { 251 Debug.logWarning("[RequestManager.getViewInfo] View with name \"" + viewStr + "\" not found", module); 252 return null; 253 } 254 } 255 256 257 public String getErrorPage(String uriStr) { 258 Map uri = getRequestMapMap(uriStr); 260 262 if (uri != null) { 263 String errorViewUri = (String ) uri.get(ConfigXMLReader.ERROR_PAGE); 264 String returnPage = getViewPage(errorViewUri); 266 268 if (returnPage != null) { 269 return returnPage; 270 } else { 271 return getDefaultErrorPage(); 272 } 273 } else { 274 return getDefaultErrorPage(); 275 } 276 } 277 278 279 public String getDefaultErrorPage() { 280 String errorPage = null; 281 errorPage = (String ) ConfigXMLReader.getConfigMap(configFileUrl).get(ConfigXMLReader.DEFAULT_ERROR_PAGE); 282 if (errorPage != null) return errorPage; 284 return "/error/error.jsp"; 285 } 286 287 public boolean requiresAuth(String uriStr) { 288 Map uri = getRequestMapMap(uriStr); 289 290 if (uri != null) { 291 String value = (String ) uri.get(ConfigXMLReader.SECURITY_AUTH); 292 293 if ("true".equalsIgnoreCase(value)) 295 return true; 296 else 297 return false; 298 } else 299 return false; 300 } 301 302 public boolean requiresHttps(String uriStr) { 303 Map uri = getRequestMapMap(uriStr); 304 305 if (uri != null) { 306 String value = (String ) uri.get(ConfigXMLReader.SECURITY_HTTPS); 307 308 if ("true".equalsIgnoreCase(value)) 310 return true; 311 else 312 return false; 313 } else 314 return false; 315 } 316 317 public boolean allowExtView(String uriStr) { 318 Map uri = getRequestMapMap(uriStr); 319 320 if (uri != null) { 321 String value = (String ) uri.get(ConfigXMLReader.SECURITY_EXTVIEW); 322 323 if ("false".equalsIgnoreCase(value)) 325 return false; 326 else 327 return true; 328 } else 329 return true; 330 } 331 332 public boolean allowDirectRequest(String uriStr) { 333 Map uri = getRequestMapMap(uriStr); 334 335 if (uri != null) { 336 String value = (String ) uri.get(ConfigXMLReader.SECURITY_DIRECT); 337 338 if ("false".equalsIgnoreCase(value)) 340 return false; 341 else 342 return true; 343 } else 344 return false; 345 } 346 347 public Collection getFirstVisitEvents() { 348 Collection c = (Collection ) ConfigXMLReader.getConfigMap(configFileUrl).get(ConfigXMLReader.FIRSTVISIT); 349 return c; 350 } 351 352 public Collection getPreProcessor() { 353 Collection c = (Collection ) ConfigXMLReader.getConfigMap(configFileUrl).get(ConfigXMLReader.PREPROCESSOR); 354 return c; 355 } 356 357 public Collection getPostProcessor() { 358 Collection c = (Collection ) ConfigXMLReader.getConfigMap(configFileUrl).get(ConfigXMLReader.POSTPROCESSOR); 359 return c; 360 } 361 362 public List getAfterLoginEventList() { 363 List lst = (List ) ConfigXMLReader.getConfigMap(configFileUrl).get("after-login"); 364 return lst; 365 } 366 367 public List getBeforeLogoutEventList() { 368 List lst = (List ) ConfigXMLReader.getConfigMap(configFileUrl).get("before-logout"); 369 return lst; 370 } 371 } 372 | Popular Tags |