fixed issue 40192: XmlEngine should not be a Servlet
authorAsier Lostalé <asier.lostale@openbravo.com>
Thu, 14 Feb 2019 09:31:22 +0100
changeset 35446 4dc18ae9b326
parent 35445 3358f7883c08
child 35447 6c4017ffae94
fixed issue 40192: XmlEngine should not be a Servlet
src-core/src/org/openbravo/xmlEngine/XmlEngine.java
src-db/database/sourcedata/AD_MODEL_OBJECT.xml
src-db/database/sourcedata/AD_MODEL_OBJECT_PARA.xml
--- a/src-core/src/org/openbravo/xmlEngine/XmlEngine.java	Mon Feb 11 18:07:30 2019 +0100
+++ b/src-core/src/org/openbravo/xmlEngine/XmlEngine.java	Thu Feb 14 09:31:22 2019 +0100
@@ -1,6 +1,6 @@
 /*
  ************************************************************************************
- * Copyright (C) 2001-2018 Openbravo S.L.U.
+ * Copyright (C) 2001-2019 Openbravo S.L.U.
  * Licensed under the Apache Software License version 2.0
  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to  in writing,  software  distributed
@@ -16,17 +16,12 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStreamReader;
-import java.io.PrintWriter;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Stack;
 import java.util.Vector;
 
 import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -35,8 +30,7 @@
 import org.xml.sax.InputSource;
 import org.xml.sax.XMLReader;
 
-public class XmlEngine extends HttpServlet {
-  private static final long serialVersionUID = 1L;
+public class XmlEngine {
   XMLReader xmlParser;
   XMLReader htmlParser;
   Hashtable<String, XmlTemplate> hasXmlTemplate;
@@ -70,45 +64,6 @@
   public XmlEngine() {
   }
 
-  @Override
-  public void init(ServletConfig config) throws ServletException {
-    if (log4jXmlEngine.isDebugEnabled()) {
-      log4jXmlEngine.debug("XmlEngine v0.846-2");
-    }
-    super.init(config);
-    configXMLEngine = config;
-    strBaseLocation = getInitParameter("BaseLocation");
-    strDriverDefault = getInitParameter("driver");
-    strUrlDefault = getInitParameter("URL");
-    if (log4jXmlEngine.isDebugEnabled()) {
-      log4jXmlEngine.debug("driver: " + strDriverDefault + " URL: " + strUrlDefault);
-    }
-    strFormatFile = getInitParameter("FormatFile");
-    fileBaseLocation = new File(strBaseLocation);
-    fileXmlEngineFormat = new File(fileBaseLocation, strFormatFile);
-    if (log4jXmlEngine.isDebugEnabled()) {
-      log4jXmlEngine.debug("BaseLocation: " + strBaseLocation);
-    }
-    strReplaceWhat = getInitParameter("ReplaceWhat");
-    strReplaceWith = getInitParameter("ReplaceWith");
-    if (log4jXmlEngine.isDebugEnabled()) {
-      log4jXmlEngine.debug(
-          "Replace attribute value: \"" + strReplaceWhat + "\" with: \"" + strReplaceWith + "\".");
-    }
-    strTextDividedByZero = getInitParameter("TextDividedByZero");
-    if (log4jXmlEngine.isDebugEnabled()) {
-      log4jXmlEngine.debug("TextDividedByZero: " + strTextDividedByZero);
-    }
-    try {
-      if (log4jXmlEngine.isDebugEnabled()) {
-        log4jXmlEngine.debug("fileBaseLocation: " + fileBaseLocation.getCanonicalPath());
-      }
-    } catch (IOException e) {
-      log4jXmlEngine.error("Error in BaseLocation: " + strBaseLocation);
-    }
-    initialize();
-  }
-
   private void loadParams() {
     /*
      * // decimal separator:. thousands separator: , DecimalFormatSymbols dfs = new
@@ -464,83 +419,6 @@
     }
   }
 
-  @Override
-  public void doPost(HttpServletRequest request, HttpServletResponse response)
-      throws ServletException, IOException {
-    doGet(request, response);
-  }
-
-  @Override
-  public void doGet(HttpServletRequest request, HttpServletResponse response)
-      throws ServletException, IOException {
-    String strReportName = request.getParameter("report");
-    String strReload = request.getParameter("reload");
-    if (strReload != null) {
-      initialize();
-    }
-    Report report = readReportConfiguration(strReportName);
-    // SQL connect();
-    for (DataValue elementDataValue : report.xmlDocument.hasDataValue.values()) {
-      elementDataValue.connect(); // SQL
-      for (Enumeration<Object> e2 = elementDataValue.vecParameterValue.elements(); e2
-          .hasMoreElements();) {
-        ParameterValue parameter = (ParameterValue) e2.nextElement();
-        parameter.strValue = request.getParameter(parameter.parameterTemplate.strName);
-        if (parameter.strValue == null) {
-          if (log4jXmlEngine.isDebugEnabled()) {
-            log4jXmlEngine.debug("getParameter: default assigned");
-          }
-          parameter.strValue = parameter.parameterTemplate.strDefault;
-        }
-        if (log4jXmlEngine.isDebugEnabled()) {
-          log4jXmlEngine.debug("getParameter: " + parameter.parameterTemplate.strName + " valor: "
-              + parameter.strValue);
-        }
-      }
-    }
-
-    // Connection of the subreports
-    for (XmlDocument subXmlDocument : report.xmlDocument.hasSubXmlDocuments.values()) {
-      for (DataValue elementDataValue : subXmlDocument.hasDataValue.values()) {
-        elementDataValue.connect(); // SQL
-      }
-    }
-
-    // Parameter of the report (not for the SQL query's)
-    for (ParameterValue parameter : report.xmlDocument.hasParameterValue.values()) {
-      parameter.strValue = request.getParameter(parameter.parameterTemplate.strName);
-      if (parameter.strValue == null) {
-        log4jXmlEngine
-            .debug("getParameter of: " + parameter.parameterTemplate.strName + " default assigned");
-        parameter.strValue = parameter.parameterTemplate.strDefault;
-      }
-      log4jXmlEngine.debug(
-          "getParameter: " + parameter.parameterTemplate.strName + " value: " + parameter.strValue);
-    }
-
-    // Label of the report (not for the SQL query's)
-    for (LabelValue label : report.xmlDocument.hasLabelValue.values()) {
-      log4jXmlEngine.debug("getting labelValues for report.xmlDocument");
-      label.strValue = request.getParameter(label.labelTemplate.strName);
-      if (label.strValue == null) {
-        log4jXmlEngine.debug("getLabel of: " + label.labelTemplate.strName + " default assigned");
-        label.strValue = label.labelTemplate.strName;
-      }
-      log4jXmlEngine
-          .debug("getLabel: " + label.labelTemplate.strName + " value: " + label.strValue);
-    }
-
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    String strBlank = request.getParameter("blank");
-    if (strBlank != null) {
-      out.println(report.xmlDocument.print(strBlank));
-    } else {
-      out.println(report.xmlDocument.print());
-    }
-    out.close();
-  }
-
   @SuppressWarnings({ "rawtypes" })
   // It's not possible to cast from xmlTemplate to Report
   void connect() {
@@ -565,11 +443,6 @@
     }
   }
 
-  @Override
-  public void destroy() {
-    closeConnections();
-  }
-
   public static void main(String argv[]) {
     int i;
     String strFile;
--- a/src-db/database/sourcedata/AD_MODEL_OBJECT.xml	Mon Feb 11 18:07:30 2019 +0100
+++ b/src-db/database/sourcedata/AD_MODEL_OBJECT.xml	Thu Feb 14 09:31:22 2019 +0100
@@ -3597,18 +3597,6 @@
 <!--681A9322B9C74AB8947C032B072ADF39-->  <OBJECT_TYPE><![CDATA[S]]></OBJECT_TYPE>
 <!--681A9322B9C74AB8947C032B072ADF39--></AD_MODEL_OBJECT>
 
-<!--69EB0238E9FE452280BCCE231E71D1E9--><AD_MODEL_OBJECT>
-<!--69EB0238E9FE452280BCCE231E71D1E9-->  <AD_MODEL_OBJECT_ID><![CDATA[69EB0238E9FE452280BCCE231E71D1E9]]></AD_MODEL_OBJECT_ID>
-<!--69EB0238E9FE452280BCCE231E71D1E9-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
-<!--69EB0238E9FE452280BCCE231E71D1E9-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
-<!--69EB0238E9FE452280BCCE231E71D1E9-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
-<!--69EB0238E9FE452280BCCE231E71D1E9-->  <ACTION><![CDATA[M]]></ACTION>
-<!--69EB0238E9FE452280BCCE231E71D1E9-->  <CLASSNAME><![CDATA[org.openbravo.xmlEngine.XmlEngine]]></CLASSNAME>
-<!--69EB0238E9FE452280BCCE231E71D1E9-->  <ISDEFAULT><![CDATA[N]]></ISDEFAULT>
-<!--69EB0238E9FE452280BCCE231E71D1E9-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
-<!--69EB0238E9FE452280BCCE231E71D1E9-->  <OBJECT_TYPE><![CDATA[S]]></OBJECT_TYPE>
-<!--69EB0238E9FE452280BCCE231E71D1E9--></AD_MODEL_OBJECT>
-
 <!--6A416305976A48E5BE94F5B3FE6F6E7A--><AD_MODEL_OBJECT>
 <!--6A416305976A48E5BE94F5B3FE6F6E7A-->  <AD_MODEL_OBJECT_ID><![CDATA[6A416305976A48E5BE94F5B3FE6F6E7A]]></AD_MODEL_OBJECT_ID>
 <!--6A416305976A48E5BE94F5B3FE6F6E7A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_MODEL_OBJECT_PARA.xml	Mon Feb 11 18:07:30 2019 +0100
+++ b/src-db/database/sourcedata/AD_MODEL_OBJECT_PARA.xml	Thu Feb 14 09:31:22 2019 +0100
@@ -131,28 +131,6 @@
 <!--91960135229C4B77B686CA14A23254F4-->  <VALUE><![CDATA[10]]></VALUE>
 <!--91960135229C4B77B686CA14A23254F4--></AD_MODEL_OBJECT_PARA>
 
-<!--954C01932B0D46168C5EBDA2015048EE--><AD_MODEL_OBJECT_PARA>
-<!--954C01932B0D46168C5EBDA2015048EE-->  <AD_MODEL_OBJECT_PARA_ID><![CDATA[954C01932B0D46168C5EBDA2015048EE]]></AD_MODEL_OBJECT_PARA_ID>
-<!--954C01932B0D46168C5EBDA2015048EE-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
-<!--954C01932B0D46168C5EBDA2015048EE-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
-<!--954C01932B0D46168C5EBDA2015048EE-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
-<!--954C01932B0D46168C5EBDA2015048EE-->  <AD_MODEL_OBJECT_ID><![CDATA[69EB0238E9FE452280BCCE231E71D1E9]]></AD_MODEL_OBJECT_ID>
-<!--954C01932B0D46168C5EBDA2015048EE-->  <LINE><![CDATA[40]]></LINE>
-<!--954C01932B0D46168C5EBDA2015048EE-->  <NAME><![CDATA[TextDividedByZero]]></NAME>
-<!--954C01932B0D46168C5EBDA2015048EE-->  <VALUE><![CDATA[Div /0]]></VALUE>
-<!--954C01932B0D46168C5EBDA2015048EE--></AD_MODEL_OBJECT_PARA>
-
-<!--9F497B6AAD5743D8BF182269054DF0DB--><AD_MODEL_OBJECT_PARA>
-<!--9F497B6AAD5743D8BF182269054DF0DB-->  <AD_MODEL_OBJECT_PARA_ID><![CDATA[9F497B6AAD5743D8BF182269054DF0DB]]></AD_MODEL_OBJECT_PARA_ID>
-<!--9F497B6AAD5743D8BF182269054DF0DB-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
-<!--9F497B6AAD5743D8BF182269054DF0DB-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
-<!--9F497B6AAD5743D8BF182269054DF0DB-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
-<!--9F497B6AAD5743D8BF182269054DF0DB-->  <AD_MODEL_OBJECT_ID><![CDATA[69EB0238E9FE452280BCCE231E71D1E9]]></AD_MODEL_OBJECT_ID>
-<!--9F497B6AAD5743D8BF182269054DF0DB-->  <LINE><![CDATA[30]]></LINE>
-<!--9F497B6AAD5743D8BF182269054DF0DB-->  <NAME><![CDATA[ReplaceWith]]></NAME>
-<!--9F497B6AAD5743D8BF182269054DF0DB-->  <VALUE><![CDATA[../]]></VALUE>
-<!--9F497B6AAD5743D8BF182269054DF0DB--></AD_MODEL_OBJECT_PARA>
-
 <!--AC2F805519B64E678E6743E395936CD9--><AD_MODEL_OBJECT_PARA>
 <!--AC2F805519B64E678E6743E395936CD9-->  <AD_MODEL_OBJECT_PARA_ID><![CDATA[AC2F805519B64E678E6743E395936CD9]]></AD_MODEL_OBJECT_PARA_ID>
 <!--AC2F805519B64E678E6743E395936CD9-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -197,17 +175,6 @@
 <!--C037A530B0334A5F82B9FA3C0A2BA041-->  <VALUE><![CDATA[${attachPath}]]></VALUE>
 <!--C037A530B0334A5F82B9FA3C0A2BA041--></AD_MODEL_OBJECT_PARA>
 
-<!--CEFE421D6DC64C109B52AAFC2D66D9A5--><AD_MODEL_OBJECT_PARA>
-<!--CEFE421D6DC64C109B52AAFC2D66D9A5-->  <AD_MODEL_OBJECT_PARA_ID><![CDATA[CEFE421D6DC64C109B52AAFC2D66D9A5]]></AD_MODEL_OBJECT_PARA_ID>
-<!--CEFE421D6DC64C109B52AAFC2D66D9A5-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
-<!--CEFE421D6DC64C109B52AAFC2D66D9A5-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
-<!--CEFE421D6DC64C109B52AAFC2D66D9A5-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
-<!--CEFE421D6DC64C109B52AAFC2D66D9A5-->  <AD_MODEL_OBJECT_ID><![CDATA[69EB0238E9FE452280BCCE231E71D1E9]]></AD_MODEL_OBJECT_ID>
-<!--CEFE421D6DC64C109B52AAFC2D66D9A5-->  <LINE><![CDATA[20]]></LINE>
-<!--CEFE421D6DC64C109B52AAFC2D66D9A5-->  <NAME><![CDATA[ReplaceWhat]]></NAME>
-<!--CEFE421D6DC64C109B52AAFC2D66D9A5-->  <VALUE><![CDATA[../../../../../../]]></VALUE>
-<!--CEFE421D6DC64C109B52AAFC2D66D9A5--></AD_MODEL_OBJECT_PARA>
-
 <!--D342465F152D452BB63C520511B76AF8--><AD_MODEL_OBJECT_PARA>
 <!--D342465F152D452BB63C520511B76AF8-->  <AD_MODEL_OBJECT_PARA_ID><![CDATA[D342465F152D452BB63C520511B76AF8]]></AD_MODEL_OBJECT_PARA_ID>
 <!--D342465F152D452BB63C520511B76AF8-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>