KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  ******************************************************************************
3  * The contents of this file are subject to the Compiere License Version 1.1
4  * ("License"); You may not use this file except in compliance with the License
5  * You may obtain a copy of the License at http://www.compiere.org/license.html
6  * Software distributed under the License is distributed on an "AS IS" basis,
7  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
8  * the specific language governing rights and limitations under the License.
9  * The Original Code is Compiere ERP & CRM Business Solution
10  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
11  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
12  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
13  * Contributor(s): Openbravo SL
14  * Contributions are Copyright (C) 2001-2006 Openbravo S.L.
15  ******************************************************************************
16 */

17 package org.openbravo.erpCommon.ad_process;
18
19 import org.openbravo.erpCommon.ad_actionButton.*;
20 import org.openbravo.erpCommon.utility.Utility;
21 import org.openbravo.erpCommon.utility.ComboTableData;
22 import org.openbravo.utils.FormatUtilities;
23 import org.openbravo.base.secureApp.HttpSecureAppServlet;
24 import org.openbravo.base.secureApp.VariablesSecureApp;
25 import org.openbravo.xmlEngine.XmlDocument;
26 import java.io.*;
27 import javax.servlet.*;
28 import javax.servlet.http.*;
29
30
31 public class ImportBudgetServlet 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 (log4j.isDebugEnabled()) log4j.debug("role: " + vars.getRole());
43     if (!Utility.hasProcessAccess(this, vars, "", "ImportBudget")) {
44       bdError(response, "AccessTableNoView", vars.getLanguage());
45       return;
46     }
47     String JavaDoc process = ImportData.processId(this, "ImportBudget");
48     if (vars.commandIn("DEFAULT")) {
49       String JavaDoc strTabId = vars.getGlobalVariable("inpTabId", "ImportBudgetServlet|tabId");
50       String JavaDoc strWindowId = vars.getGlobalVariable("inpwindowId", "ImportBudgetServlet|windowId");
51       //String strKey = vars.getGlobalVariable("inpKey", "ImportBudgetServlet|key");
52
String JavaDoc strKey = "00";
53       String JavaDoc strDeleteOld = vars.getStringParameter("inpDeleteOld", "Y");
54       printPage(response, vars, process, strWindowId, strTabId, strKey, strDeleteOld);
55     } else if (vars.commandIn("SAVE")) {
56       String JavaDoc strDeleteOld = vars.getStringParameter("inpDeleteOld", "Y");
57       String JavaDoc strRecord = vars.getGlobalVariable("inpKey", "ImportBudgetServlet|key");
58       String JavaDoc strTabId = vars.getRequestGlobalVariable("inpTabId", "ImportBudgetServlet|tabId");
59       String JavaDoc strWindowId = vars.getRequestGlobalVariable("inpwindowId", "ImportBudgetServlet|windowId");
60       String JavaDoc strBudget = vars.getRequestGlobalVariable("inpBudgetId","ImportBudgetServlet|inpBudgetId");
61
62       ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTabId);
63       String JavaDoc strWindowPath="";
64       String JavaDoc strTabName="";
65       if (tab!=null && tab.length!=0) {
66         strTabName = FormatUtilities.replace(tab[0].name);
67         if (tab[0].help.equals("Y")) strWindowPath="../utility/WindowTree_FS.html?inpTabId=" + strTabId;
68         else strWindowPath = "../" + FormatUtilities.replace(tab[0].description) + "/" + strTabName + "_Relation.html";
69       } else strWindowPath = strDefaultServlet;
70
71       ImportBudget b = new ImportBudget(this, process, strRecord, strBudget, strDeleteOld.equals("Y"));
72       b.startProcess(vars);
73       String JavaDoc strMessage = b.getLog();
74       if (!strMessage.equals("")) vars.setSessionValue(strWindowId + "|" + strTabName + ".message", strMessage);
75       printPageClosePopUp(response, vars, strWindowPath);
76     } else pageErrorPopUp(response);
77   }
78
79
80   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strProcessId, String JavaDoc strWindowId, String JavaDoc strTabId, String JavaDoc strRecordId, String JavaDoc strDeleteOld) throws IOException, ServletException {
81     if (log4j.isDebugEnabled()) log4j.debug("Output: process ImportBudgetServlet");
82     ActionButtonDefaultData[] data = null;
83     String JavaDoc strHelp="", strDescription="";
84     if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId);
85     else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId);
86     if (data!=null && data.length!=0) {
87       strDescription = data[0].description;
88       strHelp = data[0].help;
89     }
90     String JavaDoc[] discard = {""};
91     if (strHelp.equals("")) discard[0] = new String JavaDoc("helpDiscard");
92     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_process/ImportBudgetServlet").createXmlDocument();
93     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
94     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
95     xmlDocument.setParameter("question", Utility.messageBD(this, "StartProcess?", vars.getLanguage()));
96     xmlDocument.setParameter("description", strDescription);
97     xmlDocument.setParameter("help", strHelp);
98     xmlDocument.setParameter("windowId", strWindowId);
99     xmlDocument.setParameter("tabId", strTabId);
100     xmlDocument.setParameter("recordId", strRecordId);
101     xmlDocument.setParameter("deleteOld", strDeleteOld);
102
103     try {
104         ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_Budget_ID", "", "", Utility.getContext(this, vars, "#User_Org", strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), 0);
105         Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
106         xmlDocument.setData("reportC_BUDGET","liststructure", comboTableData.select(false));
107         comboTableData = null;
108     } catch (Exception JavaDoc ex) {
109         throw new ServletException(ex);
110     }
111
112
113     response.setContentType("text/html; charset=UTF-8");
114     PrintWriter out = response.getWriter();
115     out.println(xmlDocument.print());
116     out.close();
117   }
118
119   public String JavaDoc getServletInfo() {
120     return "Servlet ImportBudgetServlet";
121   } // end of getServletInfo() method
122
}
123
Popular Tags