use of com.zimbra.cs.octosync.store.PatchStore.StoredPatch in project zm-mailbox by Zimbra.
the class OctopusPatchFormatter method formatCallback.
// Formatter API
@Override
public void formatCallback(UserServletContext context) throws UserServletException, ServiceException, IOException, ServletException {
if (!(context.target instanceof Document)) {
throw UserServletException.notImplemented("can only handle documents");
}
Document doc = (Document) context.target;
String v = context.params.get(UserServlet.QP_VERSION);
int version = v != null ? Integer.parseInt(v) : -1;
if (log.isDebugEnabled()) {
log.debug("Request received for patch for " + doc.getName() + ", id: " + doc.getId() + (version == -1 ? ", latest version" : (", version: " + version)));
}
NativeFormatter.sendZimbraHeaders(context, context.resp, context.target);
HttpUtil.Browser browser = HttpUtil.guessBrowser(context.req);
if (browser == HttpUtil.Browser.IE) {
// turn off content detection..
context.resp.addHeader("X-Content-Type-Options", "nosniff");
}
if (version > 0) {
doc = (Document) doc.getMailbox().getItemRevision(context.opContext, doc.getId(), doc.getType(), version);
} else {
version = doc.getVersion();
if (log.isDebugEnabled()) {
log.debug("Latest version of " + doc.getName() + " is " + version);
}
}
StoredPatch sp = patchStore.lookupPatch(context.targetAccount.getId(), doc.getId(), version);
if (sp != null) {
sendPatch(context, doc, version, sp);
} else {
if (log.isDebugEnabled()) {
log.debug("Patch not available for " + doc.getName() + ", id: " + doc.getId() + ", version: " + version + "; will return the entire file");
}
sendFullFile(context, doc, version);
}
}
Aggregations