View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.trinidad.validator;
20  
21  import java.text.ParseException;
22  import java.text.SimpleDateFormat;
23  import java.util.ArrayList;
24  import java.util.Calendar;
25  import java.util.Date;
26  import java.util.List;
27  
28  import javax.faces.context.FacesContext;
29  
30  import org.apache.myfaces.trinidad.model.DateListProvider;
31  
32  public class TestDateListProvider implements DateListProvider
33  {
34    
35    List<Date> germanHolidays = null;
36    
37    public TestDateListProvider()
38    {
39      germanHolidays = new ArrayList<Date>();
40      germanHolidays.add(newDate("01.01.2007"));
41      germanHolidays.add(newDate("01.05.2007"));
42      germanHolidays.add(newDate("15.05.2007"));
43    }
44    
45  
46    private Date newDate(String string)
47    {
48      SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
49      Date ret = null;
50      try
51      {
52        ret = sdf.parse(string);
53      } catch (ParseException e)
54      {
55        e.printStackTrace();
56      }
57      return ret;
58    }
59  
60  
61    public List<Date> getDateList(FacesContext context, Calendar base,
62        Date rangeStart, Date rangeEnd)
63    {
64      
65      List<Date> returnDates = new ArrayList<Date>();
66      
67      for (Date it : germanHolidays)
68      {
69        if(!it.before(rangeStart) && !it.after(rangeEnd)){
70          base.setTime(it);
71          returnDates.add(base.getTime());
72        }
73      }
74      
75      return returnDates;
76    }
77  
78  }