Media media;
boolean download = false;
try {
final WebApp wapp = sess.getWebApp();
final WebAppCtrl wappc = (WebAppCtrl)wapp;
final UiEngine uieng = wappc.getUiEngine();
final Desktop desktop = wappc.getDesktopCache(sess).getDesktop(dtid);
final DesktopCtrl desktopCtrl = (DesktopCtrl)desktop;
final Execution oldexec = Executions.getCurrent();
final Execution exec = new ExecutionImpl(
_ctx, request, response, desktop, null);
uieng.activate(exec);
final Configuration config = wapp.getConfiguration();
boolean err = false;
try {
config.invokeExecutionInits(exec, oldexec);
desktopCtrl.invokeExecutionInits(exec, oldexec);
media = desktopCtrl.getDownloadMedia(uuid, false);
if (media != null) {
download = true; //yes, it is for download
} else {
final Component comp = desktop.getComponentByUuid(uuid);
final Object cc = ((ComponentCtrl)comp).getExtraCtrl();
if (!(cc instanceof DynamicMedia))
throw new ServletException(DynamicMedia.class+" must be implemented by getExtraCtrl() of "+comp);
media = ((DynamicMedia)cc).getMedia(l >= 0 ? pi.substring(l): "");
if (media == null) {
response.sendError(response.SC_GONE, Messages.get(MZk.PAGE_NOT_FOUND, pi+" - "+comp));
return;
}
}
} catch (Throwable ex) {
err = true;
final List errs = new LinkedList();
errs.add(ex);
desktopCtrl.invokeExecutionCleanups(exec, oldexec, errs);
config.invokeExecutionCleanups(exec, oldexec, errs);
final StringBuffer errmsg = new StringBuffer(100);
if (!errs.isEmpty()) {
for (Iterator it = errs.iterator(); it.hasNext();) {
final Throwable t = (Throwable)it.next();
log.realCauseBriefly("Failed to load media, "+pi, t);
errmsg.append('\n').append(Exceptions.getMessage(t));
}
}
response.sendError(response.SC_GONE,
Messages.get(MZk.PAGE_FAILED, new Object[] {pi, errmsg, ""}));
return;
} finally {
if (!err) {
desktopCtrl.invokeExecutionCleanups(exec, oldexec, null);
config.invokeExecutionCleanups(exec, oldexec, null);
}
uieng.deactivate(exec);
}
} catch (ComponentNotFoundException ex) {
//possible because view might be as late as origin comp is gone
response.sendError(response.SC_GONE, Messages.get(MZk.UPDATE_OBSOLETE_PAGE, uuid));
return;