1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.plugin.jodatime

File JodaTimePlugin.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

0
21
20
1
213
105
20
0.95
1.05
20
1

Classes

Class Line # Actions
JodaTimePlugin 46 21 0% 20 41
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20   
21    package com.xpn.xwiki.plugin.jodatime;
22   
23    import java.util.Locale;
24   
25    import org.joda.time.DateTime;
26    import org.joda.time.DateTimeZone;
27    import org.joda.time.Duration;
28    import org.joda.time.MutableDateTime;
29    import org.joda.time.ReadableInstant;
30    import org.joda.time.format.DateTimeFormat;
31    import org.joda.time.format.DateTimeFormatter;
32    import org.joda.time.format.ISODateTimeFormat;
33   
34    import com.xpn.xwiki.XWikiContext;
35    import com.xpn.xwiki.api.Api;
36    import com.xpn.xwiki.plugin.XWikiDefaultPlugin;
37    import com.xpn.xwiki.plugin.XWikiPluginInterface;
38   
39    /**
40    * Plugin for manipulating dates from velocity scripts inside xwiki documents. It is based on the <a
41    * href="http://joda-time.sourceforge.net/">JodaTime framework</a>, a quality replacement for the Java date and time
42    * classes.
43    *
44    * @see JodaTimePluginApi
45    */
 
46    public class JodaTimePlugin extends XWikiDefaultPlugin
47    {
48    /**
49    * ISO8601 date time formatter.
50    */
51    private static final DateTimeFormatter ISO_DATE_FORMATTER = ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC);
52   
53    /**
54    * @param name the plugin name, usually ignored, since plugins have a fixed name
55    * @param className the name of this class, ignored
56    * @param context the current request context
57    */
 
58  0 toggle public JodaTimePlugin(String name, String className, XWikiContext context)
59    {
60  0 super(name, className, context);
61  0 init(context);
62    }
63   
 
64  0 toggle @Override
65    public String getName()
66    {
67  0 return "jodatime";
68    }
69   
 
70  0 toggle @Override
71    public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context)
72    {
73  0 return new JodaTimePluginApi((JodaTimePlugin) plugin, context);
74    }
75   
 
76  0 toggle @Override
77    public void init(XWikiContext context)
78    {
79  0 super.init(context);
80    }
81   
82    /**
83    * @see org.joda.time.DateTime#DateTime()
84    */
 
85  0 toggle public DateTime getDateTime()
86    {
87  0 return new DateTime();
88    }
89   
90    /**
91    * @see org.joda.time.DateTime#DateTime(int, int, int, int, int, int, int)
92    */
 
93  0 toggle public DateTime getDateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour,
94    int secondOfMinute, int millisOfSecond)
95    {
96  0 return new DateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
97    }
98   
99    /**
100    * @see org.joda.time.DateTime#DateTime(long)
101    */
 
102  0 toggle public DateTime getDateTime(long instant)
103    {
104  0 return new DateTime(instant);
105    }
106   
107    /**
108    * @see org.joda.time.MutableDateTime#MutableDateTime()
109    */
 
110  0 toggle public MutableDateTime getMutableDateTime()
111    {
112  0 return new MutableDateTime();
113    }
114   
115    /**
116    * @see org.joda.time.MutableDateTime#MutableDateTime(int, int, int, int, int, int, int)
117    */
 
118  0 toggle public MutableDateTime getMutableDateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay,
119    int minuteOfHour, int secondOfMinute, int millisOfSecond)
120    {
121  0 return new MutableDateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute,
122    millisOfSecond);
123    }
124   
125    /**
126    * @see org.joda.time.MutableDateTime#MutableDateTime(long)
127    */
 
128  0 toggle public MutableDateTime getMutableDateTime(long instant)
129    {
130  0 return new MutableDateTime(instant);
131    }
132   
133    /**
134    * @see org.joda.time.format.DateTimeFormat#forPattern(String)
135    */
 
136  0 toggle public DateTimeFormatter getDateTimeFormatterForPattern(String pattern, XWikiContext context)
137    {
138  0 return DateTimeFormat.forPattern(pattern).withLocale((Locale) context.get("locale"));
139    }
140   
141    /**
142    * @see org.joda.time.format.DateTimeFormat#forStyle(String)
143    */
 
144  0 toggle public DateTimeFormatter getDateTimeFormatterForStyle(String style, XWikiContext context)
145    {
146  0 return DateTimeFormat.forStyle(style).withLocale((Locale) context.get("locale"));
147    }
148   
149    /**
150    * @see org.joda.time.DateTimeZone#getDefault()
151    */
 
152  0 toggle public DateTimeZone getServerTimezone()
153    {
154  0 return DateTimeZone.getDefault();
155    }
156   
157    /**
158    * @see org.joda.time.DateTimeZone#UTC
159    */
 
160  0 toggle public DateTimeZone getUTCTimezone()
161    {
162  0 return DateTimeZone.UTC;
163    }
164   
165    /**
166    * @see org.joda.time.DateTimeZone#forID(String)
167    */
 
168  0 toggle public DateTimeZone getTimezone(String locationOrOffset)
169    {
170  0 return DateTimeZone.forID(locationOrOffset);
171    }
172   
173    /**
174    * @see org.joda.time.DateTimeZone#forOffsetHours(int)
175    */
 
176  0 toggle public DateTimeZone getTimezone(int offsetHours)
177    {
178  0 return DateTimeZone.forOffsetHours(offsetHours);
179    }
180   
181    /**
182    * @see org.joda.time.DateTimeZone#forOffsetHoursMinutes(int, int)
183    */
 
184  0 toggle public DateTimeZone getTimezone(int offsetHours, int offsetMinutes)
185    {
186  0 return DateTimeZone.forOffsetHoursMinutes(offsetHours, offsetMinutes);
187    }
188   
189    /**
190    * @see org.joda.time.Duration#Duration(long)
191    */
 
192  0 toggle public Duration getDuration(long millis)
193    {
194  0 return new Duration(millis);
195    }
196   
197    /**
198    * @see org.joda.time.Duration#Duration(ReadableInstant, ReadableInstant)
199    */
 
200  0 toggle public Duration getDuration(ReadableInstant from, ReadableInstant to)
201    {
202  0 return new Duration(from, to);
203    }
204   
205    /**
206    * @return an ISO8601 date time formatter
207    * @since 5.2RC1
208    */
 
209  0 toggle public DateTimeFormatter getISODateTimeFormatter()
210    {
211  0 return ISO_DATE_FORMATTER;
212    }
213    }