KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_actionButton > ClearSession


1 /*
2  *************************************************************************
3  * The contents of this file are subject to the Openbravo Public License
4  * Version 1.0 (the "License"), being the Mozilla Public License
5  * Version 1.1 with a permitted attribution clause; you may not use this
6  * file except in compliance with the License. You may obtain a copy of
7  * the License at http://www.openbravo.com/legal/license.html
8  * Software distributed under the License is distributed on an "AS IS"
9  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
10  * License for the specific language governing rights and limitations
11  * under the License.
12  * The Original Code is Openbravo ERP.
13  * The Initial Developer of the Original Code is Openbravo SL
14  * All portions are Copyright (C) 2001-2006 Openbravo SL
15  * All Rights Reserved.
16  * Contributor(s): ______________________________________.
17  ************************************************************************
18 */

19 package org.openbravo.erpCommon.ad_actionButton;
20
21 import org.openbravo.base.secureApp.LoginUtils;
22 import org.openbravo.xmlEngine.XmlDocument;
23 import org.openbravo.erpCommon.utility.Utility;
24
25 import org.openbravo.base.secureApp.HttpSecureAppServlet;
26 import org.openbravo.base.secureApp.VariablesSecureApp;
27
28
29 import java.io.*;
30 import javax.servlet.*;
31 import javax.servlet.http.*;
32
33
34 public class ClearSession extends HttpSecureAppServlet {
35
36   public void init (ServletConfig config) {
37     super.init(config);
38     boolHist = false;
39   }
40
41   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
42     VariablesSecureApp vars = new VariablesSecureApp(request);
43
44     if (vars.commandIn("DEFAULT")) {
45       printPage(response, vars);
46     } else if (vars.commandIn("CLEAR")) {
47       clear(response, vars);
48     } else pageErrorPopUp(response);
49   }
50
51   void printPage(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
52     log4j.debug("Output: clear");
53     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/ClearSession").createXmlDocument();
54     response.setContentType("text/html; charset=UTF-8");
55     PrintWriter out = response.getWriter();
56     out.println(xmlDocument.print());
57     out.close();
58   }
59
60   void clear(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
61     log4j.debug("process");
62
63       String JavaDoc strRol = vars.getSessionValue("role");
64       String JavaDoc strClient = vars.getSessionValue("client");
65       String JavaDoc strOrg = vars.getSessionValue("organization");
66       String JavaDoc strWarehouse = vars.getSessionValue("warehouse");
67
68
69     String JavaDoc user = vars.getSessionValue("#AD_User_ID");
70     String JavaDoc role = vars.getSessionValue("#AD_Role_ID");
71     String JavaDoc language = vars.getSessionValue("#AD_Language");
72     String JavaDoc client = vars.getSessionValue("#AD_Client_ID");
73     String JavaDoc organization = vars.getSessionValue("#AD_Org_ID");
74     String JavaDoc userClient = vars.getSessionValue("#User_Client");
75     String JavaDoc userOrganization = vars.getSessionValue("#User_Org");
76     String JavaDoc warehouse = vars.getSessionValue("#M_Warehouse_ID");
77     String JavaDoc dbSessionID = vars.getSessionValue("#AD_Session_ID");
78    
79
80       vars.clearSession(false);
81
82     vars.setSessionValue("#AD_User_ID",user);
83     vars.setSessionValue("#AD_Role_ID",role);
84     vars.setSessionValue("#AD_Language",language);
85     vars.setSessionValue("#AD_Client_ID",client);
86     vars.setSessionValue("#AD_Org_ID",organization);
87     vars.setSessionValue("#User_Client",userClient);
88     vars.setSessionValue("#User_Org",userOrganization);
89     vars.setSessionValue("#M_Warehouse_ID",warehouse);
90     vars.setSessionValue("#AD_Session_ID",dbSessionID);
91
92       vars.setSessionValue("role",strRol);
93       vars.setSessionValue("client",strClient);
94       vars.setSessionValue("strOrg",strOrg);
95       vars.setSessionValue("warehouse",strWarehouse);
96
97      if (log4j.isDebugEnabled()) log4j.debug("role:"+role
98                                             + ",client:"+client
99                                             + ",strOrg:"+organization
100                                             + ",warehouse:"+warehouse);
101
102
103
104
105
106     
107     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/ClearSession").createXmlDocument();
108     response.setContentType("text/html; charset=UTF-8");
109     PrintWriter out = response.getWriter();
110    
111     String JavaDoc strMessage;
112
113     if (!LoginUtils.fillSessionArguments(this, vars, user , vars.getLanguage(), role, client, organization, warehouse))
114       strMessage = Utility.messageBD(this, "ProcessFailed", vars.getLanguage());
115     else
116       strMessage = Utility.messageBD(this, "Success", vars.getLanguage());
117
118     xmlDocument.setParameter("message",strMessage.equals("")?"":"alert('" + strMessage + "');window.close();");
119     out.println(xmlDocument.print());
120     out.close();
121   }
122 }
123
124
Popular Tags