1 16 package org.apache.cocoon.faces.taglib; 17 18 import org.apache.cocoon.i18n.I18nUtils; 19 20 import org.apache.cocoon.faces.FacesUtils; 21 import org.xml.sax.Attributes ; 22 import org.xml.sax.SAXException ; 23 24 import javax.faces.convert.Converter; 25 import javax.faces.convert.NumberConverter; 26 import java.util.Locale ; 27 28 31 public class ConvertNumberTag extends ConverterTag { 32 private String currencyCode; 33 private String currencySymbol; 34 private String groupingUsed; 35 private String integerOnly; 36 private String maxFractionDigits; 37 private String maxIntegerDigits; 38 private String minFractionDigits; 39 private String minIntegerDigits; 40 private String locale; 41 private String pattern; 42 private String type; 43 44 45 public void setCurrencyCode(String currencyCode) { 46 this.currencyCode = currencyCode; 47 } 48 49 public void setCurrencySymbol(String currencySymbol) { 50 this.currencySymbol = currencySymbol; 51 } 52 53 public void setGroupingUsed(String groupingUsed) { 54 this.groupingUsed = groupingUsed; 55 } 56 57 public void setIntegerOnly(String integerOnly) { 58 this.integerOnly = integerOnly; 59 } 60 61 public void setMaxFractionDigits(String maxFractionDigits) { 62 this.maxFractionDigits = maxFractionDigits; 63 } 64 65 public void setMaxIntegerDigits(String maxIntegerDigits) { 66 this.maxIntegerDigits = maxIntegerDigits; 67 } 68 69 public void setMinFractionDigits(String minFractionDigits) { 70 this.minFractionDigits = minFractionDigits; 71 } 72 73 public void setMinIntegerDigits(String minIntegerDigits) { 74 this.minIntegerDigits = minIntegerDigits; 75 } 76 77 public void setLocale(String locale) { 78 this.locale = locale; 79 } 80 81 public void setPattern(String pattern) { 82 this.pattern = pattern; 83 } 84 85 public void setType(String type) { 86 this.type = type; 87 } 88 89 90 public int doStartTag(String namespaceURI, String localName, String qName, Attributes atts) 91 throws SAXException { 92 super.setConverterId("javax.faces.Number"); 93 return super.doStartTag(namespaceURI, localName, qName, atts); 94 } 95 96 protected Converter createConverter() { 97 final UIComponentTag tag = FacesUtils.findParentUIComponentTag(this); 98 NumberConverter converter = (NumberConverter) super.createConverter(); 99 100 converter.setCurrencyCode((String ) tag.evaluate(currencyCode)); 101 converter.setCurrencySymbol((String ) tag.evaluate(currencySymbol)); 102 converter.setPattern((String ) tag.evaluate(pattern)); 103 converter.setType((String ) tag.evaluate(type)); 104 105 if (groupingUsed != null) { 106 converter.setGroupingUsed(tag.evaluateBoolean(groupingUsed)); 107 } 108 if (integerOnly != null) { 109 converter.setIntegerOnly(tag.evaluateBoolean(integerOnly)); 110 } 111 112 if (maxFractionDigits != null) { 113 converter.setMaxFractionDigits(tag.evaluateInteger(maxFractionDigits)); 114 } 115 if (maxIntegerDigits != null) { 116 converter.setMaxIntegerDigits(tag.evaluateInteger(maxIntegerDigits)); 117 } 118 if (minFractionDigits != null) { 119 converter.setMinFractionDigits(tag.evaluateInteger(minFractionDigits)); 120 } 121 if (minIntegerDigits != null) { 122 converter.setMinIntegerDigits(tag.evaluateInteger(minIntegerDigits)); 123 } 124 125 Locale l = null; 126 if (locale != null) { 127 if (FacesUtils.isExpression(locale)) { 128 l = (Locale ) tag.evaluate(locale); 129 } else { 130 l = I18nUtils.parseLocale(locale); 131 } 132 } 133 converter.setLocale(l); 134 135 return converter; 136 } 137 138 public void recycle() { 139 super.recycle(); 140 currencyCode = null; 141 currencySymbol = null; 142 groupingUsed = null; 143 integerOnly = null; 144 maxFractionDigits = null; 145 maxIntegerDigits = null; 146 minFractionDigits = null; 147 minIntegerDigits = null; 148 locale = null; 149 pattern = null; 150 type = null; 151 } 152 } 153 | Popular Tags |