KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_actionButton > Test_In


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.ad_actionButton;
21
22 import org.openbravo.erpCommon.utility.SequenceIdData;
23 import org.openbravo.base.secureApp.*;
24 import org.openbravo.xmlEngine.XmlDocument;
25 import org.openbravo.erpCommon.utility.Utility;
26 import org.openbravo.utils.FormatUtilities;
27 import org.openbravo.exception.*;
28 import java.io.*;
29 import javax.servlet.*;
30 import javax.servlet.http.*;
31 import java.sql.*;
32
33 import org.openbravo.data.*;
34
35 // imports for transactions
36
import java.sql.Connection JavaDoc;
37
38
39 public class Test_In extends HttpSecureAppServlet {
40   
41   
42   static int WARNING;
43   static int YES_NO_OPTION;
44   static int NO;
45
46   
47   //static String currentWindow = "Application managemente";
48
//static String currentFrame= "";
49
Connection JavaDoc conn;
50
51
52   public void init (ServletConfig config) {
53     super.init(config);
54     boolHist = false;
55   }
56
57   public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
58     try {
59       conn = getTransactionConnection();
60     } catch (NoConnectionAvailableException ex) {
61       throw new ServletException("@CODE=NoConnectionAvailable");
62     } catch (SQLException ex2) {
63       throw new ServletException("@CODE=" + Integer.toString(ex2.getErrorCode()) + "@" + ex2.getMessage());
64     }
65     VariablesSecureApp vars = new VariablesSecureApp(request);
66
67     if (vars.commandIn("DEFAULT")) {
68       String JavaDoc strProcessId = vars.getStringParameter("inpProcessId");
69       String JavaDoc strWindow = vars.getStringParameter("inpwindowId");
70       String JavaDoc strTab = vars.getStringParameter("inpTabId");
71       String JavaDoc strKey = vars.getRequiredGlobalVariable("inpatTestId", strWindow + "|AT_Test_ID");
72       printPage(response, vars, strKey, strWindow, strTab, strProcessId);
73     } else if (vars.commandIn("SAVE")) {
74       TestLine tl = new TestLine(vars, "inpFile", false, "AplicaciĆ³n de gestiĆ³n", "", false, this);
75       String JavaDoc strWindow = vars.getStringParameter("inpwindowId");
76       String JavaDoc strKey = vars.getStringParameter("inpatTestId");
77       vars.setSessionValue(strWindow + "|AT_Test_ID", strKey);
78       String JavaDoc strTab = vars.getStringParameter("inpTabId");
79       ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTab);
80       String JavaDoc strWindowPath="", strTabName="";
81       if (tab!=null && tab.length!=0) {
82         strTabName = FormatUtilities.replace(tab[0].name);
83         strWindowPath = "../" + FormatUtilities.replace(tab[0].description) + "/" + strTabName + "_Relation.html";
84       } else strWindowPath = strDefaultServlet;
85       String JavaDoc messageResult = processButton(vars, tl.getFieldProvider(), strKey, strWindow);
86       vars.setSessionValue(strWindow + "|" + strTabName + ".message", messageResult);
87       printPageClosePopUp(response, vars, strWindowPath);
88     } else pageErrorPopUp(response);
89   }
90
91
92   String JavaDoc processButton(VariablesSecureApp vars, FieldProvider[] dataLineas, String JavaDoc strTestId, String JavaDoc windowId) {
93
94     if (dataLineas==null) return "";
95     String JavaDoc strCommandId="";
96     String JavaDoc strType = "C";
97     String JavaDoc strLineId ="";
98     int intSeqNo = 10;
99     try {
100       if (!TestInData.countLines(this, strTestId).equals("0")) return "Las lineas del test ya han sido importadas previamente";
101       for (int i=0;i<dataLineas.length;i++) {
102         strCommandId = dataLineas[i].getField("comando");
103         if (strCommandId != null){
104           TestInData[] datacomando = TestInData.select(conn, this, strCommandId);
105           strLineId = SequenceIdData.getSequence(this, "AT_Line", vars.getClient());
106           TestInData.insert(this, strLineId, vars.getClient(), vars.getOrg(), vars.getUser(), strTestId, strCommandId, String.valueOf(intSeqNo), dataLineas[i].getField("arg1"), dataLineas[i].getField("arg2"), dataLineas[i].getField("arg3"), strType, datacomando[0].argno, datacomando[0].arghelp1, datacomando[0].arghelp2, datacomando[0].arghelp3);
107           intSeqNo = intSeqNo + 10;
108         }
109       }
110       return Utility.messageBD(this, "ProcessOK", vars.getLanguage());
111     } catch (Exception JavaDoc e) {
112       e.printStackTrace();
113       log4j.warn(e);
114       return Utility.messageBD(this, "ProcessRunError", vars.getLanguage());
115     }
116   }
117
118
119   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc windowId, String JavaDoc strTab, String JavaDoc strProcessId)
120     throws IOException, ServletException {
121       if (log4j.isDebugEnabled()) log4j.debug("Output: Button process Project Close");
122
123       ActionButtonDefaultData[] data = null;
124       String JavaDoc strHelp="", strDescription="";
125       if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId);
126       else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId);
127
128       if (data!=null && data.length!=0) {
129         strDescription = data[0].description;
130         strHelp = data[0].help;
131       }
132       String JavaDoc[] discard = {""};
133       if (strHelp.equals("")) discard[0] = new String JavaDoc("helpDiscard");
134       XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/Test_In", discard).createXmlDocument();
135       xmlDocument.setParameter("key", strKey);
136       xmlDocument.setParameter("window", windowId);
137       xmlDocument.setParameter("tab", strTab);
138       xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
139       xmlDocument.setParameter("question", Utility.messageBD(this, "StartProcess?", vars.getLanguage()));
140       xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
141       xmlDocument.setParameter("description", strDescription);
142       xmlDocument.setParameter("help", strHelp);
143
144       response.setContentType("text/html; charset=UTF-8");
145       PrintWriter out = response.getWriter();
146       out.println(xmlDocument.print());
147       out.close();
148     }
149
150   public String JavaDoc getServletInfo() {
151     return "Servlet Project set Type";
152   } // end of getServletInfo() method
153
}
154
Popular Tags