use of org.bedework.util.xml.XmlEmit in project bw-calendar-engine by Bedework.
the class DumpEntity method dump.
/**
* Dump the entire entity into the given file.
*
* @param f - the file
* @throws CalFacadeException
*/
@NoWrap
public void dump(final File f) throws CalFacadeException {
Dump dCl = getClass().getAnnotation(Dump.class);
if (dCl.format() == DumpFormat.xml) {
Writer wtr = null;
try {
XmlEmit xml = new XmlEmit();
wtr = new FileWriter(f);
xml.startEmit(wtr);
dump(xml, DumpType.def, false);
xml.flush();
return;
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
} finally {
if (wtr != null) {
try {
wtr.close();
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
}
}
if (dCl.format() == DumpFormat.vCard) {
Writer wtr = null;
try {
VCard vc = new VCard();
dump(vc, DumpType.def);
String vcStr = vc.toString();
wtr = new FileWriter(f);
wtr.append(vcStr);
return;
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
} finally {
if (wtr != null) {
try {
wtr.close();
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
}
}
throw new CalFacadeException("Unsupported dump format " + dCl.format());
}
use of org.bedework.util.xml.XmlEmit 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 in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method writeCalendar.
@Override
public String writeCalendar(final Collection<CalDAVEvent> evs, final MethodEmitted method, final XmlEmit xml, final Writer wtr, final String contentType) throws WebdavException {
try {
Collection<EventInfo> bwevs = new ArrayList<EventInfo>();
int meth = ScheduleMethods.methodTypeNone;
if (method == MethodEmitted.publish) {
meth = ScheduleMethods.methodTypePublish;
}
for (CalDAVEvent cde : evs) {
BwCalDAVEvent bcde = (BwCalDAVEvent) cde;
if (method == MethodEmitted.eventMethod) {
meth = getEvent(bcde).getScheduleMethod();
}
bwevs.add(bcde.getEvinfo());
}
String ctype = contentType;
if ((ctype == null) || (!ctype.equals("text/calendar") && !ctype.equals("application/calendar+json") && !ctype.equals(XcalTags.mimetype))) {
ctype = getDefaultContentType();
}
if (ctype.equals("text/calendar")) {
Calendar ical = trans.toIcal(bwevs, meth);
if (xml == null) {
IcalTranslator.writeCalendar(ical, wtr);
} else {
xml.cdataValue(toIcalString(ical, "text/calendar"));
}
} else if (ctype.equals("application/calendar+json")) {
if (xml == null) {
trans.writeJcal(bwevs, meth, wtr);
} else {
final StringWriter sw = new StringWriter();
trans.writeJcal(bwevs, meth, sw);
xml.cdataValue(sw.toString());
}
} else if (ctype.equals(XcalTags.mimetype)) {
XmlEmit x;
if (xml == null) {
x = new XmlEmit();
x.startEmit(wtr);
} else {
x = xml;
}
trans.writeXmlCalendar(bwevs, meth, x);
}
return ctype;
} catch (WebdavException we) {
throw we;
} catch (Throwable t) {
throw new WebdavException(t);
}
}
use of org.bedework.util.xml.XmlEmit in project bw-calendar-engine by Bedework.
the class DumpGlobals method setOut.
/**
* @param val output writer for old style dump
* @param aliases output writer for aliases
* @throws Throwable on error
*/
public void setOut(final Writer val, final Writer aliases) throws Throwable {
out = val;
xml = new XmlEmit();
xml.startEmit(out);
aliasesOut = aliases;
aliasesXml = new XmlEmit();
aliasesXml.startEmit(aliases);
}
Aggregations