throws JspException
{
try {
PageContextImpl pageContext = (PageContextImpl) this.pageContext;
JspWriter out = pageContext.getOut();
Object value = _valueExpr.evalObject(pageContext.getELContext());
if (value == null) {
if (_var != null)
CoreSetTag.setValue(pageContext, _var, _scope, null);
return EVAL_PAGE;
}
long time = 0;
if (value instanceof Number)
time = ((Number) value).longValue();
else if (value instanceof Date)
time = ((Date) value).getTime();
DateFormat format = null;
Locale locale = pageContext.getLocale();
String type = null;
ELContext env = pageContext.getELContext();
if (_typeExpr != null)
type = _typeExpr.evalString(env);
int dateStyle = DateFormat.DEFAULT;
if (_dateStyleExpr != null)
dateStyle = getDateStyle(_dateStyleExpr.evalString(env));
int timeStyle = DateFormat.DEFAULT;
if (_timeStyleExpr != null)
timeStyle = getDateStyle(_timeStyleExpr.evalString(env));
if (locale != null) {
if (type == null || type.equals("date"))
format = DateFormat.getDateInstance(dateStyle, locale);
else if (type.equals("both"))
format = DateFormat.getDateTimeInstance(dateStyle,
timeStyle,
locale);
else if (type.equals("time"))
format = DateFormat.getTimeInstance(timeStyle, locale);
else
throw new JspException(L.l("illegal type `{0}'", type));
}
else {
if (type == null || type.equals("date"))
format = DateFormat.getDateInstance(dateStyle);
else if (type.equals("both"))
format = DateFormat.getDateTimeInstance(dateStyle, timeStyle);
else if (type.equals("time"))
format = DateFormat.getTimeInstance(timeStyle);
else
throw new JspException(L.l("illegal type `{0}'", type));
}
if (format != null && _patternExpr != null) {
String pattern = _patternExpr.evalString(env);
try {
((SimpleDateFormat) format).applyPattern(pattern);
} catch (ClassCastException e) {
format = new SimpleDateFormat(pattern, locale);
}
}
if (format != null) {
TimeZone timeZone = getTimeZone();
if (timeZone != null)
format.setTimeZone(timeZone);
value = format.format(new Date(time));
}
if (_var == null)
out.print(value);
else
CoreSetTag.setValue(pageContext, _var, _scope, value);
} catch (Exception e) {
throw new JspException(e);
}