use of net.fortuna.ical4j.model.component.VTimeZone in project camel by apache.
the class ICalDataFormatTest method createTestCalendar.
/**
* Creates test calendar instance.
*
* @return ICal calendar object.
*/
protected Calendar createTestCalendar() throws ParseException {
// Create a TimeZone
TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
TimeZone timezone = registry.getTimeZone("America/New_York");
VTimeZone tz = timezone.getVTimeZone();
// Start Date is on: April 1, 2013, 9:00 am
java.util.Calendar startDate = new GregorianCalendar();
startDate.setTimeZone(timezone);
startDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL);
startDate.set(java.util.Calendar.DAY_OF_MONTH, 1);
startDate.set(java.util.Calendar.YEAR, 2013);
startDate.set(java.util.Calendar.HOUR_OF_DAY, 17);
startDate.set(java.util.Calendar.MINUTE, 0);
startDate.set(java.util.Calendar.SECOND, 0);
// End Date is on: April 1, 2013, 13:00
java.util.Calendar endDate = new GregorianCalendar();
endDate.setTimeZone(timezone);
endDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL);
endDate.set(java.util.Calendar.DAY_OF_MONTH, 1);
endDate.set(java.util.Calendar.YEAR, 2013);
endDate.set(java.util.Calendar.HOUR_OF_DAY, 21);
endDate.set(java.util.Calendar.MINUTE, 0);
endDate.set(java.util.Calendar.SECOND, 0);
// Create the event
PropertyList propertyList = new PropertyList();
propertyList.add(new DtStamp("20130324T180000Z"));
propertyList.add(new DtStart(new DateTime(startDate.getTime())));
propertyList.add(new DtEnd(new DateTime(endDate.getTime())));
propertyList.add(new Summary("Progress Meeting"));
VEvent meeting = new VEvent(propertyList);
// add timezone info..
meeting.getProperties().add(tz.getTimeZoneId());
// generate unique identifier..
meeting.getProperties().add(new Uid("00000000"));
// add attendees..
Attendee dev1 = new Attendee(URI.create("mailto:dev1@mycompany.com"));
dev1.getParameters().add(Role.REQ_PARTICIPANT);
dev1.getParameters().add(new Cn("Developer 1"));
meeting.getProperties().add(dev1);
Attendee dev2 = new Attendee(URI.create("mailto:dev2@mycompany.com"));
dev2.getParameters().add(Role.OPT_PARTICIPANT);
dev2.getParameters().add(new Cn("Developer 2"));
meeting.getProperties().add(dev2);
// Create a calendar
net.fortuna.ical4j.model.Calendar icsCalendar = new net.fortuna.ical4j.model.Calendar();
icsCalendar.getProperties().add(Version.VERSION_2_0);
icsCalendar.getProperties().add(new ProdId("-//Events Calendar//iCal4j 1.0//EN"));
icsCalendar.getProperties().add(CalScale.GREGORIAN);
// Add the event and print
icsCalendar.getComponents().add(meeting);
return icsCalendar;
}
use of net.fortuna.ical4j.model.component.VTimeZone in project zm-mailbox by Zimbra.
the class ZoneInfo2iCalendar method getTimeZoneForZoneLines.
/**
* @param zoneLines - Only the zoneLines related to a time zone that might be relevant from the reference date.
*/
private static String getTimeZoneForZoneLines(String tzid, Set<String> aliases, List<ZoneLine> zoneLines, Params params, Set<String> zoneIDs, Map<String, VTimeZone> oldTimeZones) {
if ((zoneLines == null) || (zoneLines.isEmpty())) {
return "";
}
boolean isPrimary = sPrimaryTZIDs.contains(tzid);
Integer matchScore = sMatchScores.get(tzid);
if (matchScore == null) {
if (isPrimary) {
matchScore = Integer.valueOf(TZIDMapper.DEFAULT_MATCH_SCORE_PRIMARY);
} else {
matchScore = Integer.valueOf(TZIDMapper.DEFAULT_MATCH_SCORE_NON_PRIMARY);
}
}
Iterator<String> aliasesIter = aliases.iterator();
while (aliasesIter.hasNext()) {
String curr = aliasesIter.next();
if (zoneIDs.contains(curr)) {
aliasesIter.remove();
}
}
ZoneLine zline = zoneLines.get(0);
VTimeZone oldVtz = oldTimeZones.get(zline.getName());
Property oldLastModProp = null;
if (null != oldVtz) {
oldLastModProp = oldVtz.getProperties().getProperty(Property.LAST_MODIFIED);
}
LastModified newLastModified = getLastModified(params.lastModified);
LastModified trialLastModified;
if (null != oldLastModProp && oldLastModProp instanceof LastModified) {
trialLastModified = (LastModified) oldLastModProp;
} else {
trialLastModified = newLastModified;
}
VTimeZone vtz = toVTimeZoneComp(params.referenceDate, zoneLines, trialLastModified, aliases, isPrimary, matchScore);
String asText = vtz.toString();
if ((null != oldVtz) && (trialLastModified != newLastModified)) {
String oldText = oldVtz.toString();
if (!asText.equals(oldText)) {
/* Work around non-round tripped entries where the original source has:
* X-ZIMBRA-TZ-ALIAS:(GMT+12.00) Anadyr\, Petropavlovsk-Kamchatsky (RTZ 11)
* but in this we have:
* X-ZIMBRA-TZ-ALIAS:(GMT+12.00) Anadyr\\\, Petropavlovsk-Kamchatsky (RTZ 11)
* suspect that is a bug in libical which may be fixed in a later revision
*/
String oldText2 = oldText.replace("\\\\\\,", "\\,");
if (!asText.equals(oldText2)) {
LastModified lastModProp = (LastModified) vtz.getProperties().getProperty(Property.LAST_MODIFIED);
try {
lastModProp.setValue(newLastModified.getValue());
asText = vtz.toString();
} catch (ParseException e) {
System.err.println("Problem assigning LAST-MODIFIED - " + e.getMessage());
}
}
}
}
return asText;
}
use of net.fortuna.ical4j.model.component.VTimeZone in project zm-mailbox by Zimbra.
the class ZoneInfo2iCalendar method toVTimeZoneComp.
private static VTimeZone toVTimeZoneComp(int hintYear, Observances observances, PropertyList vtzProps) {
VTimeZone vtz = new VTimeZone(vtzProps);
vtz.getObservances().add(observances.std);
if (null != observances.daylight) {
vtz.getObservances().add(observances.daylight);
}
return vtz;
}
use of net.fortuna.ical4j.model.component.VTimeZone in project zm-mailbox by Zimbra.
the class ZoneInfo2iCalendar method makeOldTimeZonesMap.
private static Map<String, VTimeZone> makeOldTimeZonesMap(Params params) {
Map<String, VTimeZone> oldTimeZones = Maps.newHashMap();
if (null != params.oldTimezonesFileName) {
try (FileInputStream fin = new FileInputStream(params.oldTimezonesFileName)) {
CalendarBuilder builder = new CalendarBuilder();
net.fortuna.ical4j.model.Calendar calendar = builder.build(fin, "UTF-8");
for (Iterator i = calendar.getComponents().iterator(); i.hasNext(); ) {
Component component = (Component) i.next();
if (Component.VTIMEZONE.equals(component.getName())) {
VTimeZone vtz = (VTimeZone) component;
Property tzprop = vtz.getProperties().getProperty(Property.TZID);
if (null != tzprop) {
oldTimeZones.put(tzprop.getValue(), vtz);
}
}
}
} catch (IOException | ParserException e) {
System.err.println("Problem loading old timezones.ics - ignoring it. " + e.getMessage());
}
}
return oldTimeZones;
}
use of net.fortuna.ical4j.model.component.VTimeZone in project zm-mailbox by Zimbra.
the class ZoneInfo2iCalendar method main.
// main
public static void main(String[] args) throws Exception {
// command line handling
CommandLine cl = null;
Params params = null;
try {
cl = parseArgs(args);
if (cl.hasOption(OPT_HELP)) {
usage(null);
System.exit(0);
}
params = initParams(cl);
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
System.exit(1);
}
// parse tzdata source
ZoneInfoParser parser = new ZoneInfoParser();
for (File tzdataFile : params.tzdataFiles) {
Reader r = null;
try {
r = new InputStreamReader(new FileInputStream(tzdataFile), "UTF-8");
parser.readTzdata(r);
} catch (ParseException e) {
System.err.println(e.getMessage());
System.err.println("Line: " + e.getErrorOffset());
System.err.println("File: " + tzdataFile.getAbsolutePath());
e.printStackTrace();
System.exit(1);
} finally {
if (r != null)
r.close();
}
}
parser.analyze();
// read extra data file containing primary TZ list and zone match scores
if (params.extraDataFile != null) {
Reader r = null;
try {
r = new InputStreamReader(new FileInputStream(params.extraDataFile), "UTF-8");
readExtraData(r);
} catch (ParseException e) {
System.err.println(e.getMessage());
System.err.println("Line: " + e.getErrorOffset());
System.err.println("File: " + params.extraDataFile.getAbsolutePath());
e.printStackTrace();
System.exit(1);
} finally {
if (r != null)
r.close();
}
}
Writer out;
if (params.outputFile != null) {
out = new PrintWriter(params.outputFile, "UTF-8");
} else {
out = new PrintWriter(new OutputStreamWriter(System.out, "UTF-8"));
}
try {
StringBuilder hdr = new StringBuilder("BEGIN:VCALENDAR");
hdr.append(CRLF);
hdr.append("PRODID:Zimbra-Calendar-Provider").append(CRLF);
hdr.append("VERSION:2.0").append(CRLF);
hdr.append("METHOD:PUBLISH").append(CRLF);
out.write(hdr.toString());
Map<String, VTimeZone> oldTimeZones = makeOldTimeZonesMap(params);
Set<Zone> zones = new TreeSet<Zone>(new ZoneComparatorByGmtOffset());
zones.addAll(parser.getZones());
Set<String> zoneIDs = new TreeSet<String>();
for (Zone zone : zones) {
zoneIDs.add(zone.getName());
}
for (Zone zone : zones) {
out.write(getTimeZoneForZone(zone, params, zoneIDs, oldTimeZones));
}
StringBuilder footer = new StringBuilder("END:VCALENDAR");
footer.append(CRLF);
out.write(footer.toString());
} finally {
out.close();
}
}
Aggregations