You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mu...@apache.org on 2024/06/22 16:56:04 UTC
(xalan-java) branch xalan-j_xslt3.0 updated: committing fix for jira issue XALANJ-2754
This is an automated email from the ASF dual-hosted git repository.
mukulg pushed a commit to branch xalan-j_xslt3.0
in repository https://gitbox.apache.org/repos/asf/xalan-java.git
The following commit(s) were added to refs/heads/xalan-j_xslt3.0 by this push:
new 1c8fa38f4 committing fix for jira issue XALANJ-2754
1c8fa38f4 is described below
commit 1c8fa38f416d0ff04dc77eb01e7bd19904887285
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Sat Jun 22 22:25:52 2024 +0530
committing fix for jira issue XALANJ-2754
---
.../apache/xpath/functions/json/FuncParseJson.java | 47 ++++++++++++++++------
1 file changed, 35 insertions(+), 12 deletions(-)
diff --git a/src/org/apache/xpath/functions/json/FuncParseJson.java b/src/org/apache/xpath/functions/json/FuncParseJson.java
index 8d646dbc6..70f8b6482 100644
--- a/src/org/apache/xpath/functions/json/FuncParseJson.java
+++ b/src/org/apache/xpath/functions/json/FuncParseJson.java
@@ -31,6 +31,7 @@ import org.apache.xpath.Expression;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.FunctionMultiArgs;
import org.apache.xpath.functions.WrongNumberArgsException;
+import org.apache.xpath.objects.ResultSequence;
import org.apache.xpath.objects.XBooleanStatic;
import org.apache.xpath.objects.XObject;
import org.apache.xpath.objects.XPathMap;
@@ -41,6 +42,8 @@ import org.json.JSONException;
import org.json.JSONObject;
import xml.xpath31.processor.types.XSBoolean;
+import xml.xpath31.processor.types.XSDouble;
+import xml.xpath31.processor.types.XSString;
/**
* Implementation of an XPath 3.1 function, fn:parse-json.
@@ -216,25 +219,47 @@ public class FuncParseJson extends FunctionMultiArgs {
*/
private XObject parseJson(Expression xpath, XPathContext xctxt) throws javax.xml.transform.TransformerException {
- XObject result;
+ XObject result = null;
SourceLocator srcLocator = xctxt.getSAXLocator();
XObject arg0Value = xpath.execute(xctxt);
- String arg0StrValue = XslTransformEvaluationHelper.getStrVal(arg0Value);
- arg0StrValue = arg0StrValue.trim();
+ String arg0StrValue = XslTransformEvaluationHelper.getStrVal(arg0Value);
Object jsonObj = null;
try {
- if (arg0StrValue.charAt(0) == '{') {
- jsonObj = new JSONObject(arg0StrValue);
+ if ((arg0StrValue.trim()).charAt(0) == '{') {
+ jsonObj = new JSONObject(arg0StrValue);
+ result = getXdmMapOrArrayFromNativeJson(jsonObj);
}
- else if (arg0StrValue.charAt(0) == '[') {
- jsonObj = new JSONArray(arg0StrValue);
+ else if ((arg0StrValue.trim()).charAt(0) == '[') {
+ jsonObj = new JSONArray(arg0StrValue);
+ result = getXdmMapOrArrayFromNativeJson(jsonObj);
}
else {
- throw new javax.xml.transform.TransformerException("FOUT1190 : The 1st argument provided with function call "
- + "fn:parse-json is not a correct json lexical string. A json "
- + "string can begin only with '{' or '[' characters.", srcLocator);
+ try {
+ Double dbl = Double.valueOf(arg0StrValue);
+ result = new XSDouble(dbl);
+ }
+ catch (NumberFormatException ex) {
+ // NO OP
+ }
+
+ if (result == null) {
+ if ("false".equals(arg0StrValue) || "0".equals(arg0StrValue)
+ || "true".equals(arg0StrValue) || "1".equals(arg0StrValue)) {
+ result = new XSBoolean(Boolean.valueOf(arg0StrValue));
+ }
+ }
+
+ if (result == null) {
+ if ("null".equals(arg0StrValue)) {
+ result = new ResultSequence();
+ }
+ }
+
+ if (result == null) {
+ result = new XSString(arg0StrValue);
+ }
}
}
catch (JSONException ex) {
@@ -244,8 +269,6 @@ public class FuncParseJson extends FunctionMultiArgs {
srcLocator);
}
- result = getXdmMapOrArrayFromNativeJson(jsonObj);
-
return result;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org