KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.openbravo.erpCommon.utility.ComboTableData;
25 import java.io.*;
26 import javax.servlet.*;
27 import javax.servlet.http.*;
28
29
30 public class ProductMultiple extends HttpSecureAppServlet {
31   
32   
33   public void init (ServletConfig config) {
34     super.init(config);
35     boolHist = false;
36   }
37
38   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
39     VariablesSecureApp vars = new VariablesSecureApp(request);
40
41     if (vars.commandIn("DEFAULT")) {
42       String JavaDoc strWindowId = vars.getStringParameter("WindowID");
43       String JavaDoc strNameValue = vars.getRequestGlobalVariable("inpNameValue", "ProductMultiple.name");
44       String JavaDoc strProductCategory = vars.getRequestGlobalVariable("inpProductCategory", "ProductMultiple.productCategory");
45       if (!strNameValue.equals("")) vars.setSessionValue("ProductMultiple.name", strNameValue + "%");
46       printPageFS(response, vars);
47     } else if (vars.commandIn("FRAME1")) {
48       String JavaDoc strKeyValue = vars.getGlobalVariable("inpKey", "ProductMultiple.key", "");
49       String JavaDoc strNameValue = vars.getGlobalVariable("inpName", "ProductMultiple.name", "");
50       printPageFrame1(response, vars, strKeyValue, strNameValue);
51     } else if (vars.commandIn("FRAME2")) {
52       String JavaDoc strKey = vars.getGlobalVariable("inpKey", "ProductMultiple.key", "");
53       String JavaDoc strName = vars.getGlobalVariable("inpName", "ProductMultiple.name", "");
54       String JavaDoc strProductCategory = vars.getRequestGlobalVariable("inpProductCategory", "ProductMultiple.productCategory");
55       printPageFrame2(response, vars, strKey, strName, strProductCategory);
56     } else if (vars.commandIn("FIND")) {
57       String JavaDoc strKey = vars.getRequestGlobalVariable("inpKey", "ProductMultiple.key");
58       String JavaDoc strName = vars.getRequestGlobalVariable("inpName", "ProductMultiple.name");
59       String JavaDoc strProductCategory = vars.getRequestGlobalVariable("inpProductCategory", "ProductMultiple.productCategory");
60       vars.setSessionValue("ProductMultiple.initRecordNumber", "0");
61
62       printPageFrame2(response, vars, strKey, strName, strProductCategory);
63     } else if (vars.commandIn("FRAME3")) {
64       printPageFrame3(response, vars);
65     } else if (vars.commandIn("PREVIOUS")) {
66       String JavaDoc strInitRecord = vars.getSessionValue("ProductMultiple.initRecordNumber");
67       String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "ProductMultiple");
68       int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
69       if (strInitRecord.equals("") || strInitRecord.equals("0")) vars.setSessionValue("ProductMultiple.initRecordNumber", "0");
70       else {
71         int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
72         initRecord -= intRecordRange;
73         strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
74         vars.setSessionValue("BusinessPartner.initRecordNumber", strInitRecord);
75       }
76
77       response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2");
78     } else if (vars.commandIn("NEXT")) {
79       String JavaDoc strInitRecord = vars.getSessionValue("ProductMultiple.initRecordNumber");
80       String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "ProductMultiple");
81       int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
82       int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
83       if (initRecord==0) initRecord=1;
84       initRecord += intRecordRange;
85       strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
86       vars.setSessionValue("ProductMultiple.initRecordNumber", strInitRecord);
87
88       response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2");
89     } else pageError(response);
90   }
91
92   void printPageFS(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
93     if (log4j.isDebugEnabled()) log4j.debug("Output: Multiple products seeker Frame Set");
94     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ProductMultiple_FS").createXmlDocument();
95
96     response.setContentType("text/html; charset=UTF-8");
97     PrintWriter out = response.getWriter();
98     out.println(xmlDocument.print());
99     out.close();
100   }
101
102
103   void printPageFrame1(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKeyValue, String JavaDoc strNameValue) throws IOException, ServletException {
104     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 1 of the multiple products seeker");
105     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ProductMultiple_F1").createXmlDocument();
106     if (strKeyValue.equals("") && strNameValue.equals("")) {
107       xmlDocument.setParameter("key", "%");
108     } else {
109       xmlDocument.setParameter("key", strKeyValue);
110     }
111     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
112     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
113     xmlDocument.setParameter("name", strNameValue);
114     try {
115         ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "M_Product_Category_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ProductMultiple"), Utility.getContext(this, vars, "#User_Client", "ProductMultiple"), 0);
116         Utility.fillSQLParameters(this, vars, null, comboTableData, "ProductMultiple", "");
117         xmlDocument.setData("reportM_Product_Category_ID","liststructure", comboTableData.select(false));
118         comboTableData = null;
119     } catch (Exception JavaDoc ex) {
120         throw new ServletException(ex);
121     }
122
123     response.setContentType("text/html; charset=UTF-8");
124     PrintWriter out = response.getWriter();
125     out.println(xmlDocument.print());
126     out.close();
127   }
128
129   void printPageFrame2(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc strName, String JavaDoc strProductCategory) throws IOException, ServletException {
130     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 2 of the multuple images seeker");
131     XmlDocument xmlDocument;
132
133     String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "ProductMultiple");
134     int intRecordRange = (strRecordRange.equals("")?0:Integer.parseInt(strRecordRange));
135     String JavaDoc strInitRecord = vars.getSessionValue("ProductMultiple.initRecordNumber");
136     int initRecordNumber = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
137
138     if (strKey.equals("") && strName.equals("") && strProductCategory.equals("")) {
139       String JavaDoc[] discard = {"sectionDetail", "hasPrevious", "hasNext"};
140       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ProductMultiple_F2", discard).createXmlDocument();
141       xmlDocument.setData("structure1", BusinessPartnerData.set());
142     } else {
143       String JavaDoc[] discard = {"withoutPrevious", "withoutNext"};
144       ProductMultipleData[] data = ProductMultipleData.select(this, strKey, strName, strProductCategory, Utility.getContext(this, vars, "#User_Client", "ProductMultiple"), Utility.getContext(this, vars, "#User_Org", "ProductMultiple"), initRecordNumber, intRecordRange);
145       if (data==null || data.length==0 || initRecordNumber<=1) discard[0] = new String JavaDoc("hasPrevious");
146       if (data==null || data.length==0 || data.length<intRecordRange) discard[1] = new String JavaDoc("hasNext");
147       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ProductMultiple_F2", discard).createXmlDocument();
148       xmlDocument.setData("structure1", data);
149     }
150     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
151     response.setContentType("text/html; charset=UTF-8");
152     PrintWriter out = response.getWriter();
153     out.println(xmlDocument.print());
154     out.close();
155   }
156
157   void printPageFrame3(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
158     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 3 of the multiple products seeker");
159     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ProductMultiple_F3").createXmlDocument();
160
161     response.setContentType("text/html; charset=UTF-8");
162     PrintWriter out = response.getWriter();
163     out.println(xmlDocument.print());
164     out.close();
165   }
166
167   public String JavaDoc getServletInfo() {
168     return "Servlet that presents the multiple products seeker";
169   } // end of getServletInfo() method
170
}
171
Popular Tags