public void doEdit(RenderRequest request, RenderResponse response)
      throws PortletException, IOException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String title = getTitleString(request);
    if (title != null) response.setTitle(title);

    Context context = new VelocityContext();
    context.put("tlang", rb);
    context.put("validator", validator);
    sendAlert(request, context);

    PortletURL url = response.createActionURL();
    context.put("actionUrl", url.toString());
    context.put("doCancel", "sakai.cancel");
    context.put("doUpdate", "sakai.update");

    // get current site
    Placement placement = ToolManager.getCurrentPlacement();
    String siteId = "";

    // find the right LTIContent object for this page
    String source = placement.getPlacementConfig().getProperty(SOURCE);
    Long key = getContentIdFromSource(source);
    if (key == null) {
      out.println(rb.getString("get.info.notconfig"));
      M_log.warn("Cannot find content id placement=" + placement.getId() + " source=" + source);
      return;
    }

    Map<String, Object> content = m_ltiService.getContent(key);
    if (content == null) {
      out.println(rb.getString("get.info.notconfig"));
      M_log.warn("Cannot find content item placement=" + placement.getId() + " key=" + key);
      return;
    }

    // attach the ltiToolId to each model attribute, so that we could have the tool configuration
    // page for multiple tools
    String foundLtiToolId = content.get(m_ltiService.LTI_TOOL_ID).toString();
    Map<String, Object> tool = m_ltiService.getTool(Long.valueOf(foundLtiToolId));
    if (tool == null) {
      out.println(rb.getString("get.info.notconfig"));
      M_log.warn("Cannot find tool placement=" + placement.getId() + " key=" + foundLtiToolId);
      return;
    }

    String[] contentToolModel = m_ltiService.getContentModel(Long.valueOf(foundLtiToolId));
    String formInput = m_ltiService.formInput(content, contentToolModel);
    context.put("formInput", formInput);

    vHelper.doTemplate(vengine, "/vm/edit.vm", context, out);
  }
Пример #2
0
 protected Properties extractPropertiesFromTool() {
   Placement placement = toolManager.getCurrentPlacement();
   Properties props = placement.getPlacementConfig();
   if (props.isEmpty()) props = placement.getConfig();
   return props;
 }
  // Render the portlet - this is not supposed to change the state of the portlet
  // Render may be called many times so if it changes the state - that is tacky
  // Render will be called when someone presses "refresh" or when another portlet
  // onthe same page is handed an Action.
  public void doView(RenderRequest request, RenderResponse response)
      throws PortletException, IOException {
    response.setContentType("text/html");

    // System.out.println("==== doView called ====");

    // Grab that underlying request to get a GET parameter
    ServletRequest req = (ServletRequest) ThreadLocalManager.get(CURRENT_HTTP_REQUEST);
    String popupDone = req.getParameter("sakai.popup");

    PrintWriter out = response.getWriter();
    Placement placement = ToolManager.getCurrentPlacement();
    response.setTitle(placement.getTitle());
    String source = placement.getPlacementConfig().getProperty(SOURCE);
    if (source == null) source = "";
    String height = placement.getPlacementConfig().getProperty(HEIGHT);
    if (height == null) height = "1200px";
    boolean maximize = "true".equals(placement.getPlacementConfig().getProperty(MAXIMIZE));

    boolean popup = false; // Comes from content item
    boolean oldPopup = "true".equals(placement.getPlacementConfig().getProperty(POPUP));

    // Retrieve the corresponding content item and tool to check the launch
    Map<String, Object> content = null;
    Map<String, Object> tool = null;
    Long key = getContentIdFromSource(source);
    if (key == null) {
      out.println(rb.getString("get.info.notconfig"));
      M_log.warn("Cannot find content id placement=" + placement.getId() + " source=" + source);
      return;
    }
    try {
      content = m_ltiService.getContent(key);
      // If we are supposed to popup (per the content), do so and optionally
      // copy the calue into the placement to communicate with the portal
      popup = getLongNull(content.get("newpage")) == 1;
      if (oldPopup != popup) {
        placement.getPlacementConfig().setProperty(POPUP, popup ? "true" : "false");
        placement.save();
      }
      String launch = (String) content.get("launch");
      Long tool_id = getLongNull(content.get("tool_id"));
      if (launch == null && tool_id != null) {
        tool = m_ltiService.getTool(tool_id);
        launch = (String) tool.get("launch");
      }

      // Force http:// to pop-up if we are https://
      String serverUrl = ServerConfigurationService.getServerUrl();
      if (request.isSecure() || (serverUrl != null && serverUrl.startsWith("https://"))) {
        if (launch != null && launch.startsWith("http://")) popup = true;
      }
    } catch (Exception e) {
      out.println(rb.getString("get.info.notconfig"));
      e.printStackTrace();
      return;
    }

    if (source != null && source.trim().length() > 0) {

      Context context = new VelocityContext();
      context.put("tlang", rb);
      context.put("validator", validator);
      context.put("source", source);
      context.put("height", height);
      sendAlert(request, context);
      context.put("popupdone", Boolean.valueOf(popupDone != null));
      context.put("popup", Boolean.valueOf(popup));
      context.put("maximize", Boolean.valueOf(maximize));

      vHelper.doTemplate(vengine, "/vm/main.vm", context, out);
    } else {
      out.println(rb.getString("get.info.notconfig"));
    }

    // System.out.println("==== doView complete ====");
  }
Пример #4
0
  /** Handle the configure context's update button */
  public void doConfigure_update(RunData data, Context context) {
    // TODO: if we do limit the initState() calls, we need to make sure we get a new one after this
    // call -ggolden

    String peid = ((JetspeedRunData) data).getJs_peid();
    SessionState state = ((JetspeedRunData) data).getPortletSessionState(peid);

    Placement placement = ToolManager.getCurrentPlacement();

    // get the site toolConfiguration, if this is part of a site.
    ToolConfiguration toolConfig = SiteService.findTool(placement.getId());

    // height
    String height = data.getParameters().getString(HEIGHT);
    if (height.equals(rb.getString("gen.heisomelse"))) {
      String customHeight = data.getParameters().getString(CUSTOM_HEIGHT);
      if ((customHeight != null) && (!customHeight.equals(""))) {
        if (!checkDigits(customHeight)) {
          addAlert(state, rb.getString("java.alert.pleentval"));
          return;
        }
        state.setAttribute(HEIGHT, customHeight);
        height = customHeight + "px";
        state.setAttribute(HEIGHT, height);
        placement.getPlacementConfig().setProperty(HEIGHT, height);
      } else {
        addAlert(state, rb.getString("java.alert.pleentval"));
        return;
      }
    } else if (SPECIAL_ANNOTATEDURL.equals(state.getAttribute(SPECIAL))) {
      // update the site info
      try {
        String desp = data.getParameters().getString("description");
        state.setAttribute(ANNOTATED_TEXT, desp);
        placement.getPlacementConfig().setProperty(ANNOTATED_TEXT, desp);

      } catch (Throwable e) {
      }
    } else {
      state.setAttribute(HEIGHT, height);
      placement.getPlacementConfig().setProperty(HEIGHT, height);
    }

    // title
    String title = data.getParameters().getString(TITLE);
    if (StringUtils.isBlank(title)) {
      addAlert(state, rb.getString("gen.tootit.empty"));
      return;
      // SAK-19515 check for LENGTH of tool title
    } else if (title.length() > MAX_TITLE_LENGTH) {
      addAlert(state, rb.getString("gen.tootit.toolong"));
      return;
    }
    placement.setTitle(title);

    // site info url
    String infoUrl = StringUtils.trimToNull(data.getParameters().getString("infourl"));
    if (infoUrl != null && infoUrl.length() > MAX_SITE_INFO_URL_LENGTH) {
      addAlert(state, rb.getString("gen.info.url.toolong"));
      return;
    }

    try {
      Site site = SiteService.getSite(toolConfig.getSiteId());
      SitePage page = site.getPage(toolConfig.getPageId());
      page.setTitleCustom(true);

      // for web content tool, if it is a site page tool, and the only tool on the page, update the
      // page title / popup.
      if ((state.getAttribute(SPECIAL) == null) && (toolConfig != null)) {
        // if this is the only tool on that page, update the page's title also
        if ((page.getTools() != null) && (page.getTools().size() == 1)) {
          String newPageTitle = data.getParameters().getString(FORM_PAGE_TITLE);

          if (StringUtils.isBlank(newPageTitle)) {
            addAlert(state, rb.getString("gen.pagtit.empty"));
            return;
          } else if (newPageTitle.length() > MAX_TITLE_LENGTH) {
            addAlert(state, rb.getString("gen.pagtit.toolong"));
            return;
          }
          page.setTitle(newPageTitle);
          state.setAttribute(STATE_PAGE_TITLE, newPageTitle);

          // popup
          boolean popup = data.getParameters().getBoolean("popup");
          page.setPopup(popup);
        }
      }

      SiteService.save(site);
    } catch (Exception ignore) {
      M_log.warn("doConfigure_update: " + ignore);
    }

    // read source if we are not special
    if (state.getAttribute(SPECIAL) == null) {
      String source = StringUtils.trimToEmpty(data.getParameters().getString(SOURCE));

      // User entered nothing in the source box; give the user an alert
      if (StringUtils.isBlank(source)) {
        addAlert(state, rb.getString("gen.url.empty"));
        return;
      }

      if ((!source.startsWith("/")) && (source.indexOf("://") == -1)) {
        source = "http://" + source;
      }

      // Validate the url
      UrlValidator urlValidator = new UrlValidator();
      if (!urlValidator.isValid(source)) {
        addAlert(state, rb.getString("gen.url.invalid"));
        return;
      }

      // update state
      placement.getPlacementConfig().setProperty(SOURCE, source);
    } else if (SPECIAL_WORKSITE.equals(state.getAttribute(SPECIAL))) {
      if ((infoUrl != null)
          && (infoUrl.length() > 0)
          && (!infoUrl.startsWith("/"))
          && (infoUrl.indexOf("://") == -1)) {
        infoUrl = "http://" + infoUrl;
      }
      String description = StringUtils.trimToNull(data.getParameters().getString("description"));
      description = FormattedText.processEscapedHtml(description);

      // update the site info
      try {
        SiteService.saveSiteInfo(
            ToolManager.getCurrentPlacement().getContext(), description, infoUrl);
      } catch (Throwable e) {
        M_log.warn("doConfigure_update: " + e);
      }
    }

    // save
    // TODO: we might have just saved the entire site, so this would not be needed -ggolden
    placement.save();

    // we are done with customization... back to the main mode
    state.removeAttribute(STATE_MODE);

    // refresh the whole page, since popup and title may have changed
    scheduleTopRefresh();
  }