use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class Events method compileAlarms.
/**
* Compile an alarm component
*
* @param val
* @return alarms or null
* @throws CalFacadeException
*/
public Set<BwAlarm> compileAlarms(final String val) throws CalFacadeException {
try {
StringReader sr = new StringReader(ValidateAlarmPrefix + val + ValidateAlarmSuffix);
IcalTranslator trans = new IcalTranslator(getSvc().getIcalCallback());
Icalendar ic = trans.fromIcal(null, sr);
if ((ic == null) || (ic.getEventInfo() == null)) {
if (debug) {
trace("Not single event");
}
return null;
}
/* There should be alarms in the Calendar object
*/
EventInfo ei = ic.getEventInfo();
BwEvent ev = ei.getEvent();
Set<BwAlarm> alarms = ev.getAlarms();
if (Util.isEmpty(alarms)) {
return null;
}
return alarms;
} catch (CalFacadeException cfe) {
if (debug) {
error(cfe);
}
return null;
}
}
use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class IcalTranslator method addIcalTimezones.
/* If the start or end dates references a timezone, we retrieve the timezone definition
* and add it to the calendar.
*/
private void addIcalTimezones(final Calendar cal, final Collection vals) throws CalFacadeException {
TreeSet<String> added = new TreeSet<String>();
Iterator it = vals.iterator();
while (it.hasNext()) {
Object o = it.next();
if (o instanceof EventInfo) {
EventInfo ei = (EventInfo) o;
BwEvent ev = ei.getEvent();
if (!ev.getSuppressed()) {
/* Add referenced timezones to the calendar */
addIcalTimezones(cal, ev, added, new EventTimeZonesRegistry(this, ev));
}
if (ei.getNumOverrides() > 0) {
for (EventInfo oei : ei.getOverrides()) {
ev = oei.getEvent();
addIcalTimezones(cal, ev, added, new EventTimeZonesRegistry(this, ev));
}
}
}
}
}
use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class IcalTranslator method toXMLIcalendar.
/**
* @param val
* @param methodType
* @param pattern
* @return XML IcalendarType
* @throws CalFacadeException
*/
public IcalendarType toXMLIcalendar(final EventInfo val, final int methodType, final IcalendarType pattern, final boolean wrapXprops) throws CalFacadeException {
IcalendarType ical = new IcalendarType();
VcalendarType vcal = new VcalendarType();
ical.getVcalendar().add(vcal);
vcal.setProperties(new ArrayOfProperties());
List<JAXBElement<? extends BasePropertyType>> pl = vcal.getProperties().getBasePropertyOrTzid();
ProdidPropType prod = new ProdidPropType();
prod.setText(prodId);
pl.add(Xutil.of.createProdid(prod));
VersionPropType vers = new VersionPropType();
vers.setText("2.0");
pl.add(Xutil.of.createVersion(vers));
if ((methodType > ScheduleMethods.methodTypeNone) && (methodType < ScheduleMethods.methodTypeUnknown)) {
MethodPropType m = new MethodPropType();
m.setText(ScheduleMethods.methods[methodType]);
pl.add(Xutil.of.createMethod(m));
}
ArrayOfComponents aoc = vcal.getComponents();
if (aoc == null) {
aoc = new ArrayOfComponents();
vcal.setComponents(aoc);
}
BwEvent ev = val.getEvent();
JAXBElement<? extends BaseComponentType> el = null;
VcalendarType vc = null;
if ((pattern != null) && !pattern.getVcalendar().isEmpty()) {
vc = pattern.getVcalendar().get(0);
}
BaseComponentType bc = matches(vc, ev.getEntityType());
if ((vc != null) && (bc == null)) {
return ical;
}
if (!ev.getSuppressed()) {
if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
el = ToXEvent.toComponent(ev, false, wrapXprops, bc);
} else {
el = ToXEvent.toComponent(ev, false, wrapXprops, bc);
}
if (el != null) {
aoc.getBaseComponent().add(el);
}
}
if (val.getNumOverrides() == 0) {
return ical;
}
for (EventInfo oei : val.getOverrides()) {
ev = oei.getEvent();
el = ToXEvent.toComponent(ev, true, wrapXprops, bc);
if (el != null) {
aoc.getBaseComponent().add(el);
}
}
if (val.getNumContainedItems() > 0) {
for (EventInfo aei : val.getContainedItems()) {
ev = aei.getEvent();
el = ToXEvent.toComponent(ev, true, wrapXprops, bc);
if (el != null) {
aoc.getBaseComponent().add(el);
}
}
}
return ical;
}
use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class IcalTranslator method addToCalendar.
/* ====================================================================
Private methods
==================================================================== */
private void addToCalendar(final Calendar cal, final EventInfo val, final TreeSet<String> added) throws CalFacadeException {
String currentPrincipal = null;
BwPrincipal principal = cb.getPrincipal();
if (principal != null) {
currentPrincipal = principal.getPrincipalRef();
}
BwEvent ev = val.getEvent();
EventTimeZonesRegistry tzreg = new EventTimeZonesRegistry(this, ev);
if (!cb.getTimezonesByReference()) {
/* Add referenced timezones to the calendar */
addIcalTimezones(cal, ev, added, tzreg);
}
if (!ev.getSuppressed()) {
/* Add it to the calendar */
Component comp;
if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
comp = VFreeUtil.toVFreeBusy(ev);
} else {
comp = VEventUtil.toIcalComponent(val, false, tzreg, currentPrincipal);
}
cal.getComponents().add((CalendarComponent) comp);
}
if (val.getNumOverrides() > 0) {
for (final EventInfo oei : val.getOverrides()) {
cal.getComponents().add((CalendarComponent) VEventUtil.toIcalComponent(oei, true, tzreg, currentPrincipal));
}
}
}
use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class JcalHandler method outJcal.
public static void outJcal(final Writer wtr, final Collection<EventInfo> vals, final int methodType, final IcalendarType pattern, final String currentPrincipal, final EventTimeZonesRegistry tzreg) throws CalFacadeException {
try {
final JsonGenerator jgen = jsonFactory.createJsonGenerator(wtr);
if (Logger.getLogger(JcalHandler.class).isDebugEnabled()) {
jgen.useDefaultPrettyPrinter();
}
jgen.writeStartArray();
calendarProps(jgen, methodType);
// for components
jgen.writeStartArray();
for (final EventInfo ei : vals) {
BwEvent ev = ei.getEvent();
final Component comp;
if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
comp = VFreeUtil.toVFreeBusy(ev);
} else {
comp = VEventUtil.toIcalComponent(ei, false, tzreg, currentPrincipal);
}
outComp(jgen, comp);
if (ei.getNumOverrides() > 0) {
for (final EventInfo oei : ei.getOverrides()) {
ev = oei.getEvent();
outComp(jgen, VEventUtil.toIcalComponent(oei, true, tzreg, currentPrincipal));
}
}
}
// for components
jgen.writeEndArray();
jgen.writeEndArray();
jgen.flush();
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
Aggregations