mmidy 2002/07/01 08:41:11
Modified: java/src/org/apache/xalan/templates ElemNumber.java
Log:
Bug6268. Patch from Ilene Seelemann. Fix Grouping separator. If no grouping
separator is specified but a gouping size is, number is not formatted. If grouping
separator is "", warning is issued and number is not formatted. If grouping separator
is more than one character, warning is issued and number is not formatted.
Revision Changes Path
1.27 +28 -9 xml-xalan/java/src/org/apache/xalan/templates/ElemNumber.java
Index: ElemNumber.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemNumber.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- ElemNumber.java 11 Jun 2002 18:58:05 -0000 1.26
+++ ElemNumber.java 1 Jul 2002 15:41:11 -0000 1.27
@@ -70,6 +70,7 @@
import java.util.*;
+import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.text.DecimalFormat;
@@ -84,6 +85,7 @@
import org.apache.xalan.res.*;
import org.apache.xalan.transformer.DecimalToRoman;
import org.apache.xalan.transformer.CountersTable;
+import org.apache.xalan.transformer.ResultTreeHandler;
import org.apache.xalan.transformer.TransformerImpl;
import org.apache.xml.utils.NodeVector;
@@ -596,7 +598,7 @@
throws TransformerException
{
- if (TransformerImpl.S_DEBUG)
+ if (TransformerImpl.S_DEBUG)
transformer.getTraceManager().fireTraceEvent(this);
int sourceNode = transformer.getXPathContext().getCurrentNode();
@@ -1129,31 +1131,47 @@
Locale locale = (Locale)getLocale(transformer, contextNode).clone();
// Helper to format local specific numbers to strings.
- DecimalFormat formatter;
+ DecimalFormat formatter = null;
//synchronized (locale)
//{
- formatter = (DecimalFormat) NumberFormat.getNumberInstance(locale);
+ // formatter = (DecimalFormat) NumberFormat.getNumberInstance(locale);
//}
String digitGroupSepValue =
(null != m_groupingSeparator_avt)
? m_groupingSeparator_avt.evaluate(
transformer.getXPathContext(), contextNode, this) : null;
+
+
+ // Validate grouping separator
+ if ((digitGroupSepValue != null) && (digitGroupSepValue.length() != 1))
+ {
+ transformer.getMsgMgr().warn(
+ this, XSLTErrorResources.WG_ILLEGAL_ATTRIBUTE_VALUE,
+ new Object[]{ Constants.ATTRNAME_NAME, m_groupingSeparator_avt.getName()
});
+ }
+
+
String nDigitsPerGroupValue =
(null != m_groupingSize_avt)
? m_groupingSize_avt.evaluate(
transformer.getXPathContext(), contextNode, this) : null;
// TODO: Handle digit-group attributes
- if ((null != digitGroupSepValue) && (null != nDigitsPerGroupValue))
+ if ((null != digitGroupSepValue) && (null != nDigitsPerGroupValue) &&
+ // Ignore if separation value is empty string
+ (digitGroupSepValue.length() > 0))
{
try
{
+ formatter = (DecimalFormat) NumberFormat.getNumberInstance(locale);
formatter.setGroupingSize(
Integer.valueOf(nDigitsPerGroupValue).intValue());
- formatter.getDecimalFormatSymbols().setGroupingSeparator(
- digitGroupSepValue.charAt(0));
+
+ DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols();
+ symbols.setGroupingSeparator(digitGroupSepValue.charAt(0));
+ formatter.setDecimalFormatSymbols(symbols);
formatter.setGroupingUsed(true);
}
catch (NumberFormatException ex)
@@ -1343,8 +1361,7 @@
throws javax.xml.transform.TransformerException
{
- DecimalFormat formatter = getNumberFormatter(transformer, contextNode);
- String padString = formatter.format(0);
+
String letterVal =
(m_lettervalue_avt != null)
? m_lettervalue_avt.evaluate(
@@ -1600,7 +1617,9 @@
break;
}
default : // "1"
- String numString = formatter.format(listElement);
+ DecimalFormat formatter = getNumberFormatter(transformer, contextNode);
+ String padString = formatter == null ? String.valueOf(0) :
formatter.format(0);
+ String numString = formatter == null ? String.valueOf(listElement) :
formatter.format(listElement);
int nPadding = numberWidth - numString.length();
for (int k = 0; k < nPadding; k++)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]