001: // Copyright %G% Sun Microsystems, Inc. All Rights Reserved.
002: // "%W% %E% Sun Microsystems"
003:
004: package com.sun.portal.wireless.taglibs.cal;
005:
006: import javax.servlet.jsp.*;
007: import javax.servlet.jsp.tagext.*;
008:
009: import com.sun.comclient.calendar.DateTime;
010:
011: import com.sun.portal.wireless.taglibs.base.BeanGetTag;
012: import com.sun.portal.wireless.taglibs.base.Util;
013: import com.sun.portal.log.common.PortalLogger;
014:
015: import java.util.logging.Logger;
016: import java.util.logging.Level;
017:
018: /**
019: * CalGetTag - extend base BeanGetTag to handle
020: * DateTime/Calendar fields. If the field attribute
021: * is specified then get that field from the DateTime.
022: *
023: * Attributes:
024: *
025: * field
026: * the java.util.Calendar field to get
027: *
028: * @author Robert O'Brien
029: * @version 1.0
030: * @see com.sun.portal.wireless.taglibs.base.BeanGetTag
031: */
032:
033: public class CalGetTag extends
034: com.sun.portal.wireless.taglibs.base.BeanGetTag {
035: // Create a logger for this class
036: private static Logger debugLogger = PortalLogger
037: .getLogger(CalGetTag.class);
038:
039: public CalGetTag() {
040: super ();
041: }
042:
043: /**
044: * The java.util.Calendar field string
045: */
046: private String field;
047:
048: /**
049: * Set the field attribute
050: *
051: * @param field the java.util.Calendar field string
052: */
053: public void setField(String field) {
054: this .field = evalAttribute(field);
055: }
056:
057: /**
058: * Perform get operation. If the field attribute
059: * isnt set then do the standard bean property get.
060: * If field is set then get the specified field
061: * from the DateTime and print to the page output.
062: *
063: * @return SKIP_BODY
064: * @exception JspException
065: */
066: public int doStartTag() throws JspException {
067:
068: if (field == null) {
069: return super .doStartTag();
070: }
071:
072: Integer fieldval = DateTime.mapField(field);
073:
074: if (fieldval == null) {
075: debugLogger.log(Level.FINE, "PSMA_CSPWTC0002", field);
076: throw new JspException(this .getClass().getName()
077: + ": invalid field value: " + field);
078: }
079:
080: try {
081: DateTime datetime = (DateTime) getBean();
082: int value = datetime.get(fieldval.intValue());
083: pageContext.getOut().print(value);
084:
085: } catch (ClassCastException e) {
086: debugLogger.fine("PSMA_CSPWTC0003");
087: throw new JspException(this .getClass().getName()
088: + ": No DateTime found for field access");
089: } catch (java.io.IOException e) {
090: debugLogger.log(Level.FINE, "PSMA_CSPWTC0001", e);
091: throw new JspException(this .getClass().getName()
092: + ".doStartTag(): IO Exception: " + e.getMessage());
093: }
094:
095: return SKIP_BODY;
096: }
097:
098: /**
099: * Cleanup
100: */
101: public void release() {
102: super.release();
103: field = null;
104: }
105: }
|