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/07 08:57:58 UTC
(xalan-java) branch xalan-j_xslt3.0 updated: committing minor changes to, comments within few xalan-j code files within this dev repos branch
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 3ffe0f98 committing minor changes to, comments within few xalan-j code files within this dev repos branch
3ffe0f98 is described below
commit 3ffe0f982a1502ee4d0eaf6323b3f6f3209b18ae
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Fri Jun 7 14:26:25 2024 +0530
committing minor changes to, comments within few xalan-j code files
within this dev repos branch
---
src/org/apache/xpath/compiler/XPathParserImpl.java | 69 +++++++++++-----------
.../xpath/functions/map/FuncMapContains.java | 6 +-
.../apache/xpath/functions/map/FuncMapEntry.java | 8 +--
.../apache/xpath/functions/map/FuncMapForEach.java | 2 +-
src/org/apache/xpath/functions/map/FuncMapGet.java | 2 +-
.../apache/xpath/functions/map/FuncMapKeys.java | 6 +-
.../apache/xpath/functions/map/FuncMapMerge.java | 68 ++++++++++-----------
src/org/apache/xpath/functions/map/FuncMapPut.java | 12 ++--
.../apache/xpath/functions/map/FuncMapSize.java | 6 +-
9 files changed, 80 insertions(+), 99 deletions(-)
diff --git a/src/org/apache/xpath/compiler/XPathParserImpl.java b/src/org/apache/xpath/compiler/XPathParserImpl.java
index 5801e879..a743435a 100644
--- a/src/org/apache/xpath/compiler/XPathParserImpl.java
+++ b/src/org/apache/xpath/compiler/XPathParserImpl.java
@@ -1602,6 +1602,37 @@ public class XPathParserImpl
}
}
+ /**
+ * Get XPath map constructor's string value.
+ */
+ private String getMapConstructorStrValue() throws TransformerException {
+ StringBuffer mapStrBuf = new StringBuffer();
+
+ mapStrBuf.append(m_token);
+
+ consumeExpected("map");
+ while (m_token != null) {
+ if (tokenIs('}')) {
+ mapStrBuf.append(m_token);
+ consumeExpected('}');
+ if (getCharCount(mapStrBuf.toString(), '{') ==
+ getCharCount(mapStrBuf.toString(), '}')) {
+ break;
+ }
+ else {
+ mapStrBuf.append(m_token);
+ nextToken();
+ }
+ }
+ else {
+ mapStrBuf.append(m_token);
+ nextToken();
+ }
+ }
+
+ return mapStrBuf.toString();
+ }
+
/**
* Get XPath array constructor's string value.
*/
@@ -1634,45 +1665,13 @@ public class XPathParserImpl
}
/**
- * Get XPath map constructor's string value.
- */
- private String getMapConstructorStrValue() throws TransformerException {
- StringBuffer mapStrBuf = new StringBuffer();
-
- mapStrBuf.append(m_token);
-
- consumeExpected("map");
- while (m_token != null) {
- if (tokenIs('}')) {
- mapStrBuf.append(m_token);
- consumeExpected('}');
- if (countCharInStr(mapStrBuf.toString(), '{') ==
- countCharInStr(mapStrBuf.toString(), '}')) {
- break;
- }
- else {
- mapStrBuf.append(m_token);
- nextToken();
- }
- }
- else {
- mapStrBuf.append(m_token);
- nextToken();
- }
- }
-
- return mapStrBuf.toString();
- }
-
- /**
- * Get the count of specified character within
- * a string.
+ * Get the count of specified character within a string.
*/
- private int countCharInStr(String str, char cVal) {
+ private int getCharCount(String str, char c) {
int count = 0;
for (int idx = 0; idx < str.length(); idx++) {
- if (str.charAt(idx) == cVal) {
+ if (str.charAt(idx) == c) {
count++;
}
}
diff --git a/src/org/apache/xpath/functions/map/FuncMapContains.java b/src/org/apache/xpath/functions/map/FuncMapContains.java
index b230f629..713129b3 100644
--- a/src/org/apache/xpath/functions/map/FuncMapContains.java
+++ b/src/org/apache/xpath/functions/map/FuncMapContains.java
@@ -18,8 +18,6 @@ package org.apache.xpath.functions.map;
import java.util.Map;
-import javax.xml.transform.SourceLocator;
-
import org.apache.xpath.Expression;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.Function2Args;
@@ -32,7 +30,7 @@ import xml.xpath31.processor.types.XSBoolean;
import xml.xpath31.processor.types.XSString;
/**
- * Implementation of an map:contains function.
+ * Implementation of an XPath 3.1 function, map:contains.
*
* @author Mukul Gandhi <mu...@apache.org>
*
@@ -46,8 +44,6 @@ public class FuncMapContains extends Function2Args {
{
XObject result = null;
- SourceLocator srcLocator = xctxt.getSAXLocator();
-
Expression arg0 = getArg0();
XPathMap xpathMap = null;
diff --git a/src/org/apache/xpath/functions/map/FuncMapEntry.java b/src/org/apache/xpath/functions/map/FuncMapEntry.java
index fc511093..e02dd545 100644
--- a/src/org/apache/xpath/functions/map/FuncMapEntry.java
+++ b/src/org/apache/xpath/functions/map/FuncMapEntry.java
@@ -16,8 +16,6 @@
*/
package org.apache.xpath.functions.map;
-import javax.xml.transform.SourceLocator;
-
import org.apache.xpath.Expression;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.Function2Args;
@@ -29,7 +27,7 @@ import org.apache.xpath.operations.Variable;
import xml.xpath31.processor.types.XSString;
/**
- * Implementation of an map:entry function.
+ * Implementation of an XPath 3.1 function, map:entry.
*
* @author Mukul Gandhi <mu...@apache.org>
*
@@ -41,9 +39,7 @@ public class FuncMapEntry extends Function2Args {
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{
- XObject result = null;
-
- SourceLocator srcLocator = xctxt.getSAXLocator();
+ XObject result = null;
Expression arg0 = getArg0();
Expression arg1 = getArg1();
diff --git a/src/org/apache/xpath/functions/map/FuncMapForEach.java b/src/org/apache/xpath/functions/map/FuncMapForEach.java
index 7e2889f2..dc466a50 100644
--- a/src/org/apache/xpath/functions/map/FuncMapForEach.java
+++ b/src/org/apache/xpath/functions/map/FuncMapForEach.java
@@ -43,7 +43,7 @@ import org.apache.xpath.operations.Variable;
import org.apache.xpath.res.XPATHErrorResources;
/**
- * Implementation of map:for-each function.
+ * Implementation of an XPath 3.1 function, map:for-each.
*
* @author Mukul Gandhi <mu...@apache.org>
*
diff --git a/src/org/apache/xpath/functions/map/FuncMapGet.java b/src/org/apache/xpath/functions/map/FuncMapGet.java
index 17702b94..afa016e4 100644
--- a/src/org/apache/xpath/functions/map/FuncMapGet.java
+++ b/src/org/apache/xpath/functions/map/FuncMapGet.java
@@ -31,7 +31,7 @@ import org.apache.xpath.operations.Variable;
import xml.xpath31.processor.types.XSString;
/**
- * Implementation of an map:get function.
+ * Implementation of an XPath 3.1 function, map:get.
*
* @author Mukul Gandhi <mu...@apache.org>
*
diff --git a/src/org/apache/xpath/functions/map/FuncMapKeys.java b/src/org/apache/xpath/functions/map/FuncMapKeys.java
index 580604b4..fe5eb1a8 100644
--- a/src/org/apache/xpath/functions/map/FuncMapKeys.java
+++ b/src/org/apache/xpath/functions/map/FuncMapKeys.java
@@ -20,8 +20,6 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import javax.xml.transform.SourceLocator;
-
import org.apache.xpath.Expression;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.FunctionOneArg;
@@ -31,7 +29,7 @@ import org.apache.xpath.objects.XPathMap;
import org.apache.xpath.operations.Variable;
/**
- * Implementation of an map:keys function.
+ * Implementation of an XPath 3.1 function, map:keys.
*
* @author Mukul Gandhi <mu...@apache.org>
*
@@ -45,8 +43,6 @@ public class FuncMapKeys extends FunctionOneArg {
{
ResultSequence resultSeq = new ResultSequence();
- SourceLocator srcLocator = xctxt.getSAXLocator();
-
Expression arg0 = getArg0();
if (arg0 instanceof Variable) {
diff --git a/src/org/apache/xpath/functions/map/FuncMapMerge.java b/src/org/apache/xpath/functions/map/FuncMapMerge.java
index a40a1ff3..d15d6d96 100644
--- a/src/org/apache/xpath/functions/map/FuncMapMerge.java
+++ b/src/org/apache/xpath/functions/map/FuncMapMerge.java
@@ -37,7 +37,7 @@ import org.apache.xpath.operations.Variable;
import xml.xpath31.processor.types.XSString;
/**
- * Implementation of an map:merge function.
+ * Implementation of an XPath 3.1 function, map:merge.
*
* @author Mukul Gandhi <mu...@apache.org>
*
@@ -82,7 +82,7 @@ public class FuncMapMerge extends FunctionMultiArgs {
validateTypeOfSecondArg(arg1, xctxt);
}
- if ((arg1 != null) && OPTION_REJECT.equals(getOptionsStrVal(arg1, xctxt)) && isMapMergeReject(arg0, xctxt)) {
+ if ((arg1 != null) && OPTION_REJECT.equals(getOptionsStrVal(arg1, xctxt)) && isMapMergeToBeRejected(arg0, xctxt)) {
throw new javax.xml.transform.TransformerException("FOJS0003 : Maps could not be merged, because one or more duplicate "
+ "keys were found within maps to be merged, and an map merge "
+ "option 'reject' was used.", srcLocator);
@@ -176,7 +176,8 @@ public class FuncMapMerge extends FunctionMultiArgs {
// This variable shall contain union of keys of all the maps, in
// an input sequence (i.e, map:merge function call's 1st argument).
- Set<XObject> distinctMapKeys = new HashSet<XObject>();
+ Set<XObject> distinctMapKeys = new HashSet<XObject>();
+
if (arg0 instanceof Variable) {
rSeq = (ResultSequence)(((Variable)arg0).execute(xctxt));
for (int idx = 0; idx < rSeq.size(); idx++) {
@@ -217,74 +218,75 @@ public class FuncMapMerge extends FunctionMultiArgs {
}
/**
- * Should the merge of maps be rejected, due to any duplicate keys present within maps.
+ * Determine, whether the merge of maps is to be rejected, due to any duplicate
+ * keys present within all input maps to be merged.
*/
- private boolean isMapMergeReject(Expression arg0, XPathContext xctxt) throws TransformerException {
+ private boolean isMapMergeToBeRejected(Expression inputMapsExpr, XPathContext xctxt) throws TransformerException {
- boolean isMapMergeReject = true;
+ boolean result = true;
ResultSequence rSeq = null;
- if (arg0 instanceof Variable) {
- rSeq = (ResultSequence)(((Variable)arg0).execute(xctxt));
+ if (inputMapsExpr instanceof Variable) {
+ rSeq = (ResultSequence)(((Variable)inputMapsExpr).execute(xctxt));
}
else {
- rSeq = (ResultSequence)(arg0.execute(xctxt));
+ rSeq = (ResultSequence)(inputMapsExpr.execute(xctxt));
}
- int totalKeys = 0;
+ int totalMapKeys = 0;
+ // This variable shall contain, distinct key values across
+ // all input maps to be merged.
Set<XObject> mergeOfKeysSet = new HashSet<XObject>();
for (int idx = 0; idx < rSeq.size(); idx++) {
XPathMap map = (XPathMap)rSeq.item(idx);
Map<XObject, XObject> nativeMap = map.getNativeMap();
Set<XObject> keysSet = nativeMap.keySet();
- totalKeys += keysSet.size();
+ totalMapKeys += keysSet.size();
mergeOfKeysSet.addAll(keysSet);
}
- int countOfKeysAfterKeyMerge = mergeOfKeysSet.size();
-
- if (totalKeys == countOfKeysAfterKeyMerge) {
- isMapMergeReject = false;
+ if (totalMapKeys == mergeOfKeysSet.size()) {
+ result = false;
}
- return isMapMergeReject;
+ return result;
}
/**
- * Get the string value, of map's key named "duplicates".
+ * Get the string value, of map entry's value for entry key name "duplicates".
*/
- private String getOptionsStrVal(Expression expr, XPathContext xctxt) throws TransformerException {
+ private String getOptionsStrVal(Expression optionsMapExpr, XPathContext xctxt) throws TransformerException {
- String optionsStrVal = null;
+ String optionsMapEntryValue = null;
- if (expr instanceof Variable) {
- XObject obj = ((Variable)expr).execute(xctxt);
+ if (optionsMapExpr instanceof Variable) {
+ XObject obj = ((Variable)optionsMapExpr).execute(xctxt);
XPathMap xpathMap = (XPathMap)obj;
obj = xpathMap.get(new XSString(DUPLICATES_KEY_NAME));
- optionsStrVal = XslTransformEvaluationHelper.getStrVal(obj);
+ optionsMapEntryValue = XslTransformEvaluationHelper.getStrVal(obj);
}
else {
- XObject obj = expr.execute(xctxt);
+ XObject obj = optionsMapExpr.execute(xctxt);
XPathMap xpathMap = (XPathMap)obj;
obj = xpathMap.get(new XSString(DUPLICATES_KEY_NAME));
- optionsStrVal = XslTransformEvaluationHelper.getStrVal(obj);
+ optionsMapEntryValue = XslTransformEvaluationHelper.getStrVal(obj);
}
- return optionsStrVal;
+ return optionsMapEntryValue;
}
/**
* Validate the expected type of map:merge function's, 1st argument.
*/
- private void validateTypeOfFirstArg(Expression arg, XPathContext xctxt) throws TransformerException {
+ private void validateTypeOfFirstArg(Expression arg0, XPathContext xctxt) throws TransformerException {
SourceLocator srcLocator = xctxt.getSAXLocator();
- if (arg instanceof Variable) {
- XObject obj = ((Variable)arg).execute(xctxt);
+ if (arg0 instanceof Variable) {
+ XObject obj = ((Variable)arg0).execute(xctxt);
if (obj instanceof ResultSequence) {
ResultSequence rSeq = (ResultSequence)obj;
for (int idx = 0; idx < rSeq.size(); idx++) {
@@ -302,7 +304,7 @@ public class FuncMapMerge extends FunctionMultiArgs {
}
}
else {
- XObject obj = arg.execute(xctxt);
+ XObject obj = arg0.execute(xctxt);
if (obj instanceof ResultSequence) {
ResultSequence rSeq = (ResultSequence)obj;
for (int idx = 0; idx < rSeq.size(); idx++) {
@@ -324,18 +326,18 @@ public class FuncMapMerge extends FunctionMultiArgs {
/**
* Validate the expected type of map:merge function's, 2nd argument.
*/
- private void validateTypeOfSecondArg(Expression arg, XPathContext xctxt) throws TransformerException {
+ private void validateTypeOfSecondArg(Expression arg1, XPathContext xctxt) throws TransformerException {
SourceLocator srcLocator = xctxt.getSAXLocator();
- if (arg instanceof Variable) {
- XObject obj = ((Variable)arg).execute(xctxt);
+ if (arg1 instanceof Variable) {
+ XObject obj = ((Variable)arg1).execute(xctxt);
if (obj instanceof XPathMap) {
validateOptionsMap(obj, srcLocator);
}
}
else {
- XObject obj = arg.execute(xctxt);
+ XObject obj = arg1.execute(xctxt);
if (obj instanceof XPathMap) {
validateOptionsMap(obj, srcLocator);
}
diff --git a/src/org/apache/xpath/functions/map/FuncMapPut.java b/src/org/apache/xpath/functions/map/FuncMapPut.java
index 7aa452e9..583cb79b 100644
--- a/src/org/apache/xpath/functions/map/FuncMapPut.java
+++ b/src/org/apache/xpath/functions/map/FuncMapPut.java
@@ -18,8 +18,6 @@ package org.apache.xpath.functions.map;
import java.util.Map;
-import javax.xml.transform.SourceLocator;
-
import org.apache.xpath.Expression;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.Function3Args;
@@ -28,7 +26,7 @@ import org.apache.xpath.objects.XPathMap;
import org.apache.xpath.operations.Variable;
/**
- * Implementation of an map:put function.
+ * Implementation of an XPath 3.1 function, map:put.
*
* @author Mukul Gandhi <mu...@apache.org>
*
@@ -42,9 +40,7 @@ public class FuncMapPut extends Function3Args {
{
XObject result = null;
- SourceLocator srcLocator = xctxt.getSAXLocator();
-
- Expression arg0 = getArg0(); // 'map' argument
+ Expression arg0 = getArg0();
XPathMap xpathMap = null;
if (arg0 instanceof Variable) {
@@ -58,10 +54,10 @@ public class FuncMapPut extends Function3Args {
Map<XObject, XObject> nativeMap = xpathMap.getNativeMap();
- Expression arg1 = getArg1(); // 'key' argument
+ Expression arg1 = getArg1();
XObject mapEntryKey = arg1.execute(xctxt);
- Expression arg2 = getArg2(); // 'value' argument
+ Expression arg2 = getArg2();
XObject mapEntryValue = arg2.execute(xctxt);
nativeMap.put(mapEntryKey, mapEntryValue);
diff --git a/src/org/apache/xpath/functions/map/FuncMapSize.java b/src/org/apache/xpath/functions/map/FuncMapSize.java
index 2b04e10e..64e40a01 100644
--- a/src/org/apache/xpath/functions/map/FuncMapSize.java
+++ b/src/org/apache/xpath/functions/map/FuncMapSize.java
@@ -16,8 +16,6 @@
*/
package org.apache.xpath.functions.map;
-import javax.xml.transform.SourceLocator;
-
import org.apache.xpath.Expression;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.FunctionOneArg;
@@ -29,7 +27,7 @@ import org.apache.xpath.operations.Variable;
import xml.xpath31.processor.types.XSInteger;
/**
- * Implementation of the map:size function.
+ * Implementation of an XPath 3.1 function, map:size.
*
* @author Mukul Gandhi <mu...@apache.org>
*
@@ -43,8 +41,6 @@ public class FuncMapSize extends FunctionOneArg {
{
XObject result = null;
- SourceLocator srcLocator = xctxt.getSAXLocator();
-
Expression arg0 = getArg0();
if (arg0 instanceof Variable) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org