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


Java Calendar.validate方法代码示例

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


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

示例1: isValid

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

示例2: testGetCalendarFromCollection

import net.fortuna.ical4j.model.Calendar; //导入方法依赖的package包/类
/**
 * Tests get calendar from collection.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testGetCalendarFromCollection() throws Exception {
    
    Calendar c1 = getCalendar("eventwithtimezone1.ics");
    Calendar c2 = getCalendar("vtodo.ics");
    NoteItem note1 = converter.convertEventCalendar(c1).iterator().next();
    NoteItem note2 = converter.convertTaskCalendar(c2);
   
    MockCollectionItem collection = new MockCollectionItem();
    collection.addStamp(new MockCalendarCollectionStamp(collection));
    collection.addChild(note1);
    collection.addChild(note2);
    
    Calendar fullCal = converter.convertCollection(collection);
    fullCal.validate();
    Assert.assertNotNull(fullCal);
    
    // VTIMEZONE, VTODO, VEVENT
    Assert.assertEquals(3,fullCal.getComponents().size());
    Assert.assertEquals(1, fullCal.getComponents(Component.VTIMEZONE).size());
    Assert.assertEquals(1, fullCal.getComponents(Component.VEVENT).size());
    Assert.assertEquals(1, fullCal.getComponents(Component.VTODO).size());
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:28,代码来源:EntityConverterTest.java

示例3: 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

示例4: createCalendar

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

示例5: icalIOS7_missingTimezoneProductIdIsAdded

import net.fortuna.ical4j.model.Calendar; //导入方法依赖的package包/类
/**
 * MKCALENDAR in icalIOS7 provides a timezone without prodid
 * @throws IOException
 * @throws ParserException
 * @throws ValidationException
 */
@Test
public void icalIOS7_missingTimezoneProductIdIsAdded() throws IOException, ParserException, ValidationException{
    Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(geticalIOS7Calendar()));
    CalendarClientsAdapter.adaptTimezoneCalendarComponent(calendar);
    calendar.validate(true);//must not throw exceptions
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:13,代码来源:CalendarClientsAdapterTest.java

示例6: 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

示例7: testConvertEvent

import net.fortuna.ical4j.model.Calendar; //导入方法依赖的package包/类
/**
 * Tests convert event.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testConvertEvent() throws Exception {
    TimeZoneRegistry registry =
        TimeZoneRegistryFactory.getInstance().createRegistry();
    NoteItem master = new MockNoteItem();
    master.setDisplayName("displayName");
    master.setBody("body");
    master.setIcalUid("icaluid");
    master.setClientModifiedDate(new DateTime("20070101T100000Z"));
    EventStamp eventStamp = new MockEventStamp(master);
    eventStamp.createCalendar();
    eventStamp.setStartDate(new DateTime("20070212T074500"));
    master.addStamp(eventStamp);
    
    Calendar cal = converter.convertNote(master);
    cal.validate();
    
    // date has no timezone, so there should be no timezones
    Assert.assertEquals(0, cal.getComponents(Component.VTIMEZONE).size());
  
    eventStamp.setStartDate(new DateTime("20070212T074500",TIMEZONE_REGISTRY.getTimeZone("America/Chicago")));
    
    cal = converter.convertNote(master);
    cal.validate();
    
    // should be a single VEVENT
    ComponentList<VEvent> comps = cal.getComponents(Component.VEVENT);
    Assert.assertEquals(1, comps.size());
    VEvent event = (VEvent) comps.get(0);
    
    // test VALUE=DATE-TIME is not present
    Assert.assertNull(event.getStartDate().getParameter(Parameter.VALUE));
    
    // test item properties got merged into calendar
    Assert.assertEquals("displayName", event.getSummary().getValue());
    Assert.assertEquals("body", event.getDescription().getValue());
    Assert.assertEquals("icaluid", event.getUid().getValue());
    Assert.assertEquals(master.getClientModifiedDate().getTime(), event.getDateStamp().getDate().getTime());
     
    // date has timezone, so there should be a timezone
    Assert.assertEquals(1, cal.getComponents(Component.VTIMEZONE).size());
    
    eventStamp.setEndDate(new DateTime("20070212T074500",TIMEZONE_REGISTRY.getTimeZone("America/Los_Angeles")));
    
    cal = converter.convertNote(master);
    cal.validate();
    
    // dates have 2 different timezones, so there should be 2 timezones
    Assert.assertEquals(2, cal.getComponents(Component.VTIMEZONE).size());
    
    // add timezones to master event calendar
    eventStamp.getEventCalendar().getComponents().add(registry.getTimeZone("America/Chicago").getVTimeZone());
    eventStamp.getEventCalendar().getComponents().add(registry.getTimeZone("America/Los_Angeles").getVTimeZone());
    
    cal = converter.convertNote(master);
    cal.validate();
    Assert.assertEquals(2, cal.getComponents(Component.VTIMEZONE).size());
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:63,代码来源:EntityConverterTest.java


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