KickJava   Java API By Example, From Geeks To Geeks.

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


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.base.secureApp.*;
22 import org.openbravo.xmlEngine.XmlDocument;
23 import org.openbravo.erpCommon.utility.Utility;
24 import java.io.*;
25 import javax.servlet.*;
26 import javax.servlet.http.*;
27 import org.openbravo.utils.Replace;
28
29
30
31 public class Locator extends HttpSecureAppServlet {
32   
33   
34   public void init (ServletConfig config) {
35     super.init(config);
36     boolHist = false;
37   }
38
39   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
40     VariablesSecureApp vars = new VariablesSecureApp(request);
41
42     if (vars.commandIn("DEFAULT")) {
43       String JavaDoc strNameValue = vars.getRequestGlobalVariable("inpNameValue", "Locator.name");
44       String JavaDoc strWarehouse = vars.getRequestGlobalVariable("inpmWarehouseId", "Locator.mWarehouseId");
45       vars.setSessionValue("Locator.warehousename", LocatorData.selectname(this, strWarehouse));
46       if (!strNameValue.equals("")) vars.setSessionValue("Locator.name", strNameValue + "%");
47       printPageFS(response, vars);
48     } else if (vars.commandIn("KEY")) {
49       String JavaDoc strKeyValue = vars.getRequestGlobalVariable("inpNameValue", "Locator.name");
50       String JavaDoc strWarehouse = vars.getRequestGlobalVariable("inpmWarehouseId", "Locator.mWarehouseId");
51       vars.setSessionValue("Locator.name", strKeyValue + "%");
52       vars.setSessionValue("Locator.warehousename", LocatorData.selectname(this, strWarehouse));
53       LocatorData[] data = LocatorData.selectKey(this, Utility.getContext(this, vars, "#User_Client", "Locator"), Utility.getContext(this, vars, "#User_Org", "Locator"), LocatorData.selectname(this, strWarehouse), strKeyValue + "%");
54       if (data!=null && data.length==1) {
55         printPageKey(response, vars, data);
56       } else printPageFS(response, vars);
57     } else if (vars.commandIn("FRAME1")) {
58       String JavaDoc strNameValue = vars.getGlobalVariable("inpName", "Locator.name", "");
59       String JavaDoc strWarehousename = vars.getGlobalVariable("inpWarehouse", "Locator.warehousename", "");
60       printPageFrame1(response, vars, strNameValue, strWarehousename);
61     } else if (vars.commandIn("FRAME2")) {
62       String JavaDoc strName = vars.getGlobalVariable("inpKey", "Locator.name", "");
63       String JavaDoc strWarehousename = vars.getGlobalVariable("inpWarehouse", "Locator.warehousename", "");
64       String JavaDoc strAisle = vars.getStringParameter("inpAisle");
65       String JavaDoc strBin = vars.getStringParameter("inpBin");
66       String JavaDoc strLevel = vars.getStringParameter("inpLevel");
67       printPageFrame2(response, vars, strName, strWarehousename, strAisle, strBin, strLevel);
68     } else if (vars.commandIn("FIND")) {
69       String JavaDoc strName = vars.getGlobalVariable("inpKey", "Locator.name", "");
70       String JavaDoc strWarehousename = vars.getGlobalVariable("inpWarehouse", "Locator.warehousename", "");
71       String JavaDoc strAisle = vars.getStringParameter("inpAisle");
72       String JavaDoc strBin = vars.getStringParameter("inpBin");
73       String JavaDoc strLevel = vars.getStringParameter("inpLevel");
74
75       vars.setSessionValue("Locator.initRecordNumber", "0");
76
77       printPageFrame2(response, vars, strName, strWarehousename, strAisle, strBin, strLevel);
78     } else if (vars.commandIn("FRAME3")) {
79       printPageFrame3(response, vars);
80     } else if (vars.commandIn("PREVIOUS")) {
81       String JavaDoc strInitRecord = vars.getSessionValue("Locator.initRecordNumber");
82       String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "Locator");
83       int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
84       if (strInitRecord.equals("") || strInitRecord.equals("0")) vars.setSessionValue("Locator.initRecordNumber", "0");
85       else {
86         int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
87         initRecord -= intRecordRange;
88         strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
89         vars.setSessionValue("Locator.initRecordNumber", strInitRecord);
90       }
91
92       response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2");
93     } else if (vars.commandIn("NEXT")) {
94       String JavaDoc strInitRecord = vars.getSessionValue("Locator.initRecordNumber");
95       String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "Locator");
96       int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
97       int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
98       if (initRecord==0) initRecord=1;
99       initRecord += intRecordRange;
100       strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
101       vars.setSessionValue("Locator.initRecordNumber", strInitRecord);
102
103       response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2");
104     } else pageError(response);
105   }
106
107   void printPageFS(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
108     if (log4j.isDebugEnabled()) log4j.debug("Output: Locators seeker Frame");
109     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Locator_FS").createXmlDocument();
110
111     response.setContentType("text/html; charset=UTF-8");
112     PrintWriter out = response.getWriter();
113     out.println(xmlDocument.print());
114     out.close();
115   }
116
117   void printPageKey(HttpServletResponse response, VariablesSecureApp vars, LocatorData[] data) throws IOException, ServletException {
118     if (log4j.isDebugEnabled()) log4j.debug("Output: Locators seeker Frame Set");
119     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/SearchUniqueKeyResponse").createXmlDocument();
120
121     xmlDocument.setParameter("script", generateResult(data));
122     response.setContentType("text/html; charset=UTF-8");
123     PrintWriter out = response.getWriter();
124     out.println(xmlDocument.print());
125     out.close();
126   }
127
128   String JavaDoc generateResult(LocatorData[] data) throws IOException, ServletException {
129     StringBuffer JavaDoc html = new StringBuffer JavaDoc();
130     
131     html.append("\nfunction depurarSelector() {\n");
132     html.append("var clave = \"" + data[0].mLocatorId + "\";\n");
133     html.append("var texto = \"" + Replace.replace(data[0].value, "\"", "\\\"") + "\";\n");
134     html.append("parent.opener.closeSearch(\"SAVE\", clave, texto);\n");
135     html.append("}\n");
136     return html.toString();
137   }
138
139   void printPageFrame1(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strNameValue, String JavaDoc strWarehousename) throws IOException, ServletException {
140     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 1 of Locators seeker");
141     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Locator_F1").createXmlDocument();
142     if (strNameValue.equals("")) {
143       xmlDocument.setParameter("key", "%");
144     } else {
145       xmlDocument.setParameter("key", strNameValue);
146     }
147     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
148     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
149     xmlDocument.setParameter("warehouse", strWarehousename);
150     response.setContentType("text/html; charset=UTF-8");
151     PrintWriter out = response.getWriter();
152     out.println(xmlDocument.print());
153     out.close();
154   }
155
156   void printPageFrame2(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strName, String JavaDoc strWarehousename, String JavaDoc strAisle, String JavaDoc strBin, String JavaDoc strLevel) throws IOException, ServletException {
157     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 2 of Locators seeker");
158     XmlDocument xmlDocument;
159
160     String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "Locator");
161     int intRecordRange = (strRecordRange.equals("")?0:Integer.parseInt(strRecordRange));
162     String JavaDoc strInitRecord = vars.getSessionValue("Locator.initRecordNumber");
163     int initRecordNumber = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
164
165     if (strName.equals("") && strWarehousename.equals("") && strAisle.equals("") && strBin.equals("") && strLevel.equals("")) {
166       String JavaDoc[] discard = {"sectionDetail", "hasPrevious", "hasNext"};
167       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Locator_F2", discard).createXmlDocument();
168       xmlDocument.setData("structure1", LocatorData.set());
169     } else {
170       String JavaDoc[] discard = {"withoutPrevious", "withoutNext"};
171       LocatorData[] data = LocatorData.select(this, vars.getLanguage(), Utility.getContext(this, vars, "#User_Client", "Locator"), Utility.getContext(this, vars, "#User_Org", "Locator"), strName, strWarehousename, strAisle, strBin, strLevel, initRecordNumber, intRecordRange);
172       if (data==null || data.length==0 || initRecordNumber<=1) discard[0] = new String JavaDoc("hasPrevious");
173       if (data==null || data.length==0 || data.length<intRecordRange) discard[1] = new String JavaDoc("hasNext");
174       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Locator_F2", discard).createXmlDocument();
175       xmlDocument.setData("structure1", data);
176     }
177     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
178     response.setContentType("text/html; charset=UTF-8");
179     PrintWriter out = response.getWriter();
180     out.println(xmlDocument.print());
181     out.close();
182   }
183
184   void printPageFrame3(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
185     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 3 of the Locators seeker");
186     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Locator_F3").createXmlDocument();
187
188     response.setContentType("text/html; charset=UTF-8");
189     PrintWriter out = response.getWriter();
190     out.println(xmlDocument.print());
191     out.close();
192   }
193
194   public String JavaDoc getServletInfo() {
195     return "Servlet that presents the Locators seeker";
196   } // end of getServletInfo() method
197
}
198
Popular Tags