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/07/22 12:51:34 UTC
(xalan-java) branch xalan-j_xslt3.0 updated: committing fix for jira issue XALANJ-2763, and minor code change in another codebase file
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 30769d9e5 committing fix for jira issue XALANJ-2763, and minor code change in another codebase file
30769d9e5 is described below
commit 30769d9e585fa9192ad8d76230454f5bd6a78bdc
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Mon Jul 22 18:21:26 2024 +0530
committing fix for jira issue XALANJ-2763, and minor code change in another codebase file
---
src/org/apache/xpath/functions/FuncReplace.java | 50 ++++++++++++-------------
src/org/apache/xpath/operations/Range.java | 16 +++++---
2 files changed, 35 insertions(+), 31 deletions(-)
diff --git a/src/org/apache/xpath/functions/FuncReplace.java b/src/org/apache/xpath/functions/FuncReplace.java
index 3600966b3..922e52f63 100644
--- a/src/org/apache/xpath/functions/FuncReplace.java
+++ b/src/org/apache/xpath/functions/FuncReplace.java
@@ -23,20 +23,17 @@ package org.apache.xpath.functions;
import javax.xml.transform.SourceLocator;
import org.apache.xalan.res.XSLMessages;
-import org.apache.xml.utils.XMLString;
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
import org.apache.xpath.XPathContext;
import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XString;
import org.apache.xpath.regex.Matcher;
import org.apache.xpath.regex.PatternSyntaxException;
import org.apache.xpath.res.XPATHErrorResources;
+import xml.xpath31.processor.types.XSString;
+
/**
- * Execute the replace() function.
- *
- * This function returns a string, produced from the input string by
- * replacing any substrings that match a given regular expression,
- * with a supplied replacement string.
+ * Implementation of the fn:replace function.
*
* @author Mukul Gandhi <mu...@apache.org>
*
@@ -49,7 +46,7 @@ public class FuncReplace extends Function4Args {
private static final String FUNCTION_NAME = "replace()";
/**
- * Execute the function. The function must return a valid object.
+ * Implementation of the function. The function must return a valid object.
*
* @param xctxt The current execution context.
* @return A valid XObject.
@@ -58,37 +55,38 @@ public class FuncReplace extends Function4Args {
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{
- SourceLocator srcLocator = xctxt.getSAXLocator();
+ XObject result = null;
+
+ SourceLocator srcLocator = xctxt.getSAXLocator();
- XMLString inputStr = m_arg0.execute(xctxt).xstr();
- XMLString pattern = m_arg1.execute(xctxt).xstr();
- XMLString replacement = m_arg2.execute(xctxt).xstr();
+ String inputStr = XslTransformEvaluationHelper.getStrVal(m_arg0.execute(xctxt));
+ String patternStr = XslTransformEvaluationHelper.getStrVal(m_arg1.execute(xctxt));
+ String replacementStr = XslTransformEvaluationHelper.getStrVal(m_arg2.execute(xctxt));
- XMLString flags = null;
+ String flagStr = null;
if (m_arg3 != null) {
- flags = m_arg3.execute(xctxt).xstr();
- if (!RegexEvaluationSupport.isFlagStrValid(flags.toString())) {
+ flagStr = XslTransformEvaluationHelper.getStrVal(m_arg3.execute(xctxt));
+ if (!RegexEvaluationSupport.isFlagStrValid(flagStr)) {
throw new javax.xml.transform.TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.
- ER_INVALID_REGEX_FLAGS, new Object[]{ FUNCTION_NAME }),
- srcLocator);
+ ER_INVALID_REGEX_FLAGS, new Object[]{ FUNCTION_NAME }),
+ srcLocator);
}
}
- String resultStr = null;
-
try {
- Matcher matcher = RegexEvaluationSupport.regex(RegexEvaluationSupport.transformRegexStrForSubtractionOp(pattern.toString()),
- flags != null ? flags.toString() : null, inputStr.toString());
- resultStr = matcher.replaceAll(replacement.toString());
+ Matcher matcher = RegexEvaluationSupport.regex(RegexEvaluationSupport.transformRegexStrForSubtractionOp(
+ patternStr), flagStr, inputStr);
+ String resultStr = matcher.replaceAll(replacementStr);
+ result = new XSString(resultStr);
}
catch (PatternSyntaxException ex) {
throw new javax.xml.transform.TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.
- ER_INVALID_REGEX, new Object[]{ FUNCTION_NAME }),
- srcLocator);
- }
+ ER_INVALID_REGEX, new Object[]{ FUNCTION_NAME }),
+ srcLocator);
+ }
- return new XString(resultStr);
+ return result;
}
/**
diff --git a/src/org/apache/xpath/operations/Range.java b/src/org/apache/xpath/operations/Range.java
index f32ae66cf..1371fc15e 100644
--- a/src/org/apache/xpath/operations/Range.java
+++ b/src/org/apache/xpath/operations/Range.java
@@ -120,13 +120,19 @@ public class Range extends Operation
if (xpathToOperand instanceof XSNumericType) {
String strVal = ((XSNumericType)xpathToOperand).stringValue();
- result = new BigInteger(strVal);
+ try {
+ result = new BigInteger(strVal);
+ }
+ catch (NumberFormatException ex) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : An XPath range 'to' operator's "
+ + "operand is not an integer.", srcLocator);
+ }
}
else if (xpathToOperand instanceof XNumber) {
double dbl = ((XNumber)xpathToOperand).num();
if (dbl > (long)dbl) {
- throw new javax.xml.transform.TransformerException("XPTY0004 : An item type of range 'to' operator's "
- + "operand is not numeric.", srcLocator);
+ throw new javax.xml.transform.TransformerException("XPTY0004 : An XPath range 'to' operator's "
+ + "operand is not an integer.", srcLocator);
}
else {
result = BigInteger.valueOf((long)dbl);
@@ -139,8 +145,8 @@ public class Range extends Operation
result = new BigInteger(strVal);
}
catch (NumberFormatException ex) {
- throw new javax.xml.transform.TransformerException("XPTY0004 : An item type of range 'to' operator's "
- + "operand is not numeric.", srcLocator);
+ throw new javax.xml.transform.TransformerException("XPTY0004 : An XPath range 'to' operator's "
+ + "operand is not an integer.", srcLocator);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org