Skip to content

Commit 10a6259

Browse files
NicolasEYSSERICmmoqui
authored andcommitted
fixing bug #5202 by :
- adding prefix http:// if it is missing - catching MalformedURLException to not block export of other events
1 parent 0063735 commit 10a6259

File tree

2 files changed

+37
-52
lines changed

2 files changed

+37
-52
lines changed

almanach/almanach-ejb/src/main/java/com/stratelia/webactiv/almanach/control/CalendarEventEncoder.java

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -25,51 +25,51 @@
2525

2626
import static com.silverpeas.calendar.CalendarEvent.anEventAt;
2727
import static com.silverpeas.calendar.CalendarEventRecurrence.every;
28-
import com.silverpeas.calendar.*;
2928
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;
3929
import static com.stratelia.webactiv.util.DateUtil.asDatable;
40-
import com.stratelia.webactiv.util.ResourceLocator;
41-
import com.stratelia.webactiv.util.exception.SilverpeasRuntimeException;
30+
4231
import java.net.MalformedURLException;
4332
import java.net.URL;
33+
import java.util.ArrayList;
34+
import java.util.Calendar;
4435
import java.util.Date;
45-
import java.util.*;
36+
import java.util.List;
37+
import java.util.Set;
38+
import java.util.TimeZone;
39+
4640
import net.fortuna.ical4j.model.TimeZoneRegistry;
4741
import net.fortuna.ical4j.model.TimeZoneRegistryFactory;
4842

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+
4956
/**
5057
* An encoder of EventDetail instances to EventCalendar instances.
5158
*/
5259
public class CalendarEventEncoder {
5360

5461
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", "");
6063

6164
/**
6265
* Encodes the specified details on almanach events into a calendar event.
6366
*
6467
* @param eventDetails details about some events in one or several almanachs.
6568
* @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.
6869
*/
69-
public List<CalendarEvent> encode(final List<EventDetail> eventDetails)
70-
throws WysiwygException, MalformedURLException {
70+
public List<CalendarEvent> encode(final List<EventDetail> eventDetails) {
7171
List<CalendarEvent> events = new ArrayList<CalendarEvent>();
72-
TimeZone timeZone = TimeZone.getTimeZone(getSettings().getString("almanach.timezone"));
72+
TimeZone timeZone = TimeZone.getTimeZone(settings.getString("almanach.timezone"));
7373
for (EventDetail eventDetail : eventDetails) {
7474
Datable<?> startDate = createDatable(eventDetail.getStartDate(), eventDetail.getStartHour()).
7575
inTimeZone(timeZone);
@@ -89,8 +89,17 @@ public List<CalendarEvent> encode(final List<EventDetail> eventDetails)
8989
if (isDefined(eventDetail.getPlace())) {
9090
event.withLocation(eventDetail.getPlace());
9191
}
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+
}
94103
}
95104
if (eventDetail.getPeriodicity() != null) {
96105
event.recur(withTheRecurrenceRuleOf(eventDetail));
@@ -104,9 +113,7 @@ public List<CalendarEvent> encode(final List<EventDetail> eventDetails)
104113
private CalendarEventRecurrence withTheRecurrenceRuleOf(final EventDetail event) {
105114
CalendarEventRecurrence recurrence = asCalendarEventRecurrence(event.getPeriodicity());
106115
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"));
110117
ExceptionDatesGenerator generator = new ExceptionDatesGenerator();
111118
Set<Date> exceptionDates = generator.generateExceptionDates(event);
112119
for (Date anExceptionDate : exceptionDates) {
@@ -233,24 +240,4 @@ private Datable<?> createDatable(final Date date, final String time) {
233240
}
234241
return datable;
235242
}
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+
}

almanach/almanach-war/src/main/java/com/stratelia/webactiv/almanach/control/AlmanachSessionController.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.io.File;
2424
import java.io.FileWriter;
2525
import java.io.IOException;
26-
import java.net.MalformedURLException;
2726
import java.text.ParseException;
2827
import java.util.ArrayList;
2928
import java.util.Arrays;
@@ -1087,8 +1086,7 @@ private AlmanachDTO getAlmanachDTO(boolean aggregated) {
10871086
* @param eventDetails details about some events in one or several almanachs.
10881087
* @return the calendar events corresponding to the almanach events.
10891088
*/
1090-
private List<CalendarEvent> asCalendarEvents(final List<EventDetail> eventDetails)
1091-
throws WysiwygException, MalformedURLException {
1089+
private List<CalendarEvent> asCalendarEvents(final List<EventDetail> eventDetails) {
10921090
CalendarEventEncoder encoder = new CalendarEventEncoder();
10931091
return encoder.encode(eventDetails);
10941092
}

0 commit comments

Comments
 (0)