net.fortuna.ical4j.model.component.VTimeZone Java Examples

The following examples show how to use net.fortuna.ical4j.model.component.VTimeZone. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IcsCalendarBuilder.java    From fredbet with Creative Commons Attribution Share Alike 4.0 International 7 votes vote down vote up
public byte[] build() {
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    TimeZone timezone = registry.getTimeZone(timeZone);
    VTimeZone tz = timezone.getVTimeZone();
    VEvent vEvent = new VEvent(toDate(this.start), toDate(this.end), this.title);
    vEvent.getProperties().add(tz.getTimeZoneId());
    vEvent.getProperties().add(uidGenerator.generateUid());
    vEvent.getProperties().add(new Description(this.content));
    vEvent.getProperties().add(new Location(this.location));

    net.fortuna.ical4j.model.Calendar icsCalendar = new net.fortuna.ical4j.model.Calendar();
    icsCalendar.getProperties().add(new ProdId("-//FredBet//iCal4j 1.0//EN"));
    icsCalendar.getProperties().add(CalScale.GREGORIAN);
    icsCalendar.getProperties().add(Version.VERSION_2_0);

    icsCalendar.getComponents().add(vEvent);

    try (ByteArrayOutputStream out = new ByteArrayOutputStream();) {
        CalendarOutputter outputter = new CalendarOutputter();
        outputter.output(icsCalendar, out);
        return out.toByteArray();
    } catch (IOException e) {
        LOG.error(e.getMessage());
        return null;
    }
}
 
Example #2
Source File: CalendarUtils.java    From cosmo with Apache License 2.0 6 votes vote down vote up
public static boolean hasMultipleComponentTypes(Calendar calendar) {
String found = null;
for (Object component : calendar.getComponents()) {
    if (component instanceof VTimeZone) {
	continue;
    }
    if (found == null) {
	found = ((CalendarComponent) component).getName();
	continue;
    }
    if (!found.equals(((CalendarComponent) component).getName())) {
	return true;
    }
}
return false;
   }
 
Example #3
Source File: CalendarFactory.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static Calendar createCalendar(List<EventBean> events) {

        final String prodIdCompany = Unit.getInstitutionName().getContent();
        Calendar calendar = new Calendar();
        calendar.getProperties().add(new ProdId("-//" + prodIdCompany + "//" + PROD_ID_APPLICATION + "//PT"));
        calendar.getProperties().add(Version.VERSION_2_0);
        calendar.getProperties().add(CalScale.GREGORIAN);

        VTimeZone tz = TIMEZONE.getVTimeZone();
        calendar.getComponents().add(tz);

        for (EventBean eventBean : events) {
            calendar.getComponents().add(convertEventBean(eventBean));
        }
        return calendar;

    }
 
Example #4
Source File: EntityConverter.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Compact timezones.
 * @param calendar The calendar.
 */
private void compactTimezones(Calendar calendar) {
    
    if (calendar==null) {
        return;
    }

    // Get list of timezones in master calendar and remove all timezone
    // definitions that are in the registry.  The idea is to not store
    // extra data.  Instead, the timezones will be added to the calendar
    // by the getCalendar() api.
    ComponentList<VTimeZone> timezones = calendar.getComponents(Component.VTIMEZONE);
    List<VTimeZone> toRemove = new ArrayList<>();
    for(VTimeZone vtz : timezones) {
        String tzid = vtz.getTimeZoneId().getValue();
        TimeZone tz = TIMEZONE_REGISTRY.getTimeZone(tzid);
        //  Remove timezone iff it matches the one in the registry
        if(tz!=null && vtz.equals(tz.getVTimeZone())) {
            toRemove.add(vtz);
        }
    }

    // remove known timezones from master calendar
    calendar.getComponents().removeAll(toRemove);
}
 
Example #5
Source File: CalendarFilter.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a CalendarFilter object from a DOM Element.
 * @param element The element.
 * @param timezone The timezone. 
 * @throws ParseException - if something is wrong this exception is thrown.
 */
public CalendarFilter(Element element, VTimeZone timezone) throws ParseException {
    // Can only have a single comp-filter element
    final ElementIterator i = DomUtil.getChildren(element,
            ELEMENT_CALDAV_COMP_FILTER, NAMESPACE_CALDAV);
    if (!i.hasNext()) {
        throw new ParseException(
                "CALDAV:filter must contain a comp-filter", -1);
    }

    final Element child = i.nextElement();

    if (i.hasNext()) {
        throw new ParseException(
                "CALDAV:filter can contain only one comp-filter", -1);
    }

    // Create new component filter and have it parse the element
    filter = new ComponentFilter(child, timezone);
}
 
Example #6
Source File: CalendarDaoICalFileImpl.java    From olat with Apache License 2.0 6 votes vote down vote up
private OlatCalendar createKalendar(final String type, final String calendarID, final Calendar calendar) {
    final OlatCalendar olatCalendar = new OlatCalendar(calendarID, type);
    for (final Iterator iter = calendar.getComponents().iterator(); iter.hasNext();) {
        final Component comp = (Component) iter.next();
        if (comp instanceof VEvent) {
            final VEvent vevent = (VEvent) comp;
            final CalendarEntry calEntry = getCalendarEntry(vevent);
            olatCalendar.addEvent(calEntry);
        } else if (comp instanceof VTimeZone) {
            log.info("createKalendar: VTimeZone Component is not supported and will not be added to calender");
            log.debug("createKalendar: VTimeZone=" + comp);
        } else {
            log.warn("createKalendar: unknown Component=" + comp);
        }
    }
    return olatCalendar;
}
 
Example #7
Source File: TimeRangeFilter.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a TimeRangeFilter object from a DOM Element
 * @param element The DOM Element.
 * @throws ParseException - if something is wrong this exception is thrown.
 */
public TimeRangeFilter(Element element, VTimeZone timezone) throws ParseException {        
    // Get start (must be present)
    String start =
        DomUtil.getAttribute(element, ATTR_CALDAV_START, null);
    if (start == null) {
        throw new ParseException("CALDAV:comp-filter time-range requires a start time", -1);
    }
    
    DateTime trstart = new DateTime(start);
    if (! trstart.isUtc()) {
        throw new ParseException("CALDAV:param-filter timerange start must be UTC", -1);
    }

    // Get end (must be present)
    String end =
        DomUtil.getAttribute(element, ATTR_CALDAV_END, null);        
    DateTime trend = end != null ? new DateTime(end) : getDefaultEndDate(trstart);
    
    if (! trend.isUtc()) {
        throw new ParseException("CALDAV:param-filter timerange end must be UTC", -1);
    }

    setPeriod(new Period(trstart, trend));
    setTimezone(timezone);
}
 
Example #8
Source File: CalendarDaoICalFileImpl.java    From olat with Apache License 2.0 6 votes vote down vote up
private OlatCalendar createKalendar(final String type, final String calendarID, final Calendar calendar) {
    final OlatCalendar olatCalendar = new OlatCalendar(calendarID, type);
    for (final Iterator iter = calendar.getComponents().iterator(); iter.hasNext();) {
        final Component comp = (Component) iter.next();
        if (comp instanceof VEvent) {
            final VEvent vevent = (VEvent) comp;
            final CalendarEntry calEntry = getCalendarEntry(vevent);
            olatCalendar.addEvent(calEntry);
        } else if (comp instanceof VTimeZone) {
            log.info("createKalendar: VTimeZone Component is not supported and will not be added to calender");
            log.debug("createKalendar: VTimeZone=" + comp);
        } else {
            log.warn("createKalendar: unknown Component=" + comp);
        }
    }
    return olatCalendar;
}
 
Example #9
Source File: ComponentFilter.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a ComponentFilter object from a DOM Element.
 * @param element The element.
 * @param timezone The timezone.
 * @throws ParseException - if something is wrong this exception is thrown.
 */
public ComponentFilter(Element element, VTimeZone timezone) throws ParseException {
    // Name must be present
    validateName(element);

    final ElementIterator i = DomUtil.getChildren(element);
    int childCount = 0;
    
    while (i.hasNext()) {
        final Element child = i.nextElement();
        childCount++;

        // if is-not-defined is present, then nothing else can be present
        validateNotDefinedState(childCount);

        Initializers.getInitializer(child.getLocalName()).initialize(child, timezone, this, childCount);
    }
}
 
Example #10
Source File: EntityConverter.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Updates note modification.
 * @param noteMod The note item modified.
 * @param event The event.
 */
private void updateNoteModification(NoteItem noteMod,
                                    VEvent event) {
    EventExceptionStamp exceptionStamp =
        StampUtils.getEventExceptionStamp(noteMod);
    exceptionStamp.setExceptionEvent(event);
    
    // copy VTIMEZONEs to front if present
    ComponentList<VTimeZone> vtimezones = exceptionStamp.getMasterStamp()
            .getEventCalendar().getComponents(Component.VTIMEZONE);
    for(VTimeZone vtimezone : vtimezones) {
        exceptionStamp.getEventCalendar().getComponents().add(0, vtimezone);
    }
    
    noteMod.setClientModifiedDate(new Date());
    noteMod.setLastModifiedBy(noteMod.getModifies().getLastModifiedBy());
    noteMod.setLastModification(ContentItem.Action.EDITED);
    
    setCalendarAttributes(noteMod, event);
}
 
Example #11
Source File: TimezoneValidator.java    From cosmo with Apache License 2.0 6 votes vote down vote up
public boolean isValid(Calendar value, ConstraintValidatorContext context) {
    if(value==null) {
        return true;
    }
    
    try {
        Calendar calendar = (Calendar) value;
        
        // validate entire icalendar object
        calendar.validate(true);
        
        // make sure we have a VTIMEZONE
        VTimeZone timezone = (VTimeZone) calendar.getComponents()
                .getComponents(Component.VTIMEZONE).get(0);
        return timezone != null;
    } catch(ValidationException ve) {
        return false;
    } catch (RuntimeException e) {
        return false;
    }
}
 
Example #12
Source File: QueryReport.java    From cosmo with Apache License 2.0 6 votes vote down vote up
private static VTimeZone findTimeZone(ReportInfo info) throws CosmoDavException {
    Element propdata =
        DomUtil.getChildElement(getReportElementFrom(info),
                                XML_PROP, NAMESPACE);
    if (propdata == null) {
        return null;
    }

    Element tzdata =
        DomUtil.getChildElement(propdata, ELEMENT_CALDAV_TIMEZONE,
                                NAMESPACE_CALDAV);
    if (tzdata == null) {
        return null;
    }

    String icaltz = DomUtil.getTextTrim(tzdata);
    if (icaltz == null) {
        throw new UnprocessableEntityException("Expected text content for " + QN_CALDAV_TIMEZONE);
    }

    return TimeZoneExtractor.extract(icaltz);
}
 
Example #13
Source File: MockCalendarCollectionStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Gets timezone.
 * 
 * @return timezone.
 */
public TimeZone getTimezone() {
    Calendar timezone = getTimezoneCalendar();
    if (timezone == null) {
        return null;
    }
    VTimeZone vtz = (VTimeZone) timezone.getComponents().getComponent(Component.VTIMEZONE);
    return new TimeZone(vtz);
}
 
Example #14
Source File: DavCalendarCollection.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * @return The default timezone for this calendar collection, if one has been set.
 */
public VTimeZone getTimeZone() {
    Calendar obj = getCalendarCollectionStamp().getTimezoneCalendar();
    if (obj == null) {
        return null;
    }
    return (VTimeZone) obj.getComponents().getComponent(Component.VTIMEZONE);
}
 
Example #15
Source File: LimitRecurrenceSetTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Tests limit recurrence set.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testLimitRecurrenceSet() throws Exception {
    CalendarBuilder cb = new CalendarBuilder();
    FileInputStream fis = new FileInputStream(baseDir + "limit_recurr_test.ics");
    Calendar calendar = cb.build(fis);
    
    Assert.assertEquals(5, calendar.getComponents().getComponents("VEVENT").size());
    
    VTimeZone vtz = (VTimeZone) calendar.getComponents().getComponent("VTIMEZONE");
    TimeZone tz = new TimeZone(vtz);
    OutputFilter filter = new OutputFilter("test");
    DateTime start = new DateTime("20060104T010000", tz);
    DateTime end = new DateTime("20060106T010000", tz);
    start.setUtc(true);
    end.setUtc(true);
    
    Period period = new Period(start, end);
    filter.setLimit(period);
    filter.setAllSubComponents();
    filter.setAllProperties();
    
    StringBuilder buffer = new StringBuilder();
    filter.filter(calendar, buffer);
    StringReader sr = new StringReader(buffer.toString());
    
    Calendar filterCal = cb.build(sr);
    
    ComponentList<CalendarComponent> comps = filterCal.getComponents();
    Assert.assertEquals(3, comps.getComponents("VEVENT").size());
    Assert.assertEquals(1, comps.getComponents("VTIMEZONE").size());
    
    // Make sure 3rd and 4th override are dropped

    ComponentList<CalendarComponent> events = comps.getComponents("VEVENT");
    for(CalendarComponent c : events) {            
        Assert.assertNotSame("event 6 changed 3",c.getProperties().getProperty("SUMMARY").getValue());
        Assert.assertNotSame("event 6 changed 4",c.getProperties().getProperty("SUMMARY").getValue());
    }
}
 
Example #16
Source File: LimitRecurrenceSetTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the set of limit recurrence.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testLimitRecurrenceSetThisAndFuture() throws Exception {
    CalendarBuilder cb = new CalendarBuilder();
    FileInputStream fis = new FileInputStream(baseDir + "limit_recurr_taf_test.ics");
    Calendar calendar = cb.build(fis);
    
    Assert.assertEquals(4, calendar.getComponents().getComponents("VEVENT").size());
    
    VTimeZone vtz = (VTimeZone) calendar.getComponents().getComponent("VTIMEZONE");
    TimeZone tz = new TimeZone(vtz);
    OutputFilter filter = new OutputFilter("test");
    DateTime start = new DateTime("20060108T170000", tz);
    DateTime end = new DateTime("20060109T170000", tz);
    start.setUtc(true);
    end.setUtc(true);
    
    Period period = new Period(start, end);
    filter.setLimit(period);
    filter.setAllSubComponents();
    filter.setAllProperties();
    
    StringBuilder buffer = new StringBuilder();
    filter.filter(calendar, buffer);
    StringReader sr = new StringReader(buffer.toString());
    
    Calendar filterCal = cb.build(sr);
    
    Assert.assertEquals(2, filterCal.getComponents().getComponents("VEVENT").size());
    // Make sure 2nd and 3rd override are dropped
    ComponentList<VEvent> vevents = filterCal.getComponents().getComponents(VEvent.VEVENT);
    
    for(VEvent c : vevents) {            
        Assert.assertNotSame("event 6 changed",c.getProperties().getProperty("SUMMARY").getValue());
        Assert.assertNotSame("event 6 changed 2",c.getProperties().getProperty("SUMMARY").getValue());
    }   
}
 
Example #17
Source File: ICalFormatTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private 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:[email protected]"));
    dev1.getParameters().add(Role.REQ_PARTICIPANT);
    dev1.getParameters().add(new Cn("Developer 1"));
    meeting.getProperties().add(dev1);

    Attendee dev2 = new Attendee(URI.create("mailto:[email protected]"));
    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;
}
 
Example #18
Source File: TestHelper.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Makes dummy calendar with event.
 * @return The calendar.
 */
public Calendar makeDummyCalendarWithEvent() {
    Calendar cal = makeDummyCalendar();

    VEvent e1 = makeDummyEvent();
    cal.getComponents().add(e1);

    VTimeZone tz1 = TimeZoneRegistryFactory.getInstance().createRegistry().
    getTimeZone("America/Los_Angeles").getVTimeZone();
    cal.getComponents().add(tz1);

    return cal;
}
 
Example #19
Source File: ExternalCalendaringServiceImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public VTimeZone getTimeZone(boolean timeIsLocal) {
	//timezone. All dates are in GMT so we need to explicitly set that
	TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
	
	//To prevent NPE on timezone
	TimeZone timezone = null;
	if (timeIsLocal == true) {
		timezone = registry.getTimeZone(timeService.getLocalTimeZone().getID());
	}
	if (timezone == null) {
		//This is guaranteed to return timezone if timeIsLocal == false or it fails and returns null
		timezone = registry.getTimeZone("GMT");
	}
	return timezone.getVTimeZone();
}
 
Example #20
Source File: ExternalCalendaringServiceImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Calendar createCalendar(List<VEvent> events, String method, boolean timeIsLocal) {
	
	if(!isIcsEnabled()) {
		log.debug("ExternalCalendaringService is disabled. Enable via calendar.ics.generation.enabled=true in sakai.properties");
		return null;
	}
	
	//setup calendar
	Calendar calendar = setupCalendar(method);
	
	//null check
	if(CollectionUtils.isEmpty(events)) {
		log.error("List of VEvents was null or empty, no calendar will be created.");
		return null;
	}
	
	//add vevents to calendar
	calendar.getComponents().addAll(events);
	
	//add vtimezone
	VTimeZone tz = getTimeZone(timeIsLocal);

	calendar.getComponents().add(tz);
	
	//validate
	try {
		calendar.validate(true);
	} catch (ValidationException e) {
		log.error("createCalendar failed validation", e);
		return null;
	}
	
	if(log.isDebugEnabled()){
		log.debug("Calendar:" + calendar);
	}
	
	return calendar;
	
}
 
Example #21
Source File: ICalUtils.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
protected static Calendar createTestCalendar(ZonedDateTime start, ZonedDateTime end, String summary, String attendee) {
    // Create a TimeZone
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    String tzId = start.getZone().getId();
    TimeZone timezone = registry.getTimeZone(tzId.equals("Z") ? "UTC" : tzId);
    VTimeZone tz = timezone.getVTimeZone();

    // Create the event
    PropertyList propertyList = new PropertyList();
    DateTime ts = new DateTime(true);
    ts.setTime(0);
    propertyList.add(new DtStamp(ts));
    propertyList.add(new DtStart(toDateTime(start, registry)));
    propertyList.add(new DtEnd(toDateTime(end, registry)));
    propertyList.add(new Summary(summary));
    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:" + attendee));
    dev1.getParameters().add(Role.REQ_PARTICIPANT);
    dev1.getParameters().add(new Cn(attendee));
    meeting.getProperties().add(dev1);

    // 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;
}
 
Example #22
Source File: CalendarFilterEvaluater.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Gets subcomponents.
 * @param component The component.
 * @return The component list.
 */
private ComponentList<? extends Component> getSubComponents(Component component) {
    if(component instanceof VEvent) {
        return ((VEvent) component).getAlarms();
    }
    else if(component instanceof VTimeZone) {
        return ((VTimeZone) component).getObservances();
    }
    else if(component instanceof VToDo) {
        return ((VToDo) component).getAlarms();
    }
    
    return new ComponentList<>();
}
 
Example #23
Source File: ComponentFilter.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initialize(Element element, 
                        VTimeZone timezone, 
                        ComponentFilter componentFilter, 
                        int childCount) throws ParseException {
 // XXX provided for backwards compatibility with
    // Evolution 2.6, which does not implement
    // is-not-defined;
    if (childCount > 1) {
        throw new ParseException(
                "CALDAV:is-defined cannnot be present with other child elements", -1);
    }
    LOG.warn("old style 'is-defined' ignored from (outdated) client!");
}
 
Example #24
Source File: HibCalendarCollectionStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public TimeZone getTimezone() {
    Calendar timezone = getTimezoneCalendar();
    if (timezone == null) {
        return null;
    }
    VTimeZone vtz = (VTimeZone) timezone.getComponents().getComponent(Component.VTIMEZONE);
    return new TimeZone(vtz);
}
 
Example #25
Source File: ComponentFilter.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initialize(Element element,     
                        VTimeZone timezone,  
                        ComponentFilter componentFilter, 
                        int childCount) throws ParseException {
    if (childCount > 1) {
        throw new ParseException(
                "CALDAV:is-not-defined cannnot be present with other child elements", -1);
    }
    componentFilter.isNotDefinedFilter = new IsNotDefinedFilter();
}
 
Example #26
Source File: ExternalCalendaringServiceImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public VTimeZone getTimeZone(boolean timeIsLocal) {
	//timezone. All dates are in GMT so we need to explicitly set that
	TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
	
	//To prevent NPE on timezone
	TimeZone timezone = null;
	if (timeIsLocal == true) {
		timezone = registry.getTimeZone(timeService.getLocalTimeZone().getID());
	}
	if (timezone == null) {
		//This is guaranteed to return timezone if timeIsLocal == false or it fails and returns null
		timezone = registry.getTimeZone("GMT");
	}
	return timezone.getVTimeZone();
}
 
Example #27
Source File: ComponentFilter.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initialize(Element element,     
                        VTimeZone timezone, 
                        ComponentFilter componentFilter, 
                        int childCount) throws ParseException { 
 // Add to list
    componentFilter.propFilters.add(new PropertyFilter(element, timezone));
}
 
Example #28
Source File: ComponentFilter.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initialize(Element element, 
                        VTimeZone timezone, 
                        ComponentFilter componentFilter, 
                        int childCount) throws ParseException {
 // Add to list
    componentFilter.componentFilters.add(new ComponentFilter(element, timezone));
}
 
Example #29
Source File: ComponentFilter.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initialize(Element element, 
                        VTimeZone timezone, 
                        ComponentFilter componentFilter, 
                        int childCount) throws ParseException {
 // Can only have one time-range element in a comp-filter
    if (componentFilter.timeRangeFilter != null) {
        throw new ParseException(
                "CALDAV:comp-filter only one time-range element permitted",
                -1);
    }

    componentFilter.timeRangeFilter = new TimeRangeFilter(element, timezone);
}
 
Example #30
Source File: ExternalCalendaringServiceImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Calendar createCalendar(List<VEvent> events, String method, boolean timeIsLocal) {
	
	if(!isIcsEnabled()) {
		log.debug("ExternalCalendaringService is disabled. Enable via calendar.ics.generation.enabled=true in sakai.properties");
		return null;
	}
	
	//setup calendar
	Calendar calendar = setupCalendar(method);
	
	//null check
	if(CollectionUtils.isEmpty(events)) {
		log.error("List of VEvents was null or empty, no calendar will be created.");
		return null;
	}
	
	//add vevents to calendar
	calendar.getComponents().addAll(events);
	
	//add vtimezone
	VTimeZone tz = getTimeZone(timeIsLocal);

	calendar.getComponents().add(tz);
	
	//validate
	try {
		calendar.validate(true);
	} catch (ValidationException e) {
		log.error("createCalendar failed validation", e);
		return null;
	}
	
	if(log.isDebugEnabled()){
		log.debug("Calendar:" + calendar);
	}
	
	return calendar;
	
}