Search in sources :

Example 16 with ParameterList

use of net.fortuna.ical4j.model.ParameterList in project ofbiz-framework by apache.

the class ICalConverter method loadPartyAssignment.

protected static void loadPartyAssignment(Property property, GenericValue partyAssign, Map<String, Object> context) {
    getPartyUrl(property, partyAssign, context);
    if (UtilValidate.isEmpty(property.getValue())) {
        try {
            // RFC 2445 4.8.4.1 and 4.8.4.3 Value must be a URL
            property.setValue("MAILTO:ofbiz-test@example.com");
        } catch (Exception e) {
            Debug.logError(e, "Error while setting Property value: ", module);
        }
    }
    ParameterList parameterList = property.getParameters();
    replaceParameter(parameterList, toXParameter(partyIdXParamName, partyAssign.getString("partyId")));
    replaceParameter(parameterList, new Cn(makePartyName(partyAssign)));
    replaceParameter(parameterList, toParticipationStatus(partyAssign.getString("assignmentStatusId")));
}
Also used : ParameterList(net.fortuna.ical4j.model.ParameterList) Cn(net.fortuna.ical4j.model.parameter.Cn) URISyntaxException(java.net.URISyntaxException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) ParserException(net.fortuna.ical4j.data.ParserException) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GeneralException(org.apache.ofbiz.base.util.GeneralException) ValidationException(net.fortuna.ical4j.model.ValidationException) IOException(java.io.IOException)

Example 17 with ParameterList

use of net.fortuna.ical4j.model.ParameterList in project zm-mailbox by Zimbra.

the class DefaultTnefToICalendar method addAlarmComponent.

/**
 * @param icalOutput
 * @param reminderDelta number of minutes before Start
 * @throws ParserException
 * @throws URISyntaxException
 * @throws IOException
 * @throws ParseException
 */
private void addAlarmComponent(ContentHandler icalOutput, Integer reminderDelta) throws ParserException, URISyntaxException, IOException, ParseException {
    if (reminderDelta == null) {
        return;
    }
    icalOutput.startComponent(Component.VALARM);
    IcalUtil.addProperty(icalOutput, Action.DISPLAY);
    IcalUtil.addProperty(icalOutput, Property.DESCRIPTION, "Reminder", false);
    String trigStr;
    if (reminderDelta % 60 == 0) {
        reminderDelta = reminderDelta / 60;
        if (reminderDelta % 24 == 0) {
            reminderDelta = reminderDelta / 24;
            trigStr = String.format("-PT%dD", reminderDelta);
        } else {
            trigStr = String.format("-PT%dH", reminderDelta);
        }
    } else {
        trigStr = String.format("-PT%dM", reminderDelta);
    }
    ParameterList trigParams = new ParameterList();
    trigParams.add(Related.START);
    Trigger trigger = new Trigger(trigParams, trigStr);
    IcalUtil.addProperty(icalOutput, trigger);
    icalOutput.endComponent(Component.VALARM);
}
Also used : Trigger(net.fortuna.ical4j.model.property.Trigger) ParameterList(net.fortuna.ical4j.model.ParameterList)

Example 18 with ParameterList

use of net.fortuna.ical4j.model.ParameterList in project opencast by opencast.

the class CalendarGenerator method addEvent.

/**
 * Adds an SchedulerEvent as a new entry to this iCalendar
 *
 * @param mp
 *          {@link MediaPackage} of event
 * @param agentId
 *          the agent identifier
 * @param start
 *          the start date
 * @param end
 *          the end date
 * @param captureAgentMetadata
 *          properties for capture agent metadata
 *
 * @return true if the event could be added.
 */
public boolean addEvent(MediaPackage mp, DublinCoreCatalog catalog, String agentId, Date start, Date end, Date lastModified, String captureAgentMetadata) {
    String eventId = mp.getIdentifier().compact();
    logger.debug("Creating iCaleandar VEvent from scheduled event '{}'", eventId);
    DateTime startDate = new DateTime(start);
    DateTime endDate = new DateTime(end);
    Date marginEndDate = new org.joda.time.DateTime(endDate.getTime()).plusHours(1).toDate();
    if (marginEndDate.before(new Date())) {
        logger.debug("Event has already passed more than an hour, skipping!");
        return false;
    }
    startDate.setUtc(true);
    endDate.setUtc(true);
    String seriesID = null;
    VEvent event = new VEvent(startDate, endDate, catalog.getFirst(DublinCore.PROPERTY_TITLE));
    try {
        ParameterList pl = new ParameterList();
        if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_CREATOR))) {
            pl.add(new Cn(catalog.getFirst(DublinCore.PROPERTY_CREATOR)));
        }
        event.getProperties().add(new Uid(eventId));
        DateTime lastModifiedDate = new DateTime(lastModified);
        lastModifiedDate.setUtc(true);
        event.getProperties().add(new LastModified(lastModifiedDate));
        // TODO Organizer should be URI (email-address?) created fake address
        if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_CREATOR))) {
            URI organizer = new URI("mailto", catalog.getFirst(DublinCore.PROPERTY_CREATOR) + "@opencast.tld", null);
            event.getProperties().add(new Organizer(pl, organizer));
        }
        if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_DESCRIPTION))) {
            event.getProperties().add(new Description(catalog.getFirst(DublinCore.PROPERTY_DESCRIPTION)));
        }
        event.getProperties().add(new Location(agentId));
        if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_IS_PART_OF))) {
            seriesID = catalog.getFirst(DublinCore.PROPERTY_IS_PART_OF);
            event.getProperties().add(new RelatedTo(seriesID));
        }
        ParameterList dcParameters = new ParameterList();
        dcParameters.add(new FmtType("application/xml"));
        dcParameters.add(Value.BINARY);
        dcParameters.add(Encoding.BASE64);
        dcParameters.add(new XParameter("X-APPLE-FILENAME", "episode.xml"));
        Attach metadataAttachment = new Attach(dcParameters, catalog.toXmlString().getBytes("UTF-8"));
        event.getProperties().add(metadataAttachment);
        String seriesDC = getSeriesDublinCoreAsString(seriesID);
        if (seriesDC != null) {
            logger.debug("Attaching series {} information to event {}", seriesID, eventId);
            ParameterList sDcParameters = new ParameterList();
            sDcParameters.add(new FmtType("application/xml"));
            sDcParameters.add(Value.BINARY);
            sDcParameters.add(Encoding.BASE64);
            sDcParameters.add(new XParameter("X-APPLE-FILENAME", "series.xml"));
            Attach seriesAttachment = new Attach(sDcParameters, seriesDC.getBytes("UTF-8"));
            event.getProperties().add(seriesAttachment);
        } else {
            logger.debug("No series provided for event {}.", eventId);
        }
        ParameterList caParameters = new ParameterList();
        caParameters.add(new FmtType("application/text"));
        caParameters.add(Value.BINARY);
        caParameters.add(Encoding.BASE64);
        caParameters.add(new XParameter("X-APPLE-FILENAME", "org.opencastproject.capture.agent.properties"));
        Attach agentsAttachment = new Attach(caParameters, captureAgentMetadata.getBytes("UTF-8"));
        event.getProperties().add(agentsAttachment);
    } catch (Exception e) {
        logger.error("Unable to add event '{}' to recording calendar: {}", eventId, ExceptionUtils.getStackTrace(e));
        return false;
    }
    cal.getComponents().add(event);
    logger.debug("new VEvent = {} ", event.toString());
    return true;
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) Description(net.fortuna.ical4j.model.property.Description) Organizer(net.fortuna.ical4j.model.property.Organizer) Attach(net.fortuna.ical4j.model.property.Attach) Cn(net.fortuna.ical4j.model.parameter.Cn) URI(java.net.URI) DateTime(net.fortuna.ical4j.model.DateTime) Date(java.util.Date) SeriesException(org.opencastproject.series.api.SeriesException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) LastModified(net.fortuna.ical4j.model.property.LastModified) Uid(net.fortuna.ical4j.model.property.Uid) FmtType(net.fortuna.ical4j.model.parameter.FmtType) ParameterList(net.fortuna.ical4j.model.ParameterList) RelatedTo(net.fortuna.ical4j.model.property.RelatedTo) XParameter(net.fortuna.ical4j.model.parameter.XParameter) Location(net.fortuna.ical4j.model.property.Location)

Example 19 with ParameterList

use of net.fortuna.ical4j.model.ParameterList in project zm-mailbox by Zimbra.

the class ZoneInfo2iCalendar method toObservanceComp.

private static Observance toObservanceComp(int hintYear, RuleLine rline, boolean isStandard, Time standardOffset, Time daylightOffset, String tznameFormat) {
    PropertyList props = new PropertyList();
    String tzname = getObservanceName(tznameFormat, rline);
    if (tzname != null) {
        props.add(new TzName(tzname));
    }
    Time at = rline.getAt();
    Time onset;
    switch(at.getType()) {
        case STANDARD_TIME:
            if (isStandard) {
                // We're moving from daylight time to standard time.  In iCalendar we want hh:mm:ss in
                // wall clock in the pre-transition time, so it's daylight time.
                // daylight = utc + daylight offset = (standard - standard offset) + daylight offset
                onset = addTimes(subtractTimes(at, standardOffset), daylightOffset);
            } else {
                // We're moving from standard time to daylight time.  In iCalendar we want hh:mm:ss in
                // wall clock in the pre-transition time, so it's standard time.  at is already in
                // standard time.
                onset = at;
            }
            break;
        case UTC_TIME:
            if (isStandard) {
                // We're moving from daylight time to standard time.  In iCalendar we want hh:mm:ss in
                // wall clock in the pre-transition time, so it's daylight time.
                // daylight = utc + daylightOffset.
                onset = addTimes(at, daylightOffset);
            } else {
                // We're moving from standard time to daylight time.  In iCalendar we want hh:mm:ss in
                // wall clock in the pre-transition time, so it's standard time.
                // standard = utc + standard offset.
                onset = addTimes(at, standardOffset);
            }
            break;
        default:
            // WALL_TIME
            // at is already in the iCalendar style.
            onset = at;
            break;
    }
    int hh = onset.getHour();
    int mm = onset.getMinute();
    int ss = onset.getSecond();
    if (hh >= 24) {
        // Hour should be between 0 and 23, but sometimes we can get 24:00:00 from the zoneinfo source.
        // Since hour part in iCalendar only allows 0-23, let's approximate any time with hour >= 24 to
        // 23:59:59.
        hh = 23;
        mm = 59;
        ss = 59;
    }
    // YYYYMMDD fixed to 16010101 (MS Outlook style)
    props.add(getDtStart(String.format("16010101T%02d%02d%02d", hh, mm, ss)));
    Time toOffset, fromOffset;
    if (isStandard) {
        toOffset = standardOffset;
        fromOffset = daylightOffset;
    } else {
        toOffset = daylightOffset;
        fromOffset = standardOffset;
    }
    props.add(new TzOffsetTo(new UtcOffset(getUtcOffset(toOffset))));
    props.add(new TzOffsetFrom(new UtcOffset(getUtcOffset(fromOffset))));
    int month = rline.getIn();
    StringBuilder rruleVal = new StringBuilder();
    rruleVal.append("FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=").append(month).append(";");
    rruleVal.append(dayToICalRRulePart(hintYear, month, rline.getOn()));
    try {
        RRule rrule = new RRule(new ParameterList(), rruleVal.toString());
        props.add(rrule);
    } catch (ParseException e) {
    }
    if (isStandard) {
        return new Standard(props);
    } else {
        return new Daylight(props);
    }
}
Also used : TzName(net.fortuna.ical4j.model.property.TzName) RRule(net.fortuna.ical4j.model.property.RRule) DateTime(net.fortuna.ical4j.model.DateTime) Time(com.zimbra.common.calendar.ZoneInfoParser.Time) Standard(net.fortuna.ical4j.model.component.Standard) UtcOffset(net.fortuna.ical4j.model.UtcOffset) PropertyList(net.fortuna.ical4j.model.PropertyList) Daylight(net.fortuna.ical4j.model.component.Daylight) TzOffsetTo(net.fortuna.ical4j.model.property.TzOffsetTo) TzOffsetFrom(net.fortuna.ical4j.model.property.TzOffsetFrom) ParameterList(net.fortuna.ical4j.model.ParameterList) ParseException(java.text.ParseException) TZDataParseException(com.zimbra.common.calendar.ZoneInfoParser.TZDataParseException)

Example 20 with ParameterList

use of net.fortuna.ical4j.model.ParameterList in project zm-mailbox by Zimbra.

the class IcalUtil method addProperty.

public static void addProperty(ContentHandler icalOutput, Property icalProp) throws ParserException, URISyntaxException, IOException, ParseException {
    if (icalProp == null) {
        return;
    }
    icalOutput.startProperty(icalProp.getName());
    icalOutput.propertyValue(icalProp.getValue());
    ParameterList plist = icalProp.getParameters();
    if (plist != null) {
        for (Iterator<?> it = plist.iterator(); it.hasNext(); ) {
            Object currObj = it.next();
            if (currObj instanceof Parameter) {
                Parameter parameter = (Parameter) currObj;
                icalOutput.parameter(parameter.getName(), parameter.getValue());
            }
        }
    }
    icalOutput.endProperty(icalProp.getName());
}
Also used : ParameterList(net.fortuna.ical4j.model.ParameterList) Parameter(net.fortuna.ical4j.model.Parameter)

Aggregations

ParameterList (net.fortuna.ical4j.model.ParameterList)31 Parameter (net.fortuna.ical4j.model.Parameter)13 Iterator (java.util.Iterator)5 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)5 DateTime (net.fortuna.ical4j.model.DateTime)4 XParameter (net.fortuna.ical4j.model.parameter.XParameter)4 PropertyList (net.fortuna.ical4j.model.PropertyList)3 Cn (net.fortuna.ical4j.model.parameter.Cn)3 Value (net.fortuna.ical4j.model.parameter.Value)3 BwAttendee (org.bedework.calfacade.BwAttendee)3 IOException (java.io.IOException)2 URI (java.net.URI)2 Property (net.fortuna.ical4j.model.Property)2 VEvent (net.fortuna.ical4j.model.component.VEvent)2 VVoter (net.fortuna.ical4j.model.component.VVoter)2 FmtType (net.fortuna.ical4j.model.parameter.FmtType)2 PartStat (net.fortuna.ical4j.model.parameter.PartStat)2 Attach (net.fortuna.ical4j.model.property.Attach)2 DateListProperty (net.fortuna.ical4j.model.property.DateListProperty)2 BwAttachment (org.bedework.calfacade.BwAttachment)2