KickJava   Java API By Example, From Geeks To Geeks.

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


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
28
29
30 public class ImageInfo 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 strKey = vars.getStringParameter("inpNameValue");
44       String JavaDoc strNameValue = ImageInfoData.selectName(this, strKey);
45       String JavaDoc strBpartner = Utility.getContext(this, vars, "isSOTrx", strWindowId);
46       if (!strNameValue.equals("")) vars.setSessionValue("ImageInfo.name", strNameValue + "%");
47       printPageFS(response, vars);
48     } else if (vars.commandIn("FRAME1")) {
49       String JavaDoc strNameValue = vars.getGlobalVariable("inpName", "ImageInfo.name", "");
50       printPageFrame1(response, vars, strNameValue);
51     } else if (vars.commandIn("FRAME2")) {
52       String JavaDoc strName = vars.getGlobalVariable("inpName", "ImageInfo.name", "");
53       String JavaDoc strURL = vars.getStringParameter("inpURL");
54       printPageFrame2(response, vars, strName, strURL);
55     } else if (vars.commandIn("FIND")) {
56       String JavaDoc strName = vars.getRequestGlobalVariable("inpName", "ImageInfo.name");
57       String JavaDoc strURL = vars.getStringParameter("inpURL");
58
59       vars.setSessionValue("ImageInfo.initRecordNumber", "0");
60
61       printPageFrame2(response, vars, strName, strURL);
62     } else if (vars.commandIn("FRAME3")) {
63       printPageFrame3(response, vars);
64     } else if (vars.commandIn("PREVIOUS")) {
65       String JavaDoc strInitRecord = vars.getSessionValue("ImageInfo.initRecordNumber");
66       String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "ImageInfo");
67       int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
68       if (strInitRecord.equals("") || strInitRecord.equals("0")) vars.setSessionValue("ImageInfo.initRecordNumber", "0");
69       else {
70         int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
71         initRecord -= intRecordRange;
72         strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
73         vars.setSessionValue("ImageInfo.initRecordNumber", strInitRecord);
74       }
75
76       response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2");
77     } else if (vars.commandIn("NEXT")) {
78       String JavaDoc strInitRecord = vars.getSessionValue("ImageInfo.initRecordNumber");
79       String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "ImageInfo");
80       int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
81       int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
82       if (initRecord==0) initRecord=1;
83       initRecord += intRecordRange;
84       strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
85       vars.setSessionValue("ImageInfo.initRecordNumber", strInitRecord);
86
87       response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2");
88     } else pageError(response);
89   }
90
91   void printPageFS(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
92     if (log4j.isDebugEnabled()) log4j.debug("Output: Image seeker Frame Set");
93     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ImageInfo_FS").createXmlDocument();
94
95     response.setContentType("text/html; charset=UTF-8");
96     PrintWriter out = response.getWriter();
97     out.println(xmlDocument.print());
98     out.close();
99   }
100
101   void printPageFrame1(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strNameValue) throws IOException, ServletException {
102     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 1 of the image seeker");
103     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ImageInfo_F1").createXmlDocument();
104     if (strNameValue.equals("")) {
105       xmlDocument.setParameter("name", "%");
106     } else {
107       xmlDocument.setParameter("name", strNameValue);
108     }
109     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
110     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
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 printPageFrame2(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strName, String JavaDoc strURL) throws IOException, ServletException {
118     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 2 of the image seeker");
119     XmlDocument xmlDocument;
120
121     String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "ImageInfo");
122     int intRecordRange = (strRecordRange.equals("")?0:Integer.parseInt(strRecordRange));
123     String JavaDoc strInitRecord = vars.getSessionValue("ImageInfo.initRecordNumber");
124     int initRecordNumber = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
125
126     if (strName.equals("") && strURL.equals("")) {
127       String JavaDoc[] discard = {"sectionDetail", "hasPrevious", "hasNext"};
128       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ImageInfo_F2", discard).createXmlDocument();
129       xmlDocument.setData("structure1", ImageInfoData.set());
130     } else {
131       String JavaDoc[] discard = {"withoutPrevious", "withoutNext"};
132       ImageInfoData[] data = ImageInfoData.select(this, Utility.getContext(this, vars, "#User_Client", "ImageInfo"), Utility.getContext(this, vars, "#User_Org", "ImageInfo"), strName, strURL, initRecordNumber, intRecordRange);
133       if (data==null || data.length==0 || initRecordNumber<=1) discard[0] = new String JavaDoc("hasPrevious");
134       if (data==null || data.length==0 || data.length<intRecordRange) discard[1] = new String JavaDoc("hasNext");
135       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ImageInfo_F2", discard).createXmlDocument();
136       xmlDocument.setData("structure1", data);
137     }
138     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
139     response.setContentType("text/html; charset=UTF-8");
140     PrintWriter out = response.getWriter();
141     out.println(xmlDocument.print());
142     out.close();
143   }
144
145   void printPageFrame3(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
146     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 3 of the image seeker");
147     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ImageInfo_F3").createXmlDocument();
148
149     response.setContentType("text/html; charset=UTF-8");
150     PrintWriter out = response.getWriter();
151     out.println(xmlDocument.print());
152     out.close();
153   }
154
155   public String JavaDoc getServletInfo() {
156     return "Servlet that presents que image seeker";
157   } // end of getServletInfo() method
158
}
159
Popular Tags