details:   https://code.openbravo.com/erp/devel/pi/rev/4dc18ae9b326
changeset: 35446:4dc18ae9b326
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Feb 14 09:31:22 2019 +0100
summary:   fixed issue 40192: XmlEngine should not be a Servlet

details:   https://code.openbravo.com/erp/devel/pi/rev/6c4017ffae94
changeset: 35447:6c4017ffae94
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Feb 14 09:32:18 2019 +0100
summary:   fixed issue 40192: XmlEngine shouldn't be standalone executuble

details:   https://code.openbravo.com/erp/devel/pi/rev/1175ab44522d
changeset: 35448:1175ab44522d
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Feb 14 10:05:31 2019 +0100
summary:   related to issue 40192: additional cleanup

  Removed unnecessary methods
  Reduced visibility
  Minor code refactors

details:   https://code.openbravo.com/erp/devel/pi/rev/b32c4494df35
changeset: 35449:b32c4494df35
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Feb 14 12:05:41 2019 +0100
summary:   related to issue 40192: removed unused Report class

diffstat:

 src-core/src/org/openbravo/xmlEngine/Report.java    |   46 --
 src-core/src/org/openbravo/xmlEngine/XmlEngine.java |  450 ++-----------------
 src-db/database/sourcedata/AD_MODEL_OBJECT.xml      |   12 -
 src-db/database/sourcedata/AD_MODEL_OBJECT_PARA.xml |   33 -
 4 files changed, 52 insertions(+), 489 deletions(-)

diffs (truncated from 762 to 300 lines):

diff -r 3358f7883c08 -r b32c4494df35 
src-core/src/org/openbravo/xmlEngine/Report.java
--- a/src-core/src/org/openbravo/xmlEngine/Report.java  Mon Feb 11 18:07:30 
2019 +0100
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
- 
************************************************************************************
- * Copyright (C) 2001-2010 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
- * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  
WARRANTIES  OR
- * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  
for  the
- * specific language governing permissions and limitations under the License.
- 
************************************************************************************
- */
-package org.openbravo.xmlEngine;
-
-import org.openbravo.data.FieldProvider;
-
-class Report {
-  XmlDocument xmlDocument;
-
-  public Report(String strReportFile, String[] discard, XmlEngine xmlEngine) {
-    xmlDocument = xmlEngine.readXmlTemplate(strReportFile, 
discard).createXmlDocument(null);
-  }
-
-  public void setParameter(String strName, String strValue) {
-    xmlDocument.setParameter(strName, strValue);
-  }
-
-  public void setData(String structureName, FieldProvider[] data) {
-    xmlDocument.setData(structureName, data);
-  }
-
-  public void setData(String xmlDocumentName, String structureName, 
FieldProvider[] data) {
-    xmlDocument.setData(xmlDocumentName, structureName, data);
-  }
-
-  public void setDataArray(String xmlDocumentName, String structureName, 
FieldProvider[][] data) {
-    xmlDocument.setDataArray(xmlDocumentName, structureName, data);
-  }
-
-  public String print() {
-    return xmlDocument.print();
-  }
-
-  public String print(String strText) {
-    return xmlDocument.print(strText);
-  }
-}
diff -r 3358f7883c08 -r b32c4494df35 
src-core/src/org/openbravo/xmlEngine/XmlEngine.java
--- 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 
12:05:41 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
@@ -13,21 +13,11 @@
 
 import java.io.File;
 import java.io.FileInputStream;
-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;
 import org.apache.xerces.parsers.SAXParser;
@@ -35,18 +25,16 @@
 import org.xml.sax.InputSource;
 import org.xml.sax.XMLReader;
 
-public class XmlEngine extends HttpServlet {
-  private static final long serialVersionUID = 1L;
-  XMLReader xmlParser;
-  XMLReader htmlParser;
-  Hashtable<String, XmlTemplate> hasXmlTemplate;
-  Stack<XmlTemplate> stcRead;
+public class XmlEngine {
+  private XMLReader xmlParser;
+  private XMLReader htmlParser;
+  private Hashtable<String, XmlTemplate> hasXmlTemplate;
+  private Stack<XmlTemplate> stcRead;
   Hashtable<String, FormatCouple> formatHashtable;
   Hashtable<String, Vector<ReplaceElement>> replaceHashtable;
-  String strDriverDefault;
-  String strUrlDefault;
-  String strBaseLocation;
-  String strFormatFile;
+  private String strDriverDefault;
+  private String strUrlDefault;
+  private String strFormatFile;
   public File fileXmlEngineFormat;
   public File fileBaseLocation;
   public String sessionLanguage;
@@ -54,12 +42,10 @@
   public String strReplaceWith;
   public boolean isResource = false;
 
-  ServletConfig configXMLEngine;
+  public static String strTextDividedByZero;
 
-  static public String strTextDividedByZero;
-
-  static Logger log4jXmlEngine = LogManager.getLogger();
-  static Logger log4jReloadXml = LogManager.getLogger("reloadXml");
+  private static final Logger log4jXmlEngine = LogManager.getLogger();
+  private static final Logger log4jReloadXml = 
LogManager.getLogger("reloadXml");
 
   ConnectionProvider connProvider;
 
@@ -70,78 +56,11 @@
   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
-     * DecimalFormatSymbols(); 
log4jXmlEngine.info("InternationalCurrencySymbol: " +
-     * dfs.getInternationalCurrencySymbol()); 
log4jXmlEngine.info("CurrencySymbol: " +
-     * dfs.getCurrencySymbol()); dfs.setDecimalSeparator('.'); 
dfs.setGroupingSeparator(',');
-     * DecimalFormatSymbols dfsSpanish = new DecimalFormatSymbols();
-     * dfsSpanish.setDecimalSeparator(','); 
dfsSpanish.setGroupingSeparator('.'); // various
-     * formats, pending of create a configuration file FormatCouple fc; fc= 
new FormatCouple(new
-     * DecimalFormat("#,##0.00",dfs), new DecimalFormat("#0.00",dfs));
-     * formatHashtable.put("euroInform", fc); fc = new FormatCouple(new 
DecimalFormat("#0.00",dfs),
-     * new DecimalFormat("#0.00",dfs)); formatHashtable.put("euroEdition", 
fc); fc = new
-     * FormatCouple(new DecimalFormat("#,##0",dfs), new 
DecimalFormat("#0",dfs));
-     * formatHashtable.put("integerInform", fc); fc = new FormatCouple(new 
DecimalFormat("#0",dfs),
-     * new DecimalFormat("#0",dfs)); formatHashtable.put("integerEdition", 
fc); fc = new
-     * FormatCouple(new DecimalFormat("#,##0.##",dfs),new 
DecimalFormat("#0.00",dfs));
-     * formatHashtable.put("existenciasInforme", fc);
-     */
-    replaceHashtable = new Hashtable<String, Vector<ReplaceElement>>();
-    Vector<ReplaceElement> htmlReplaceVector = new Vector<ReplaceElement>();
+    replaceHashtable = new Hashtable<>();
+    Vector<ReplaceElement> htmlReplaceVector = new Vector<>();
     htmlReplaceVector.addElement(new ReplaceElement("&", "&amp;")); // this
-    // must
-    // be
-    // the
-    // first
-    // for
-    // not
-    // replace
-    // the
-    // next
-    // &
     htmlReplaceVector.addElement(new ReplaceElement("\"", "&quot;"));
-    // htmlReplaceVector.addElement(new ReplaceElement("'","\\'"));
     htmlReplaceVector.addElement(new ReplaceElement("\n", " "));
     htmlReplaceVector.addElement(new ReplaceElement("\r", " "));
     htmlReplaceVector.addElement(new ReplaceElement("<", "&lt;"));
@@ -151,7 +70,8 @@
     htmlReplaceVector.addElement(new ReplaceElement("ñ", "&ntilde;"));
     htmlReplaceVector.addElement(new ReplaceElement("Ñ", "&Ntilde;"));
     replaceHashtable.put("html", htmlReplaceVector);
-    Vector<ReplaceElement> foReplaceVector = new Vector<ReplaceElement>();
+
+    Vector<ReplaceElement> foReplaceVector = new Vector<>();
     foReplaceVector.addElement(new ReplaceElement("&", "&#38;"));
     foReplaceVector.addElement(new ReplaceElement("<", "&#60;"));
     foReplaceVector.addElement(new ReplaceElement(">", "&#62;"));
@@ -162,35 +82,31 @@
     foReplaceVector.addElement(new ReplaceElement("€", "&#8364;"));
     foReplaceVector.addElement(new ReplaceElement("\n", "&#10;"));
     replaceHashtable.put("fo", foReplaceVector);
-    Vector<ReplaceElement> htmlPreformatedReplaceVector = new 
Vector<ReplaceElement>();
+
+    Vector<ReplaceElement> htmlPreformatedReplaceVector = new Vector<>();
     htmlPreformatedReplaceVector.addElement(new ReplaceElement("&", "&amp;"));
     htmlPreformatedReplaceVector.addElement(new ReplaceElement("\"", 
"&quot;"));
-    // htmlPreformatedReplaceVector.addElement(new
-    // ReplaceElement("'","\\'"));
     htmlPreformatedReplaceVector.addElement(new ReplaceElement("<", "&lt;"));
     htmlPreformatedReplaceVector.addElement(new ReplaceElement(">", "&gt;"));
     htmlPreformatedReplaceVector.addElement(new ReplaceElement("\n", "<BR>"));
     htmlPreformatedReplaceVector.addElement(new ReplaceElement("\r", " "));
     htmlPreformatedReplaceVector.addElement(new ReplaceElement("®", "&reg;"));
     replaceHashtable.put("htmlPreformated", htmlPreformatedReplaceVector);
-    Vector<ReplaceElement> htmlHelpReplaceVector = new 
Vector<ReplaceElement>();
+
+    Vector<ReplaceElement> htmlHelpReplaceVector = new Vector<>();
     htmlHelpReplaceVector.addElement(new ReplaceElement("\n", "<BR>"));
     htmlHelpReplaceVector.addElement(new ReplaceElement("\r", ""));
     replaceHashtable.put("htmlHelp", htmlHelpReplaceVector);
-    Vector<ReplaceElement> htmlPreformatedTextareaReplaceVector = new 
Vector<ReplaceElement>();
+
+    Vector<ReplaceElement> htmlPreformatedTextareaReplaceVector = new 
Vector<>();
     htmlPreformatedTextareaReplaceVector.addElement(new ReplaceElement("&", 
"&amp;"));
     htmlPreformatedTextareaReplaceVector.addElement(new ReplaceElement("\"", 
"&quot;"));
-    // htmlPreformatedTextareaReplaceVector.addElement(new
-    // ReplaceElement("'","\\'"));
     htmlPreformatedTextareaReplaceVector.addElement(new ReplaceElement("<", 
"&lt;"));
     htmlPreformatedTextareaReplaceVector.addElement(new ReplaceElement(">", 
"&gt;"));
-    // htmlPreformatedTextareaReplaceVector.addElement(new
-    // ReplaceElement("\n","<BR>"));
-    // htmlPreformatedTextareaReplaceVector.addElement(new
-    // ReplaceElement("\r","<BR>"));
     htmlPreformatedTextareaReplaceVector.addElement(new ReplaceElement("®", 
"&reg;"));
     replaceHashtable.put("htmlPreformatedTextarea", 
htmlPreformatedTextareaReplaceVector);
-    Vector<ReplaceElement> htmlJavaScriptReplaceVector = new 
Vector<ReplaceElement>();
+
+    Vector<ReplaceElement> htmlJavaScriptReplaceVector = new Vector<>();
     htmlJavaScriptReplaceVector.addElement(new ReplaceElement("'", "\\'"));
     htmlJavaScriptReplaceVector.addElement(new ReplaceElement("\"", "&quot;"));
     htmlJavaScriptReplaceVector.addElement(new ReplaceElement("\n", "\\n"));
@@ -198,39 +114,19 @@
   }
 
   public void initialize() {
-    hasXmlTemplate = new Hashtable<String, XmlTemplate>(); // vector of
-    // XmlTemplates
-    stcRead = new Stack<XmlTemplate>(); // stack of XmlTemplates not readed
-    formatHashtable = new Hashtable<String, FormatCouple>();
+    hasXmlTemplate = new Hashtable<>();
+    stcRead = new Stack<>(); // stack of XmlTemplates not read
+    formatHashtable = new Hashtable<>();
     XMLReader xmlParserFormat = new SAXParser();
     xmlParserFormat.setContentHandler(new FormatRead(formatHashtable));
-    if (log4jXmlEngine.isDebugEnabled()) {
-      log4jXmlEngine.debug("XmlEngine file formats: " + strFormatFile);
-    }
-    // File fileXmlEngineFormat = new File (fileBaseLocation,
-    // strFormatFile);
-    // String strFormatFile =
-    // "c:\\Apps\\src\\org\\openbravo\\data\\examples\\FormatExample1.xml";
-    // File fileXmlEngineFormat = new File (strFormatFile);
-    if (log4jXmlEngine.isDebugEnabled()) {
-      log4jXmlEngine.debug("fileXmlEngineFormat: " + 
fileXmlEngineFormat.toString());
-    }
+
+    log4jXmlEngine.debug("XmlEngine file formats: {}", strFormatFile);
+    log4jXmlEngine.debug("fileXmlEngineFormat: {}", fileXmlEngineFormat);
     try {
-      // xmlParserFormat.parse(new InputSource(new
-      // FileReader(fileXmlEngineFormat)));
       xmlParserFormat.parse(new InputSource(
           new InputStreamReader(new FileInputStream(fileXmlEngineFormat), 
"UTF-8")));
-    } catch (FileNotFoundException e) {
-      log4jXmlEngine
-          .error("not found fileXmlEngineFormat: " + fileXmlEngineFormat + 
"\n" + e.getMessage());
-      return;
-    } catch (IOException e) {
-      log4jXmlEngine.error("IOException in fileXmlEngineFormat: " + 
fileXmlEngineFormat);
-      e.printStackTrace();
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to