KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > utility > MessagesJS


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
20 package org.openbravo.erpCommon.utility;
21
22 import java.io.*;
23
24 import javax.servlet.*;
25 import javax.servlet.http.*;
26
27 import org.openbravo.base.secureApp.HttpSecureAppServlet;
28 import org.openbravo.base.secureApp.VariablesSecureApp;
29 import org.openbravo.utils.FormatUtilities;
30
31
32 public class MessagesJS extends HttpSecureAppServlet {
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     printPageDataSheet(response, vars);
42   }
43
44   private void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
45     if (log4j.isDebugEnabled()) log4j.debug("Output: print page");
46     OBError myError = null;
47     MessagesJSData[] data = null;
48     try {
49       data = MessagesJSData.select(this, vars.getLanguage());
50     } catch(ServletException ex) {
51       myError = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
52       log4j.error("Error in MessagesJS.printPageDataSheet(): " + myError.getTitle() + " - " + myError.getMessage());
53       return;
54     }
55     StringBuffer JavaDoc arrayType = new StringBuffer JavaDoc();
56     StringBuffer JavaDoc array = new StringBuffer JavaDoc();
57     arrayType.append("function messageType(_messageID, _messageType) {\n");
58     arrayType.append(" this.id = _messageID;\n");
59     arrayType.append(" this.type = _messageType;\n");
60     arrayType.append("}\n");
61     arrayType.append("function messagesTexts(_language, _message, _text, _defaultText) {\n");
62     arrayType.append(" this.language = _language;\n");
63     arrayType.append(" this.message = _message;\n");
64     arrayType.append(" this.text = _text;\n");
65     arrayType.append(" this.defaultText = _defaultText;\n");
66     arrayType.append("}\n");
67     arrayType.append("var arrTypes = new Array(\n");
68     array.append("var arrMessages = new Array(\n");
69     if (data!=null && data.length!=0) {
70       for (int i=0;i<data.length;i++) {
71         String JavaDoc num = data[i].value.replace("JS", "");
72         if (i>0) {
73           arrayType.append(",\n");
74           array.append(",\n");
75         }
76         arrayType.append("new messageType(\"").append(num).append("\",").append(data[i].msgtype.equals("C")?"1":"0").append(")");
77         array.append("new messagesTexts(\"").append(vars.getLanguage()).append("\", \"");
78         array.append(num).append("\", \"").append(FormatUtilities.replaceJS(data[i].msgtext)).append("\", null)");
79       }
80       
81     }
82     arrayType.append(");\n");
83     array.append(");\n");
84     
85     response.setContentType("text/javascript; charset=UTF-8");
86     response.setHeader("Cache-Control", "no-cache");
87     PrintWriter out = response.getWriter();
88     if (log4j.isDebugEnabled()) log4j.debug(arrayType.toString() + array.toString());
89     out.println(arrayType.toString() + array.toString());
90     out.close();
91   }
92 }
93
Popular Tags