当前位置: 首页>>代码示例>>Java>>正文


Java Calendar.getComponents方法代码示例

本文整理汇总了Java中net.fortuna.ical4j.model.Calendar.getComponents方法的典型用法代码示例。如果您正苦于以下问题:Java Calendar.getComponents方法的具体用法?Java Calendar.getComponents怎么用?Java Calendar.getComponents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.fortuna.ical4j.model.Calendar的用法示例。


在下文中一共展示了Calendar.getComponents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseCalendartoAppointments

import net.fortuna.ical4j.model.Calendar; //导入方法依赖的package包/类
/**
 * Parses a Calendar with multiple VEvents into Appointments
 *
 * @param calendar Calendar to Parse
 * @param ownerId  Owner of the Appointments
 * @return <code>List</code> of Appointments
 */
public List<Appointment> parseCalendartoAppointments(Calendar calendar, Long ownerId) {
	List<Appointment> appointments = new ArrayList<>();
	ComponentList<CalendarComponent> events = calendar.getComponents(Component.VEVENT);
	User owner = userDao.get(ownerId);

	for (CalendarComponent event : events) {
		Appointment a = new Appointment();
		a.setOwner(owner);
		a.setDeleted(false);
		a.setRoom(createDefaultRoom());
		a.setReminder(Appointment.Reminder.none);
		a = addVEventPropertiestoAppointment(a, event);
		appointments.add(a);
	}
	return appointments;
}
 
开发者ID:apache,项目名称:openmeetings,代码行数:24,代码来源:IcalUtils.java

示例2: hasMultipleComponentTypes

import net.fortuna.ical4j.model.Calendar; //导入方法依赖的package包/类
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;
}
 
开发者ID:ksokol,项目名称:carldav,代码行数:17,代码来源:CalendarUtils.java

示例3: compactTimezones

import net.fortuna.ical4j.model.Calendar; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:29,代码来源:EntityConverter.java

示例4: filterCalendar

import net.fortuna.ical4j.model.Calendar; //导入方法依赖的package包/类
public void filterCalendar(Calendar calendar) {
   
    try {
        ComponentList<VEvent> events = calendar.getComponents(Component.VEVENT);
        for(VEvent event : events) {                 
            // fix VALUE=DATE-TIME instances
            fixDateTimeProperties(event);
            // fix EXDATEs
            if(event.getRecurrenceId()==null) {
                fixExDates(event);
            }
        }
    } catch (Exception e) {
        throw new CosmoException(e);
    } 
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:17,代码来源:ICal3ClientFilter.java

示例5: getICalendar

import net.fortuna.ical4j.model.Calendar; //导入方法依赖的package包/类
/** Returns a calendar derived from a Work Effort calendar publish point.
 * @param workEffortId ID of a work effort with <code>workEffortTypeId</code> equal to
 * <code>PUBLISH_PROPS</code>.
 * @param context The conversion context
 * @return An iCalendar as a <code>String</code>, or <code>null</code>
 * if <code>workEffortId</code> is invalid.
 * @throws GenericEntityException
 */
public static ResponseProperties getICalendar(String workEffortId, Map<String, Object> context) throws GenericEntityException {
    Delegator delegator = (Delegator) context.get("delegator");
    GenericValue publishProperties = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", workEffortId).queryOne();
    if (!isCalendarPublished(publishProperties)) {
        Debug.logInfo("WorkEffort calendar is not published: " + workEffortId, module);
        return ICalWorker.createNotFoundResponse(null);
    }
    if (!"WES_PUBLIC".equals(publishProperties.get("scopeEnumId"))) {
        if (context.get("userLogin") == null) {
            return ICalWorker.createNotAuthorizedResponse(null);
        }
        if (!hasPermission(workEffortId, "VIEW", context)) {
            return ICalWorker.createForbiddenResponse(null);
        }
    }
    Calendar calendar = makeCalendar(publishProperties, context);
    ComponentList components = calendar.getComponents();
    List<GenericValue> workEfforts = getRelatedWorkEfforts(publishProperties, context);
    if (workEfforts != null) {
        for (GenericValue workEffort : workEfforts) {
            ResponseProperties responseProps = toCalendarComponent(components, workEffort, context);
            if (responseProps != null) {
                return responseProps;
            }
        }
    }
    if (Debug.verboseOn()) {
        try {
            calendar.validate(true);
            Debug.logVerbose("iCalendar passes validation", module);
        } catch (ValidationException e) {
            Debug.logVerbose("iCalendar fails validation: " + e, module);
        }
    }
    return ICalWorker.createOkResponse(calendar.toString());
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:45,代码来源:ICalConverter.java

示例6: isOccurrence

import net.fortuna.ical4j.model.Calendar; //导入方法依赖的package包/类
/**
 * Determine if date is a valid occurence in recurring calendar component
 * @param calendar recurring calendar component
 * @param occurrence occurrence date
 * @return true if the occurrence date is a valid occurrence, otherwise false
 */
public boolean isOccurrence(Calendar calendar, Date occurrence) {
    java.util.Calendar cal = Dates.getCalendarInstance(occurrence);
    cal.setTime(occurrence);
   
    // Add a second or day (one unit forward) so we can set a range for
    // finding instances.  This is required because ical4j's Recur apis
    // only calculate recurring dates up until but not including the 
    // end date of the range.
    if(occurrence instanceof DateTime) {
        cal.add(java.util.Calendar.SECOND, 1);
    }
    else {
        cal.add(java.util.Calendar.DAY_OF_WEEK, 1);
    }
    
    Date rangeEnd = 
        org.unitedinternet.cosmo.calendar.util.Dates.getInstance(cal.getTime(), occurrence);
    
    TimeZone tz = null;
    
    for(Object obj : calendar.getComponents(Component.VEVENT)){
    	VEvent evt = (VEvent)obj;
    	if(evt.getRecurrenceId() == null && evt.getStartDate() != null){
    		tz = evt.getStartDate().getTimeZone();
    	}
    }
    InstanceList instances = getOcurrences(calendar, occurrence, rangeEnd, tz);
    
    for(Iterator<Instance> it = instances.values().iterator(); it.hasNext();) {
        Instance instance = it.next();
        if(instance.getRid().getTime()==occurrence.getTime()) {
            return true;
        }
    }
    
    return false;
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:44,代码来源:RecurrenceExpander.java

示例7: hasSupportedComponent

import net.fortuna.ical4j.model.Calendar; //导入方法依赖的package包/类
public static boolean hasSupportedComponent(Calendar calendar) {
    for (Object component: calendar.getComponents()) {
        if (isSupportedComponent(((CalendarComponent)component).getName())) {
             return true;
        }
     }
     return false;
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:9,代码来源:CalendarUtils.java

示例8: getFreeBusyCalendar

import net.fortuna.ical4j.model.Calendar; //导入方法依赖的package包/类
/**
 * Obfuscates the specified calendar by removing unnecessary properties and replacing text fields with specified
 * text.
 * 
 * @param original
 *            calendar to be obfuscated
 * @param productId
 *            productId to be set for the copy calendar.
 * @param freeBusyText
 * @return obfuscated calendar.
 */
public static Calendar getFreeBusyCalendar(Calendar original, String productId, String freeBusyText) {
    // Make a copy of the original calendar
    Calendar copy = new Calendar();
    copy.getProperties().add(new ProdId(productId));
    copy.getProperties().add(Version.VERSION_2_0);
    copy.getProperties().add(CalScale.GREGORIAN);
    copy.getProperties().add(new XProperty(FREE_BUSY_X_PROPERTY, Boolean.TRUE.toString()));

    ComponentList<CalendarComponent> events = original.getComponents(Component.VEVENT);
    for (Component event : events) {
        copy.getComponents().add(getFreeBusyEvent((VEvent) event, freeBusyText));
    }
    return copy;
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:26,代码来源:FreeBusyUtil.java

示例9: setCalendar

import net.fortuna.ical4j.model.Calendar; //导入方法依赖的package包/类
protected void setCalendar(Calendar calendar)
    throws CosmoDavException {
    
    ComponentList<VEvent> vevents = calendar.getComponents(Component.VEVENT);
    if (vevents.isEmpty()) {
        throw new UnprocessableEntityException("VCALENDAR does not contain any VEVENTs");
    }

    getEventStamp().setEventCalendar(calendar);
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:11,代码来源:DavEvent.java

示例10: setCalendar

import net.fortuna.ical4j.model.Calendar; //导入方法依赖的package包/类
/**
 * <p>
 * @param cal Imports a calendar object containing a VJOURNAL. Sets the
 * following properties:
 * </p>
 * <ul>
 * <li>display name: the VJOURNAL's SUMMARY (or the item's name, if the
 * SUMMARY is blank)</li>
 * <li>icalUid: the VJOURNAL's UID</li>
 * <li>body: the VJOURNAL's DESCRIPTION</li>
 * </ul>
 */
public void setCalendar(Calendar cal)
    throws CosmoDavException {
    NoteItem note = (NoteItem) getItem();
  
    ComponentList<VJournal> vjournals = cal.getComponents(Component.VJOURNAL);
    if (vjournals.isEmpty()) {
        throw new UnprocessableEntityException("VCALENDAR does not contain any VJOURNALS");
    }

    EntityConverter converter = new EntityConverter(getEntityFactory());
    converter.convertJournalCalendar(note, cal);
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:25,代码来源:DavJournal.java

示例11: testLimitRecurrenceSet

import net.fortuna.ical4j.model.Calendar; //导入方法依赖的package包/类
/**
 * 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();
    
    StringBuffer buffer = new StringBuffer();
    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());
    }
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:44,代码来源:LimitRecurrenceSetTest.java

示例12: getICalendar

import net.fortuna.ical4j.model.Calendar; //导入方法依赖的package包/类
/** Returns a calendar derived from a Work Effort calendar publish point.
 * @param workEffortId ID of a work effort with <code>workEffortTypeId</code> equal to
 * <code>PUBLISH_PROPS</code>.
 * @param context The conversion context
 * @return An iCalendar as a <code>String</code>, or <code>null</code>
 * if <code>workEffortId</code> is invalid.
 * @throws GenericEntityException
 */
public static ResponseProperties getICalendar(String workEffortId, Map<String, Object> context) throws GenericEntityException {
    Delegator delegator = (Delegator) context.get("delegator");
    GenericValue publishProperties = delegator.findOne("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId), false);
    if (!isCalendarPublished(publishProperties)) {
        Debug.logInfo("WorkEffort calendar is not published: " + workEffortId, module);
        return ICalWorker.createNotFoundResponse(null);
    }
    if (!"WES_PUBLIC".equals(publishProperties.get("scopeEnumId"))) {
        if (context.get("userLogin") == null) {
            return ICalWorker.createNotAuthorizedResponse(null);
        }
        if (!hasPermission(workEffortId, "VIEW", context)) {
            return ICalWorker.createForbiddenResponse(null);
        }
    }
    Calendar calendar = makeCalendar(publishProperties, context);
    ComponentList components = calendar.getComponents();
    List<GenericValue> workEfforts = getRelatedWorkEfforts(publishProperties, context);
    if (workEfforts != null) {
        for (GenericValue workEffort : workEfforts) {
            ResponseProperties responseProps = toCalendarComponent(components, workEffort, context);
            if (responseProps != null) {
                return responseProps;
            }
        }
    }
    if (Debug.verboseOn()) {
        try {
            calendar.validate(true);
            Debug.logVerbose("iCalendar passes validation", module);
        } catch (ValidationException e) {
            Debug.logVerbose("iCalendar fails validation: " + e, module);
        }
    }
    return ICalWorker.createOkResponse(calendar.toString());
}
 
开发者ID:gildaslemoal,项目名称:elpi,代码行数:45,代码来源:ICalConverter.java

示例13: getCalendarEvents

import net.fortuna.ical4j.model.Calendar; //导入方法依赖的package包/类
private ArrayList<CalendarEvent> getCalendarEvents() {
    ArrayList<CalendarEvent> calendarEvents = new ArrayList<>();
    CacheManager cacheManager = CacheManager.getInstance();
    Cache cache = cacheManager.getCache("calendar");

    //Return data from the cache, if available
    Element element = cache.get("calendar");
    if (element != null) {
        return (ArrayList<CalendarEvent>) element.getObjectValue();
    }

    InputStream stream;

    //Download and parse .ics and refresh the cache
    try {

        OkHttpClient client = new OkHttpClient();

        Request request = new Request.Builder()
                .url(CALENDAR_URL)
                .get()
                .build();

        Response response = client.newCall(request).execute();

        String redirect = response.header("Location");
        if (redirect != null) {
            request = new Request.Builder()
                    .url(redirect)
                    .get()
                    .build();
            response = client.newCall(request).execute();
        }

        stream = response.body().byteStream();

        CalendarBuilder builder = new CalendarBuilder();
        Calendar calendar = builder.build(stream);


        SimpleDateFormat dateParser = new SimpleDateFormat("yyyyMMdd");

        for (CalendarComponent calendarComponent : calendar.getComponents()) {
            Date dtstart = dateParser.parse(calendarComponent.getProperty("DTSTART").getValue());
            String uid = calendarComponent.getProperty("UID").getValue();
            Date dtend = dateParser.parse(calendarComponent.getProperty("DTEND").getValue());
            String summary = calendarComponent.getProperty("SUMMARY").getValue();

            calendarEvents.add(new CalendarEvent(dtstart, uid, dtend, summary));
        }

        cache.put(new Element("calendar", calendarEvents));

    } catch (ParserException | IOException | ParseException e) {
        e.printStackTrace();
    }

    return calendarEvents;
}
 
开发者ID:ApplETS,项目名称:applets-java-api,代码行数:60,代码来源:CalendarResource.java

示例14: testLimitRecurrenceSet

import net.fortuna.ical4j.model.Calendar; //导入方法依赖的package包/类
/**
 * 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();
    
    StringBuffer buffer = new StringBuffer();
    filter.filter(calendar, buffer);
    StringReader sr = new StringReader(buffer.toString());
    
    Calendar filterCal = cb.build(sr);
    
    ComponentList 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
    @SuppressWarnings("unchecked")
    Iterator<Component> it = comps.getComponents("VEVENT").iterator();
    while(it.hasNext()) {
        Component c = it.next();
        Assert.assertNotSame("event 6 changed 3",c.getProperties().getProperty("SUMMARY").getValue());
        Assert.assertNotSame("event 6 changed 4",c.getProperties().getProperty("SUMMARY").getValue());
    }
}
 
开发者ID:ksokol,项目名称:carldav,代码行数:45,代码来源:LimitRecurrenceSetTest.java

示例15: splitCalendar

import net.fortuna.ical4j.model.Calendar; //导入方法依赖的package包/类
/**
 * Given a calendar with many different components, split into
 * separate calendars that contain only a single component type
 * and a single UID.
 * @param calendar The calendar.
 * @return The split calendar.
 */
private CalendarContext[] splitCalendar(Calendar calendar) {
    Vector<CalendarContext> contexts = new Vector<CalendarContext>();
    Set<String> allComponents = new HashSet<String>();
    Map<String, ComponentList<CalendarComponent>> componentMap = new HashMap<>();
    
    ComponentList<CalendarComponent> comps = calendar.getComponents();
    for(CalendarComponent comp : comps) {            
        // ignore vtimezones for now
        if(comp instanceof VTimeZone) {
            continue;
        }
        
        Uid uid = (Uid) comp.getProperty(Property.UID);
        RecurrenceId rid = (RecurrenceId) comp.getProperty(Property.RECURRENCE_ID);
        
        String key = uid.getValue();
        if(rid!=null) {
            key+=rid.toString();
        }
        
        // ignore duplicates
        if(allComponents.contains(key)) {
            continue;
        }
        
        allComponents.add(key);
        
        ComponentList<CalendarComponent> cl = componentMap.get(uid.getValue());
        
        if(cl==null) {
            cl = new ComponentList<>();
            componentMap.put(uid.getValue(), cl);
        }
        
        cl.add(comp);
    }
    
    for(Entry<String, ComponentList<CalendarComponent>> entry : componentMap.entrySet()) {
       
        Component firstComp = (Component) entry.getValue().get(0);
        
        Calendar cal = ICalendarUtils.createBaseCalendar();
        cal.getComponents().addAll(entry.getValue());
        addTimezones(cal);
        
        CalendarContext cc = new CalendarContext();
        cc.calendar = cal;
        cc.type = firstComp.getName();
        
        contexts.add(cc);
    }
    
    return contexts.toArray(new CalendarContext[contexts.size()]);
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:62,代码来源:EntityConverter.java


注:本文中的net.fortuna.ical4j.model.Calendar.getComponents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。