Search in sources :

Example 1 with DataType

use of org.bedework.util.calendar.PropertyIndex.DataType in project bw-calendar-engine by Bedework.

the class IcalTranslator method xmlProperty.

private void xmlProperty(final XmlEmit xml, final Property val) throws CalFacadeException {
    try {
        QName tag = openTag(xml, val.getName());
        ParameterList pl = val.getParameters();
        if (pl.size() > 0) {
            xml.openTag(XcalTags.parameters);
            Iterator pli = pl.iterator();
            while (pli.hasNext()) {
                xmlParameter(xml, (Parameter) pli.next());
            }
            xml.closeTag(XcalTags.parameters);
        }
        PropertyInfoIndex pii = PropertyInfoIndex.fromName(val.getName());
        QName ptype = XcalTags.textVal;
        if (pii != null) {
            DataType dtype = pii.getPtype();
            if (dtype != null) {
                ptype = dtype.getXcalType();
            }
        }
        if (ptype == null) {
            // Special processing I haven't done
            warn("Unimplemented value type for " + val.getName());
            ptype = XcalTags.textVal;
        }
        if (ptype.equals(XcalTags.recurVal)) {
            // Emit individual parts of recur rule
            xml.openTag(ptype);
            Recur r;
            if (val instanceof ExRule) {
                r = ((ExRule) val).getRecur();
            } else {
                r = ((RRule) val).getRecur();
            }
            xml.property(XcalTags.freq, r.getFrequency());
            xmlProp(xml, XcalTags.wkst, r.getWeekStartDay().name());
            if (r.getUntil() != null) {
                xmlProp(xml, XcalTags.until, r.getUntil().toString());
            }
            xmlProp(xml, XcalTags.count, String.valueOf(r.getCount()));
            xmlProp(xml, XcalTags.interval, String.valueOf(r.getInterval()));
            xmlProp(xml, XcalTags.bymonth, r.getMonthList());
            xmlProp(xml, XcalTags.byweekno, r.getWeekNoList());
            xmlProp(xml, XcalTags.byyearday, r.getYearDayList());
            xmlProp(xml, XcalTags.bymonthday, r.getMonthDayList());
            xmlProp(xml, XcalTags.byday, r.getDayList());
            xmlProp(xml, XcalTags.byhour, r.getHourList());
            xmlProp(xml, XcalTags.byminute, r.getMinuteList());
            xmlProp(xml, XcalTags.bysecond, r.getSecondList());
            xmlProp(xml, XcalTags.bysetpos, r.getSetPosList());
            xml.closeTag(ptype);
        } else {
            xml.property(ptype, val.getValue());
        }
        xml.closeTag(tag);
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) ParameterList(net.fortuna.ical4j.model.ParameterList) DataType(org.bedework.util.calendar.PropertyIndex.DataType) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) Recur(net.fortuna.ical4j.model.Recur) ExRule(net.fortuna.ical4j.model.property.ExRule)

Example 2 with DataType

use of org.bedework.util.calendar.PropertyIndex.DataType in project bw-calendar-engine by Bedework.

the class IcalTranslator method xmlParameter.

private void xmlParameter(final XmlEmit xml, final Parameter val) throws CalFacadeException {
    try {
        ParameterInfoIndex pii = ParameterInfoIndex.lookupPname(val.getName());
        QName ptype = XcalTags.textVal;
        if (pii != null) {
            DataType dtype = pii.getPtype();
            if (dtype != null) {
                ptype = dtype.getXcalType();
            }
        }
        if (ptype.equals(XcalTags.textVal)) {
            QName tag = new QName(XcalTags.namespace, val.getName().toLowerCase());
            xml.property(tag, val.getValue());
        } else {
            QName tag = openTag(xml, val.getName());
            xml.property(ptype, val.getValue());
            xml.closeTag(tag);
        }
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : QName(javax.xml.namespace.QName) ParameterInfoIndex(org.bedework.util.calendar.PropertyIndex.ParameterInfoIndex) DataType(org.bedework.util.calendar.PropertyIndex.DataType) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 3 with DataType

use of org.bedework.util.calendar.PropertyIndex.DataType in project bw-calendar-engine by Bedework.

the class JsonProperty method getType.

private static DataType getType(final Property prop) {
    final PropertyInfoIndex pii = PropertyInfoIndex.fromName(prop.getName());
    if (pii == null) {
        return DataType.TEXT;
    }
    final DataType dtype = pii.getPtype();
    if (dtype == null) {
        return DataType.TEXT;
    }
    final String nm = prop.getName().toLowerCase();
    if ((dtype != DataType.SPECIAL) && (!types.contains(nm))) {
        return dtype;
    }
    if (prop instanceof DateProperty) {
        // dtend, dtstart, due
        final DateProperty dp = (DateProperty) prop;
        if (Value.DATE.equals(dp.getParameter(Parameter.VALUE))) {
            return DataType.DATE;
        }
        return DataType.DATE_TIME;
    }
    if (prop instanceof DateListProperty) {
        // exdate, rdate
        final DateListProperty dlp = (DateListProperty) prop;
        if (Value.DATE.equals(dlp.getDates().getType())) {
            return DataType.DATE;
        }
        return DataType.DATE_TIME;
    }
    if ("attach".equals(nm)) {
        final Attach att = (Attach) prop;
        if (att.getUri() != null) {
            return DataType.URI;
        }
        return DataType.BINARY;
    }
    if ("trigger".equals(nm)) {
        final Trigger tr = (Trigger) prop;
        if (tr.getDuration() != null) {
            return DataType.DURATION;
        }
        return DataType.DATE_TIME;
    }
    // in the absence of anything else callit text
    return DataType.TEXT;
}
Also used : PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) Trigger(net.fortuna.ical4j.model.property.Trigger) DateListProperty(net.fortuna.ical4j.model.property.DateListProperty) DateProperty(net.fortuna.ical4j.model.property.DateProperty) Attach(net.fortuna.ical4j.model.property.Attach) DataType(org.bedework.util.calendar.PropertyIndex.DataType)

Example 4 with DataType

use of org.bedework.util.calendar.PropertyIndex.DataType in project bw-calendar-engine by Bedework.

the class JsonProperty method addFields.

public static void addFields(final JsonGenerator jgen, final Property prop) throws CalFacadeException {
    try {
        jgen.writeStartArray();
        jgen.writeString(prop.getName().toLowerCase());
        JsonParameters.addFields(jgen, prop);
        final DataType type = getType(prop);
        jgen.writeString(type.getJsonType());
        outValue(jgen, prop, type);
        jgen.writeEndArray();
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : DataType(org.bedework.util.calendar.PropertyIndex.DataType) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

DataType (org.bedework.util.calendar.PropertyIndex.DataType)4 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)3 QName (javax.xml.namespace.QName)2 PropertyInfoIndex (org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex)2 Iterator (java.util.Iterator)1 ParameterList (net.fortuna.ical4j.model.ParameterList)1 Recur (net.fortuna.ical4j.model.Recur)1 Attach (net.fortuna.ical4j.model.property.Attach)1 DateListProperty (net.fortuna.ical4j.model.property.DateListProperty)1 DateProperty (net.fortuna.ical4j.model.property.DateProperty)1 ExRule (net.fortuna.ical4j.model.property.ExRule)1 Trigger (net.fortuna.ical4j.model.property.Trigger)1 ParameterInfoIndex (org.bedework.util.calendar.PropertyIndex.ParameterInfoIndex)1