net.fortuna.ical4j.data.UnfoldingReader Java Examples
The following examples show how to use
net.fortuna.ical4j.data.UnfoldingReader.
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: IcsConverter.java From ganttproject with GNU General Public License v3.0 | 7 votes |
public static void main(String[] args) throws Exception { Args mainArgs = new Args(); try { new JCommander(new Object[] { mainArgs }, args); } catch (Throwable e) { e.printStackTrace(); return; } if (mainArgs.file.size() != 1) { System.err.println("Only 1 input file should be specified"); return; } CalendarBuilder builder = new CalendarBuilder(); Calendar c = builder.build(new UnfoldingReader(new FileReader(mainArgs.file.get(0)))); for (Component comp : (List<Component>)c.getComponents()) { System.err.println(comp); } }
Example #2
Source File: EventCollectionResource.java From XPagesExtensionLibrary with Apache License 2.0 | 6 votes |
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; }
Example #3
Source File: EventCollectionResource.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
/** * Formats a list of events as a JSON array. * * @param events * @param uriInfo * @return * @throws JsonException * @throws IOException */ private String createJsonArray(String eventString, UriInfo uriInfo) throws ParserException, IOException { StringReader reader = new StringReader(eventString); StringBuilder sb = new StringBuilder(); CalendarParser parser = CalendarParserFactory.getInstance().createParser(); URI baseURI = UriHelper.copy(uriInfo.getAbsolutePath(),CalendarService.isUseRelativeUrls()); baseURI = CalendarService.adaptUriToScn(baseURI); parser.parse(new UnfoldingReader(reader, true), new JsonCalendarGenerator(sb, baseURI, false)); return sb.toString(); }
Example #4
Source File: IcsFileImporter.java From ganttproject with GNU General Public License v3.0 | 4 votes |
/** * Reads calendar events from file * @return a list of events if file was parsed successfully or null otherwise */ private static List<CalendarEvent> readEvents(File f) { try { CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING, true); CalendarBuilder builder = new CalendarBuilder(); List<CalendarEvent> gpEvents = Lists.newArrayList(); Calendar c = builder.build(new UnfoldingReader(new FileReader(f))); for (Component comp : (List<Component>)c.getComponents()) { if (comp instanceof VEvent) { VEvent event = (VEvent) comp; if (event.getStartDate() == null) { GPLogger.log("No start date found, ignoring. Event="+event); continue; } Date eventStartDate = event.getStartDate().getDate(); if (event.getEndDate() == null) { GPLogger.log("No end date found, using start date instead. Event="+event); } Date eventEndDate = event.getEndDate() == null ? eventStartDate : event.getEndDate().getDate(); TimeDuration oneDay = GPTimeUnitStack.createLength(GPTimeUnitStack.DAY, 1); if (eventEndDate != null) { java.util.Date startDate = GPTimeUnitStack.DAY.adjustLeft(eventStartDate); java.util.Date endDate = GPTimeUnitStack.DAY.adjustLeft(eventEndDate); RRule recurrenceRule = (RRule) event.getProperty(Property.RRULE); boolean recursYearly = false; if (recurrenceRule != null) { recursYearly = Recur.YEARLY.equals(recurrenceRule.getRecur().getFrequency()) && 1 == recurrenceRule.getRecur().getInterval(); } while (startDate.compareTo(endDate) <= 0) { Summary summary = event.getSummary(); gpEvents.add(CalendarEvent.newEvent( startDate, recursYearly, CalendarEvent.Type.HOLIDAY, summary == null ? "" : summary.getValue(), null)); startDate = GPCalendarCalc.PLAIN.shiftDate(startDate, oneDay); } } } } return gpEvents; } catch (IOException | ParserException e) { GPLogger.log(e); return null; } }