public Object fillBackingObject(Object incomingModel, Map request, Map session, Map application) throws Exception { PresentationManager presentationManager = getPresentationManager(); Presentation presentation = (Presentation) incomingModel; if (presentation.getSecretExportKey() != null) { String secretExportKey = presentation.getSecretExportKey(); presentation = presentationManager.getPresentation(presentation.getId(), secretExportKey); presentation.setSecretExportKey(secretExportKey); return presentation; } else { // if it exists, get the presentation from memory that is being edited Presentation previewPres = (Presentation) session.get("presentation"); if (previewPres != null && previewPres.getId().getValue().equals(presentation.getId().getValue())) { // side step any authz issues as the presentation only exists in the users session previewPres.setIsPublic(true); previewPres.setIsPreview(true); return previewPres; } return getPresentationManager().getLightweightPresentation(presentation.getId()); } }
public ModelAndView handleRequest( Object requestModel, Map request, Map session, Map application, Errors errors) { Presentation pres = (Presentation) requestModel; if (pres.getSecretExportKey() == null) { if (!pres.getIsPublic()) { if (getAuthManager().getAgent().isInRole(Agent.ROLE_ANONYMOUS)) { try { Site site = SiteService.getSite(pres.getSiteId()); ToolConfiguration toolConfig = site.getToolForCommonId(PresentationFunctionConstants.PRES_TOOL_ID); String placement = toolConfig.getId(); ToolSession ts = SessionManager.getCurrentSession().getToolSession(placement); SessionManager.setCurrentToolSession(ts); SessionManager.getCurrentSession() .setAttribute(Tool.HELPER_DONE_URL, pres.getExternalUri()); Map model = new Hashtable(); model.put("sakai.tool.placement.id", placement); return new ModelAndView("authnRedirect", model); } catch (IdUnusedException e) { logger.error("", e); } } else { getAuthzManager() .checkPermission(PresentationFunctionConstants.VIEW_PRESENTATION, pres.getId()); } } if (pres.isExpired() && !pres.getOwner().getId().equals(getAuthManager().getAgent().getId())) { return new ModelAndView("expired"); } } if (!pres.isPreview()) { logViewedPresentation(pres); } Hashtable model = new Hashtable(); try { model.put("presentation", pres); Document doc = null; if (pres.getPresentationType().equals(Presentation.TEMPLATE_TYPE)) doc = getPresentationManager().createDocument(pres); else { String page = (String) request.get("page"); if (pres.isPreview()) { doc = getPresentationManager().getPresentationPreviewLayoutAsXml(pres, page); } else { doc = getPresentationManager().getPresentationLayoutAsXml(pres, page); } } Site site = SiteService.getSite(pres.getSiteId()); getAuthzManager().pushAuthzGroups(site.getId()); ToolConfiguration toolConfig = site.getToolForCommonId(PresentationFunctionConstants.PRES_TOOL_ID); String placement = toolConfig.getId(); model.put("placementId", placement); if (doc != null) model.put("document", doc); else return new ModelAndView("notFound", model); model.put("renderer", getTransformer(pres, request)); model.put("uriResolver", getUriResolver()); if (!getAuthManager().getAgent().isInRole(Agent.ROLE_ANONYMOUS)) { model.put("currentAgent", getAuthManager().getAgent()); } if (!pres.isPreview()) { model.put( "comments", getPresentationManager() .getPresentationComments(pres.getId(), getAuthManager().getAgent())); boolean allowComments = getAuthzManager() .isAuthorized(PresentationFunctionConstants.COMMENT_PRESENTATION, pres.getId()); model.put("allowComments", allowComments); } else { model.put("allowComments", pres.isAllowComments()); } if (request.get(BindException.ERROR_KEY_PREFIX + "newComment") == null) { request.put( BindException.ERROR_KEY_PREFIX + "newComment", new BindException(new PresentationComment(), "newComment")); } } catch (PersistenceException e) { logger.error("", e); throw new OspException(e); } catch (IdUnusedException e) { logger.error("", e); } boolean headers = pres.getTemplate().isIncludeHeaderAndFooter(); String viewName = "withoutHeader"; if (headers) { if (ToolManager.getCurrentPlacement() == null) { viewName = "withHeaderStandalone"; } else { viewName = "withHeader"; } } return new ModelAndView(viewName, model); }