Esempio n. 1
0
  /** Handle the configure context's update button */
  public void doSave(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);
    ParameterParser params = data.getParameters();
    String parentId = params.getString("parentSite");

    if (!SiteService.allowUpdateSite(parentId)) {
      addAlert(state, rb.getString("error.cannot.update"));
      return;
    }

    try {
      Site site;
      site = SiteService.getSite(getSiteId(state));
      ResourcePropertiesEdit rpe = site.getPropertiesEdit();
      rpe.addProperty("sakai:parent-id", parentId);
      SiteService.save(site);
      SessionManager.getCurrentToolSession().setAttribute(LINK_MODE, MODE_DONE);
      scheduleTopRefresh();
    } catch (Exception e) {
      addAlert(state, rb.getString("error.cannot.update"));
    }
  }
Esempio n. 2
0
  /** doImport called when "eventSubmit_doImport" is in the request parameters to run an import. */
  public void doImport(RunData data, Context context) {
    SessionState state =
        ((JetspeedRunData) data).getPortletSessionState(((JetspeedRunData) data).getJs_peid());

    if (!securityService.isSuperUser()) {
      addAlert(state, rb.getString("archive.import"));
      return;
    }

    String id = data.getParameters().getString("import-id");
    String file = data.getParameters().getString("import-file");
    if ((id != null) && (id.trim().length() > 0) && (file != null) && (file.trim().length() > 0)) {
      String msg = archiveService.merge(file.trim(), id.trim(), null);
      addAlert(state, rb.getFormattedMessage("archive.import2", new Object[] {file, id}) + msg);
    } else {
      addAlert(state, rb.getString("archive.file"));
    }
  } // doImport
Esempio n. 3
0
  /**
   * doImport called when "eventSubmit_doBatch_Archive_PreProcess" is in the request parameters to
   * do the prep work for archiving a bunch of sites that match the criteria
   */
  public void doBatch_Archive_PreProcess(RunData data, Context context) {

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

    if (!securityService.isSuperUser()) {
      addAlert(state, rb.getString("archive.batch.auth"));
      return;
    }

    // if we have a selected term then use that as the batch export param
    String selectedTerm = data.getParameters().getString("archive-term");

    log.debug("selectedTerm: " + selectedTerm);

    if (StringUtils.isBlank(selectedTerm)) {
      addAlert(state, rb.getString("archive.batch.term.text.missingterm"));
      state.setAttribute(STATE_MODE, BATCH_MODE);
      return;
    }

    // set the message
    state.setAttribute(
        "confirmString",
        rb.getFormattedMessage("archive.batch.term.text.confirm.1", new Object[] {selectedTerm}));

    // get the sites that match the criteria
    Map<String, String> propertyCriteria = new HashMap<String, String>();
    propertyCriteria.put("term_eid", selectedTerm);
    List<Site> sites =
        siteService.getSites(
            SelectionType.ANY, null, null, propertyCriteria, SortType.TITLE_ASC, null);

    if (sites.isEmpty()) {
      addAlert(
          state,
          rb.getFormattedMessage("archive.batch.term.text.nosites", new Object[] {selectedTerm}));
      state.setAttribute(STATE_MODE, BATCH_MODE);
      return;
    }

    // convert to new list so that we dont load entire sites into context
    List<SparseSite> ssites = new ArrayList<SparseSite>();
    for (Site s : sites) {
      ssites.add(new SparseSite(s.getId(), s.getTitle()));
    }

    state.setAttribute("sites", ssites);

    // put into state for next pass
    state.setAttribute("selectedTerm", selectedTerm);

    // set mode so we go to next template
    state.setAttribute(STATE_MODE, BATCH_ARCHIVE_CONFIRM_MODE);
  }
 /**
  * to show different permission settings based on user selection of authz group
  *
  * @param data
  */
 public void doView_permission_option(RunData data) {
   String viewAuthzId = data.getParameters().getString("authzGroupSelection");
   SessionState state =
       ((JetspeedRunData) data).getPortletSessionState(((JetspeedRunData) data).getJs_peid());
   // reset attributes
   state.setAttribute(STATE_REALM_ROLES_ID, viewAuthzId);
   state.removeAttribute(STATE_VIEW_REALM_EDIT);
   state.removeAttribute(STATE_ABILITIES);
   state.removeAttribute(STATE_ROLES);
   state.removeAttribute(STATE_ROLE_ABILITIES);
 }
Esempio n. 5
0
  /**
   * doImport called when "eventSubmit_doBatch_Import" is in the request parameters to run an
   * import.
   */
  public void doBatch_Import(RunData data, Context context) {
    SessionState state =
        ((JetspeedRunData) data).getPortletSessionState(((JetspeedRunData) data).getJs_peid());

    Hashtable fTable = new Hashtable();

    if (!securityService.isSuperUser()) {
      addAlert(state, rb.getString("archive.batch.auth"));
      return;
    }

    // String fileName = data.getParameters().getString("import-file");
    FileItem fi = data.getParameters().getFileItem("importFile");
    if (fi == null) {
      addAlert(state, rb.getString("archive.batch.missingname"));
    } else {
      // get content
      String content = fi.getString();

      String[] lines = content.split("\n");
      for (int i = 0; i < lines.length; i++) {
        String lineContent = (String) lines[i];
        String[] lineContents = lineContent.split("\t");
        if (lineContents.length == 2) {
          fTable.put(lineContents[0], lineContents[1]);
        } else {
          addAlert(state, rb.getString("archive.batch.wrongformat"));
        }
      }
    }

    if (!fTable.isEmpty()) {
      Enumeration importFileName = fTable.keys();
      int count = 1;
      while (importFileName.hasMoreElements()) {
        String path = StringUtils.trimToNull((String) importFileName.nextElement());
        String siteCreatorName = StringUtils.trimToNull((String) fTable.get(path));
        if (path != null && siteCreatorName != null) {
          String nSiteId = idManager.createUuid();

          try {
            Object[] params = new Object[] {count, path, nSiteId, siteCreatorName};
            addAlert(state, rb.getFormattedMessage("archive.import1", params));
            addAlert(state, archiveService.merge(path, nSiteId, siteCreatorName));

          } catch (Exception ignore) {
          }
        }

        count++;
      }
    }
  }
Esempio n. 6
0
  /**
   * doArchive called when "eventSubmit_doArchive" is in the request parameters to run the archive.
   */
  public void doArchive(RunData data, Context context) {
    SessionState state =
        ((JetspeedRunData) data).getPortletSessionState(((JetspeedRunData) data).getJs_peid());

    if (!securityService.isSuperUser()) {
      addAlert(state, rb.getString("archive.limited"));
      return;
    }

    String id = data.getParameters().getString("archive-id");
    if (StringUtils.isNotBlank(id)) {
      String msg = archiveService.archive(id.trim());
      addAlert(state, rb.getFormattedMessage("archive", new Object[] {id}) + " \n " + msg);
    } else {
      addAlert(state, rb.getString("archive.please"));
    }
  } // doArchive
  /** Read the permissions form. */
  private void readForm(RunData data, AuthzGroup edit, SessionState state) {
    List abilities = (List) state.getAttribute(STATE_ABILITIES);
    List roles = (List) state.getAttribute(STATE_ROLES);

    // look for each role's ability field
    for (Iterator iRoles = roles.iterator(); iRoles.hasNext(); ) {
      Role role = (Role) iRoles.next();

      for (Iterator iLocks = abilities.iterator(); iLocks.hasNext(); ) {
        String lock = (String) iLocks.next();

        String checked = data.getParameters().getString(role.getId() + lock);
        if (checked != null) {
          // we have an ability! Make sure there's a role
          Role myRole = edit.getRole(role.getId());
          if (myRole == null) {
            try {
              myRole = edit.addRole(role.getId());
            } catch (RoleAlreadyDefinedException e) {
              M_log.warn(
                  "PermissionsAction.readForm: addRole after getRole null: "
                      + role.getId()
                      + " : "
                      + e);
            }
          }
          if (myRole != null) {
            myRole.allowFunction(lock);
          }
        } else {
          // if we do have this role, make sure there's not this lock
          Role myRole = edit.getRole(role.getId());
          if (myRole != null) {
            myRole.disallowFunction(lock);
          }
        }
      }
    }
  }
Esempio n. 8
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();
  }