public int compare(Presentation p1, Presentation p2) {
   final Agent p1Owner = p1.getOwner();
   final Agent p2Owner = p2.getOwner();
   if (p1Owner == null) {
     if (p2Owner == null) {
       return 0;
     } else {
       return -1;
     }
   } else if (p2Owner == null) {
     return 1;
   } else {
     // get the sort names
     String name1 = p1Owner.getDisplayName();
     String name2 = p2Owner.getDisplayName();
     try {
       name1 = UserDirectoryService.getUserByEid(p1Owner.getEid().getValue()).getSortName();
     } catch (Exception e) {
       // nothing to do
     }
     try {
       name2 = UserDirectoryService.getUserByEid(p2Owner.getEid().getValue()).getSortName();
     } catch (Exception e) {
       // nothing to do
     }
     int result = stringComparator.compare(name1, name2);
     if (result == 0) {
       result = nameComparator.compare(p1, p2);
     }
     return result;
   }
 }
 public ModelAndView handleRequest(
     Object requestModel, Map request, Map session, Map application, Errors errors) {
   Presentation presentation = (Presentation) requestModel;
   return new ModelAndView(
       "success",
       "presentationLogs",
       getPresentationManager().findLogsByPresID(presentation.getId()));
 }
 public Object fillBackingObject(Object incomingModel, Map request, Map session, Map application)
     throws Exception {
   Presentation presentation = (Presentation) incomingModel;
   presentation = getPresentationManager().getPresentation(presentation.getId());
   // TODO do we want to make this an authz ?
   if (!presentation.getOwner().equals(getAuthManager().getAgent())) {
     throw new AuthorizationFailedException(
         "you are not authorized to view stats on this presentation");
   }
   return presentation;
 }
 public void toolRemoved(SiteTool siteTool) {
   Id toolId = getIdManager().getId(siteTool.getToolId());
   try {
     for (Iterator i = getPresentationManager().findPresentationsByTool(toolId).iterator();
         i.hasNext(); ) {
       Presentation presentation = (Presentation) i.next();
       getPresentationManager().deletePresentation(presentation.getId());
     }
     getAuthzManager().deleteAuthorizations(toolId);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  // cache the template...
  protected Transformer getTransformer(Presentation presentation, Map request)
      throws PersistenceException {
    Id renderer = presentation.getTemplate().getRenderer();
    TransformerWrapper wrapper = (TransformerWrapper) presentationTemplateCache.get(renderer);

    if (wrapper == null) {
      wrapper = new TransformerWrapper();
      wrapper.modified = 0;
    }

    Node xsl = getPresentationManager().getNode(renderer);

    if (xsl.getTechnicalMetadata().getLastModified().getTime() > wrapper.modified) {
      try {
        wrapper.transformer =
            TransformerFactory.newInstance().newTransformer(new StreamSource(xsl.getInputStream()));
        wrapper.modified = xsl.getTechnicalMetadata().getLastModified().getTime();
      } catch (TransformerConfigurationException e) {
        throw new OspException(e);
      }
    }

    wrapper.transformer.clearParameters();

    // send request params in as transform params
    for (Iterator i = request.keySet().iterator(); i.hasNext(); ) {
      String paramName = (String) i.next();
      wrapper.transformer.setParameter(paramName, request.get(paramName));
    }

    presentationTemplateCache.put(renderer, wrapper);

    return wrapper.transformer;
  }
    public final int compare(Presentation p1, Presentation p2) {
      final Date p1Modified = p1.getModified();
      final Date p2Modified = p2.getModified();

      if (p1Modified == null) {
        if (p2Modified == null) {
          return 0;
        } else {
          return -1;
        }
      } else if (p2Modified == null) {
        return 1;
      } else {
        int result = p1Modified.compareTo(p2Modified);
        if (result == 0) {
          result = nameComparator.compare(p1, p2);
        }
        return result;
      }
    }
  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);
  }
 public final int compare(Presentation p1, Presentation p2) {
   return stringComparator.compare(p1.getName(), p2.getName());
 }
 public int compare(Presentation p1, Presentation p2) {
   final Boolean b1 = p1.getIsDefault();
   final Boolean b2 = p2.getIsDefault();
   return b1.compareTo(b2);
 }