diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/string/FlexibleStringExpander.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/string/FlexibleStringExpander.java index 22296e8661..03f4a950e9 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/string/FlexibleStringExpander.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/string/FlexibleStringExpander.java @@ -31,6 +31,7 @@ import javax.el.PropertyNotFoundException; import org.apache.ofbiz.base.lang.IsEmpty; import org.apache.ofbiz.base.lang.SourceMonitored; import org.apache.ofbiz.base.util.Debug; +import org.apache.ofbiz.base.util.GeneralException; import org.apache.ofbiz.base.util.ObjectType; import org.apache.ofbiz.base.util.ScriptUtil; import org.apache.ofbiz.base.util.UtilDateTime; @@ -441,7 +442,8 @@ public abstract class FlexibleStringExpander implements Serializable, IsEmpty { buffer.append(ObjectType.simpleTypeConvert(obj, "String", null, timeZone, locale, true)); } } - } catch (Exception e) { + } catch (GeneralException | RuntimeException e) { + Debug.log(e, module); buffer.append(obj); } if (buffer.length() > this.hint) { diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/string/JuelConnector.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/string/JuelConnector.java index 8dc51ff2c0..8b2b712931 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/string/JuelConnector.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/string/JuelConnector.java @@ -78,7 +78,9 @@ public class JuelConnector { Object base = null; try { base = prefix.eval(bindings, context); - } catch (Exception e) {} + } catch (Exception e) { + Debug.log(e, module); + } Object property = getProperty(bindings, context); if (property == null && strict) { throw new PropertyNotFoundException(LocalMessages.get("error.property.property.notfound", "null", base)); @@ -112,7 +114,9 @@ public class JuelConnector { Object base = null; try { base = prefix.eval(bindings, context); - } catch (Exception e) {} + } catch (Exception e) { + Debug.log(e, module); + } Object property = getProperty(bindings, context); if (property == null && strict) { throw new PropertyNotFoundException(LocalMessages.get("error.property.property.notfound", "null", base)); @@ -179,9 +183,7 @@ public class JuelConnector { public Tree build(String expression) throws ELException { try { return new ExtendedParser(this, expression).tree(); - } catch (ScanException e) { - throw new ELException(LocalMessages.get("error.build", expression, e.getMessage())); - } catch (ParseException e) { + } catch (ScanException | ParseException e) { throw new ELException(LocalMessages.get("error.build", expression, e.getMessage())); } } diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java index 3773e5f63e..9d5ac47964 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java @@ -22,6 +22,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; +import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Method; import java.net.URL; @@ -34,6 +35,8 @@ import java.util.Map; import java.util.TimeZone; import javax.el.FunctionMapper; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamSource; @@ -41,11 +44,13 @@ import org.apache.ofbiz.base.location.FlexibleLocation; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.FileUtil; import org.apache.ofbiz.base.util.UtilDateTime; +import org.apache.ofbiz.base.util.UtilIO; import org.apache.ofbiz.base.util.UtilProperties; import org.apache.ofbiz.base.util.UtilXml; import org.cyberneko.html.parsers.DOMParser; import org.w3c.dom.Document; import org.w3c.dom.Node; +import org.xml.sax.SAXException; /** Implements Unified Expression Language functions. *
Built-in functions are divided into a number of
@@ -261,7 +266,7 @@ public class UelFunctions {
this.functionMap.put("dom:toHtmlString", UelFunctions.class.getMethod("toHtmlString", Node.class, String.class, boolean.class, int.class));
this.functionMap.put("dom:toXmlString", UelFunctions.class.getMethod("toXmlString", Node.class, String.class, boolean.class, boolean.class, int.class));
this.functionMap.put("dom:writeXmlDocument", UelFunctions.class.getMethod("writeXmlDocument", String.class, Node.class, String.class, boolean.class, boolean.class, int.class));
- } catch (Exception e) {
+ } catch (NoSuchMethodException | NullPointerException | SecurityException e) {
Debug.logError(e, "Error while initializing UelFunctions.Functions instance", module);
}
Debug.logVerbose("UelFunctions.Functions loaded " + this.functionMap.size() + " functions", module);
@@ -403,14 +408,14 @@ public class UelFunctions {
public static String toLowerCase(String str) {
try {
- return str.toLowerCase();
+ return str.toLowerCase(Locale.getDefault());
} catch (Exception e) {}
return null;
}
public static String toUpperCase(String str) {
try {
- return str.toUpperCase();
+ return str.toUpperCase(Locale.getDefault());
} catch (Exception e) {}
return null;
}
@@ -447,11 +452,13 @@ public class UelFunctions {
try {
URL url = FlexibleLocation.resolveLocation(str);
if (url != null) {
- InputStream is = url.openStream();
+ try (InputStream is = url.openStream();) {
result = true;
- is.close();
+ }
}
- } catch (Exception e) {}
+ } catch (IOException e) {
+ Debug.log(e, module);
+ }
return result;
}
@@ -467,7 +474,7 @@ public class UelFunctions {
} else {
Debug.logError("Unable to locate HTML document " + str, module);
}
- } catch (Exception e) {
+ } catch (IOException | SAXException e) {
Debug.logError(e, "Error while reading HTML document " + str, module);
}
return document;
@@ -478,13 +485,13 @@ public class UelFunctions {
try {
URL url = FlexibleLocation.resolveLocation(str);
if (url != null) {
- InputStream is = url.openStream();
- document = UtilXml.readXmlDocument(is, str);
- is.close();
+ try (InputStream is = url.openStream();) {
+ document = UtilXml.readXmlDocument(is, str);
+ }
} else {
Debug.logError("Unable to locate XML document " + str, module);
}
- } catch (Exception e) {
+ } catch (IOException | SAXException | ParserConfigurationException e) {
Debug.logError(e, "Error while reading XML document " + str, module);
}
return document;
@@ -494,14 +501,14 @@ public class UelFunctions {
try {
File file = FileUtil.getFile(str);
if (file != null) {
- FileOutputStream os = new FileOutputStream(file);
- UtilXml.writeXmlDocument(node, os, encoding, omitXmlDeclaration, indent, indentAmount);
- os.close();
- return true;
+ try (FileOutputStream os = new FileOutputStream(file);) {
+ UtilXml.writeXmlDocument(node, os, encoding, omitXmlDeclaration, indent, indentAmount);
+ return true;
+ }
} else {
Debug.logError("Unable to create XML document " + str, module);
}
- } catch (Exception e) {
+ } catch (IOException | TransformerException | SecurityException e) {
Debug.logError(e, "Error while writing XML document " + str, module);
}
return false;
@@ -526,25 +533,23 @@ public class UelFunctions {
sb.append("/>\n