There are two ways to return error messages to the client. The method that works with all operations is to throw a VirtualViewerAPIException.

For example:

if (currentSecLevel.equals("0"))
{throw new VirtualViewerAPIException("Security violation detected");

For Send and Save operations you may return an error message through ContentHandlerResult.ERROR_MESSAGE as shown in the following example:

if (currentSecLevel.equals("0")) {
ContentHandlerResult failResult = new ContentHandlerResult(); failResult.put(ContentHandlerResult.ERROR_MESSAGE, "Security violation detected");
failResult.put(ContentHandlerResult.KEY_DOCUMENT_DISPLAY_NAME, "Security error");
return failResult;
}