Java Code Examples for net.fortuna.ical4j.model.Component#getProperty()

The following examples show how to use net.fortuna.ical4j.model.Component#getProperty() . 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: DavAvailability.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Imports a calendar object containing a VAVAILABILITY. 
 * @param cal The calendar imported.
 * @throws CosmoDavException - if something is wrong this exception is thrown.
 * </p>
 */
public void setCalendar(Calendar cal) throws CosmoDavException {
    AvailabilityItem availability = (AvailabilityItem) getItem();
    
    availability.setAvailabilityCalendar(cal);
    
    Component comp = cal.getComponent(ICalendarConstants.COMPONENT_VAVAILABLITY);
    if (comp==null) {
        throw new UnprocessableEntityException("VCALENDAR does not contain a VAVAILABILITY");
    }

    String val = null;
    Property prop = comp.getProperty(Property.UID);
    if (prop != null) {
        val = prop.getValue();
    }
    if (StringUtils.isBlank(val)) {
        throw new UnprocessableEntityException("VAVAILABILITY does not contain a UID");
    }
    availability.setIcalUid(val);
}
 
Example 2
Source File: IcalUtils.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the VTimezone Component of the given Calendar. If no, VTimezone component is found the
 * User Timezone is used
 *
 * @param calendar Calendar to parse
 * @param owner    Owner of the Calendar
 * @return Parsed TimeZone
 */
public TimeZone parseTimeZone(Calendar calendar, User owner) {
	if (calendar != null) {
		Component timezone = calendar.getComponent(Component.VTIMEZONE);
		if (timezone != null) {
			Property tzid = timezone.getProperty(Property.TZID);
			if (tzid != null) {
				return getTimeZone(tzid.getValue());
			}
		}
	}
	return getTimeZone(owner);
}
 
Example 3
Source File: CalendarFilterEvaluater.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Evaluates VEvent time range.
 * @param comps The component list.
 * @param filter The time range filter.
 * @return The result.
 */
private boolean evaluateVEventTimeRange(ComponentList<? extends Component> comps, TimeRangeFilter filter) {
    
    InstanceList instances = new InstanceList();
    if(filter.getTimezone()!=null) {
        instances.setTimezone(new TimeZone(filter.getTimezone()));
    }
    ArrayList<Component> mods = new ArrayList<Component>();
    
    for(Component comp : comps) {
        // Add master first
        if(comp.getProperty(Property.RECURRENCE_ID)==null) {
            instances.addComponent(comp, filter.getPeriod().getStart(), filter.getPeriod().getEnd());
        }
    }
    
    // Add overides after master has been added
    for(Component mod : mods) {
        instances.addOverride(mod, filter.getPeriod().getStart(), filter.getPeriod().getEnd());
    }
    
    if(instances.size()>0) {
        return true;
    }
    
    return false;
}
 
Example 4
Source File: EntityConverter.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * gets master component.
 * @param components The component list.
 * @return The component.
 */
private Component getMasterComponent(ComponentList<? extends Component> components) {
    Iterator<? extends Component> it = components.iterator();
    while(it.hasNext()) {
        Component c = it.next();
        if(c.getProperty(Property.RECURRENCE_ID)==null) {
            return c;
        }
    }
    
    throw new IllegalArgumentException("no master found");
}
 
Example 5
Source File: StandardContentService.java    From cosmo with Apache License 2.0 5 votes vote down vote up
private void checkDatesForComponent(Component component){
    if(component == null){
        return;
    }
    
    Property dtStart = component.getProperty(Property.DTSTART);
    Property dtEnd = component.getProperty(Property.DTEND);
    
    if( dtStart instanceof DtStart && dtStart.getValue()!= null 
        && dtEnd instanceof DtEnd && dtEnd.getValue() != null 
       && ((DtStart)dtStart).getDate().compareTo(((DtEnd)dtEnd).getDate()) > 0 ){
        throw new IllegalArgumentException("End date [" + dtEnd + " is lower than start date [" + dtStart + "]");
    }
    
}
 
Example 6
Source File: ICalendarUtils.java    From cosmo with Apache License 2.0 4 votes vote down vote up
/**
 * Return the date that a trigger refers to, which can be an absolute
 * date or a date relative to the start or end time of a parent 
 * component (VEVENT/VTODO).
 * @param trigger The trigger.
 * @param parent The component.
 * @return date of trigger.
 */
public static Date getTriggerDate(Trigger trigger, Component parent) {
    
    if(trigger==null) {
        return null;
    }
    
    // if its absolute then we are done
    if(trigger.getDateTime()!=null) {
        return trigger.getDateTime();
    }
    
    // otherwise we need a start date if VEVENT
    DtStart start = (DtStart) parent.getProperty(Property.DTSTART);
    if(start==null && parent instanceof VEvent) {
        return null;
    }
    
    // is trigger relative to start or end
    Related related = (Related) trigger.getParameter(Parameter.RELATED);
    if(related==null || related.equals(Related.START)) {    
        // must have start date
        if(start==null) {
            return null;
        }
        
        // relative to start
        return Dates.getInstance(trigger.getDuration().getTime(start.getDate()), start.getDate());
    } else {
        // relative to end
        Date endDate = null;
        
        // need an end date or duration or due 
        DtEnd end = (DtEnd) parent.getProperty(Property.DTEND);
        if(end!=null) {
            endDate = end.getDate();
        }
       
        if(endDate==null) {
            Duration dur = (Duration) parent.getProperty(Property.DURATION);
            if(dur!=null && start!=null) {
                endDate= Dates.getInstance(dur.getDuration().getTime(start.getDate()), start.getDate());
            }
        }
        
        if(endDate==null) {
            Due due = (Due) parent.getProperty(Property.DUE);
            if(due!=null) {
                endDate = due.getDate();
            }
        }
        
        // require end date
        if(endDate==null) {
            return null;
        }
        
        return Dates.getInstance(trigger.getDuration().getTime(endDate), endDate);
    }
}
 
Example 7
Source File: CalendarFilterEvaluater.java    From cosmo with Apache License 2.0 4 votes vote down vote up
/**
 * Evaluates VToDo Time Range.
 * @param comps The component list.
 * @param filter The time range filter.
 * @return The boolean.
 * 
 */
private boolean evaulateVToDoTimeRange(ComponentList<? extends Component> comps, TimeRangeFilter filter) {
    ArrayList<Component> mods = new ArrayList<Component>();
    VToDo master = null;
    
    for(Component comp : comps) {
        // Add master first
        if(comp.getProperty(Property.RECURRENCE_ID)==null) {
            master = (VToDo) comp;
        }
    }
    
    // If there is no DTSTART, evaluate using special rules as
    // listed in the nice state table above
    if(mods.size()==0 && master.getStartDate()==null) {        
        return isVToDoInRange(master, filter.getPeriod());
    }
    
    // Otherwise use standard InstantList, which relies on
    // DTSTART,DURATION. 
    // TODO: Handle case of no DURATION and instead DUE
    // DUE is kind of like DTEND
    InstanceList instances = new InstanceList();
    if(filter.getTimezone()!=null) {
        instances.setTimezone(new TimeZone(filter.getTimezone()));
    }
    
    instances.addComponent(master, filter.getPeriod().getStart(), filter
            .getPeriod().getEnd());
    
    // Add overides after master has been added
    for(Component mod : mods) {
        instances.addOverride(mod, filter.getPeriod().getStart(), filter.getPeriod().getEnd());
    }
    
    if(instances.size()>0) {
        return true;
    }
    
    return false;
}
 
Example 8
Source File: ICalendarService.java    From axelor-open-suite with GNU Affero General Public License v3.0 4 votes vote down vote up
protected String getValue(Component component, String name) {
  if (component.getProperty(name) != null) {
    return component.getProperty(name).getValue();
  }
  return null;
}