Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/xpn/xwiki/plugin/calendar/CalendarParams.java


1   /**
2    * ===================================================================
3    *
4    * Copyright (c) 2003,2004 Ludovic Dubost, All rights reserved.
5    *
6    * This program is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public License
8    * as published by the Free Software Foundation; either version 2
9    * of the License, or (at your option) any later version.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Lesser General Public License for more details, published at 
15   * http://www.gnu.org/copyleft/lesser.html or in lesser.txt in the
16   * root folder of this distribution.
17  
18   * Created by
19   * User: Ludovic Dubost
20   * Date: 10 oct. 2004
21   * Time: 10:05:18
22   */
23  package com.xpn.xwiki.plugin.calendar;
24  
25  import java.util.*;
26  
27  public class CalendarParams {
28      private Map map = new HashMap();
29  
30      public CalendarParams() {
31      }
32  
33      public CalendarParams(Map map) {
34          this.map = map;
35      }
36  
37      public Object get(Object key) {
38          return map.get(key);
39      }
40  
41      public void put(Object key, Object value) {
42          map.put(key, value);
43      }
44  
45      public Calendar getCalendar(Locale locale) {
46          Calendar cal = Calendar.getInstance(locale);
47          cal.setTime(new Date());
48          String smonth = (String)get("month");
49          if (smonth!=null) {
50           if (smonth.indexOf("+")!=-1) {
51              cal.add(Calendar.MONTH, Integer.parseInt(smonth.substring(1)));
52           } else if (smonth.indexOf("-")!=-1) {
53              cal.add(Calendar.MONTH, -Integer.parseInt(smonth.substring(1)));
54           } else {
55              cal.set(Calendar.MONTH, Integer.parseInt(smonth));
56           }
57          }
58          String syear = (String)get("year");
59          if (syear!=null) {
60           if (syear.indexOf("+")!=-1) {
61              cal.add(Calendar.YEAR, Integer.parseInt(syear));
62           } else if (syear.indexOf("-")!=-1) {
63              cal.add(Calendar.YEAR, Integer.parseInt(syear));
64           } else {
65              cal.set(Calendar.YEAR, Integer.parseInt(syear));
66           }
67          }
68          return cal;
69      }
70  }