25
25
26
26
import static com .silverpeas .calendar .CalendarEvent .anEventAt ;
27
27
import static com .silverpeas .calendar .CalendarEventRecurrence .every ;
28
- import com .silverpeas .calendar .*;
29
28
import static com .silverpeas .util .StringUtil .isDefined ;
30
- import org .silverpeas .wysiwyg .WysiwygException ;
31
- import com .stratelia .webactiv .almanach .control .ejb .AlmanachRuntimeException ;
32
- import com .stratelia .webactiv .almanach .model .EventDetail ;
33
- import com .stratelia .webactiv .almanach .model .Periodicity ;
34
- import com .stratelia .webactiv .almanach .model .PeriodicityException ;
35
- import com .stratelia .webactiv .persistence .IdPK ;
36
- import com .stratelia .webactiv .persistence .PersistenceException ;
37
- import com .stratelia .webactiv .persistence .SilverpeasBeanDAO ;
38
- import com .stratelia .webactiv .persistence .SilverpeasBeanDAOFactory ;
39
29
import static com .stratelia .webactiv .util .DateUtil .asDatable ;
40
- import com .stratelia .webactiv .util .ResourceLocator ;
41
- import com .stratelia .webactiv .util .exception .SilverpeasRuntimeException ;
30
+
42
31
import java .net .MalformedURLException ;
43
32
import java .net .URL ;
33
+ import java .util .ArrayList ;
34
+ import java .util .Calendar ;
44
35
import java .util .Date ;
45
- import java .util .*;
36
+ import java .util .List ;
37
+ import java .util .Set ;
38
+ import java .util .TimeZone ;
39
+
46
40
import net .fortuna .ical4j .model .TimeZoneRegistry ;
47
41
import net .fortuna .ical4j .model .TimeZoneRegistryFactory ;
48
42
43
+ import com .silverpeas .calendar .CalendarEvent ;
44
+ import com .silverpeas .calendar .CalendarEventRecurrence ;
45
+ import com .silverpeas .calendar .Datable ;
46
+ import com .silverpeas .calendar .DateTime ;
47
+ import com .silverpeas .calendar .DayOfWeek ;
48
+ import com .silverpeas .calendar .DayOfWeekOccurrence ;
49
+ import com .silverpeas .calendar .TimeUnit ;
50
+ import com .silverpeas .util .StringUtil ;
51
+ import com .stratelia .silverpeas .silvertrace .SilverTrace ;
52
+ import com .stratelia .webactiv .almanach .model .EventDetail ;
53
+ import com .stratelia .webactiv .almanach .model .Periodicity ;
54
+ import com .stratelia .webactiv .util .ResourceLocator ;
55
+
49
56
/**
50
57
* An encoder of EventDetail instances to EventCalendar instances.
51
58
*/
52
59
public class CalendarEventEncoder {
53
60
54
61
private static ResourceLocator settings = new ResourceLocator (
55
- "com.stratelia.webactiv.almanach.settings.almanachSettings" , "" );
56
-
57
- private static ResourceLocator getSettings () {
58
- return settings ;
59
- }
62
+ "org.silverpeas.almanach.settings.almanachSettings" , "" );
60
63
61
64
/**
62
65
* Encodes the specified details on almanach events into a calendar event.
63
66
*
64
67
* @param eventDetails details about some events in one or several almanachs.
65
68
* @return the calendar events corresponding to the almanach events.
66
- * @throws MalformedURLException if the URL of an event is invalid.
67
- * @throws WysiwygException if an error occurs while fetching the WYSIWYG description of an event.
68
69
*/
69
- public List <CalendarEvent > encode (final List <EventDetail > eventDetails )
70
- throws WysiwygException , MalformedURLException {
70
+ public List <CalendarEvent > encode (final List <EventDetail > eventDetails ) {
71
71
List <CalendarEvent > events = new ArrayList <CalendarEvent >();
72
- TimeZone timeZone = TimeZone .getTimeZone (getSettings () .getString ("almanach.timezone" ));
72
+ TimeZone timeZone = TimeZone .getTimeZone (settings .getString ("almanach.timezone" ));
73
73
for (EventDetail eventDetail : eventDetails ) {
74
74
Datable <?> startDate = createDatable (eventDetail .getStartDate (), eventDetail .getStartHour ()).
75
75
inTimeZone (timeZone );
@@ -89,8 +89,17 @@ public List<CalendarEvent> encode(final List<EventDetail> eventDetails)
89
89
if (isDefined (eventDetail .getPlace ())) {
90
90
event .withLocation (eventDetail .getPlace ());
91
91
}
92
- if (isDefined (eventDetail .getEventUrl ())) {
93
- event .withUrl (new URL (eventDetail .getEventUrl ()));
92
+ String url = eventDetail .getEventUrl ();
93
+ if (isDefined (url )) {
94
+ if (!StringUtil .startsWithIgnoreCase (url , "http" )) {
95
+ url = "http://" + url ;
96
+ }
97
+ try {
98
+ event .withUrl (new URL (url ));
99
+ } catch (MalformedURLException e ) {
100
+ SilverTrace .warn ("almanach" , "CalendarEventEncoder.encode" , "root.ERROR" ,
101
+ "Following URL '" + url + "' is malformed !" );
102
+ }
94
103
}
95
104
if (eventDetail .getPeriodicity () != null ) {
96
105
event .recur (withTheRecurrenceRuleOf (eventDetail ));
@@ -104,9 +113,7 @@ public List<CalendarEvent> encode(final List<EventDetail> eventDetails)
104
113
private CalendarEventRecurrence withTheRecurrenceRuleOf (final EventDetail event ) {
105
114
CalendarEventRecurrence recurrence = asCalendarEventRecurrence (event .getPeriodicity ());
106
115
TimeZoneRegistry registry = TimeZoneRegistryFactory .getInstance ().createRegistry ();
107
- ResourceLocator almanachSettings =
108
- new ResourceLocator ("com.stratelia.webactiv.almanach.settings.almanachSettings" , "" );
109
- TimeZone timeZone = registry .getTimeZone (almanachSettings .getString ("almanach.timezone" ));
116
+ TimeZone timeZone = registry .getTimeZone (settings .getString ("almanach.timezone" ));
110
117
ExceptionDatesGenerator generator = new ExceptionDatesGenerator ();
111
118
Set <Date > exceptionDates = generator .generateExceptionDates (event );
112
119
for (Date anExceptionDate : exceptionDates ) {
@@ -233,24 +240,4 @@ private Datable<?> createDatable(final Date date, final String time) {
233
240
}
234
241
return datable ;
235
242
}
236
-
237
- /**
238
- * Gets all the exceptions of the specified periodicity.
239
- *
240
- * @param periodicity an event periodicity
241
- * @return a collection of exceptions that were applied to the specified periodicity.
242
- */
243
- private Collection <PeriodicityException > getPeriodicityExceptions (final Periodicity periodicity ) {
244
- try {
245
- IdPK pk = new IdPK ();
246
- SilverpeasBeanDAO <PeriodicityException > dao = SilverpeasBeanDAOFactory .getDAO (
247
- "com.stratelia.webactiv.almanach.model.PeriodicityException" );
248
- return dao .findByWhereClause (pk , "periodicityId = " + periodicity .getPK ().getId ());
249
- } catch (PersistenceException e ) {
250
- throw new AlmanachRuntimeException (
251
- "AlmanachBmEJB.getListPeriodicityException()" ,
252
- SilverpeasRuntimeException .ERROR ,
253
- "almanach.EX_GET_PERIODICITY_EXCEPTION" , e );
254
- }
255
- }
256
- }
243
+ }
0 commit comments