use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class IcalTranslator method toIcal.
/**
* Turn a collection of events into a calendar
*
* @param vals
* @param methodType int value fromIcalendar
* @return Calendar
* @throws CalFacadeException
*/
public Calendar toIcal(final Collection vals, final int methodType) throws CalFacadeException {
Calendar cal = newIcal(methodType);
if ((vals == null) || (vals.size() == 0)) {
return cal;
}
TreeSet<String> added = new TreeSet<String>();
try {
Iterator it = vals.iterator();
while (it.hasNext()) {
Object o = it.next();
if (o instanceof EventInfo) {
addToCalendar(cal, (EventInfo) o, added);
} else {
// XXX implement
warn("Unimplemented toIcal for " + o.getClass().getName());
continue;
}
}
return cal;
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class IcalTranslator method xmlComponent.
private void xmlComponent(final XmlEmit xml, final Component val) throws CalFacadeException {
try {
QName tag = openTag(xml, val.getName());
PropertyList pl = val.getProperties();
if (pl.size() > 0) {
xml.openTag(XcalTags.properties);
for (Object po : pl) {
xmlProperty(xml, (Property) po);
}
xml.closeTag(XcalTags.properties);
}
ComponentList cl = null;
if (val instanceof VTimeZone) {
cl = ((VTimeZone) val).getObservances();
} else if (val instanceof VEvent) {
cl = ((VEvent) val).getAlarms();
} else if (val instanceof VToDo) {
cl = ((VToDo) val).getAlarms();
}
if ((cl != null) && (cl.size() > 0)) {
xml.openTag(XcalTags.components);
for (Object o : cl) {
xmlComponent(xml, (Component) o);
}
xml.closeTag(XcalTags.components);
}
xml.closeTag(tag);
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class IcalTranslator method doTimeZone.
private TimeZoneInfo doTimeZone(final VTimeZone vtz) throws CalFacadeException {
TzId tzid = vtz.getTimeZoneId();
if (tzid == null) {
throw new CalFacadeException("Missing tzid property");
}
String id = tzid.getValue();
try {
TimeZone tz = Timezones.getTz(id);
String tzSpec = null;
if (tz == null) {
tz = new TimeZone(vtz);
tzSpec = vtz.toString();
}
return new TimeZoneInfo(id, tz, tzSpec);
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.exc.CalFacadeException 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);
}
}
use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class IcalUtil method parseVpollCandidates.
/**
* @param poll the poll entity
* @return Parsed components.
* @throws Throwable
*/
public static Map<Integer, Component> parseVpollCandidates(final BwEvent poll) throws Throwable {
final StringBuilder sb = new StringBuilder();
sb.append("BEGIN:VCALENDAR\n");
sb.append("PRODID://Bedework.org//BedeWork V3.9//EN\n");
sb.append("VERSION:2.0\n");
if (!Util.isEmpty(poll.getPollItems())) {
for (final String s : poll.getPollItems()) {
sb.append(s);
}
}
sb.append("END:VCALENDAR\n");
try {
final StringReader sr = new StringReader(sb.toString());
final Icalendar ic = new Icalendar();
final CalendarBuilder bldr = new CalendarBuilder(new CalendarParserImpl(), ic);
final UnfoldingReader ufrdr = new UnfoldingReader(sr, true);
final Calendar ical = bldr.build(ufrdr);
final Map<Integer, Component> comps = new HashMap<>();
for (final Object o : ical.getComponents()) {
final Component comp = (Component) o;
final PollItemId pid = (PollItemId) comp.getProperty(Property.POLL_ITEM_ID);
if (pid == null) {
continue;
}
comps.put(pid.getPollitemid(), comp);
}
return comps;
} catch (final ParserException pe) {
throw new IcalMalformedException(pe.getMessage());
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
Aggregations