use of com.zimbra.cs.convert.ConversionUnsupportedException in project zm-mailbox by Zimbra.
the class NativeFormatter method handleDocument.
private void handleDocument(UserServletContext context, Document doc) throws IOException, ServiceException, ServletException {
String v = context.params.get(UserServlet.QP_VERSION);
int version = v != null ? Integer.parseInt(v) : -1;
String contentType = doc.getContentType();
doc = (version > 0 ? (Document) doc.getMailbox().getItemRevision(context.opContext, doc.getId(), doc.getType(), version) : doc);
InputStream is = doc.getContentStream();
if (HTML_VIEW.equals(context.getView()) && !(contentType != null && contentType.startsWith(MimeConstants.CT_TEXT_HTML))) {
if (ExtensionUtil.getExtension("convertd") != null) {
// If the requested view is html, but the requested content is not, use convertd extension when deployed
handleConversion(context, is, doc.getName(), doc.getContentType(), doc.getDigest(), doc.getSize());
} else {
// either an error page, or page invoking an error callback handler can be shown
try {
updateClient(context, new ConversionUnsupportedException(String.format("Native format cannot be displayed inline: %s", contentType)));
} catch (UserServletException e) {
throw new ServletException(e.getLocalizedMessage(), e);
}
}
} else {
String defaultCharset = context.targetAccount.getAttr(Provisioning.A_zimbraPrefMailDefaultCharset, null);
boolean neuter = doc.getAccount().getBooleanAttr(Provisioning.A_zimbraNotebookSanitizeHtml, true);
if (neuter)
sendbackOriginalDoc(is, contentType, defaultCharset, doc.getName(), null, doc.getSize(), context.req, context.resp);
else
sendbackBinaryData(context.req, context.resp, is, contentType, null, doc.getName(), doc.getSize());
}
}
use of com.zimbra.cs.convert.ConversionUnsupportedException in project zm-mailbox by Zimbra.
the class Formatter method updateClient.
protected void updateClient(UserServletContext context, Exception e, List<ServiceException> w) throws UserServletException, IOException, ServletException, ServiceException {
String callback = context.params.get(QP_CALLBACK);
Throwable exception = null;
PrintWriter out = null;
if (e != null) {
Throwable cause = e.getCause();
exception = cause instanceof UserServletException || cause instanceof ServletException || cause instanceof IOException ? cause : e;
context.logError(exception);
}
// This ensures seamless display of manual download link provided by error callback, or otherwise a null blank preview pane.
if (exception instanceof ConversionUnsupportedException && (callback == null || !callback.startsWith("ZmPreviewView._errorCallback"))) {
exception = null;
}
/* Make doubly sure that parameters are valid. In the past, a path which failed to call this during
* initial formatter setup was missed. Ideally, should have caught this issue earlier to avoid
* wasting effort.
*/
validateParams(context);
if (callback == null || callback.equals("")) {
if (context.params.get(PROGRESS) == null) {
if (exception == null) {
return;
} else if (exception instanceof UserServletException) {
throw (UserServletException) exception;
} else if (exception instanceof ServletException) {
throw (ServletException) exception;
} else if (exception instanceof IOException) {
throw (IOException) exception;
} else if (exception instanceof NoSuchItemException) {
throw (ServiceException) exception;
} else if (exception instanceof ServiceException) {
ServiceException se = (ServiceException) exception;
if (se.getCode() == ServiceException.INVALID_REQUEST) {
throw se;
}
}
throw ServiceException.FAILURE(getType() + " formatter failure", exception);
}
try {
out = updateClient(context, false);
} catch (IllegalStateException ise) {
ZimbraLog.misc.warn("format output has already been written.");
return;
}
if (exception == null && (w == null || w.isEmpty())) {
out.println("<body></body>\n</html>");
} else {
ZimbraLog.misc.warn(getType() + " formatter exception", exception);
out.println("<body>\n<pre>");
if (exception != null)
out.print(exception.getLocalizedMessage());
for (ServiceException warning : w) {
out.println("<br>");
out.println(warning.toString().replace("\n", "<br>"));
}
out.println("</pre>\n</body>\n</html>");
}
} else if (!"2".equals(context.params.get(PROGRESS))) {
String result;
if (exception != null) {
if (exception instanceof ConversionUnsupportedException) {
ZimbraLog.misc.warn(getType() + " formatter exception, " + exception.getMessage());
} else {
ZimbraLog.misc.warn(getType() + " formatter exception", exception);
}
result = "fail";
} else if (w == null || w.size() == 0) {
if (context.req.getMethod().equals("GET")) {
return;
}
result = "success";
} else {
result = "warn";
}
try {
out = updateClient(context, false);
} catch (IllegalStateException ise) {
ZimbraLog.misc.warn("format output has already been written.");
return;
}
// mark done no matter what happens next
context.params.put(PROGRESS, "2");
out.println("<body onload='onLoad()'>");
out.println("<script>");
out.println("function onLoad() {");
out.print(" window.parent." + callback + "('" + result + "'");
if (exception != null) {
ServiceException se = exception instanceof ServiceException ? (ServiceException) exception : FormatterServiceException.UNKNOWN_ERROR(exception);
out.print(",\n\t");
out.print(SoapProtocol.SoapJS.soapFault(se));
}
if (w != null) {
for (ServiceException warning : w) {
out.print(",\n\t");
out.print(SoapProtocol.SoapJS.soapFault(warning));
}
}
out.println(");");
out.println("}");
out.println("</script>");
out.println("</body>");
out.println("</html>");
}
}
Aggregations