Home » struts-2.1.8.1-src » org.apache » struts2 » showcase » [javadoc | source]

    1   /*
    2    * $Id: DateAction.java 476710 2006-11-19 05:05:14Z mrdon $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
   10    * with the License.  You may obtain a copy of the License at
   11    *
   12    *  http://www.apache.org/licenses/LICENSE-2.0
   13    *
   14    * Unless required by applicable law or agreed to in writing,
   15    * software distributed under the License is distributed on an
   16    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   17    * KIND, either express or implied.  See the License for the
   18    * specific language governing permissions and limitations
   19    * under the License.
   20    */
   21   package org.apache.struts2.showcase;
   22   
   23   import java.text.DateFormat;
   24   import java.util.Calendar;
   25   import java.util.Date;
   26   import java.util.GregorianCalendar;
   27   
   28   import com.opensymphony.xwork2.ActionSupport;
   29   
   30   /**
   31    * <code>DateAction</code>
   32    *
   33    */
   34   public class DateAction extends ActionSupport {
   35   
   36       private static DateFormat DF = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
   37   
   38       private Date now;
   39       private Date past;
   40       private Date future;
   41       private Date after;
   42       private Date before;
   43   
   44   
   45       public String getDate() {
   46           return DF.format(new Date());
   47       }
   48   
   49   
   50       /**
   51        * @return Returns the future.
   52        */
   53       public Date getFuture() {
   54           return future;
   55       }
   56   
   57       /**
   58        * @return Returns the now.
   59        */
   60       public Date getNow() {
   61           return now;
   62       }
   63   
   64       /**
   65        * @return Returns the past.
   66        */
   67       public Date getPast() {
   68           return past;
   69       }
   70   
   71       /**
   72        *
   73        * @return Returns the before date.
   74        */
   75       public Date getBefore() {
   76           return before;
   77       }
   78   
   79       /**
   80        *
   81        * @return Returns the after date.
   82        */
   83       public Date getAfter() {
   84           return after;
   85       }
   86   
   87       /**
   88        */
   89       public String browse() throws Exception {
   90           Calendar cal = GregorianCalendar.getInstance();
   91           now = cal.getTime();
   92           cal.roll(Calendar.DATE, -1);
   93           cal.roll(Calendar.HOUR, -3);
   94           past = cal.getTime();
   95           cal.roll(Calendar.DATE, 2);
   96           future = cal.getTime();
   97   
   98           cal.roll(Calendar.YEAR, -1);
   99           before = cal.getTime();
  100   
  101           cal.roll(Calendar.YEAR, 2);
  102           after = cal.getTime();
  103           return SUCCESS;
  104       }
  105   
  106   }

Home » struts-2.1.8.1-src » org.apache » struts2 » showcase » [javadoc | source]