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);
}
}
Aggregations