KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > base > secureApp > VariablesHistory


1 /*
2  ************************************************************************************
3  * Copyright (C) 2001-2006 Openbravo S.L.
4  * Licensed under the Apache Software License version 2.0
5  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6  * Unless required by applicable law or agreed to in writing, software distributed
7  * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8  * CONDITIONS OF ANY KIND, either express or implied. See the License for the
9  * specific language governing permissions and limitations under the License.
10  ************************************************************************************
11 */

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 JavaDoc currentHistoryIndex;
19   private static final int reqHistoryLength = 10;
20   HttpSession session;
21   private String JavaDoc role;
22   private String JavaDoc language;
23   private String JavaDoc 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 JavaDoc 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 JavaDoc getCurrentServletPath(String JavaDoc defaultServletPath) {
49     return getSessionValue("reqHistory.path" + getCurrentHistoryIndex(), defaultServletPath);
50   }
51   public String JavaDoc getCurrentServletCommand() {
52     return getSessionValue("reqHistory.command" + getCurrentHistoryIndex(), "DEFAULT");
53   }
54
55   public String JavaDoc getSessionValue(String JavaDoc sessionAttribute) {
56     return getSessionValue(sessionAttribute, "");
57   }
58
59   public String JavaDoc getSessionValue(String JavaDoc sessionAttribute, String JavaDoc defaultValue) {
60     String JavaDoc auxStr = null;
61     try {
62       auxStr = (String JavaDoc) session.getAttribute(sessionAttribute.toUpperCase());
63       if (auxStr==null || auxStr.trim().equals(""))
64         auxStr = defaultValue;
65     }
66     catch (Exception JavaDoc 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 JavaDoc attribute, String JavaDoc 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 JavaDoc e) {
79       log4j.error("setSessionValue error: " + attribute + ":..." + value);
80     }
81   }
82
83   public void removeSessionValue(String JavaDoc attribute) {
84     try {
85       session.removeAttribute(attribute.toUpperCase());
86     }
87     catch (Exception JavaDoc e) {
88       log4j.error("removeSessionValue error: " + attribute);
89     }
90   }
91
92   public String JavaDoc getRole() {
93     return role;
94   }
95
96   public String JavaDoc getLanguage() {
97     return language;
98   }
99
100   public String JavaDoc getDBSession() {
101     return dbSessionID;
102   }
103 }
104
Popular Tags