KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > security > Login


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.security;
20
21 import org.openbravo.base.HttpBaseServlet;
22 import org.openbravo.base.secureApp.VariablesSecureApp;
23 import org.openbravo.xmlEngine.XmlDocument;
24
25
26 import java.io.*;
27 import javax.servlet.*;
28 import javax.servlet.http.*;
29
30 import org.openbravo.erpCommon.ad_combos.LanguageComboData;
31 import org.openbravo.erpCommon.ad_combos.RoleComboData;
32 import org.openbravo.erpCommon.ad_combos.ClientComboData;
33 import org.openbravo.erpCommon.ad_combos.OrganizationComboData;
34 import org.openbravo.erpCommon.ad_combos.WarehouseComboData;
35 import org.openbravo.erpCommon.utility.*;
36 import java.util.StringTokenizer JavaDoc;
37 import java.util.Vector JavaDoc;
38
39 public class Login extends HttpBaseServlet {
40
41   public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
42     VariablesSecureApp vars = new VariablesSecureApp(request);
43
44     if (vars.commandIn("LOGIN")) {
45       if (log4j.isDebugEnabled()) log4j.debug("Command: Login");
46       vars.clearSession(false);
47       printPageIdentificacion(response);
48
49 // } else if (vars.commandIn("OPTIONS")) {
50
// if (vars.getUser().equals("")) printPageIdentificacion(response);
51
// else printPageOptions(response, vars);
52

53     } else if (vars.commandIn("BLANK")) {
54       printPageBlank(response);
55     } else if (vars.commandIn("WELCOME")) {
56       if (log4j.isDebugEnabled()) log4j.debug("Command: Welcome");
57       printPageWelcome(response);
58     } else if (vars.commandIn("LOGO")) {
59       printPageLogo(response);
60
61 // } else if (vars.commandIn("LOGED")) {
62
// String target = vars.getSessionValue("target");
63
// printPageFrameIdentificacion(response, "../utility/VerticalMenu.html", (target.equals("")?"../utility/Home.html":target));
64
//
65
// } else if (vars.commandIn("CLOSE_SESSION")) {
66
// vars.clearSession(true);
67
// if (log4j.isDebugEnabled()) log4j.debug("Cerrando session");
68
// if (!vars.getDBSession().equals("")) SessionLoginData.saveProcessed(this, vars.getUser(), vars.getDBSession());
69
// response.sendRedirect(strDireccion + request.getServletPath());
70

71     } else {
72       printPageFrameIdentificacion(response, "Login_Welcome.html?Command=WELCOME", "Login_F1.html?Command=LOGIN");
73     }
74   }
75
76   public void printPageFrameIdentificacion(HttpServletResponse response, String JavaDoc strMenu, String JavaDoc strDetalle) throws IOException, ServletException {
77     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/security/Login_FS").createXmlDocument();
78
79     xmlDocument.setParameter("frameMenu", strMenu);
80     xmlDocument.setParameter("frame1", strDetalle);
81     response.setContentType("text/html; charset=UTF-8");
82     PrintWriter out = response.getWriter();
83     out.println(xmlDocument.print());
84     out.close();
85   }
86
87   public void printPageBlank(HttpServletResponse response) throws IOException, ServletException {
88     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/security/Login_F0").createXmlDocument();
89
90     response.setContentType("text/html; charset=UTF-8");
91     PrintWriter out = response.getWriter();
92     out.println(xmlDocument.print());
93     out.close();
94   }
95
96   public void printPageWelcome(HttpServletResponse response) throws IOException, ServletException {
97     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/security/Login_Welcome").createXmlDocument();
98
99     response.setContentType("text/html; charset=UTF-8");
100     PrintWriter out = response.getWriter();
101     out.println(xmlDocument.print());
102     out.close();
103   }
104
105   public void printPageLogo(HttpServletResponse response) throws IOException, ServletException {
106     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/security/Login_Logo").createXmlDocument();
107
108     response.setContentType("text/html; charset=UTF-8");
109     PrintWriter out = response.getWriter();
110     out.println(xmlDocument.print());
111     out.close();
112   }
113
114   public void printPageIdentificacion(HttpServletResponse response) throws IOException, ServletException {
115     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/security/Login_F1").createXmlDocument();
116
117     response.setContentType("text/html; charset=UTF-8");
118     PrintWriter out = response.getWriter();
119     out.println(xmlDocument.print());
120     out.close();
121   }
122
123   void goToRetry(HttpServletResponse res) throws IOException {
124     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/base/secureApp/HtmlErrorLogin").createXmlDocument();
125
126     res.setContentType("text/html");
127     PrintWriter out = res.getWriter();
128     out.println(xmlDocument.print());
129     out.close();
130   }
131
132 // public void printPageOptions(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
133
// XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/security/Login_Options_F1").createXmlDocument();
134
//
135
// RoleComboData[] data = RoleComboData.select(this, vars.getUser());
136
// if (data==null || data.length==0) {
137
// goToRetry(response);
138
// return;
139
// }
140
// xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
141
// ClientData[] clients = null;
142
// {
143
// ClientData[] data1 = ClientData.select(this);
144
// if (data1==null || data1.length==0) {
145
// bdError(response, "NoClientLogin", vars.getLanguage());
146
// return;
147
// } else {
148
// Vector<Object> vecClients = new Vector<Object>();
149
// for (int i=0;i<data.length;i++) {
150
// StringTokenizer st = new StringTokenizer(data[i].clientlist, ",", false);
151
//
152
// while (st.hasMoreTokens()) {
153
// String token = st.nextToken().trim();
154
// ClientData auxClient = new ClientData();
155
// auxClient.padre = data[i].adRoleId;
156
// auxClient.id = token;
157
// auxClient.name = getDescriptionFromArray(data1, token);
158
// vecClients.addElement(auxClient);
159
// }
160
// }
161
// clients = new ClientData[vecClients.size()];
162
// vecClients.copyInto(clients);
163
// }
164
// xmlDocument.setParameter("clientes", arrayDobleEntrada("arrClientes", clients));
165
// }
166
// {
167
// OrganizationData[] data1 = OrganizationData.select(this);
168
// if (data1==null || data1.length==0) {
169
// bdError(response, "NoOrgLogin", vars.getLanguage());
170
// return;
171
// }
172
// xmlDocument.setParameter("organizaciones", arrayDobleEntrada("arrOrgs", data1));
173
// }
174
// xmlDocument.setParameter("warehouses", arrayDobleEntrada("arrWare", WarehouseData.select(this)));
175
// xmlDocument.setData("structureRol", data);
176
// ClientComboData[] clientCombo = null;
177
// {
178
// Vector<Object> vecClientCombo = new Vector<Object>();
179
// for (int i=0;i<clients.length;i++) {
180
// if (clients[i].padre.equals(data[0].adRoleId)) {
181
// ClientComboData auxCombo = new ClientComboData();
182
// auxCombo.adClientId = clients[i].id;
183
// auxCombo.name = clients[i].name;
184
// vecClientCombo.addElement(auxCombo);
185
// }
186
// }
187
// clientCombo = new ClientComboData[vecClientCombo.size()];
188
// vecClientCombo.copyInto(clientCombo);
189
// }
190
// xmlDocument.setData("structureCliente", clientCombo);
191
// xmlDocument.setData("structureOrganizacion", OrganizationComboData.select(this, data[0].adRoleId));
192
// xmlDocument.setData("structureAlmacen", WarehouseComboData.select(this, data[0].adRoleId, data[0].adClientId));
193
//
194
// response.setContentType("text/html; charset=UTF-8");
195
// PrintWriter out = response.getWriter();
196
// out.println(xmlDocument.print());
197
// out.close();
198
// }
199

200   public void bdError(HttpServletResponse response, String JavaDoc strCode, String JavaDoc strLanguage) throws IOException {
201     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/base/secureApp/Error").createXmlDocument();
202
203     xmlDocument.setParameter("ParamTitulo", strCode);
204     xmlDocument.setParameter("ParamTexto", Utility.messageBD(this, strCode, strLanguage));
205     response.setContentType("text/html; charset=UTF-8");
206     PrintWriter out = response.getWriter();
207     out.println(xmlDocument.print());
208     out.close();
209   }
210
211   private String JavaDoc getDescriptionFromArray(ClientData[] data, String JavaDoc clave) {
212     if (data==null || data.length==0) return "";
213     for (int i=0;i<data.length;i++) {
214       if (data[i].id.equalsIgnoreCase(clave)) return data[i].name;
215     }
216     return "";
217   }
218
219   public String JavaDoc getServletInfo() {
220     return "Login servlet";
221   }
222 }
223
Popular Tags