本文整理汇总了Java中net.fortuna.ical4j.data.CalendarBuilder类的典型用法代码示例。如果您正苦于以下问题:Java CalendarBuilder类的具体用法?Java CalendarBuilder怎么用?Java CalendarBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CalendarBuilder类属于net.fortuna.ical4j.data包,在下文中一共展示了CalendarBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ReadCalendarFiles
import net.fortuna.ical4j.data.CalendarBuilder; //导入依赖的package包/类
public ReadCalendarFiles(String filePath) throws IOException, ParserException {
Map<String, String> calendarEntry = null;
FileInputStream fin = new FileInputStream(filePath);
CalendarBuilder builder = new CalendarBuilder();
net.fortuna.ical4j.model.Calendar calendar = builder.build(fin);
for (Iterator i = calendar.getComponents().iterator(); i.hasNext(); ) {
Component component = (Component) i.next();
if (component.getName().equalsIgnoreCase("VEVENT")) {
calendarEntry = new HashMap<>();
for (Iterator j = component.getProperties().iterator(); j.hasNext(); ) {
net.fortuna.ical4j.model.Property property = (Property) j.next();
calendarEntry.put(property.getName(), property.getValue());
}
calendarEntries.add(calendarEntry);
}
}
}
示例2: readCalendarData
import net.fortuna.ical4j.data.CalendarBuilder; //导入依赖的package包/类
private String readCalendarData(DavCalendarResource resource)
throws CosmoDavException {
if (! resource.exists()) {
return null;
}
final String calendarString = resource.getCalendar();
StringBuffer buffer = new StringBuffer();
if (outputFilter != null) {
try {
final Calendar calendar = new CalendarBuilder().build(new StringReader(calendarString));
outputFilter.filter(calendar, buffer);
} catch (Exception exception) {
throw new RuntimeException(exception.getMessage(), exception);
}
}
else {
buffer.append(calendarString);
}
return buffer.toString();
}
示例3: readCalendar
import net.fortuna.ical4j.data.CalendarBuilder; //导入依赖的package包/类
/**
* Internal read calendar file from filesystem
*/
@Override
public Calendar readCalendar(final String type, final String calendarID) {
log.debug("readCalendar from file, type=" + type + " calendarID=" + calendarID);
final File calendarFile = getCalendarFile(type, calendarID);
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(calendarFile));
} catch (final FileNotFoundException fne) {
throw new OLATRuntimeException("Not found: " + calendarFile, fne);
}
final CalendarBuilder builder = new CalendarBuilder();
Calendar calendar = null;
try {
calendar = builder.build(in);
} catch (final Exception e) {
throw new OLATRuntimeException("Error parsing calendar file.", e);
} finally {
if (in != null) {
FileUtils.closeSafely(in);
}
}
return calendar;
}
示例4: extractUid
import net.fortuna.ical4j.data.CalendarBuilder; //导入依赖的package包/类
private String extractUid(String icalendar) throws IOException, ParserException {
String uid = null;
StringReader reader = new StringReader(icalendar);
CalendarBuilder builder = new CalendarBuilder();
Calendar calendar = builder.build(new UnfoldingReader(reader, true));
if ( calendar != null && calendar.getComponents() != null ) {
Iterator<Component> iterator = calendar.getComponents().iterator();
while (iterator.hasNext()) {
Component component = iterator.next();
if ( component instanceof VEvent ) {
uid = ((VEvent)component).getUid().getValue();
break;
}
}
}
return uid;
}
示例5: loadCalendar
import net.fortuna.ical4j.data.CalendarBuilder; //导入依赖的package包/类
public static Calendar loadCalendar(final URL url) throws IOException, ParserException {
//noetig wegen ical4j-Bug #167
CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING, true);
final CalendarBuilder b = new CalendarBuilder();
final URLConnection conn = url.openConnection();
try (InputStream in = conn.getInputStream()) {
return b.build(in);
}
}
示例6: extractNews
import net.fortuna.ical4j.data.CalendarBuilder; //导入依赖的package包/类
private List<News> extractNews(String path) throws IOException, ParserException {
FileInputStream fin = new FileInputStream(path);
CalendarBuilder builder = new CalendarBuilder();
net.fortuna.ical4j.model.Calendar calendar = builder.build(fin);
ComponentList events = calendar.getComponents(Component.VEVENT);
List<News> news = new ArrayList<>();
for (Object e : events) {
VEvent event = (VEvent) e;
news.add(new News(event.getSummary().getValue(), event.getStartDate().getDate(), event.getDescription().getValue()));
}
return news;
}
示例7: clearTZRegistry
import net.fortuna.ical4j.data.CalendarBuilder; //导入依赖的package包/类
private static void clearTZRegistry(CalendarBuilder cb) {
// clear timezone registry if present
TimeZoneRegistry tzr = cb.getRegistry();
if(tzr!=null) {
tzr.clear();
}
}
示例8: convert
import net.fortuna.ical4j.data.CalendarBuilder; //导入依赖的package包/类
public Item convert(Item calendarItem) {
try {
final Calendar calendar = new CalendarBuilder().build(new StringReader(calendarItem.getCalendar()));
Component component = getFirstComponent(calendar.getComponents(calendarItem.getType().name()));
setCalendarAttributes(calendarItem, component);
calculateEventStampIndexes(calendar, component, calendarItem);
calendarItem.setMimetype(ICALENDAR_MEDIA_TYPE);
return calendarItem;
} catch (Exception exception) {
throw new RuntimeException(exception.getMessage(), exception);
}
}
示例9: convertContent
import net.fortuna.ical4j.data.CalendarBuilder; //导入依赖的package包/类
public Calendar convertContent(Item item) {
if(item.getCalendar() != null) {
try {
return new CalendarBuilder().build(new StringReader(item.getCalendar()));
} catch (Exception exception) {
throw new RuntimeException(exception.getMessage(), exception);
}
}
return null;
}
示例10: getCalendar
import net.fortuna.ical4j.data.CalendarBuilder; //导入依赖的package包/类
/**
* Gets calendar.
* @param name The name.
* @return The calendar.
* @throws Exception - if something is wrong this exception is thrown.
*/
protected Calendar getCalendar(String name) throws Exception {
CalendarBuilder cb = new CalendarBuilder();
InputStream in = getClass().getClassLoader().getResourceAsStream("testdata/" + name);
if (in == null) {
throw new IllegalStateException("resource " + name + " not found");
}
Calendar calendar = cb.build(in);
return calendar;
}
示例11: testLimitFloatingRecurrenceSet
import net.fortuna.ical4j.data.CalendarBuilder; //导入依赖的package包/类
/**
* Tests limit floating recurrence set.
* @throws Exception - if something is wrong this exception is thrown.
*/
@Test
public void testLimitFloatingRecurrenceSet() throws Exception {
CalendarBuilder cb = new CalendarBuilder();
FileInputStream fis = new FileInputStream(baseDir + "limit_recurr_float_test.ics");
Calendar calendar = cb.build(fis);
Assert.assertEquals(3, calendar.getComponents().getComponents("VEVENT").size());
OutputFilter filter = new OutputFilter("test");
DateTime start = new DateTime("20060102T170000");
DateTime end = new DateTime("20060104T170000");
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);
Assert.assertEquals(2, filterCal.getComponents().getComponents("VEVENT").size());
// Make sure 2nd override is dropped
ComponentList vevents = filterCal.getComponents().getComponents(VEvent.VEVENT);
Iterator<VEvent> it = vevents.iterator();
while(it.hasNext()) {
Component c = it.next();
Assert.assertNotSame("event 6 changed 2",c.getProperties().getProperty("SUMMARY").getValue());
}
}
示例12: testLimitRecurrenceSetThisAndFuture
import net.fortuna.ical4j.data.CalendarBuilder; //导入依赖的package包/类
/**
* 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();
StringBuffer buffer = new StringBuffer();
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 vevents = filterCal.getComponents().getComponents(VEvent.VEVENT);
Iterator<VEvent> it = vevents.iterator();
while(it.hasNext()) {
Component c = it.next();
Assert.assertNotSame("event 6 changed",c.getProperties().getProperty("SUMMARY").getValue());
Assert.assertNotSame("event 6 changed 2",c.getProperties().getProperty("SUMMARY").getValue());
}
}
示例13: getCalendar
import net.fortuna.ical4j.data.CalendarBuilder; //导入依赖的package包/类
/**
* Gets calendar.
* @param name The name.
* @return The calendar.
* @throws Exception - if something is wrong this exception is thrown.
*/
protected Calendar getCalendar(String name) throws Exception {
CalendarBuilder cb = new CalendarBuilder();
InputStream in = getClass().getClassLoader().getResourceAsStream("testdata/expander/" + name);
if (in == null) {
throw new IllegalStateException("resource " + name + " not found");
}
Calendar calendar = cb.build(in);
return calendar;
}
示例14: getCalendar
import net.fortuna.ical4j.data.CalendarBuilder; //导入依赖的package包/类
/**
* Gets calendar.
*
* @param name The name.
* @return The calendar.
* @throws Exception - if something is wrong this exception is thrown.
*/
protected Calendar getCalendar(String name) throws Exception {
CalendarBuilder cb = new CalendarBuilder();
InputStream in = getClass().getClassLoader().getResourceAsStream("testdata/instancelist/" + name);
if (in == null) {
throw new IllegalStateException("resource " + name + " not found");
}
Calendar calendar = cb.build(in);
return calendar;
}
示例15: parseCalendar
import net.fortuna.ical4j.data.CalendarBuilder; //导入依赖的package包/类
/**
* Parse icalendar string into Calendar object.
* @param calendar icalendar string
* @return Calendar object
* @throws ParserException - if something is wrong this exception is thrown.
* @throws IOException - if something is wrong this exception is thrown.
*/
public static Calendar parseCalendar(String calendar) throws ParserException, IOException {
if (calendar == null) {
return null;
}
CalendarBuilder builder = CalendarBuilderDispenser.getCalendarBuilder();
clearTZRegistry(builder);
StringReader sr = new StringReader(calendar);
return builder.build(sr);
}