1 16 17 package org.apache.taglibs.i18n; 18 19 import java.io.IOException ; 20 import java.text.DecimalFormat ; 21 import java.text.DecimalFormatSymbols ; 22 import java.text.Format ; 23 import java.text.NumberFormat ; 24 import java.util.Enumeration ; 25 import java.util.Locale ; 26 27 33 public class FormatNumberTag extends FormatTagSupport { 34 35 protected static final String _tagname = "i18n:formatNumber"; 36 37 private NumberFormat format; 38 private String pattern; 39 40 41 public void release() { 44 super.release(); 45 format = null; 46 pattern = null; 47 } 48 49 52 56 public Format getFormat() { 57 if ( format == null ) { 58 String pattern = getPattern(); 59 if ( pattern != null ) { 60 format = getPatternFormat( pattern ); 61 } 62 if ( pattern == null ) { 63 format = getNumberFormat(); 64 } 65 } 66 return format; 67 } 68 69 public void setFormat( NumberFormat format ) { 70 this.format = format; 71 } 72 73 public String getPattern() { 74 return pattern; 75 } 76 77 public void setPattern( String pattern ) { 78 this.pattern = pattern; 79 } 80 81 protected NumberFormat getPatternFormat( String pattern ) { 84 return new DecimalFormat ( pattern, new DecimalFormatSymbols ( getLocale() ) ); 87 } 88 89 91 protected NumberFormat getNumberFormat() { 92 return NumberFormat.getInstance( getLocale() ); 93 } 96 97 } 98 | Popular Tags |