View Javadoc

1   /*
2    * Copyright 2000-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.portals.applications.desktop.calendar;
17  
18  import java.text.SimpleDateFormat;
19  import java.util.Date;
20  import java.util.Locale;
21  
22  import javax.faces.context.FacesContext;
23  import javax.portlet.PortletPreferences;
24  import javax.portlet.PortletRequest;
25  
26  /***
27   * CalendarBean
28   * 
29   * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
30   * @version $Id: CalendarBean.java 187966 2004-11-19 22:53:35 +0100 (Fri, 19 Nov 2004) taylor $
31   */
32  
33  public class CalendarBean
34  {
35      private Date date = new Date();
36      private String notes = "";
37  
38      public Date getDate()
39      {
40          return date;
41      }
42  
43      public void setDate(Date date)
44      {
45          if (date != null)
46          {
47              this.date = date;
48          }
49      }
50      
51      public String getNotes()
52      {
53          return notes;
54      }
55      
56      public void setNotes(String notes)
57      {
58          this.notes = notes;
59      }
60      
61     public String getDateKey(Date date)  
62     {
63         SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd", Locale.getDefault());
64         return formatter.format(date);
65         
66     }
67      /*
68       * actions
69       */
70      
71      public String save()
72      {
73          if (this.date != null)
74          {
75              PortletRequest request = (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
76              PortletPreferences prefs = request.getPreferences();
77              try
78              {
79                  
80                  prefs.setValue(getDateKey(this.date), this.notes);
81                  prefs.store();
82              }
83              catch (Exception e)
84              {
85                  System.err.println("error storing prefs " + e);
86              }
87          }
88          return "returnFromNotes";
89      }
90      
91      public String selectDate()
92      {
93          if (this.date == null)
94          {
95              return "editNotes";
96          }
97          String selectedDate = getDateKey(this.date);
98          PortletRequest request = (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
99          notes = request.getPreferences().getValue(selectedDate, "");
100         return "editNotes"; // goto the navigation rule
101     }
102 }