Package net.fortuna.ical4j.model

Examples of net.fortuna.ical4j.model.Calendar


    }

    @Override
    protected byte[] doExecute(PartakeConnection con, IPartakeDAOs daos) throws DAOException, PartakeException {
        try {
            Calendar calendar = CalendarUtil.createCalendarSkeleton();
            CalendarDAOFacade.addCalendarByCategoryName(con, daos, categoryName, calendar);
            return CalendarUtil.outputCalendar(calendar);
        } catch (IOException e) {
            throw new PartakeException(ServerErrorCode.CALENDAR_CREATION_FAILURE, e);
        } catch (ValidationException e) {
View Full Code Here


    protected Result doExecute() throws DAOException, PartakeException {
        checkIdParameterIsValid(calendarId, UserErrorCode.INVALID_NOTFOUND, UserErrorCode.INVALID_NOTFOUND);

        // TODO: CalendarLinkage should have cache. Maybe ShowCalendarTransaction should return
        // InputStream instead of Calendar?
        Calendar calendar = new ShowCalendarTransaction(calendarId).execute();
        try {
            byte[] body = CalendarUtil.outputCalendar(calendar);
            return render(body, "text/calendar; charset=utf-8", "inline");
        } catch (IOException e) {
            return renderError(ServerErrorCode.CALENDAR_CREATION_FAILURE, e);
View Full Code Here

        User user = daos.getUserAccess().find(con, calendarLinkage.getUserId());
        if (user == null)
            throw new PartakeException(UserErrorCode.INVALID_NOTFOUND);

        Calendar calendar = CalendarUtil.createCalendarSkeleton();

        // TODO: We only consider the first 1000 entries of enrollments due to memory limit.
        List<UserTicket> enrollments =
                daos.getEnrollmentAccess().findByUserId(con, user.getId(), 0, 1000);
        for (UserTicket enrollment : enrollments) {
View Full Code Here

        TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
        JST_TIMEZONE = registry.getTimeZone("Asia/Tokyo");
    }

    public static Calendar createCalendarSkeleton() {
        Calendar calendar = new Calendar();

        calendar.getProperties().add(new ProdId("-//Events Calendar//iCal4j 1.0//EN"));
        calendar.getProperties().add(Version.VERSION_2_0);
        calendar.getProperties().add(CalScale.GREGORIAN);
        calendar.getComponents().add(JST_TIMEZONE.getVTimeZone());

        return calendar;
    }
View Full Code Here

            }
            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());
    }
View Full Code Here

        GenericValue iCalValue = workEffort.getRelatedOne("WorkEffortIcalData");
        if (iCalValue != null) {
            iCalData = iCalValue.getString("icalData");
        }
        boolean newCalendar = true;
        Calendar calendar = null;
        if (iCalData == null) {
            Debug.logVerbose("iCalendar Data not found, creating new Calendar", module);
            calendar = new Calendar();
        } else {
            Debug.logVerbose("iCalendar Data found, using saved Calendar", module);
            StringReader reader = new StringReader(iCalData);
            CalendarBuilder builder = new CalendarBuilder();
            try {
                calendar = builder.build(reader);
                newCalendar = false;
            } catch (Exception e) {
                Debug.logError(e, "Error while parsing saved iCalendar, creating new iCalendar: ", module);
                calendar = new Calendar();
            }
        }
        PropertyList propList = calendar.getProperties();
        replaceProperty(propList, prodId);
        replaceProperty(propList, new XProperty(workEffortIdXPropName, workEffort.getString("workEffortId")));
        if (newCalendar) {
            propList.add(Version.VERSION_2_0);
            propList.add(CalScale.GREGORIAN);
            // TODO: Get time zone from publish properties value
            java.util.TimeZone tz = java.util.TimeZone.getDefault();
            TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
            net.fortuna.ical4j.model.TimeZone timezone = registry.getTimeZone(tz.getID());
            calendar.getComponents().add(timezone.getVTimeZone());
        }
        return calendar;
    }
View Full Code Here

     * @throws GenericEntityException
     * @throws GenericServiceException
     */
    public static ResponseProperties storeCalendar(InputStream is, Map<String, Object> context) throws IOException, ParserException, GenericEntityException, GenericServiceException {
        CalendarBuilder builder = new CalendarBuilder();
        Calendar calendar = null;
        try {
            calendar = builder.build(is);
        } finally {
            if (is != null) {
                is.close();
            }
        }
        if (Debug.verboseOn()) {
            Debug.logVerbose("Processing calendar:\r\n" + calendar, module);
        }
        String workEffortId = fromXProperty(calendar.getProperties(), workEffortIdXPropName);
        if (workEffortId == null) {
            workEffortId = (String) context.get("workEffortId");
        }
        if (!workEffortId.equals(context.get("workEffortId"))) {
            Debug.logWarning("Spoof attempt: received calendar workEffortId " + workEffortId +
                    " on URL workEffortId " + context.get("workEffortId"), module);
            return ICalWorker.createForbiddenResponse(null);
        }
        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 (context.get("userLogin") == null) {
            return ICalWorker.createNotAuthorizedResponse(null);
        }
        if (!hasPermission(workEffortId, "UPDATE", context)) {
            return ICalWorker.createForbiddenResponse(null);
        }
        boolean hasCreatePermission = hasPermission(workEffortId, "CREATE", context);
        List<GenericValue> workEfforts = getRelatedWorkEfforts(publishProperties, context);
        Set<String> validWorkEfforts = FastSet.newInstance();
        if (UtilValidate.isNotEmpty(workEfforts)) {
            // Security issue: make sure only related work efforts get updated
            for (GenericValue workEffort : workEfforts) {
                validWorkEfforts.add(workEffort.getString("workEffortId"));
            }
        }
        List<Component> components = UtilGenerics.checkList(calendar.getComponents(), Component.class);
        ResponseProperties responseProps = null;
        for (Component component : components) {
            if (Component.VEVENT.equals(component.getName()) || Component.VTODO.equals(component.getName())) {
                workEffortId = fromXProperty(component.getProperties(), workEffortIdXPropName);
                if (workEffortId == null) {
                    Property uid = component.getProperty(Uid.UID);
                    if (uid != null) {
                        GenericValue workEffort = EntityUtil.getFirst(delegator.findByAnd("WorkEffort", UtilMisc.toMap("universalId", uid.getValue())));
                        if (workEffort != null) {
                            workEffortId = workEffort.getString("workEffortId");
                        }
                    }
                }
                if (workEffortId != null) {
                    if (validWorkEfforts.contains(workEffortId)) {
                        replaceProperty(component.getProperties(), toXProperty(workEffortIdXPropName, workEffortId));
                        responseProps = storeWorkEffort(component, context);
                    } else {
                        Debug.logWarning("Spoof attempt: unrelated workEffortId " + workEffortId +
                                " on URL workEffortId " + context.get("workEffortId"), module);
                        responseProps = ICalWorker.createForbiddenResponse(null);
                    }
                } else if (hasCreatePermission) {
                    responseProps = createWorkEffort(component, context);
                }
                if (responseProps != null) {
                    return responseProps;
                }
            }
        }
        Map<String, ? extends Object> serviceMap = UtilMisc.toMap("workEffortId", context.get("workEffortId"), "icalData", calendar.toString());
        GenericValue iCalData = publishProperties.getRelatedOne("WorkEffortIcalData");
        Map<String, Object> serviceResult = null;
        if (iCalData == null) {
            serviceResult = invokeService("createWorkEffortICalData", serviceMap, context);
        } else {
View Full Code Here

        if (delegator == null) {
            Debug.logError("[ICalServlet.doGet] ERROR: delegator not found in ServletContext", module);
            resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return;
        }
        Calendar calendar = null;
        try {
            calendar = ICalendarWorker.getICalendar(delegator, workEffortId);
        } catch (Exception e) {
            Debug.logError("[ICalServlet.doGet] Error while getting iCalendar: " + e, module);
            resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return;
        }
        if (calendar == null) {
            resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        resp.setContentType("text/calendar");
        resp.setStatus(HttpServletResponse.SC_OK);
        Writer writer = null;
        if (UtilJ2eeCompat.useOutputStreamNotWriter(this.getServletContext())) {
            ServletOutputStream ros = resp.getOutputStream();
            writer = new OutputStreamWriter(ros, "UTF-8");
        } else {
            writer = resp.getWriter();
        }
        writer.write(calendar.toString());
        writer.close();
        if (Debug.infoOn()) {
            Debug.logInfo("[ICalServlet.doGet] finished request", module);
        }
    }
View Full Code Here

          if (disposition != null && disposition.equals(Part.ATTACHMENT)) {
            if (part.getFileName().equals("invite.ics")) {
              log.info("Found an iCal attachement. Filename: " + part.getFileName());
              CalendarBuilder builder = new CalendarBuilder();
              Calendar calendar = builder.build(part.getInputStream());
              Component event = calendar.getComponent(Component.VEVENT);
              Property startDate = event.getProperty(Property.DTSTART);
              Property endDate = event.getProperty(Property.DTEND);
              Property attendee = null;
              String login = null;
              for (Iterator j = event.getProperties(Property.ATTENDEE).iterator(); j.hasNext();) {
View Full Code Here

     * @throws ParseException
     * @throws IOException the OutoutStream cannot be written
     */
    public void toIcal(List<EventVO> events, OutputStream out) throws ValidationException, ParseException, IOException
    {
        Calendar icalendar = new Calendar();
        icalendar.getProperties().add(new ProdId("-//OpenCustomer 0.3.0//iCal4j 1.0//DE"));
        icalendar.getProperties().add(Version.VERSION_2_0);
        icalendar.getProperties().add(CalScale.GREGORIAN);
        icalendar.getProperties().add(Method.PUBLISH);
        List<VEvent> vevents = new ArrayList<VEvent>();
        int i = 0;
        for(EventVO event : events)
        {
            VEvent vevent = new VEvent();
            if(!event.isAllDay()){
                vevent.getProperties().add(new DtStart(new DateTime(event.getStartDate())));
                vevent.getProperties().add(new DtEnd(new DateTime(event.getEndDate().getTime())));
            }
            else
            {
                vevent.getProperties().add(new DtStart(new Date(event.getStartDate())));
                vevent.getProperties().getProperty(Property.DTSTART).getParameters().add(Value.DATE);
                vevent.getProperties().add(new DtEnd(new Date(event.getEndDate().getTime())));
                vevent.getProperties().getProperty(Property.DTEND).getParameters().add(Value.DATE);
            }
           
            if(event.isOccupied())
                vevent.getProperties().add(new Transp("OPAQUE"));
            else
                vevent.getProperties().add(new Transp("TRANSPARENT"));
            vevent.getProperties().add(new Summary(event.getTitle()));
            vevent.getProperties().add(new Created(new DateTime(event.getCreateDate())));
            vevent.getProperties().add(new DtStamp(new DateTime(event.getModifyDate())));
            vevent.getProperties().add(new LastModified(new DateTime(event.getModifyDate())));
            vevent.getProperties().add(new Description(event.getDescription()));
            vevent.getProperties().add(new Uid(event.getId().toString() + "@opencustomer"));
            vevent.getProperties().add(new XProperty("X-OC-ID",event.getId().toString()));
            if(event.getRecurrenceType() != EventVO.RecurrenceType.NONE)
                vevent.getProperties().add(getRRule(event));
            vevents.add(vevent);
        }
        icalendar.getComponents().addAll(vevents);
        CalendarOutputter calout = new CalendarOutputter();
        if(!vevents.isEmpty()) // no calendar output if there is no component
            calout.output(icalendar,out);
    }
View Full Code Here

TOP

Related Classes of net.fortuna.ical4j.model.Calendar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.