net.fortuna.ical4j.model.property.Version Java Examples
The following examples show how to use
net.fortuna.ical4j.model.property.Version.
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: TestHelper.java From cosmo with Apache License 2.0 | 6 votes |
/** * Makes dummy calendar. * @return The dummy calendar. */ public Calendar makeDummyCalendar() { Calendar cal =new Calendar(); cal.getProperties().add(new ProdId(CosmoConstants.PRODUCT_ID)); cal.getProperties().add(Version.VERSION_2_0); return cal; }
Example #2
Source File: Util.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
public static Calendar createCalendar(CalDavEvent calDavEvent, DateTimeZone timeZone) { TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); TimeZone timezone = registry.getTimeZone(timeZone.getID()); Calendar calendar = new Calendar(); calendar.getProperties().add(Version.VERSION_2_0); calendar.getProperties().add(new ProdId("openHAB")); VEvent vEvent = new VEvent(); vEvent.getProperties().add(new Summary(calDavEvent.getName())); vEvent.getProperties().add(new Description(calDavEvent.getContent())); final DtStart dtStart = new DtStart(new net.fortuna.ical4j.model.DateTime(calDavEvent.getStart().toDate())); dtStart.setTimeZone(timezone); vEvent.getProperties().add(dtStart); final DtEnd dtEnd = new DtEnd(new net.fortuna.ical4j.model.DateTime(calDavEvent.getEnd().toDate())); dtEnd.setTimeZone(timezone); vEvent.getProperties().add(dtEnd); vEvent.getProperties().add(new Uid(calDavEvent.getId())); vEvent.getProperties().add(Clazz.PUBLIC); vEvent.getProperties() .add(new LastModified(new net.fortuna.ical4j.model.DateTime(calDavEvent.getLastChanged().toDate()))); calendar.getComponents().add(vEvent); return calendar; }
Example #3
Source File: CalendarFactory.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 6 votes |
public static Calendar createCalendar(List<EventBean> events) { final String prodIdCompany = Unit.getInstitutionName().getContent(); Calendar calendar = new Calendar(); calendar.getProperties().add(new ProdId("-//" + prodIdCompany + "//" + PROD_ID_APPLICATION + "//PT")); calendar.getProperties().add(Version.VERSION_2_0); calendar.getProperties().add(CalScale.GREGORIAN); VTimeZone tz = TIMEZONE.getVTimeZone(); calendar.getComponents().add(tz); for (EventBean eventBean : events) { calendar.getComponents().add(convertEventBean(eventBean)); } return calendar; }
Example #4
Source File: ExternalCalendaringServiceTest.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Ensure we can get a ical4j Calendar from the generated event. */ @Test public void testGeneratingCalendar() { //generate new event CalendarEvent event = generateEvent(); //create vevent net.fortuna.ical4j.model.component.VEvent vevent = service.createEvent(event); //create calendar from vevent net.fortuna.ical4j.model.Calendar calendar = service.createCalendar(Collections.singletonList(vevent)); log.debug("testGeneratingCalendar"); log.debug("######################"); log.debug("{}", calendar); Assert.assertNotNull(calendar); //check attributes of the ical4j calendar are what we expect and match those in the event Assert.assertEquals(Version.VERSION_2_0, calendar.getVersion()); Assert.assertEquals(CalScale.GREGORIAN, calendar.getCalendarScale()); }
Example #5
Source File: CalendarDaoICalFileImpl.java From olat with Apache License 2.0 | 6 votes |
private Calendar buildCalendar(final OlatCalendar olatCalendar) { final Calendar calendar = new Calendar(); // add standard propeties calendar.getProperties().add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN")); calendar.getProperties().add(Version.VERSION_2_0); calendar.getProperties().add(CalScale.GREGORIAN); for (final Iterator<CalendarEntry> iter = olatCalendar.getAllCalendarEntries().iterator(); iter.hasNext();) { final CalendarEntry kEvent = iter.next(); final VEvent vEvent = getVEvent(kEvent); calendar.getComponents().add(vEvent); } return calendar; }
Example #6
Source File: CalendarCollectionProvider.java From cosmo with Apache License 2.0 | 6 votes |
/** * @param collectionItem * @return */ private Calendar getCalendarFromCollection(DavRequest req, CollectionItem collectionItem) { Calendar result = new Calendar(); if (productId == null) { synchronized (this) { if (productId == null) { Environment environment = WebApplicationContextUtils .findWebApplicationContext(req.getServletContext()).getEnvironment(); productId = environment.getProperty(PRODUCT_ID_KEY); } } } result.getProperties().add(new ProdId(productId)); result.getProperties().add(Version.VERSION_2_0); result.getProperties().add(CalScale.GREGORIAN); for (Item item : collectionItem.getChildren()) { if (!NoteItem.class.isInstance(item)) { continue; } for (Stamp s : item.getStamps()) { if (BaseEventStamp.class.isInstance(s)) { BaseEventStamp baseEventStamp = BaseEventStamp.class.cast(s); result.getComponents().add(baseEventStamp.getEvent()); } } } return result; }
Example #7
Source File: FreeBusyUtil.java From cosmo with Apache License 2.0 | 6 votes |
/** * 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; }
Example #8
Source File: ExternalCalendaringServiceTest.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Ensure we can get a ical4j Calendar from the generated event. */ @Test public void testGeneratingCalendar() { //generate new event CalendarEvent event = generateEvent(); //create vevent net.fortuna.ical4j.model.component.VEvent vevent = service.createEvent(event); //create calendar from vevent net.fortuna.ical4j.model.Calendar calendar = service.createCalendar(Collections.singletonList(vevent)); log.debug("testGeneratingCalendar"); log.debug("######################"); log.debug("{}", calendar); Assert.assertNotNull(calendar); //check attributes of the ical4j calendar are what we expect and match those in the event Assert.assertEquals(Version.VERSION_2_0, calendar.getVersion()); Assert.assertEquals(CalScale.GREGORIAN, calendar.getCalendarScale()); }
Example #9
Source File: IcalUtils.java From openmeetings with Apache License 2.0 | 6 votes |
/** * Parses a List of Appointments into a VCALENDAR component. * * @param appointments List of Appointments for the Calendar * @param ownerId Owner of the Appointments * @return VCALENDAR representation of the Appointments */ public Calendar parseAppointmentstoCalendar(List<Appointment> appointments, Long ownerId) { String tzid = parseTimeZone(null, userDao.get(ownerId)).getID(); TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); net.fortuna.ical4j.model.TimeZone timeZone = registry.getTimeZone(tzid); if (timeZone == null) { throw new NoSuchElementException("Unable to get time zone by id provided: " + tzid); } Calendar icsCalendar = new Calendar(); icsCalendar.getProperties().add(new ProdId(PROD_ID)); icsCalendar.getProperties().add(Version.VERSION_2_0); icsCalendar.getProperties().add(CalScale.GREGORIAN); icsCalendar.getComponents().add(timeZone.getVTimeZone()); for (Appointment appointment : appointments) { DateTime start = new DateTime(appointment.getStart()), end = new DateTime(appointment.getEnd()); VEvent meeting = new VEvent(start, end, appointment.getTitle()); meeting = addVEventpropsfromAppointment(appointment, meeting); icsCalendar.getComponents().add(meeting); } return icsCalendar; }
Example #10
Source File: CalendarDaoICalFileImpl.java From olat with Apache License 2.0 | 5 votes |
private Calendar buildCalendar(final OlatCalendar olatCalendar) { final Calendar calendar = new Calendar(); // add standard propeties calendar.getProperties().add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN")); calendar.getProperties().add(Version.VERSION_2_0); calendar.getProperties().add(CalScale.GREGORIAN); for (final Iterator<CalendarEntry> iter = olatCalendar.getAllCalendarEntries().iterator(); iter.hasNext();) { final CalendarEntry kEvent = iter.next(); final VEvent vEvent = getVEvent(kEvent); calendar.getComponents().add(vEvent); } return calendar; }
Example #11
Source File: IcalHandler.java From openmeetings with Apache License 2.0 | 5 votes |
/** * Constructor * * @param method * (@see IcalHandler) constants */ public IcalHandler(Method method) { log.debug("Icalhandler method type : {}", method); icsCalendar = new Calendar(); icsCalendar.getProperties().add(new ProdId("-//Events Calendar//iCal4j 1.0//EN")); icsCalendar.getProperties().add(Version.VERSION_2_0); icsCalendar.getProperties().add(CalScale.GREGORIAN); icsCalendar.getProperties().add(method); }
Example #12
Source File: ICalFormatTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
private Calendar createTestCalendar() throws ParseException { // Create a TimeZone TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); TimeZone timezone = registry.getTimeZone("America/New_York"); VTimeZone tz = timezone.getVTimeZone(); // Start Date is on: April 1, 2013, 9:00 am java.util.Calendar startDate = new GregorianCalendar(); startDate.setTimeZone(timezone); startDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL); startDate.set(java.util.Calendar.DAY_OF_MONTH, 1); startDate.set(java.util.Calendar.YEAR, 2013); startDate.set(java.util.Calendar.HOUR_OF_DAY, 17); startDate.set(java.util.Calendar.MINUTE, 0); startDate.set(java.util.Calendar.SECOND, 0); // End Date is on: April 1, 2013, 13:00 java.util.Calendar endDate = new GregorianCalendar(); endDate.setTimeZone(timezone); endDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL); endDate.set(java.util.Calendar.DAY_OF_MONTH, 1); endDate.set(java.util.Calendar.YEAR, 2013); endDate.set(java.util.Calendar.HOUR_OF_DAY, 21); endDate.set(java.util.Calendar.MINUTE, 0); endDate.set(java.util.Calendar.SECOND, 0); // Create the event PropertyList propertyList = new PropertyList(); propertyList.add(new DtStamp("20130324T180000Z")); propertyList.add(new DtStart(new DateTime(startDate.getTime()))); propertyList.add(new DtEnd(new DateTime(endDate.getTime()))); propertyList.add(new Summary("Progress Meeting")); VEvent meeting = new VEvent(propertyList); // add timezone info.. meeting.getProperties().add(tz.getTimeZoneId()); // generate unique identifier.. meeting.getProperties().add(new Uid("00000000")); // add attendees.. Attendee dev1 = new Attendee(URI.create("mailto:[email protected]")); dev1.getParameters().add(Role.REQ_PARTICIPANT); dev1.getParameters().add(new Cn("Developer 1")); meeting.getProperties().add(dev1); Attendee dev2 = new Attendee(URI.create("mailto:[email protected]")); dev2.getParameters().add(Role.OPT_PARTICIPANT); dev2.getParameters().add(new Cn("Developer 2")); meeting.getProperties().add(dev2); // Create a calendar net.fortuna.ical4j.model.Calendar icsCalendar = new net.fortuna.ical4j.model.Calendar(); icsCalendar.getProperties().add(Version.VERSION_2_0); icsCalendar.getProperties().add(new ProdId("-//Events Calendar//iCal4j 1.0//EN")); icsCalendar.getProperties().add(CalScale.GREGORIAN); // Add the event and print icsCalendar.getComponents().add(meeting); return icsCalendar; }
Example #13
Source File: IcalUtils.java From openmeetings with Apache License 2.0 | 5 votes |
/** * Methods to parse Appointment to iCalendar according RFC 2445 * * @param appointment to be converted to iCalendar * @return iCalendar representation of the Appointment */ public Calendar parseAppointmenttoCalendar(Appointment appointment) { String tzid = parseTimeZone(null, appointment.getOwner()).getID(); TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); net.fortuna.ical4j.model.TimeZone timeZone = registry.getTimeZone(tzid); if (timeZone == null) { throw new NoSuchElementException("Unable to get time zone by id provided: " + tzid); } Calendar icsCalendar = new Calendar(); icsCalendar.getProperties().add(new ProdId("-//Events Calendar//Apache Openmeetings//EN")); icsCalendar.getProperties().add(Version.VERSION_2_0); icsCalendar.getProperties().add(CalScale.GREGORIAN); icsCalendar.getComponents().add(timeZone.getVTimeZone()); DateTime start = new DateTime(appointment.getStart()), end = new DateTime(appointment.getEnd()); VEvent meeting = new VEvent(start, end, appointment.getTitle()); meeting = addVEventpropsfromAppointment(appointment, meeting); icsCalendar.getComponents().add(meeting); return icsCalendar; }
Example #14
Source File: ExternalCalendaringServiceTest.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Ensure we can get a ical4j Calendar from the list of vevents. */ @Test public void testGeneratingCalendarWithMultipleVEvents() { //create list of vevents List<net.fortuna.ical4j.model.component.VEvent> vevents = new ArrayList<net.fortuna.ical4j.model.component.VEvent>(); for(int i=0;i<10;i++) { vevents.add(service.createEvent(generateEvent())); } //create calendar from vevent net.fortuna.ical4j.model.Calendar calendar = service.createCalendar(vevents); log.debug("testGeneratingCalendarWithMultipleVEvents"); log.debug("#########################################"); log.debug("{}", calendar); Assert.assertNotNull(calendar); //check attributes of the ical4j calendar are what we expect and match those in the event Assert.assertEquals(Version.VERSION_2_0, calendar.getVersion()); Assert.assertEquals(CalScale.GREGORIAN, calendar.getCalendarScale()); //TODO check count of vevents }
Example #15
Source File: ExternalCalendaringServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Helper method to setup the standard parts of the calendar * @return */ private Calendar setupCalendar(String method) { String serverName = sakaiProxy.getServerName(); //setup calendar Calendar calendar = new Calendar(); calendar.getProperties().add(new ProdId("-//"+serverName+"//Sakai External Calendaring Service//EN")); calendar.getProperties().add(Version.VERSION_2_0); calendar.getProperties().add(CalScale.GREGORIAN); if (method != null) { calendar.getProperties().add(new Method(method)); } return calendar; }
Example #16
Source File: ICalendarService.java From axelor-open-suite with GNU Affero General Public License v3.0 | 5 votes |
public static Calendar newCalendar() { final Calendar cal = new Calendar(); cal.getProperties().add(new ProdId(PRODUCT_ID)); cal.getProperties().add(Version.VERSION_2_0); cal.getProperties().add(CalScale.GREGORIAN); return cal; }
Example #17
Source File: ExternalCalendaringServiceTest.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Ensure we can get a ical4j Calendar from the list of vevents. */ @Test public void testGeneratingCalendarWithMultipleVEvents() { //create list of vevents List<net.fortuna.ical4j.model.component.VEvent> vevents = new ArrayList<net.fortuna.ical4j.model.component.VEvent>(); for(int i=0;i<10;i++) { vevents.add(service.createEvent(generateEvent())); } //create calendar from vevent net.fortuna.ical4j.model.Calendar calendar = service.createCalendar(vevents); log.debug("testGeneratingCalendarWithMultipleVEvents"); log.debug("#########################################"); log.debug("{}", calendar); Assert.assertNotNull(calendar); //check attributes of the ical4j calendar are what we expect and match those in the event Assert.assertEquals(Version.VERSION_2_0, calendar.getVersion()); Assert.assertEquals(CalScale.GREGORIAN, calendar.getCalendarScale()); //TODO check count of vevents }
Example #18
Source File: ContextServiceExtensionsAdviceTest.java From cosmo with Apache License 2.0 | 5 votes |
/** * Creates a simple item which will be checked with simpleCheckCallExpectedHandler. * * @param user * @return * @throws URISyntaxException */ private ContentItem createSimpleContentItem(User user) throws URISyntaxException { //call service ContentItem contentItem = testHelper.makeDummyContent(user); HibEventStamp eventStamp = new HibEventStamp(); VEvent vEvent = new VEvent(); vEvent.getProperties().add(Method.REQUEST); vEvent.getProperties().add(Version.VERSION_2_0); Attendee dev1 = new Attendee(URI.create("MAILTO:" + ATTENDEE_1)); dev1.getParameters().add(Role.REQ_PARTICIPANT); dev1.getParameters().add(PartStat.NEEDS_ACTION); dev1.getParameters().add(Rsvp.TRUE); vEvent.getProperties().add(dev1); Organizer organizer = new Organizer("MAILTO:" + ORGANIZER); vEvent.getProperties().add(organizer); vEvent.getProperties().add(Status.VEVENT_CONFIRMED); vEvent.getProperties().add(Transp.OPAQUE); Calendar calendar = new Calendar(); calendar.getComponents().add(vEvent); eventStamp.setEventCalendar(calendar); contentItem.addStamp(eventStamp); return contentItem; }
Example #19
Source File: ICalUtils.java From camel-quarkus with Apache License 2.0 | 5 votes |
protected static Calendar createTestCalendar(ZonedDateTime start, ZonedDateTime end, String summary, String attendee) { // Create a TimeZone TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); String tzId = start.getZone().getId(); TimeZone timezone = registry.getTimeZone(tzId.equals("Z") ? "UTC" : tzId); VTimeZone tz = timezone.getVTimeZone(); // Create the event PropertyList propertyList = new PropertyList(); DateTime ts = new DateTime(true); ts.setTime(0); propertyList.add(new DtStamp(ts)); propertyList.add(new DtStart(toDateTime(start, registry))); propertyList.add(new DtEnd(toDateTime(end, registry))); propertyList.add(new Summary(summary)); VEvent meeting = new VEvent(propertyList); // add timezone info.. meeting.getProperties().add(tz.getTimeZoneId()); // generate unique identifier.. meeting.getProperties().add(new Uid("00000000")); // add attendees.. Attendee dev1 = new Attendee(URI.create("mailto:" + attendee)); dev1.getParameters().add(Role.REQ_PARTICIPANT); dev1.getParameters().add(new Cn(attendee)); meeting.getProperties().add(dev1); // Create a calendar net.fortuna.ical4j.model.Calendar icsCalendar = new net.fortuna.ical4j.model.Calendar(); icsCalendar.getProperties().add(Version.VERSION_2_0); icsCalendar.getProperties().add(new ProdId("-//Events Calendar//iCal4j 1.0//EN")); icsCalendar.getProperties().add(CalScale.GREGORIAN); // Add the event and print icsCalendar.getComponents().add(meeting); return icsCalendar; }
Example #20
Source File: ExternalCalendaringServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Helper method to setup the standard parts of the calendar * @return */ private Calendar setupCalendar(String method) { String serverName = sakaiProxy.getServerName(); //setup calendar Calendar calendar = new Calendar(); calendar.getProperties().add(new ProdId("-//"+serverName+"//Sakai External Calendaring Service//EN")); calendar.getProperties().add(Version.VERSION_2_0); calendar.getProperties().add(CalScale.GREGORIAN); if (method != null) { calendar.getProperties().add(new Method(method)); } return calendar; }
Example #21
Source File: ICalendarUtils.java From cosmo with Apache License 2.0 | 5 votes |
/** * Create a base Calendar containing no components. * @return base Calendar */ public static Calendar createBaseCalendar() { Calendar cal = new Calendar(); cal.getProperties().add(new ProdId(CosmoConstants.PRODUCT_ID)); cal.getProperties().add(Version.VERSION_2_0); cal.getProperties().add(CalScale.GREGORIAN); return cal; }
Example #22
Source File: TestSendIcalMessage.java From openmeetings with Apache License 2.0 | 4 votes |
public void simpleInvitionIcalLink() { // Create a TimeZone TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); TimeZone timezone = registry.getTimeZone("America/Mexico_City"); VTimeZone tz = timezone.getVTimeZone(); // Start Date is on: April 1, 2008, 9:00 am java.util.Calendar startDate = new GregorianCalendar(); startDate.setTimeZone(timezone); startDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL); startDate.set(java.util.Calendar.DAY_OF_MONTH, 1); startDate.set(java.util.Calendar.YEAR, 2008); startDate.set(java.util.Calendar.HOUR_OF_DAY, 9); startDate.set(java.util.Calendar.MINUTE, 0); startDate.set(java.util.Calendar.SECOND, 0); // End Date is on: April 1, 2008, 13:00 java.util.Calendar endDate = new GregorianCalendar(); endDate.setTimeZone(timezone); endDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL); endDate.set(java.util.Calendar.DAY_OF_MONTH, 1); endDate.set(java.util.Calendar.YEAR, 2008); endDate.set(java.util.Calendar.HOUR_OF_DAY, 13); endDate.set(java.util.Calendar.MINUTE, 0); endDate.set(java.util.Calendar.SECOND, 0); // Create the event String eventName = "Progress Meeting"; DateTime start = new DateTime(startDate.getTime()); DateTime end = new DateTime(endDate.getTime()); VEvent meeting = new VEvent(start, end, eventName); // add timezone info.. meeting.getProperties().add(tz.getTimeZoneId()); // generate unique identifier.. Uid uid = new Uid(randomUUID().toString()); meeting.getProperties().add(uid); // add attendees.. Attendee dev1 = new Attendee(URI.create("mailto:[email protected]")); dev1.getParameters().add(Role.REQ_PARTICIPANT); dev1.getParameters().add(new Cn("Developer 1")); meeting.getProperties().add(dev1); Attendee dev2 = new Attendee(URI.create("mailto:[email protected]")); dev2.getParameters().add(Role.OPT_PARTICIPANT); dev2.getParameters().add(new Cn("Developer 2")); meeting.getProperties().add(dev2); // Create a calendar net.fortuna.ical4j.model.Calendar icsCalendar = new net.fortuna.ical4j.model.Calendar(); icsCalendar.getProperties().add( new ProdId("-//Events Calendar//iCal4j 1.0//EN")); icsCalendar.getProperties().add(CalScale.GREGORIAN); icsCalendar.getProperties().add(Version.VERSION_2_0); // Add the event and print icsCalendar.getComponents().add(meeting); Organizer orger = new Organizer(URI.create("[email protected]")); orger.getParameters().add(new Cn("Sebastian Wagner")); meeting.getProperties().add(orger); icsCalendar.getProperties().add(Method.REQUEST); log.debug(icsCalendar.toString()); ByteArrayOutputStream bout = new ByteArrayOutputStream(); CalendarOutputter outputter = new CalendarOutputter(); try { outputter.output(icsCalendar, bout); iCalMimeBody = bout.toByteArray(); sendIcalMessage(); } catch (Exception e) { log.error("Error", e); } }
Example #23
Source File: CalendarFeed.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
/** * creates a calendar for the user, identified by his name and authentication key. * @param params * * @param userName * @param userKey * @return a calendar, null if authentication fails */ private Calendar createCal(final Map<String, String> params, final Integer userId, final String authKey, final String timesheetUserParam) { final UserDao userDao = Registry.instance().getDao(UserDao.class); final PFUserDO loggedInUser = userDao.getUserByAuthenticationToken(userId, authKey); if (loggedInUser == null) { return null; } PFUserDO timesheetUser = null; if (StringUtils.isNotBlank(timesheetUserParam) == true) { final Integer timesheetUserId = NumberHelper.parseInteger(timesheetUserParam); if (timesheetUserId != null) { if (timesheetUserId.equals(loggedInUser.getId()) == false) { log.error("Not yet allowed: all users are only allowed to download their own time-sheets."); return null; } timesheetUser = userDao.getUserGroupCache().getUser(timesheetUserId); if (timesheetUser == null) { log.error("Time-sheet user with id '" + timesheetUserParam + "' not found."); return null; } } } // creating a new calendar final Calendar calendar = new Calendar(); final Locale locale = PFUserContext.getLocale(); calendar.getProperties().add( new ProdId("-//" + loggedInUser.getDisplayUsername() + "//ProjectForge//" + locale.toString().toUpperCase())); calendar.getProperties().add(Version.VERSION_2_0); calendar.getProperties().add(CalScale.GREGORIAN); // setup event is needed for empty calendars calendar.getComponents().add(new VEvent(new net.fortuna.ical4j.model.Date(0), SETUP_EVENT)); // adding events for (final VEvent event : getEvents(params, timesheetUser)) { calendar.getComponents().add(event); } return calendar; }
Example #24
Source File: HCalendarParser.java From cosmo with Apache License 2.0 | 4 votes |
/** * Builds calendar. * @param d The document. * @param handler The content handler. * @throws ParserException - if something is wrong this exception is thrown. */ private void buildCalendar(Document d, ContentHandler handler) throws ParserException { // "The root class name for hCalendar is "vcalendar". An element with a // class name of "vcalendar" is itself called an hCalendar. // // The root class name for events is "vevent". An element with a class // name of "vevent" is itself called an hCalender event. // // For authoring convenience, both "vevent" and "vcalendar" are // treated as root class names for parsing purposes. If a document // contains elements with class name "vevent" but not "vcalendar", the // entire document has an implied "vcalendar" context." // XXX: We assume that the entire document has a single vcalendar // context. It is possible that the document contains more than one // vcalendar element. In this case, we should probably only process // that element and log a warning about skipping the others. if (LOG.isDebugEnabled()) { LOG.debug("Building calendar"); } handler.startCalendar(); // no PRODID, as the using application should set that itself handler.startProperty(Property.VERSION); try { handler.propertyValue(Version.VERSION_2_0.getValue()); } catch (URISyntaxException | ParseException | IOException e) { LOG.warn("", e); } handler.endProperty(Property.VERSION); for (Element vevent : findElements(XPATH_VEVENTS, d)) { buildEvent(vevent, handler); } // XXX: support other "first class components": vjournal, vtodo, // vfreebusy, vavailability, vvenue handler.endCalendar(); }