use of org.bedework.util.xml.XmlEmit.NameSpace in project bw-calendar-engine by Bedework.
the class AbstractDirImpl method matching.
private List<MatchResult> matching(final BasicHttpClient cl, final String url, final String addrDataCtype, final List<WebdavProperty> props) throws CalFacadeException {
try {
final XmlEmit xml = new XmlEmit();
xml.addNs(new NameSpace(WebdavTags.namespace, "DAV"), true);
xml.addNs(new NameSpace(CarddavTags.namespace, "C"), false);
final StringWriter sw = new StringWriter();
xml.startEmit(sw);
xml.openTag(CarddavTags.addressbookQuery);
xml.openTag(WebdavTags.prop);
xml.emptyTag(WebdavTags.getetag);
if (addrDataCtype == null) {
xml.emptyTag(CarddavTags.addressData);
} else {
xml.emptyTag(CarddavTags.addressData, "content-type", addrDataCtype);
}
xml.closeTag(WebdavTags.prop);
xml.openTag(CarddavTags.filter, "test", "anyof");
for (final WebdavProperty wd : props) {
if (wd.getTag().equals(CaldavTags.calendarUserType)) {
// Should match onto KIND
continue;
}
if (wd.getTag().equals(BedeworkServerTags.emailProp)) {
// Match Email
xml.openTag(CarddavTags.propFilter, "name", "EMAIL");
xml.startTagSameLine(CarddavTags.textMatch);
xml.attribute("collation", "i;unicode-casemap");
xml.attribute("match-type", "contains");
xml.endOpeningTag();
xml.value(wd.getPval());
xml.closeTagSameLine(CarddavTags.textMatch);
xml.closeTag(CarddavTags.propFilter);
continue;
}
if (wd.getTag().equals(WebdavTags.displayname)) {
// Match FN
xml.openTag(CarddavTags.propFilter, "name", "FN");
xml.startTagSameLine(CarddavTags.textMatch);
xml.attribute("collation", "i;unicode-casemap");
xml.attribute("match-type", "contains");
xml.endOpeningTag();
xml.value(wd.getPval());
xml.closeTagSameLine(CarddavTags.textMatch);
xml.closeTag(CarddavTags.propFilter);
// continue;
}
}
xml.closeTag(CarddavTags.filter);
xml.closeTag(CarddavTags.addressbookQuery);
final DavUtil du = new DavUtil();
final byte[] content = sw.toString().getBytes();
final int res = du.sendRequest(cl, "REPORT", url, new BasicHeader("depth", "infinity"), // contentType,
"text/xml", // contentLen,
content.length, content);
// not defined for some reason
final int SC_MULTI_STATUS = 207;
if (res != SC_MULTI_STATUS) {
if (debug) {
debug("Got response " + res + " for path " + url);
}
return null;
}
final List<MatchResult> mrs = new ArrayList<>();
final MultiStatusResponse msr = du.getMultiStatusResponse(cl.getResponseBodyAsStream());
for (final MultiStatusResponseElement msre : msr.responses) {
MatchResult mr = new MatchResult();
mrs.add(mr);
mr.href = msre.href;
for (final PropstatElement pe : msre.propstats) {
if (pe.status != HttpServletResponse.SC_OK) {
continue;
}
for (final Element e : pe.props) {
if (XmlUtil.nodeMatches(e, WebdavTags.getetag)) {
mr.etag = XmlUtil.getElementContent(e);
continue;
}
if (XmlUtil.nodeMatches(e, CarddavTags.addressData)) {
mr.card = XmlUtil.getElementContent(e);
}
}
}
}
return mrs;
} catch (final Throwable t) {
throw new CalFacadeException(t);
} finally {
try {
cl.release();
} catch (final Throwable ignored) {
}
}
}
use of org.bedework.util.xml.XmlEmit.NameSpace in project bw-calendar-engine by Bedework.
the class IcalTranslator method writeXmlCalendar.
/**
* Write a collection of calendar data as xml
*
* @param vals
* @param methodType int value fromIcalendar
* @param xml for output
* @throws CalFacadeException
*/
public void writeXmlCalendar(final Collection vals, final int methodType, final XmlEmit xml) throws CalFacadeException {
try {
xml.addNs(new NameSpace(XcalTags.namespace, "X"), false);
xml.openTag(XcalTags.icalendar);
xml.openTag(XcalTags.vcalendar);
xml.openTag(XcalTags.properties);
xmlProp(xml, Property.PRODID, XcalTags.textVal, prodId);
xmlProp(xml, Property.VERSION, XcalTags.textVal, Version.VERSION_2_0.getValue());
xml.closeTag(XcalTags.properties);
boolean componentsOpen = false;
if (!cb.getTimezonesByReference()) {
// To collect timezones
Calendar cal = newIcal(methodType);
addIcalTimezones(cal, vals);
// Emit timezones
for (Object o : cal.getComponents()) {
if (!(o instanceof VTimeZone)) {
continue;
}
if (!componentsOpen) {
xml.openTag(XcalTags.components);
componentsOpen = true;
}
xmlComponent(xml, (Component) o);
}
}
String currentPrincipal = null;
final BwPrincipal principal = cb.getPrincipal();
if (principal != null) {
currentPrincipal = principal.getPrincipalRef();
}
for (final Object o : vals) {
if (o instanceof EventInfo) {
final EventInfo ei = (EventInfo) o;
BwEvent ev = ei.getEvent();
final EventTimeZonesRegistry tzreg = new EventTimeZonesRegistry(this, ev);
final Component comp;
if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
comp = VFreeUtil.toVFreeBusy(ev);
} else {
comp = VEventUtil.toIcalComponent(ei, false, tzreg, currentPrincipal);
}
if (!componentsOpen) {
xml.openTag(XcalTags.components);
componentsOpen = true;
}
xmlComponent(xml, comp);
if (ei.getNumOverrides() > 0) {
for (final EventInfo oei : ei.getOverrides()) {
ev = oei.getEvent();
xmlComponent(xml, VEventUtil.toIcalComponent(oei, true, tzreg, currentPrincipal));
}
}
}
}
if (componentsOpen) {
xml.closeTag(XcalTags.components);
}
xml.closeTag(XcalTags.vcalendar);
xml.closeTag(XcalTags.icalendar);
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
Aggregations