FormatDateSupportpublic abstract class FormatDateSupport extends javax.servlet.jsp.tagext.TagSupport Support for tag handlers for <formatDate>, the date and time
formatting tag in JSTL 1.0. |
Fields Summary |
---|
private static final String | DATE | private static final String | TIME | private static final String | DATETIME | protected Date | value | protected String | type | protected String | pattern | protected Object | timeZone | protected String | dateStyle | protected String | timeStyle | private String | var | private int | scope |
Constructors Summary |
---|
public FormatDateSupport() // 'scope' attribute
//*********************************************************************
// Constructor and initialization
super();
init();
|
Methods Summary |
---|
private java.text.DateFormat | createFormatter(java.util.Locale loc)
DateFormat formatter = null;
if ((type == null) || DATE.equalsIgnoreCase(type)) {
formatter = DateFormat.getDateInstance(
Util.getStyle(dateStyle, "FORMAT_DATE_INVALID_DATE_STYLE"),
loc);
} else if (TIME.equalsIgnoreCase(type)) {
formatter = DateFormat.getTimeInstance(
Util.getStyle(timeStyle, "FORMAT_DATE_INVALID_TIME_STYLE"),
loc);
} else if (DATETIME.equalsIgnoreCase(type)) {
formatter = DateFormat.getDateTimeInstance(
Util.getStyle(dateStyle, "FORMAT_DATE_INVALID_DATE_STYLE"),
Util.getStyle(timeStyle, "FORMAT_DATE_INVALID_TIME_STYLE"),
loc);
} else {
throw new JspException(
Resources.getMessage("FORMAT_DATE_INVALID_TYPE",
type));
}
return formatter;
| public int | doEndTag()
String formatted = null;
if (value == null) {
if (var != null) {
pageContext.removeAttribute(var, scope);
}
return EVAL_PAGE;
}
// Create formatter
Locale locale = SetLocaleSupport.getFormattingLocale(pageContext,
this,
true,
true);
if (locale != null) {
DateFormat formatter = createFormatter(locale);
// Apply pattern, if present
if (pattern != null) {
try {
((SimpleDateFormat) formatter).applyPattern(pattern);
} catch (ClassCastException cce) {
formatter = new SimpleDateFormat(pattern, locale);
}
}
// Set time zone
TimeZone tz = null;
if ((timeZone instanceof String)
&& ((String) timeZone).equals("")) {
timeZone = null;
}
if (timeZone != null) {
if (timeZone instanceof String) {
tz = TimeZone.getTimeZone((String) timeZone);
} else if (timeZone instanceof TimeZone) {
tz = (TimeZone) timeZone;
} else {
throw new JspTagException(
Resources.getMessage("FORMAT_DATE_BAD_TIMEZONE"));
}
} else {
tz = TimeZoneSupport.getTimeZone(pageContext, this);
}
if (tz != null) {
formatter.setTimeZone(tz);
}
formatted = formatter.format(value);
} else {
// no formatting locale available, use Date.toString()
formatted = value.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()
type = dateStyle = timeStyle = null;
pattern = var = null;
value = null;
timeZone = null;
scope = PageContext.PAGE_SCOPE;
| public void | release()
init();
| public void | setScope(java.lang.String scope)
this.scope = Util.getScope(scope);
| public void | setVar(java.lang.String var)
this.var = var;
|
|