KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > info > Location


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.info;
20
21 import org.openbravo.erpCommon.utility.SequenceIdData;
22 import org.openbravo.base.secureApp.*;
23 import org.openbravo.xmlEngine.XmlDocument;
24 import org.openbravo.erpCommon.utility.ComboTableData;
25 import java.io.*;
26 import javax.servlet.*;
27 import javax.servlet.http.*;
28 import org.openbravo.utils.Replace;
29
30 import org.openbravo.erpCommon.utility.Utility;
31
32
33 public class Location extends HttpSecureAppServlet {
34   
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       String JavaDoc strcLocationId = vars.getRequestGlobalVariable("inpIDValue", "Location.inpcLocationId");
46       //String strcLocationId = vars.getRequestGlobalVariable("inpNameValue", "Location.inpcLocationId");
47
String JavaDoc strWindow = vars.getRequestGlobalVariable("inpwindowId", "Location.inpwindowId");
48       printPageFS(response, vars);
49     } else if (vars.commandIn("KEY")) {
50       String JavaDoc strcLocationId = vars.getStringParameter("inpIDValue");
51       //String strcLocationId = vars.getStringParameter("inpNameValue");
52
if (log4j.isDebugEnabled()) log4j.debug("1 Location: "+strcLocationId);
53       LocationSearchData[] data = LocationSearchData.select(this, strcLocationId);
54       if (data!=null && data.length==1) {
55         printPageKey(response, vars, data[0]);
56       } else {
57         vars.setSessionValue("Location.inpcLocationId", strcLocationId);
58         String JavaDoc strWindow = vars.getRequestGlobalVariable("inpwindowId", "Location.inpwindowId");
59         printPageFS(response, vars);
60       }
61     } else if (vars.commandIn("FRAME1")) {
62       String JavaDoc strcLocationId = vars.getSessionValue("Location.inpcLocationId");
63       vars.removeSessionValue("Location.inpcLocationId");
64       String JavaDoc strWindow = vars.getSessionValue("Location.inpwindowId");
65       vars.removeSessionValue("Location.inpwindowId");
66       printPageSheet(response, vars, strcLocationId, strWindow);
67     } else if (vars.commandIn("SAVE_NEW")) {
68       LocationSearchData data = getEditVariables(vars);
69       String JavaDoc strSequence = SequenceIdData.getSequence(this, "C_Location", vars.getClient());
70       log4j.error("Sequence: " + strSequence);
71       data.cLocationId = strSequence;
72       data.insert(this);
73       data.name = LocationSearchData.locationAddress(this, data.cLocationId);
74       printPageKey(response, vars, data);
75     } else if (vars.commandIn("SAVE_EDIT")) {
76       LocationSearchData data = getEditVariables(vars);
77       data.update(this);
78       data.name = LocationSearchData.locationAddress(this, data.cLocationId);
79       printPageKey(response, vars, data);
80     } else if (vars.commandIn("OBTENER_ARRAY")) {
81       String JavaDoc strcCountryId = vars.getStringParameter("inpcCountryId");
82       String JavaDoc strWindow = vars.getSessionValue("Location.inpwindowId");
83       printPageF2(response, vars, strcCountryId, strWindow);
84     } else pageError(response);
85   }
86
87
88 LocationSearchData getEditVariables(VariablesSecureApp vars) {
89     LocationSearchData data = new LocationSearchData();
90     data.cLocationId = vars.getStringParameter("inpCLocationId");
91     data.adClientId = vars.getClient();
92     data.adOrgId = vars.getOrg();
93     data.createdby = vars.getUser();
94     data.updatedby = vars.getUser();
95     data.cCountryId = vars.getStringParameter("inpcCountryId");
96     data.cRegionId = vars.getStringParameter("inpCRegionId");
97     data.address1 = vars.getStringParameter("inpAddress1");
98     data.address2 = vars.getStringParameter("inpAddress2");
99     data.postal = vars.getStringParameter("inpPostal");
100     data.city = vars.getStringParameter("inpCity");
101     return data;
102   }
103
104   void printPageKey(HttpServletResponse response, VariablesSecureApp vars, LocationSearchData data) throws IOException, ServletException {
105     if (log4j.isDebugEnabled()) log4j.debug("Output: Location seeker Frame Set");
106     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/SearchUniqueKeyResponse").createXmlDocument();
107
108     xmlDocument.setParameter("script", generateResult(data));
109     response.setContentType("text/html; charset=UTF-8");
110     PrintWriter out = response.getWriter();
111     out.println(xmlDocument.print());
112     out.close();
113   }
114
115   String JavaDoc generateResult(LocationSearchData data) throws IOException, ServletException {
116     StringBuffer JavaDoc html = new StringBuffer JavaDoc();
117     
118     html.append("\nfunction depurarSelector() {\n");
119     html.append("var clave = \"" + data.cLocationId + "\";\n");
120     html.append("var texto = \"" + Replace.replace(Replace.replace(data.name, "\\", "\\\\"), "\"", "\\\\\\\"") + "\";\n");
121     html.append("parent.opener.closeSearch(\"SAVE\", clave, texto);\n");
122     html.append("}\n");
123     return html.toString();
124   }
125
126   void printPageFS(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
127     if (log4j.isDebugEnabled()) log4j.debug("Output: FS Locations seeker");
128     
129     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Location_FS").createXmlDocument();
130     
131     response.setContentType("text/html; charset=UTF-8");
132     PrintWriter out = response.getWriter();
133     out.println(xmlDocument.print());
134     out.close();
135   }
136
137
138   void printPageSheet(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strcLocationId, String JavaDoc strWindow) throws IOException, ServletException {
139     if (log4j.isDebugEnabled()) log4j.debug("Output: F1 Locations seeker");
140     XmlDocument xmlDocument;
141
142     LocationSearchData[] data;
143
144     if (strcLocationId.equals("")) {
145       String JavaDoc[] discard = {"sectionDetail"};
146       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Location_F1").createXmlDocument();
147       xmlDocument.setParameter("Command","NEW");
148       data = LocationSearchData.set(Utility.getDefault(this, vars, "C_Country_ID", "", strWindow, ""));
149     } else {
150       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Location_F1").createXmlDocument();
151       xmlDocument.setParameter("Command","EDIT");
152       if (log4j.isDebugEnabled()) log4j.debug("2 Location: "+strcLocationId);
153       data = LocationSearchData.select(this, strcLocationId);
154     }
155     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
156     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
157     // Get the country id; default
158
xmlDocument.setData("structure1", data);
159     
160     try {
161       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_Country_ID", "", "", Utility.getContext(this, vars, "#User_Org", strWindow), Utility.getContext(this, vars, "#User_Client", strWindow), 0);
162       Utility.fillSQLParameters(this, vars, null, comboTableData, strWindow, data[0].cCountryId);
163       xmlDocument.setData("reportCountry","liststructure", comboTableData.select(false));
164       comboTableData = null;
165     } catch (Exception JavaDoc ex) {
166       throw new ServletException(ex);
167     }
168
169     try {
170       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_Region_ID", "", "C_Region of Country", Utility.getContext(this, vars, "#User_Org", strWindow), Utility.getContext(this, vars, "#User_Client", strWindow), 0);
171       Utility.fillSQLParameters(this, vars, data[0], comboTableData, strWindow, data[0].cRegionId);
172       xmlDocument.setData("reportRegion","liststructure", comboTableData.select(false));
173       comboTableData = null;
174     } catch (Exception JavaDoc ex) {
175       throw new ServletException(ex);
176     }
177
178
179     response.setContentType("text/html; charset=UTF-8");
180     PrintWriter out = response.getWriter();
181     out.println(xmlDocument.print());
182     out.close();
183   }
184
185   void printPageF2(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strcCountryId, String JavaDoc strWindow) throws IOException, ServletException {
186     if (log4j.isDebugEnabled()) log4j.debug("Output: F2 Locations seeker");
187     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Location_F2").createXmlDocument();
188     //Getcountry; default
189
try {
190       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_Region_ID", "", "C_Region of Country", Utility.getContext(this, vars, "#User_Org", strWindow), Utility.getContext(this, vars, "#User_Client", strWindow), 0);
191       Utility.fillSQLParameters(this, vars, null, comboTableData, strWindow, "");
192       xmlDocument.setParameter("array", arrayEntradaSimple("regions", comboTableData.select(false)));
193       comboTableData = null;
194     } catch (Exception JavaDoc ex) {
195       throw new ServletException(ex);
196     }
197
198     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
199     response.setContentType("text/html; charset=UTF-8");
200     PrintWriter out = response.getWriter();
201     out.println(xmlDocument.print());
202     out.close();
203   }
204
205   public String JavaDoc getServletInfo() {
206     return "Servlet that presents the Locations seeker";
207   } // end of getServletInfo() method
208
}
209
Popular Tags