Methods Summary |
---|
private void | configureFormatter(java.text.NumberFormat formatter)
if (groupingUsedSpecified)
formatter.setGroupingUsed(isGroupingUsed);
if (maxIntegerDigitsSpecified)
formatter.setMaximumIntegerDigits(maxIntegerDigits);
if (minIntegerDigitsSpecified)
formatter.setMinimumIntegerDigits(minIntegerDigits);
if (maxFractionDigitsSpecified)
formatter.setMaximumFractionDigits(maxFractionDigits);
if (minFractionDigitsSpecified)
formatter.setMinimumFractionDigits(minFractionDigits);
|
private java.text.NumberFormat | createFormatter(java.util.Locale loc)
NumberFormat formatter = null;
if ((type == null) || NUMBER.equalsIgnoreCase(type)) {
formatter = NumberFormat.getNumberInstance(loc);
} else if (CURRENCY.equalsIgnoreCase(type)) {
formatter = NumberFormat.getCurrencyInstance(loc);
} else if (PERCENT.equalsIgnoreCase(type)) {
formatter = NumberFormat.getPercentInstance(loc);
} else {
throw new JspException(
Resources.getMessage("FORMAT_NUMBER_INVALID_TYPE", type));
}
return formatter;
|
public int | doEndTag()
String formatted = null;
Object input = null;
// determine the input by...
if (valueSpecified) {
// ... reading 'value' attribute
input = value;
} else {
// ... retrieving and trimming our body
if (bodyContent != null && bodyContent.getString() != null)
input = bodyContent.getString().trim();
}
if ((input == null) || input.equals("")) {
// Spec says:
// If value is null or empty, remove the scoped variable
// if it is specified (see attributes var and scope).
if (var != null) {
pageContext.removeAttribute(var, scope);
}
return EVAL_PAGE;
}
/*
* If 'value' is a String, it is first parsed into an instance of
* java.lang.Number
*/
if (input instanceof String) {
try {
if (((String) input).indexOf('.") != -1) {
input = Double.valueOf((String) input);
} else {
input = Long.valueOf((String) input);
}
} catch (NumberFormatException nfe) {
throw new JspException(
Resources.getMessage("FORMAT_NUMBER_PARSE_ERROR", input),
nfe);
}
}
// Determine formatting locale
Locale loc = SetLocaleSupport.getFormattingLocale(pageContext,
this,
false,
true);
if (loc != null) {
// Create formatter
NumberFormat formatter = null;
if ((pattern != null) && !pattern.equals("")) {
// if 'pattern' is specified, 'type' is ignored
DecimalFormatSymbols symbols = new DecimalFormatSymbols(loc);
formatter = new DecimalFormat(pattern, symbols);
} else {
formatter = createFormatter(loc);
}
if (((pattern != null) && !pattern.equals(""))
|| CURRENCY.equalsIgnoreCase(type)) {
try {
setCurrency(formatter);
} catch (Exception e) {
throw new JspException(
Resources.getMessage("FORMAT_NUMBER_CURRENCY_ERROR"),
e);
}
}
configureFormatter(formatter);
formatted = formatter.format(input);
} else {
// no formatting locale available, use toString()
formatted = input.toString();
}
if (var != null) {
pageContext.setAttribute(var, formatted, scope);
} else {
try {
pageContext.getOut().print(formatted);
} catch (IOException ioe) {
throw new JspTagException(ioe.toString(), ioe);
}
}
return EVAL_PAGE;
|
private void | init()
value = type = null;
valueSpecified = false;
pattern = var = currencyCode = currencySymbol = null;
groupingUsedSpecified = false;
maxIntegerDigitsSpecified = minIntegerDigitsSpecified = false;
maxFractionDigitsSpecified = minFractionDigitsSpecified = false;
scope = PageContext.PAGE_SCOPE;
|
public void | release()
init();
|
private void | setCurrency(java.text.NumberFormat formatter)
String code = null;
String symbol = null;
if ((currencyCode == null) && (currencySymbol == null)) {
return;
}
if ((currencyCode != null) && (currencySymbol != null)) {
if (currencyClass != null)
code = currencyCode;
else
symbol = currencySymbol;
} else if (currencyCode == null) {
symbol = currencySymbol;
} else {
if (currencyClass != null)
code = currencyCode;
else
symbol = currencyCode;
}
if (code != null) {
Object[] methodArgs = new Object[1];
/*
* java.util.Currency.getInstance()
*/
Method m = currencyClass.getMethod("getInstance",
GET_INSTANCE_PARAM_TYPES);
methodArgs[0] = code;
Object currency = m.invoke(null, methodArgs);
/*
* java.text.NumberFormat.setCurrency()
*/
Class[] paramTypes = new Class[1];
paramTypes[0] = currencyClass;
Class numberFormatClass = Class.forName("java.text.NumberFormat");
m = numberFormatClass.getMethod("setCurrency", paramTypes);
methodArgs[0] = currency;
m.invoke(formatter, methodArgs);
} else {
/*
* Let potential ClassCastException propagate up (will almost
* never happen)
*/
DecimalFormat df = (DecimalFormat) formatter;
DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
dfs.setCurrencySymbol(symbol);
df.setDecimalFormatSymbols(dfs);
}
|
public void | setScope(java.lang.String scope)
this.scope = Util.getScope(scope);
|
public void | setVar(java.lang.String var)
this.var = var;
|