KickJava   Java API By Example, From Geeks To Geeks.

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


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 UserContact 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", "UserContact.name");
44       vars.removeSessionValue("UserContact.key");
45       if (!strNameValue.equals("")) vars.setSessionValue("UserContact.name", strNameValue + "%");
46       printPageFS(response, vars);
47     } else if (vars.commandIn("KEY")) {
48       String JavaDoc strKeyValue = vars.getRequestGlobalVariable("inpNameValue", "UserContact.key");
49       vars.removeSessionValue("UserContact.name");
50       vars.setSessionValue("UserContact.key", strKeyValue + "%");
51       UserContactData[] data = UserContactData.selectKey(this, strKeyValue + "%");
52       if (data!=null && data.length==1) {
53         printPageKey(response, vars, data);
54       } else printPageFS(response, vars);
55     } else if (vars.commandIn("FRAME1")) {
56       String JavaDoc strKeyValue = vars.getGlobalVariable("inpKey", "UserContact.key", "");
57       String JavaDoc strNameValue = vars.getGlobalVariable("inpName", "UserContact.name", "");
58       printPageFrame1(response, vars, strKeyValue, strNameValue);
59     } else if (vars.commandIn("FRAME2")) {
60       String JavaDoc strKey = vars.getGlobalVariable("inpKey", "UserContact.key", "");
61       String JavaDoc strName = vars.getGlobalVariable("inpName", "UserContact.name", "");
62       String JavaDoc strLastResult = vars.getStringParameter("inpLastResult");
63       String JavaDoc strFax = vars.getStringParameter("inpFax");
64       String JavaDoc strTelephone = vars.getStringParameter("inpTelephone");
65       printPageFrame2(response, vars, strKey, strName, strLastResult, strFax, strTelephone);
66     } else if (vars.commandIn("FIND")) {
67       String JavaDoc strKey = vars.getRequestGlobalVariable("inpKey", "UserContact.key");
68       String JavaDoc strName = vars.getRequestGlobalVariable("inpName", "UserContact.name");
69       String JavaDoc strLastResult = vars.getStringParameter("inpLastResult");
70       String JavaDoc strFax = vars.getStringParameter("inpFax");
71       String JavaDoc strTelephone = vars.getStringParameter("inpTelephone");
72
73       vars.setSessionValue("UserContact.initRecordNumber", "0");
74
75       printPageFrame2(response, vars, strKey, strName, strLastResult, strFax, strTelephone);
76     } else if (vars.commandIn("FRAME3")) {
77       printPageFrame3(response, vars);
78     } else if (vars.commandIn("PREVIOUS")) {
79       String JavaDoc strInitRecord = vars.getSessionValue("UserContact.initRecordNumber");
80       String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "UserContact");
81       int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
82       if (strInitRecord.equals("") || strInitRecord.equals("0")) vars.setSessionValue("UserContact.initRecordNumber", "0");
83       else {
84         int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
85         initRecord -= intRecordRange;
86         strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
87         vars.setSessionValue("UserContact.initRecordNumber", strInitRecord);
88       }
89
90       response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2");
91     } else if (vars.commandIn("NEXT")) {
92       String JavaDoc strInitRecord = vars.getSessionValue("UserContact.initRecordNumber");
93       String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "UserContact");
94       int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
95       int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
96       if (initRecord==0) initRecord=1;
97       initRecord += intRecordRange;
98       strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
99       vars.setSessionValue("UserContact.initRecordNumber", strInitRecord);
100
101       response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2");
102     } else pageError(response);
103   }
104
105   void printPageFS(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
106     if (log4j.isDebugEnabled()) log4j.debug("Output: business partners seeker Frame Set");
107     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/UserContact_FS").createXmlDocument();
108
109     response.setContentType("text/html; charset=UTF-8");
110     PrintWriter out = response.getWriter();
111     out.println(xmlDocument.print());
112     out.close();
113   }
114
115   void printPageKey(HttpServletResponse response, VariablesSecureApp vars, UserContactData[] data) throws IOException, ServletException {
116     if (log4j.isDebugEnabled()) log4j.debug("Output: user seeker Frame Set");
117     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/SearchUniqueKeyResponse").createXmlDocument();
118
119     xmlDocument.setParameter("script", generateResult(data));
120     response.setContentType("text/html; charset=UTF-8");
121     PrintWriter out = response.getWriter();
122     out.println(xmlDocument.print());
123     out.close();
124   }
125
126   String JavaDoc generateResult(UserContactData[] data) throws IOException, ServletException {
127     StringBuffer JavaDoc html = new StringBuffer JavaDoc();
128     
129     html.append("\nfunction depurarSelector() {\n");
130     html.append("var clave = \"" + data[0].id + "\";\n");
131     html.append("var texto = \"" + Replace.replace(data[0].name, "\"", "\\\"") + "\";\n");
132     html.append("parent.opener.closeSearch(\"SAVE\", clave, texto, null);\n");
133     html.append("}\n");
134     return html.toString();
135   }
136
137   void printPageFrame1(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKeyValue, String JavaDoc strNameValue) throws IOException, ServletException {
138     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 1 of the business partners seeker");
139     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/UserContact_F1").createXmlDocument();
140     if (strKeyValue.equals("") && strNameValue.equals("")) {
141       xmlDocument.setParameter("key", "%");
142     } else {
143       xmlDocument.setParameter("key", strKeyValue);
144     }
145     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
146     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
147     response.setContentType("text/html; charset=UTF-8");
148     PrintWriter out = response.getWriter();
149     out.println(xmlDocument.print());
150     out.close();
151   }
152
153   void printPageFrame2(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc strName, String JavaDoc strLastResult, String JavaDoc strFax, String JavaDoc strTelephone) throws IOException, ServletException {
154     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 2 of the business partners seeker");
155     XmlDocument xmlDocument;
156
157     String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "UserContact");
158     int intRecordRange = (strRecordRange.equals("")?0:Integer.parseInt(strRecordRange));
159     String JavaDoc strInitRecord = vars.getSessionValue("UserContact.initRecordNumber");
160     int initRecordNumber = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
161
162     if (strKey.equals("") && strName.equals("") && strLastResult.equals("") && strFax.equals("") && strTelephone.equals("")) {
163       String JavaDoc[] discard = {"sectionDetail", "hasPrevious", "hasNext"};
164       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/UserContact_F2", discard).createXmlDocument();
165       xmlDocument.setData("structure1", UserContactData.set());
166     } else {
167       String JavaDoc[] discard = {"withoutPrevious", "withoutNext"};
168       UserContactData[] data = UserContactData.select(this, strTelephone, strFax, strLastResult, strKey, initRecordNumber, intRecordRange);
169       if (data==null || data.length==0 || initRecordNumber<=1) discard[0] = new String JavaDoc("hasPrevious");
170       if (data==null || data.length==0 || data.length<intRecordRange) discard[1] = new String JavaDoc("hasNext");
171       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/UserContact_F2", discard).createXmlDocument();
172       xmlDocument.setData("structure1", data);
173     }
174     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
175     response.setContentType("text/html; charset=UTF-8");
176     PrintWriter out = response.getWriter();
177     out.println(xmlDocument.print());
178     out.close();
179   }
180
181   void printPageFrame3(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
182     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 3 of the business partners seeker");
183     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/UserContact_F3").createXmlDocument();
184
185     response.setContentType("text/html; charset=UTF-8");
186     PrintWriter out = response.getWriter();
187     out.println(xmlDocument.print());
188     out.close();
189   }
190
191   public String JavaDoc getServletInfo() {
192     return "Servlet that presents the business partners seeker";
193   } // end of getServletInfo() method
194
}
195
Popular Tags