KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_process > RequestReOpen


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.ad_process;
20
21 import org.openbravo.erpCommon.utility.ToolBar;
22 import org.openbravo.erpCommon.utility.SequenceIdData;
23 import org.openbravo.erpCommon.reference.*;
24 import org.openbravo.erpCommon.utility.Utility;
25 import org.openbravo.utils.Replace;
26 import org.openbravo.erpCommon.ad_actionButton.*;
27 import org.openbravo.base.secureApp.HttpSecureAppServlet;
28 import org.openbravo.base.secureApp.VariablesSecureApp;
29 import org.openbravo.xmlEngine.XmlDocument;
30 import java.io.*;
31 import javax.servlet.*;
32 import javax.servlet.http.*;
33
34
35 public class RequestReOpen extends HttpSecureAppServlet {
36   
37
38   public void init (ServletConfig config) {
39     super.init(config);
40     boolHist = false;
41   }
42
43   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
44     VariablesSecureApp vars = new VariablesSecureApp(request);
45
46     if (!Utility.hasProcessAccess(this, vars, "", "R_Request_ReOpen")) {
47       bdError(response, "AccessTableNoView", vars.getLanguage());
48       return;
49     }
50
51     if (vars.commandIn("DEFAULT")) {
52       printPage(response, vars);
53     } else if (vars.commandIn("SAVE")) {
54       String JavaDoc strRequest = vars.getRequiredStringParameter("inprRequestId");
55       String JavaDoc strMessage = processSave(vars, strRequest);
56       if (!strMessage.equals("")) vars.setSessionValue("RequestReOpen.message", strMessage);
57       printPage(response, vars);
58     } else pageErrorPopUp(response);
59   }
60
61   String JavaDoc processSave(VariablesSecureApp vars, String JavaDoc strRequest) {
62     if (log4j.isDebugEnabled()) log4j.debug("Save: RequestReOpen");
63     if (strRequest.equals("")) return "";
64     try {
65       String JavaDoc pinstance = SequenceIdData.getSequence(this, "AD_PInstance", vars.getClient());
66       PInstanceProcessData.insertPInstance(this, pinstance, "195", strRequest, "N", vars.getUser(), vars.getClient(), vars.getOrg());
67       PInstanceProcessData.insertPInstanceParamNumber(this, pinstance, "10", "R_Request_ID", strRequest, vars.getClient(), vars.getOrg(), vars.getUser());
68       RequestReOpenData.processRequest(this, pinstance);
69     } catch (ServletException e) {
70       e.printStackTrace();
71       log4j.warn("Rollback in transaction");
72       return Utility.messageBD(this, "ProcessRunError", vars.getLanguage());
73     }
74     return Utility.messageBD(this, "Success", vars.getLanguage());
75   }
76
77   void printPage(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
78       if (log4j.isDebugEnabled()) log4j.debug("Output: process RequestReOpen");
79       ActionButtonDefaultData[] data = null;
80       String JavaDoc strHelp="", strDescription="", strProcessId="195";
81       if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId);
82       else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId);
83       if (data!=null && data.length!=0) {
84         strDescription = data[0].description;
85         strHelp = data[0].help;
86       }
87       String JavaDoc[] discard = {""};
88       if (strHelp.equals("")) discard[0] = new String JavaDoc("helpDiscard");
89       XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_process/RequestReOpen").createXmlDocument();
90       
91       ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "RequestReOpen", false, "", "", "",false, "ad_process", strReplaceWith, false, true);
92       toolbar.prepareSimpleToolBarTemplate();
93       xmlDocument.setParameter("toolbar", toolbar.toString());
94       
95       xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
96       xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
97       xmlDocument.setParameter("question", Utility.messageBD(this, "StartProcess?", vars.getLanguage()));
98       xmlDocument.setParameter("description", strDescription);
99       xmlDocument.setParameter("help", strHelp);
100       String JavaDoc strMessage = vars.getSessionValue("RequestReOpen.message");
101       if (!strMessage.equals("")) {
102         vars.removeSessionValue("RequestReOpen.message");
103         strMessage = "alert('" + Replace.replace(strMessage, "'", "\'") + "');";
104       }
105       xmlDocument.setParameter("body", strMessage);
106       response.setContentType("text/html; charset=UTF-8");
107       PrintWriter out = response.getWriter();
108       out.println(xmlDocument.print());
109       out.close();
110     }
111
112   public String JavaDoc getServletInfo() {
113     return "Servlet RequestReOpen";
114   } // end of getServletInfo() method
115
}
116
117
Popular Tags