View Javadoc

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