Search in sources :

Example 1 with JsonCardBuilder

use of org.bedework.util.vcard.JsonCardBuilder in project bw-calendar-engine by Bedework.

the class BwPrincipalInfo method setPropertiesFromVCard.

/**
 * @param cardStr
 * @throws CalFacadeException
 */
public void setPropertiesFromVCard(final String cardStr, final String addrDataCtype) throws CalFacadeException {
    if (cardStr == null) {
        return;
    }
    this.cardStr = cardStr;
    addProperty(new PrincipalProperty<String>("vcard", cardStr));
    try {
        if ("application/vcard+json".equals(addrDataCtype)) {
            card = new JsonCardBuilder(null).build(new StringReader(cardStr));
        } else {
            card = new VCardBuilder(new StringReader(cardStr)).build();
        }
        Property piprop = card.getExtendedProperty("X-BW-PRINCIPALHREF");
        if (piprop != null) {
            setPrincipalHref(piprop.getValue());
        }
        piprop = card.getExtendedProperty("X-ICAL4J-TOV3-KIND");
        if (piprop != null) {
            setKind(piprop.getValue());
        }
        if (getKind() == null) {
            // Check for member attributes
            piprop = card.getProperty(Id.MEMBER);
            if (piprop != null) {
                setKind(Kind.GROUP.getValue());
            }
        }
        for (PrincipalPropertyInfo ppi : BwPrincipalInfo.getPrincipalPropertyInfoSet()) {
            Property.Id pname = ppi.getVcardPname();
            if (pname == null) {
                // Not a vcard property
                continue;
            }
            if (!ppi.getMulti()) {
                // Single valued
                Property prop = card.getProperty(pname);
                if (prop == null) {
                    continue;
                }
                addProperty(ppi, prop);
            } else {
                List<Property> ps = card.getProperties(pname);
                if (Util.isEmpty(ps)) {
                    continue;
                }
                for (Property prop : ps) {
                    addProperty(ppi, prop);
                }
            }
        }
    } catch (final Throwable t) {
        if (debug) {
            debug("CardStr was " + cardStr);
        }
        throw new CalFacadeException(t);
    }
}
Also used : Id(net.fortuna.ical4j.vcard.Property.Id) VCardBuilder(net.fortuna.ical4j.vcard.VCardBuilder) StringReader(java.io.StringReader) ToString(org.bedework.util.misc.ToString) Property(net.fortuna.ical4j.vcard.Property) JsonCardBuilder(org.bedework.util.vcard.JsonCardBuilder) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

StringReader (java.io.StringReader)1 Property (net.fortuna.ical4j.vcard.Property)1 Id (net.fortuna.ical4j.vcard.Property.Id)1 VCardBuilder (net.fortuna.ical4j.vcard.VCardBuilder)1 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1 ToString (org.bedework.util.misc.ToString)1 JsonCardBuilder (org.bedework.util.vcard.JsonCardBuilder)1