KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > businessUtility > MessageJS


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.businessUtility;
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.xmlEngine.XmlDocument;
30 import org.openbravo.erpCommon.utility.Utility;
31
32
33 public class MessageJS extends HttpSecureAppServlet {
34
35   public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
36     VariablesSecureApp vars = new VariablesSecureApp(request);
37
38     String JavaDoc strValue = vars.getRequiredStringParameter("inpvalue");
39     printPage(response, vars, strValue);
40   }
41
42   private void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strValue) throws IOException, ServletException {
43     if (log4j.isDebugEnabled()) log4j.debug("Output: print page message");
44     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/businessUtility/MessageJS").createXmlDocument();
45     String JavaDoc type = "Hidden";
46     String JavaDoc title = "";
47     String JavaDoc description = "";
48     String JavaDoc strLanguage = vars.getStringParameter("inplanguage");
49     if (strLanguage==null || strLanguage.equals("")) strLanguage = vars.getLanguage();
50     MessageJSData[] data = null;
51     try {
52       data = MessageJSData.getMessage(this, strLanguage, strValue);
53     } catch (Exception JavaDoc ex) {
54       type = "Error";
55       title = "Error";
56       description = ex.toString();
57     }
58     if (data!=null && data.length>0) {
59       type = (data[0].msgtype.equals("E")?"Error":(data[0].msgtype.equals("I")?"Info":"Warning"));
60       title = Utility.messageBD(this, type, strLanguage);
61       description = "<![CDATA[" + data[0].msgtext + "]]>";
62     }
63     xmlDocument.setParameter("type", type);
64     xmlDocument.setParameter("title", title);
65     xmlDocument.setParameter("description", description);
66     response.setContentType("text/xml; charset=UTF-8");
67     response.setHeader("Cache-Control", "no-cache");
68     PrintWriter out = response.getWriter();
69     if (log4j.isDebugEnabled()) log4j.debug(xmlDocument.print());
70     out.println(xmlDocument.print());
71     out.close();
72   }
73 }
74
Popular Tags