KickJava   Java API By Example, From Geeks To Geeks.

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


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-2007 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.*;
22
23 import org.openbravo.utils.Replace;
24 import org.openbravo.erpCommon.ad_actionButton.*;
25 import org.openbravo.erpCommon.businessUtility.WindowTabs;
26 import org.openbravo.base.secureApp.HttpSecureAppServlet;
27 import org.openbravo.base.secureApp.VariablesSecureApp;
28 import org.openbravo.xmlEngine.XmlDocument;
29 import java.io.*;
30 import javax.servlet.*;
31 import javax.servlet.http.*;
32
33
34 import org.openbravo.erpCommon.ad_help.*;
35
36
37 public class GenerateHelp extends HttpSecureAppServlet {
38   
39
40   public void init (ServletConfig config) {
41     super.init(config);
42     boolHist = false;
43   }
44
45   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
46     VariablesSecureApp vars = new VariablesSecureApp(request);
47
48     if (!Utility.hasProcessAccess(this, vars, "", "GenerateHelp")) {
49       bdError(response, "AccessTableNoView", vars.getLanguage());
50       return;
51     }
52
53     if (vars.commandIn("DEFAULT")) {
54       printPage(response, vars);
55     } else if (vars.commandIn("SAVE")) {
56       String JavaDoc strWindow = vars.getGlobalVariable("inpadWindowId", "GenerateHelp|windowID");
57       String JavaDoc strPath = vars.getRequiredStringParameter("inpPath");
58       String JavaDoc strMessage = processSave(vars, strWindow, strPath);
59       if (!strMessage.equals("")) vars.setSessionValue("GenerateHelp.message", strMessage);
60       printPage(response, vars);
61     } else pageErrorPopUp(response);
62   }
63
64   String JavaDoc processSave(VariablesSecureApp vars, String JavaDoc strWindow, String JavaDoc strPath) throws IOException {
65     if (log4j.isDebugEnabled()) log4j.debug("Save: GenerateHelp");
66     String JavaDoc strMessage = "";
67     try {
68       GenerateHelpData[] data = GenerateHelpData.select(this, vars.getLanguage(), strWindow );
69       if (data==null || data.length==0) {
70         log4j.error("There're no windows for window: " + strWindow);
71         return Utility.messageBD(this, "ProcessRunError", vars.getLanguage());
72       }
73       int i=0;
74       for (i=0;i<data.length;i++) generateFile(strPath, data[i].adWindowId + ".html", HelpWindow.generateWindow(this, xmlEngine, vars, true, data[i].adWindowId));
75       strMessage = Utility.messageBD(this, "Created", vars.getLanguage()) + ": " + i;
76     } catch (ServletException e) {
77       e.printStackTrace();
78       log4j.warn("Rollback in transaction");
79       return Utility.messageBD(this, "ProcessRunError", vars.getLanguage());
80     }
81     return strMessage;
82   }
83
84   private boolean generateFile(String JavaDoc strPath, String JavaDoc strFile, String JavaDoc data) {
85     try {
86       File fileData = new File(strPath, strFile);
87       FileWriter fileWriterData = new FileWriter(fileData);
88       PrintWriter printWriterData = new PrintWriter(fileWriterData);
89       printWriterData.print(data);
90       fileWriterData.close();
91     } catch (IOException e) {
92       e.printStackTrace();
93       log4j.error("Problem of IOExceptio in file: " + strPath + " - " + strFile);
94       return false;
95     }
96     return true;
97   }
98
99   void printPage(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
100       if (log4j.isDebugEnabled()) log4j.debug("Output: process GenerateHelp");
101       ActionButtonDefaultData[] data = null;
102       String JavaDoc strHelp="", strDescription="", strProcessId="800071";
103       if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId);
104       else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId);
105       if (data!=null && data.length!=0) {
106         strDescription = data[0].description;
107         strHelp = data[0].help;
108       }
109       String JavaDoc[] discard = {""};
110       if (strHelp.equals("")) discard[0] = new String JavaDoc("helpDiscard");
111       XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_process/GenerateHelp").createXmlDocument();
112       
113       ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "GenerateHelp", false, "", "", "",false, "ad_process", strReplaceWith, false, true);
114       toolbar.prepareSimpleToolBarTemplate();
115       xmlDocument.setParameter("toolbar", toolbar.toString());
116       
117       xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
118       xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
119       xmlDocument.setParameter("question", Utility.messageBD(this, "StartProcess?", vars.getLanguage()));
120       xmlDocument.setParameter("description", strDescription);
121       xmlDocument.setParameter("help", strHelp);
122       
123              // New interface paramenters
124
try {
125         KeyMap key = new KeyMap(this, vars, "GenerateHelp.html");
126         xmlDocument.setParameter("keyMap", key.getActionButtonKeyMaps());
127       } catch (Exception JavaDoc ex) {
128         throw new ServletException(ex);
129       }
130       try {
131         WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_process.GenerateHelp");
132
133         xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
134         xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
135         xmlDocument.setParameter("childTabContainer", tabs.childTabs());
136         xmlDocument.setParameter("theme", vars.getTheme());
137         NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "GenerateHelp.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb());
138         xmlDocument.setParameter("navigationBar", nav.toString());
139         LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "GenerateHelp.html", strReplaceWith);
140         xmlDocument.setParameter("leftTabs", lBar.manualTemplate());
141       } catch (Exception JavaDoc ex) {
142         throw new ServletException(ex);
143       }
144       {
145         OBError myMessage = vars.getMessage("GenerateHelp");
146         vars.removeMessage("GenerateHelp");
147         if (myMessage!=null) {
148           xmlDocument.setParameter("messageType", myMessage.getType());
149           xmlDocument.setParameter("messageTitle", myMessage.getTitle());
150           xmlDocument.setParameter("messageMessage", myMessage.getMessage());
151         }
152       }
153       
154      ////----
155

156      
157       String JavaDoc strMessage = vars.getSessionValue("GenerateHelp.message");
158       if (!strMessage.equals("")) {
159         vars.removeSessionValue("GenerateHelp.message");
160         strMessage = "alert('" + Replace.replace(strMessage, "'", "\'") + "');";
161       }
162       xmlDocument.setParameter("body", strMessage);
163
164     try {
165         ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "AD_Window_ID", "", "", Utility.getContext(this, vars, "#User_Org", "GenerateHelp"), Utility.getContext(this, vars, "#User_Client", "GenerateHelp"), 0);
166         Utility.fillSQLParameters(this, vars, null, comboTableData, "GenerateHelp", "");
167         xmlDocument.setData("reportAD_Window_ID","liststructure", comboTableData.select(false));
168         comboTableData = null;
169     } catch (Exception JavaDoc ex) {
170         throw new ServletException(ex);
171     }
172
173       response.setContentType("text/html; charset=UTF-8");
174       PrintWriter out = response.getWriter();
175       out.println(xmlDocument.print());
176       out.close();
177     }
178
179   public String JavaDoc getServletInfo() {
180     return "Servlet GenerateHelp";
181   } // end of getServletInfo() method
182
}
183
184
Popular Tags