001: /*
002: * DateTag.java
003: *
004: * Version: $Revision: 1947 $
005: *
006: * Date: $Date: 2007-05-18 08:50:29 -0500 (Fri, 18 May 2007) $
007: *
008: * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
009: * Institute of Technology. All rights reserved.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are
013: * met:
014: *
015: * - Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * - Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in the
020: * documentation and/or other materials provided with the distribution.
021: *
022: * - Neither the name of the Hewlett-Packard Company nor the name of the
023: * Massachusetts Institute of Technology nor the names of their
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038: * DAMAGE.
039: */
040: package org.dspace.app.webui.jsptag;
041:
042: import java.io.IOException;
043:
044: import javax.servlet.http.HttpServletRequest;
045: import javax.servlet.jsp.JspException;
046: import javax.servlet.jsp.tagext.TagSupport;
047:
048: import org.dspace.app.webui.util.UIUtil;
049: import org.dspace.content.DCDate;
050:
051: /**
052: * Date rendering tag for DCDates. Takes two parameter - "date", a DCDate, and
053: * "notime", which, if present, means the date is rendered without the time
054: *
055: * @author Robert Tansley
056: * @version $Revision: 1947 $
057: */
058: public class DateTag extends TagSupport {
059: /** The date to display */
060: private DCDate date;
061:
062: /** Display the time? */
063: private boolean displayTime = true;
064:
065: /**
066: * Get the date
067: *
068: * @return the date to display
069: */
070: public DCDate getDate() {
071: return date;
072: }
073:
074: /**
075: * Set the date
076: *
077: * @param d
078: * the date to display
079: */
080: public void setDate(DCDate d) {
081: date = d;
082: }
083:
084: /**
085: * Get the "don't display the time" flag
086: *
087: * @return the date to display
088: */
089: public String getNotime() {
090: // Note inverse of internal flag
091: return (displayTime ? "false" : "true");
092: }
093:
094: /**
095: * Set the "don't display the time" flag
096: *
097: * @param dummy
098: * can be anything - always sets the flag if present
099: */
100: public void setNotime(String dummy) {
101: displayTime = false;
102: }
103:
104: public int doStartTag() throws JspException {
105: String toDisplay = UIUtil.displayDate(date, displayTime, true,
106: (HttpServletRequest) pageContext.getRequest());
107:
108: try {
109: pageContext.getOut().print(toDisplay);
110: } catch (IOException ie) {
111: throw new JspException(ie);
112: }
113:
114: return SKIP_BODY;
115: }
116: }
|