1 12 package org.openbravo.base.secureApp; 13 14 import javax.servlet.http.*; 15 import org.apache.log4j.Logger ; 16 17 public class VariablesHistory { 18 private String currentHistoryIndex; 19 private static final int reqHistoryLength = 10; 20 HttpSession session; 21 private String role; 22 private String language; 23 private String dbSessionID; 24 static Logger log4j = Logger.getLogger(VariablesHistory.class); 25 26 public VariablesHistory(HttpServletRequest request) { 27 this.session = request.getSession(true); 28 this.currentHistoryIndex = getSessionValue("reqHistory.current", "0"); 29 this.role = getSessionValue("#AD_Role_ID"); 30 this.language = getSessionValue("#AD_Language"); 31 this.dbSessionID = getSessionValue("#AD_Session_ID"); 32 } 33 34 public String getCurrentHistoryIndex() { 35 return Integer.toString(Integer.valueOf(this.currentHistoryIndex).intValue()%reqHistoryLength); 36 } 37 38 public void upCurrentHistoryIndex() { 39 this.currentHistoryIndex = Integer.toString(Integer.valueOf(this.currentHistoryIndex).intValue() + 1); 40 setSessionValue("reqHistory.current", this.currentHistoryIndex); 41 } 42 43 public void downCurrentHistoryIndex() { 44 this.currentHistoryIndex = Integer.toString(Integer.valueOf(this.currentHistoryIndex).intValue() - 1); 45 setSessionValue("reqHistory.current", this.currentHistoryIndex); 46 } 47 48 public String getCurrentServletPath(String defaultServletPath) { 49 return getSessionValue("reqHistory.path" + getCurrentHistoryIndex(), defaultServletPath); 50 } 51 public String getCurrentServletCommand() { 52 return getSessionValue("reqHistory.command" + getCurrentHistoryIndex(), "DEFAULT"); 53 } 54 55 public String getSessionValue(String sessionAttribute) { 56 return getSessionValue(sessionAttribute, ""); 57 } 58 59 public String getSessionValue(String sessionAttribute, String defaultValue) { 60 String auxStr = null; 61 try { 62 auxStr = (String ) session.getAttribute(sessionAttribute.toUpperCase()); 63 if (auxStr==null || auxStr.trim().equals("")) 64 auxStr = defaultValue; 65 } 66 catch (Exception e) { 67 auxStr = defaultValue; 68 } 69 if (!sessionAttribute.equalsIgnoreCase("menuVertical")) if (log4j.isDebugEnabled()) log4j.debug("Session attribute: " + sessionAttribute + ":..." + auxStr); 70 return auxStr; 71 } 72 73 public void setSessionValue(String attribute, String value) { 74 try { 75 session.setAttribute(attribute.toUpperCase(), value); 76 if (!attribute.equalsIgnoreCase("menuVertical")) if (log4j.isDebugEnabled()) log4j.debug("session value: " + attribute + ":..." + value.toString()); 77 } 78 catch (Exception e) { 79 log4j.error("setSessionValue error: " + attribute + ":..." + value); 80 } 81 } 82 83 public void removeSessionValue(String attribute) { 84 try { 85 session.removeAttribute(attribute.toUpperCase()); 86 } 87 catch (Exception e) { 88 log4j.error("removeSessionValue error: " + attribute); 89 } 90 } 91 92 public String getRole() { 93 return role; 94 } 95 96 public String getLanguage() { 97 return language; 98 } 99 100 public String getDBSession() { 101 return dbSessionID; 102 } 103 } 104 | Popular Tags |