KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_forms > BackgroundProcessList


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_forms;
20
21 import org.openbravo.erpCommon.utility.ToolBar;
22
23 import org.openbravo.erpCommon.utility.*;
24 import org.openbravo.erpCommon.businessUtility.WindowTabs;
25 import org.openbravo.base.secureApp.HttpSecureAppServlet;
26 import org.openbravo.base.secureApp.VariablesSecureApp;
27 import org.openbravo.xmlEngine.XmlDocument;
28 import java.io.*;
29 import javax.servlet.*;
30 import javax.servlet.http.*;
31
32 import org.openbravo.erpCommon.ad_background.*;
33
34
35 public class BackgroundProcessList extends HttpSecureAppServlet {
36   
37
38   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
39     VariablesSecureApp vars = new VariablesSecureApp(request);
40
41     if (!Utility.hasFormAccess(this, vars, "", "org.openbravo.erpCommon.ad_forms.BackgroundProcessList")) {
42       bdError(response, "AccessTableNoView", vars.getLanguage());
43       return;
44     }
45
46     if (vars.commandIn("DEFAULT")) {
47       printPage(response, vars);
48     } else if (vars.commandIn("START")) {
49       String JavaDoc adProcessId = vars.getStringParameter("inpKey");
50       PeriodicBackground bg = getBackgroundProcess(adProcessId);
51       bg.setActive(true);
52       bg = null;
53       response.sendRedirect(strDireccion + request.getServletPath());
54     } else if (vars.commandIn("STOP")) {
55       String JavaDoc adProcessId = vars.getStringParameter("inpKey");
56       PeriodicBackground bg = getBackgroundProcess(adProcessId);
57       bg.setActive(false);
58       bg = null;
59       response.sendRedirect(strDireccion + request.getServletPath());
60     } else if (vars.commandIn("LOG")) {
61       String JavaDoc adProcessId = vars.getStringParameter("inpKey");
62       printPageLog(response, vars, adProcessId);
63     } else pageError(response);
64   }
65
66   void printPage(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
67     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_forms/BackgroundProcessList").createXmlDocument();
68     BackgroundProcessListData[] data = null;
69     if (vars.getLanguage().equals("en_US")) {
70       data = BackgroundProcessListData.select(this);
71     } else {
72       data = BackgroundProcessListData.selectLanguage(this, vars.getLanguage());
73     }
74     if (data!=null && data.length>0) {
75       String JavaDoc strActivate = Utility.messageBD(this, "Activate", vars.getLanguage());
76       String JavaDoc strDeactivate = Utility.messageBD(this, "Deactivate", vars.getLanguage());
77       for (int i=0;i<data.length;i++) {
78         PeriodicBackground bg = getBackgroundProcess(data[i].id);
79         if (bg!=null) {
80           data[i].status = (bg.isActive()?strDeactivate:strActivate);
81           data[i].commandName = (bg.isActive()?"STOP":"START");
82           data[i].isprocessing = (bg.isProcessing()?Utility.messageBD(this, "Y", vars.getLanguage()):Utility.messageBD(this, "N", vars.getLanguage()));
83           bg = null;
84         }
85       }
86     }
87
88     ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "BackgroundProcessList", false, "", "", "",false, "ad_forms", strReplaceWith, false, true);
89     toolbar.prepareSimpleToolBarTemplate();
90     xmlDocument.setParameter("toolbar", toolbar.toString());
91     try {
92       KeyMap key = new KeyMap(this, vars, "BackgroundProcessList.html");
93       xmlDocument.setParameter("keyMap", key.getActionButtonKeyMaps());
94     } catch (Exception JavaDoc ex) {
95       throw new ServletException(ex);
96     }
97     try {
98       WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_forms.BackgroundProcessList");
99       xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
100       xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
101       xmlDocument.setParameter("childTabContainer", tabs.childTabs());
102       xmlDocument.setParameter("theme", vars.getTheme());
103       NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "BackgroundProcessList.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb());
104       xmlDocument.setParameter("navigationBar", nav.toString());
105       LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "BackgroundProcessList.html", strReplaceWith);
106       xmlDocument.setParameter("leftTabs", lBar.manualTemplate());
107     } catch (Exception JavaDoc ex) {
108       throw new ServletException(ex);
109     }
110     {
111       OBError myMessage = vars.getMessage("BackgroundProcessList");
112       vars.removeMessage("BackgroundProcessList");
113       if (myMessage!=null) {
114         xmlDocument.setParameter("messageType", myMessage.getType());
115         xmlDocument.setParameter("messageTitle", myMessage.getTitle());
116         xmlDocument.setParameter("messageMessage", myMessage.getMessage());
117       }
118     }
119
120     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
121     xmlDocument.setParameter("paramLanguage", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
122     xmlDocument.setParameter("theme", vars.getTheme());
123     xmlDocument.setData("structure1", data);
124     response.setContentType("text/html; charset=UTF-8");
125     PrintWriter out = response.getWriter();
126     out.println(xmlDocument.print());
127     out.close();
128   }
129
130   void printPageLog(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc adProcessId) throws IOException, ServletException {
131     response.setContentType("text/html; charset=UTF-8");
132     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_forms/Log_POP").createXmlDocument();
133     xmlDocument.setParameter("log", getBackgroundProcess(adProcessId).getLog());
134     response.setContentType("text/html; charset=UTF-8");
135     PrintWriter out = response.getWriter();
136     out.println(xmlDocument.print());
137     out.close();
138   }
139
140   public String JavaDoc getServletInfo() {
141     return "Servlet for the background processes control";
142   } // end of getServletInfo() method
143
}
144
Popular Tags