private DecimalFormat getNumberFormatter ( TransformerImpl transformer , int contextNode ) throws TransformerException { // Patch from Steven Serocki // Maybe we really want to do the clone in getLocale() and return // a clone of the default Locale?? Locale locale = ( Locale ) getLocale ( transformer , contextNode ) . clone ( ) ; // Helper to format local specific numbers to strings. DecimalFormat formatter = null ; //synchronized (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 an AVT was used; otherwise this was // validated statically in XSLTAttributeDef.java. if ( ( digitGroupSepValue != null ) && ( ! m_groupingSeparator_avt . isSimple ( ) ) && ( 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 ) && // Ignore if separation value is empty string ( digitGroupSepValue . length ( ) > 0 ) ) { try { formatter = ( DecimalFormat ) NumberFormat . getNumberInstance ( locale ) ; formatter . setGroupingSize ( Integer . valueOf ( nDigitsPerGroupValue ) . intValue ( ) ) ; DecimalFormatSymbols symbols = formatter . getDecimalFormatSymbols ( ) ; symbols . setGroupingSeparator ( digitGroupSepValue . charAt ( 0 ) ) ; formatter . setDecimalFormatSymbols ( symbols ) ; formatter . setGroupingUsed ( true ) ; } catch ( NumberFormatException ex ) { formatter . setGroupingUsed ( false ) ; } } return formatter ; }
Get the number formatter to be used the format the numbers