This is an automated email from the ASF dual-hosted git repository. jleroux pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push: new 7af04a8473 Improved: Remove deprecated unused code (OFBIZ-12919) 7af04a8473 is described below commit 7af04a8473a498af01fbf28739e14d48b91351cf Author: Jacques Le Roux <jacques.le.r...@les7arts.com> AuthorDate: Tue Feb 27 16:59:06 2024 +0100 Improved: Remove deprecated unused code (OFBIZ-12919) A part of XslTransform class code was marked as deprecated with OFBIZ-6274, ie at least 8 years ago. I confirm this part is not used at all. I did not spot it by chance. This was bring to my attention by codeQL as a possible XXE. Even if in our case it's impossible since we don't use this code. Semantic code analysis engine like codeQL are not able to discover that, would be far too long anyway. Whatever, it's good to get rid of it now. --- .../ofbiz/base/util/template/XslTransform.java | 87 ---------------------- 1 file changed, 87 deletions(-) diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java index 17b1f89e0e..e5d970a00e 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/template/XslTransform.java @@ -19,35 +19,19 @@ package org.apache.ofbiz.base.util.template; import java.io.IOException; -import java.io.InputStream; -import java.io.StringReader; import java.io.StringWriter; -import java.net.URL; -import java.net.URLConnection; -import java.util.Map; import javax.xml.parsers.SAXParserFactory; -import javax.xml.transform.Source; import javax.xml.transform.Templates; import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMResult; -import javax.xml.transform.dom.DOMSource; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; -import org.apache.ofbiz.base.location.FlexibleLocation; import org.apache.ofbiz.base.util.Debug; -import org.apache.ofbiz.base.util.GeneralException; -import org.apache.ofbiz.base.util.URLConnector; -import org.apache.ofbiz.base.util.UtilValidate; -import org.apache.ofbiz.base.util.UtilXml; import org.apache.ofbiz.base.util.cache.UtilCache; -import org.w3c.dom.Document; -import org.w3c.dom.Node; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; @@ -93,75 +77,4 @@ public final class XslTransform { } return result; } - - /* - * it does not look like the rest of this file is working or used..........better set it to deprecated - * @deprecated - */ - @Deprecated - public static Document transform(Map<String, Object> context, Map<String, Object> params) - throws GeneralException, IOException, TransformerConfigurationException, TransformerException { - Document outputDocument = null; - TransformerFactory tFactory = TransformerFactory.newInstance(); - Templates translet = null; - String templateName = (String) context.get("templateName"); - if (UtilValidate.isNotEmpty(templateName)) { - translet = XSL_TEMPLATE_CACHE.get(templateName); - } - - if (translet == null) { - String templateUrl = (String) context.get("templateUrl"); - String templateString = (String) context.get("templateString"); - Document templateDocument = (Document) context.get("templateDocument"); - Source templateSource = getSource(templateDocument, templateUrl, templateString); - translet = tFactory.newTemplates(templateSource); - if (UtilValidate.isNotEmpty(templateName)) { - translet = XSL_TEMPLATE_CACHE.putIfAbsentAndGet(templateName, translet); - } - } - if (translet != null) { - Transformer transformer = translet.newTransformer(); - if (params != null) { - for (Map.Entry<String, Object> entry : params.entrySet()) { - String key = entry.getKey(); - Object val = entry.getValue(); - transformer.setParameter(key, val); - } - } - - DOMResult outputResult = new DOMResult(UtilXml.makeEmptyXmlDocument()); - - String inputUrl = (String) context.get("inputUrl"); - String inputString = (String) context.get("inputString"); - Document inputDocument = (Document) context.get("inputDocument"); - Source inputSource = getSource(inputDocument, inputUrl, inputString); - - transformer.transform(inputSource, outputResult); - Node nd = outputResult.getNode(); - outputDocument = (Document) nd; - } - - return outputDocument; - } - - /* - * it does not look like the rest of this file is working or used..........better set it to deprecated - * @deprecated - */ - @Deprecated - private static Source getSource(Document inputDocument, String inputUrl, String inputString) throws IOException { - Source source = null; - if (inputDocument != null) { - source = new DOMSource(inputDocument); - } else if (UtilValidate.isNotEmpty(inputString)) { - source = new StreamSource(new StringReader(inputString)); - } else if (UtilValidate.isNotEmpty(inputUrl)) { - URL url = FlexibleLocation.resolveLocation(inputUrl); - URLConnection conn = URLConnector.openConnection(url); - try (InputStream in = conn.getInputStream()) { - source = new StreamSource(in); - } - } - return source; - } }