* @throws NullPointerException if sGuFellow or dtFrom or dtTo is <b>null</b>
*/
public static ICalendar createICalendar(JDCConnection oConn, String sGuFellow,
Date dtFrom, Date dtTo, String sLanguage)
throws SQLException,IllegalArgumentException,NullPointerException {
ICalendarVEvent oEvt;
String sTpRoom, sOrganizerName, sOrganizerMail;
Date dtNow = new Date();
if (DebugFile.trace) {
DebugFile.writeln("Begin ICalendarFactory([JDCConnection],"+sGuFellow+","+dtFrom.toString()+","+dtTo.toString()+","+sLanguage+")");
DebugFile.incIdent();
}
if (sGuFellow==null) {
if (DebugFile.trace) DebugFile.decIdent();
throw new NullPointerException("ICalendarFactory.createICalendar() Fellow GUID parameter is required");
}
if (dtFrom==null || dtTo==null) {
if (DebugFile.trace) DebugFile.decIdent();
throw new NullPointerException("ICalendarFactory.createICalendar() Both start and end date are required");
}
if (dtFrom.compareTo(dtTo)>0) {
if (DebugFile.trace) DebugFile.decIdent();
throw new IllegalArgumentException("ICalendarFactory.createICalendar() End date cannot be prior to start date");
}
if (sLanguage==null) sLanguage=Locale.getDefault().getLanguage();
Fellow oFlw = new Fellow();
if (!oFlw.load(oConn, new Object[]{sGuFellow})) {
if (DebugFile.trace) DebugFile.decIdent();
throw new SQLException("Fellow "+sGuFellow+" not found at "+DB.k_fellows+" table");
}
DBSubset oMeetings = new DBSubset (DB.k_meetings+" m,"+DB.k_x_meeting_fellow+" f",
"m."+DB.gu_meeting+",m."+DB.dt_start+",m."+DB.dt_end+","+
"m."+DB.bo_private+",m."+DB.gu_writer+",m."+DB.df_before+","+
"m."+DB.tp_meeting+",m."+DB.tx_meeting+",m."+DB.de_meeting+","+
"m."+DB.tx_status,
"f."+DB.gu_fellow+"=? AND m."+DB.gu_fellow+"=f."+DB.gu_fellow, 100);
int iMeetings = oMeetings.load(oConn, new Object[]{sGuFellow});
if (DebugFile.trace) DebugFile.writeln(String.valueOf(iMeetings)+" meetings found");
DBSubset oRooms = new DBSubset(DB.k_x_meeting_room+" x,"+DB.k_rooms+" r",
"r."+DB.gu_workarea+",r."+DB.tp_room+",r."+DB.nm_room+","+"r."+DB.tx_location,
"x."+DB.gu_meeting+"=? AND "+"x."+DB.nm_room+"=r."+DB.nm_room,2);
int iRooms;
ICalendar oCal = new ICalendar();
oCal.setProdId("JICAL");
oCal.setVersion("2.0");
for (int m=0; m<iMeetings; m++) {
if (DebugFile.trace) DebugFile.writeln("Loading meeting "+oMeetings.getStringNull(7,m,""));
oEvt = new ICalendarVEvent(oMeetings.getDate(1,m),oMeetings.getDate(2,m),
oMeetings.getStringNull(8,m,""),
duration(oMeetings.getDate(1,m),oMeetings.getDate(2,m)),
oMeetings.getStringNull(7,m,""), null, null);
oEvt.setSequence(0);
oEvt.setDateStamp(dtNow);
oEvt.setCreated(dtNow);
oEvt.setLastModified(dtNow);
oEvt.setEventClass(oMeetings.getShort(3,m)==0 ? "PUBLIC" : "PRIVATE");
oEvt.setTransparency("OPAQUE");
if (!oMeetings.isNull(6,m)) oEvt.setCategories(oMeetings.getString(6,m));
if (oMeetings.isNull(4,m) || sGuFellow.equals(oMeetings.get(4,m))) {
sOrganizerName = (oFlw.getStringNull(DB.tx_name,"")+" "+oFlw.getStringNull(DB.tx_surname,"")).trim();
sOrganizerMail = oFlw.getStringNull(DB.tx_email,"");
} else {
ACLUser oWrt = new ACLUser();
if (oWrt.load(oConn, new Object[]{oMeetings.get(4,m)})) {
sOrganizerName = (oFlw.getStringNull(DB.nm_user,"")+" "+oFlw.getStringNull(DB.tx_surname1,"")+" "+oFlw.getStringNull(DB.tx_surname2,"")).trim();
sOrganizerMail = oFlw.getStringNull(DB.tx_main_email,"");
} else {
sOrganizerName = (oFlw.getStringNull(DB.tx_name,"")+" "+oFlw.getStringNull(DB.tx_surname,"")).trim();
sOrganizerMail = oFlw.getStringNull(DB.tx_email,"");
}
}
if (DebugFile.trace) DebugFile.writeln("Organizer is \""+sOrganizerName+"\" <"+sOrganizerMail+">");
oEvt.setOrganizer("CN=:\""+sOrganizerName.replace((char)34,(char)32)+"\":MAILTO:"+sOrganizerMail);
oEvt.setUid("hipergate-"+oMeetings.getString(0,m));
oEvt.setPriority(3);
if (!oMeetings.isNull(9,m)) oEvt.setStatus(oMeetings.getString(9,m));
iRooms = oRooms.load(oConn, new Object[]{oMeetings.getString(0,m)});
if (iRooms>0) {
if (DebugFile.trace) DebugFile.writeln(String.valueOf(iRooms)+" rooms found");
if (sLanguage!=null)
sTpRoom = DBLanguages.getLookUpTranslation(oConn, DB.k_rooms_lookup, oRooms.getString(1,0), DB.tp_room, sLanguage, oRooms.getString(2,0));
else
sTpRoom = null;
if (null==sTpRoom) sTpRoom=""; else sTpRoom+=" ";
oEvt.setLocation(sTpRoom+oRooms.getString(2,0)+(oRooms.isNull(3,0) ? "" : " "+oRooms.getStringNull(3,0,"")));
}
oCal.icalEventCollection.add(oEvt);
} // next
if (DebugFile.trace) {
DebugFile.decIdent();