예제 #1
0
  private void handleCASAList(HttpServletRequest request, HttpServletResponse response) {
    ArrayList<Application> apps = new ArrayList<Application>();

    String allowedToolsConfig =
        ServerConfigurationService.getString("basiclti.provider.allowedtools", "");
    String[] allowedTools = allowedToolsConfig.split(":");
    List<String> allowedToolsList = Arrays.asList(allowedTools);

    for (String toolId : allowedToolsList) {
      Application app = SakaiCASAUtil.getCASAEntry(toolId);
      if (app == null) {
        M_log.warn("Could not produce CASA entry for " + toolId);
        continue;
      }
      apps.add(app);
    }

    try {
      response.setCharacterEncoding("UTF-8");
      response.setContentType("application/json");
      PrintWriter out = response.getWriter();
      out.write(JacksonUtil.prettyPrint(apps));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #2
0
  private void handleContentItem(
      HttpServletRequest request, HttpServletResponse response, Map payload)
      throws ServletException, IOException {

    String allowedToolsConfig =
        ServerConfigurationService.getString("basiclti.provider.allowedtools", "");
    String[] allowedTools = allowedToolsConfig.split(":");
    List<String> allowedToolsList = Arrays.asList(allowedTools);

    String tool_id = (String) request.getParameter("install");
    if (tool_id == null) {
      ArrayList<Tool> tools = new ArrayList<Tool>();
      for (String toolId : allowedToolsList) {
        Tool theTool = ToolManager.getTool(toolId);
        if (theTool == null) continue;
        tools.add(theTool);
      }
      request.setAttribute("tools", tools);
    } else {
      if (!allowedToolsList.contains(tool_id)) {
        doError(request, response, "launch.tool.notallowed", tool_id, null);
        return;
      }
      final Tool toolCheck = ToolManager.getTool(tool_id);
      if (toolCheck == null) {
        doError(request, response, "launch.tool.notfound", tool_id, null);
        return;
      }

      String content_item_return_url = (String) payload.get("content_item_return_url");
      if (content_item_return_url == null) {
        doError(request, response, "content_item.return_url.notfound", tool_id, null);
        return;
      }

      ContentItemResponse resp = SakaiContentItemUtil.getContentItemResponse(tool_id);
      if (resp == null) {
        doError(request, response, "launch.tool.notfound", tool_id, null);
        return;
      }
      String content_items = resp.prettyPrintLog();

      // Set up the return
      Map<String, String> ltiMap = new HashMap<String, String>();
      Map<String, String> extra = new HashMap<String, String>();
      ltiMap.put(
          BasicLTIConstants.LTI_MESSAGE_TYPE,
          BasicLTIConstants.LTI_MESSAGE_TYPE_CONTENTITEMSELECTION);
      ltiMap.put(BasicLTIConstants.LTI_VERSION, BasicLTIConstants.LTI_VERSION_1);
      ltiMap.put("content_items", content_items);
      String data = (String) payload.get("data");
      if (data != null) ltiMap.put("data", data);
      M_log.debug("ltiMap=" + ltiMap);

      boolean dodebug = M_log.isDebugEnabled();
      boolean autosubmit = false;
      String launchtext = rb.getString("content_item.install.button");
      String back_to_store = rb.getString("content_item.back.to.store");
      extra.put(
          "button_html",
          "<input type=\"submit\" value=\""
              + back_to_store
              + "\"onclick=\"location.href='content.item'; return false;\">");
      String launch_html =
          BasicLTIUtil.postLaunchHTML(
              ltiMap, content_item_return_url, launchtext, autosubmit, dodebug, extra);

      request.setAttribute("back_to_store", rb.getString("content_item.back.to.store"));
      request.setAttribute("install", tool_id);
      request.setAttribute("launch_html", launch_html);
      request.setAttribute("tool", toolCheck);
    }

    // Forward to the JSP
    ServletContext sc = this.getServletContext();
    RequestDispatcher rd = sc.getRequestDispatcher("/contentitem.jsp");
    try {
      rd.forward(request, response);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }