String 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("")) {
if (var != null) {
pageContext.removeAttribute(var, scope);
}
return EVAL_PAGE;
}
/*
* Set up parsing locale: Use locale specified via the 'parseLocale'
* attribute (if present), or else determine page's locale.
*/
Locale loc = parseLocale;
if (loc == null)
loc = SetLocaleSupport.getFormattingLocale(pageContext,
this,
false,
false);
if (loc == null) {
throw new JspException(
Resources.getMessage("PARSE_NUMBER_NO_PARSE_LOCALE"));
}
// Create parser
NumberFormat parser = null;
if ((pattern != null) && !pattern.equals("")) {
// if 'pattern' is specified, 'type' is ignored
DecimalFormatSymbols symbols = new DecimalFormatSymbols(loc);
parser = new DecimalFormat(pattern, symbols);
} else {
parser = createParser(loc);
}
// Configure parser
if (integerOnlySpecified)
parser.setParseIntegerOnly(isIntegerOnly);
// Parse number
Number parsed = null;
try {
parsed = parser.parse(input);
} catch (ParseException pe) {
throw new JspException(
Resources.getMessage("PARSE_NUMBER_PARSE_ERROR", input),
pe);
}
if (var != null) {
pageContext.setAttribute(var, parsed, scope);
} else {
try {
pageContext.getOut().print(parsed);
} catch (IOException ioe) {
throw new JspTagException(ioe.toString(), ioe);
}
}
return EVAL_PAGE;