Package net.fortuna.ical4j.model

Examples of net.fortuna.ical4j.model.Calendar


        CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_UNFOLDING, true);
        CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING, true);
        CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_OUTLOOK_COMPATIBILITY, true);
       
        List<EventVO> events = new ArrayList<EventVO>();
        Calendar icalendar = new CalendarBuilder().build(ical);
        List<Component> components = icalendar.getComponents();
        for(Component comp : components)
        {
            EventVO event = new EventVO();
            if(log.isDebugEnabled())
                log.debug("import component: " + comp);
View Full Code Here


        this.builder = builder;
    }

    @Override
    public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
        Calendar calendar = exchange.getContext().getTypeConverter().convertTo(Calendar.class, graph);
        outputer.output(calendar, stream);
    }
View Full Code Here

        endpoint.assertIsSatisfied();
    }

    @Test
    public void testMarshal() throws Exception {
        Calendar testCalendar = createTestCalendar();
        MockEndpoint endpoint = getMockEndpoint("mock:result");

        endpoint.expectedBodiesReceived(testCalendar.toString());

        template.sendBody("direct:marshal", testCalendar);

        endpoint.assertIsSatisfied();
    }
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

        endpoint.assertIsSatisfied();
    }

    @Test
    public void testMarshal() throws Exception {
        Calendar testCalendar = createTestCalendar();
        MockEndpoint endpoint = getMockEndpoint("mock:result");

        endpoint.expectedBodiesReceived(testCalendar.toString());

        template.sendBody("direct:marshal", testCalendar);

        endpoint.assertIsSatisfied();
    }
View Full Code Here

        assertThat(output, is(notNullValue()));
        Reader reader = null;
        try {
            reader = new StringReader(output);
            CalendarBuilder builder = new CalendarBuilder();
            Calendar calendar = builder.build(reader);
            assertThat(calendar, is(notNullValue()));
            assertThat(
                calendar.getProperty("PRODID").getValue(),
                is("nico2ical"));
            assertThat(calendar.getProperty("VERSION").getValue(), is("2.0"));
            assertThat(
                calendar.getProperty("X-WR-CALNAME").getValue(),
                is("ニコニコ生放送"));
            ComponentList components = calendar.getComponents();
            assertThat(components, is(notNullValue()));
            assertThat(components.size(), is(3));
            // DTSTARTが古い順にイベントが並んでいる。
            int i = 2;
            for (Object object : components) {
View Full Code Here

        assertThat(output, is(notNullValue()));
        Reader reader = null;
        try {
            reader = new StringReader(output);
            CalendarBuilder builder = new CalendarBuilder();
            Calendar calendar = builder.build(reader);
            assertThat(calendar, is(notNullValue()));
            assertThat(
                calendar.getProperty("PRODID").getValue(),
                is("nico2ical"));
            assertThat(calendar.getProperty("VERSION").getValue(), is("2.0"));
            assertThat(
                calendar.getProperty("X-WR-CALNAME").getValue(),
                is("ニコニコ生放送"));
            ComponentList components = calendar.getComponents();
            assertThat(components, is(notNullValue()));
            assertThat(components.size(), is(4));
            // DTSTARTが古い順にイベントが並んでいる。
            int i = 3;
            for (Object object : components) {
View Full Code Here

        assertThat(controller1, is(notNullValue()));
        assertThat(tester.isRedirect(), is(false));
        assertThat(tester.response.getStatus(), is(200));
        assertThat(tester.getDestinationPath(), is(nullValue()));
        String output1 = tester.response.getOutputAsString();
        Calendar calendar1 = null;
        try {
            Reader reader = new StringReader(output1);
            CalendarBuilder builder = new CalendarBuilder();
            calendar1 = builder.build(reader);
        } catch (IOException e) {
            fail(e.getMessage());
        } catch (ParserException e) {
            fail(e.getMessage());
        }

        // 取得した内容がキャッシュにも保存されている。
        Object cache = Memcache.get(memcacheKey);
        assertThat(output1, is(instanceOf(String.class)));
        Calendar calendarCache = null;
        try {
            Reader reader = new StringReader((String) cache);
            CalendarBuilder builder = new CalendarBuilder();
            calendarCache = builder.build(reader);
        } catch (IOException e) {
            fail(e.getMessage());
        } catch (ParserException e) {
            fail(e.getMessage());
        }
        assertThat(calendar1, is(calendarCache));

        // 同じ条件でもう一度コントローラーを呼ぶと、キャッシュに保存している内容を取得する。
        tester.param("startWeek", 1);
        tester.param("keyword", "テスト 説明 文");
        tester.start("/Calendar");
        CalendarController controller2 = tester.getController();
        assertThat(controller2, is(notNullValue()));
        assertThat(tester.isRedirect(), is(false));
        assertThat(tester.response.getStatus(), is(200));
        assertThat(tester.getDestinationPath(), is(nullValue()));
        String output2 = tester.response.getOutputAsString();
        Calendar calendar2 = null;
        try {
            Reader reader = new StringReader(output2);
            CalendarBuilder builder = new CalendarBuilder();
            calendar2 = builder.build(reader);
        } catch (IOException e) {
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.