public void addBody(Body body) throws WingException, SQLException, AuthorizeException {
    // Get all our parameters
    MetadataSchema[] schemas = MetadataSchema.findAll(context);
    String idsString = parameters.getParameter("fieldIDs", null);

    ArrayList<MetadataField> fields = new ArrayList<MetadataField>();
    for (String id : idsString.split(",")) {
      MetadataField field = MetadataField.find(context, Integer.valueOf(id));
      fields.add(field);
    }

    // DIVISION: metadata-field-move
    Division moved =
        body.addInteractiveDivision(
            "metadata-field-move",
            contextPath + "/admin/metadata-registry",
            Division.METHOD_POST,
            "primary administrative metadata-registry");
    moved.setHead(T_head1);
    moved.addPara(T_para1);

    Table table = moved.addTable("metadata-field-move", fields.size() + 1, 3);
    Row header = table.addRow(Row.ROLE_HEADER);
    header.addCell().addContent(T_column1);
    header.addCell().addContent(T_column2);
    header.addCell().addContent(T_column3);

    for (MetadataField field : fields) {
      String fieldID = String.valueOf(field.getID());
      String fieldEelement = field.getElement();
      String fieldQualifier = field.getQualifier();

      MetadataSchema schema = MetadataSchema.find(context, field.getSchemaID());
      String schemaName = schema.getName();

      String fieldName = schemaName + "." + fieldEelement;
      if (fieldQualifier != null && fieldQualifier.length() > 0) fieldName += "." + fieldQualifier;

      String fieldScopeNote = field.getScopeNote();

      Row row = table.addRow();
      row.addCell().addContent(fieldID);
      row.addCell().addContent(fieldName);
      row.addCell().addContent(fieldScopeNote);
    }

    Row row = table.addRow();
    Cell cell = row.addCell(1, 3);
    cell.addContent(T_para2);
    Select toSchema = cell.addSelect("to_schema");
    for (MetadataSchema schema : schemas) {
      toSchema.addOption(schema.getID(), schema.getNamespace());
    }

    Para buttons = moved.addPara();
    buttons.addButton("submit_move").setValue(T_submit_move);
    buttons.addButton("submit_cancel").setValue(T_submit_cancel);

    moved.addHidden("administrative-continue").setValue(knot.getId());
  }
Esempio n. 2
0
  protected void buildSearchControls(Division div) throws WingException {
    Table controlsTable = div.addTable("search-controls", 1, 3);
    Row controlsRow = controlsTable.addRow(Row.ROLE_DATA);

    // Create a control for the number of records to display
    Cell rppCell = controlsRow.addCell();
    rppCell.addContent(T_rpp);
    Select rppSelect = rppCell.addSelect("rpp");
    for (int i : RESULTS_PER_PAGE_PROGRESSION) {
      rppSelect.addOption((i == getParameterRpp()), i, Integer.toString(i));
    }

    Cell sortCell = controlsRow.addCell();
    try {
      // Create a drop down of the different sort columns available
      sortCell.addContent(T_sort_by);
      Select sortSelect = sortCell.addSelect("sort_by");
      sortSelect.addOption(false, 0, T_sort_by_relevance);
      for (SortOption so : SortOption.getSortOptions()) {
        if (so.isVisible()) {
          sortSelect.addOption(
              (so.getNumber() == getParameterSortBy()),
              so.getNumber(),
              message("xmlui.ArtifactBrowser.AbstractSearch.sort_by." + so.getName()));
        }
      }
    } catch (SortException se) {
      throw new WingException("Unable to get sort options", se);
    }

    // Create a control to changing ascending / descending order
    Cell orderCell = controlsRow.addCell();
    orderCell.addContent(T_order);
    Select orderSelect = orderCell.addSelect("order");
    orderSelect.addOption(
        SortOption.ASCENDING.equals(getParameterOrder()), SortOption.ASCENDING, T_order_asc);
    orderSelect.addOption(
        SortOption.DESCENDING.equals(getParameterOrder()), SortOption.DESCENDING, T_order_desc);

    // Create a control for the number of authors per item to display
    // FIXME This is currently disabled, as the supporting functionality
    // is not currently present in xmlui
    // if (isItemBrowse(info))
    // {
    //    controlsForm.addContent(T_etal);
    //    Select etalSelect = controlsForm.addSelect(BrowseParams.ETAL);
    //
    //    etalSelect.addOption((info.getEtAl() < 0), 0, T_etal_all);
    //    etalSelect.addOption(1 == info.getEtAl(), 1, Integer.toString(1));
    //
    //    for (int i = 5; i <= 50; i += 5)
    //    {
    //        etalSelect.addOption(i == info.getEtAl(), i, Integer.toString(i));
    //    }
    // }
  }
Esempio n. 3
0
  public void addListGroups(String groupID, List form, int errorFlag, Collection owningCollection)
      throws WingException, SQLException {

    if (isAdvancedFormEnabled) {
      // currently set group
      form.addLabel(T_groups);
      Select groupSelect = form.addItem().addSelect("group_id");
      groupSelect.setMultiple(false);

      java.util.List<Group> loadedGroups = null;

      // retrieve groups
      String name = ConfigurationManager.getProperty("webui.submission.restrictstep.groups");
      if (name != null) {
        Group uiGroup = groupService.findByName(context, name);
        if (uiGroup != null) loadedGroups = uiGroup.getMemberGroups();
      }
      if (loadedGroups == null || loadedGroups.size() == 0) {
        loadedGroups = groupService.findAll(context, GroupService.NAME);
      }

      // if no group selected for default set anonymous
      if (groupID == null || groupID.equals("")) groupID = "0";
      // when we're just loading the main step, also default to anonymous
      if (errorFlag == AccessStep.STATUS_COMPLETE) {
        groupID = "0";
      }
      for (Group group : loadedGroups) {
        boolean selectGroup = group.getID().toString().equals(groupID);
        groupSelect.addOption(selectGroup, group.getID().toString(), group.getName());
      }

      if (errorFlag == AccessStep.STATUS_DUPLICATED_POLICY
          || errorFlag == AccessStep.EDIT_POLICY_STATUS_DUPLICATED_POLICY
          || errorFlag == UploadWithEmbargoStep.STATUS_EDIT_POLICIES_DUPLICATED_POLICY
          || errorFlag == UploadWithEmbargoStep.STATUS_EDIT_POLICY_DUPLICATED_POLICY) {
        groupSelect.addError(T_error_duplicated_policy);
      }
    }
  }
Esempio n. 4
0
  /**
   * Add options to the search scope field. This field determines in what communities or collections
   * to search for the query.
   *
   * <p>The scope list will depend upon the current search scope. There are three cases:
   *
   * <p>No current scope: All top level communities are listed.
   *
   * <p>The current scope is a community: All collections contained within the community are listed.
   *
   * <p>The current scope is a collection: All parent communities are listed.
   *
   * @param scope The current scope field.
   */
  protected void buildScopeList(Select scope) throws SQLException, WingException {

    DSpaceObject scopeDSO = getScope();
    if (scopeDSO == null) {
      // No scope, display all root level communities
      scope.addOption("/", T_all_of_dspace);
      scope.setOptionSelected("/");
      for (Community community : Community.findAllTop(context)) {
        scope.addOption(community.getHandle(), community.getMetadata("name"));
      }
    } else if (scopeDSO instanceof Community) {
      // The scope is a community, display all collections contained
      // within
      Community community = (Community) scopeDSO;
      scope.addOption("/", T_all_of_dspace);
      scope.addOption(community.getHandle(), community.getMetadata("name"));
      scope.setOptionSelected(community.getHandle());

      for (Collection collection : community.getCollections()) {
        scope.addOption(collection.getHandle(), collection.getMetadata("name"));
      }
    } else if (scopeDSO instanceof Collection) {
      // The scope is a collection, display all parent collections.
      Collection collection = (Collection) scopeDSO;
      scope.addOption("/", T_all_of_dspace);
      scope.addOption(collection.getHandle(), collection.getMetadata("name"));
      scope.setOptionSelected(collection.getHandle());

      Community[] communities = collection.getCommunities()[0].getAllParents();
      for (Community community : communities) {
        scope.addOption(community.getHandle(), community.getMetadata("name"));
      }
    }
  }
Esempio n. 5
0
  public void addBody(Body body)
      throws SAXException, WingException, UIException, SQLException, IOException,
          AuthorizeException {
    Request request = ObjectModelHelper.getRequest(objectModel);
    boolean help = false, error = false;
    if (request.getParameter("help") != null) {
      help = true;
    }
    if (request.getParameter("error") != null) {
      error = true;
    }

    Division div = body.addInteractiveDivision("test", "", "post", "primary");
    div.setHead("Inline form test");
    div.addPara(
        "There are two options you can use to control how this page is generated. First is the help parameter, if this is present then help text will be provided for all fields. Next is the error parameter, if it is provided then all fields will be generated in error conditions.");

    if (help) {
      div.addPara().addXref(makeURL(false, error), "Turn help OFF");
    } else {
      div.addPara().addXref(makeURL(true, error), "Turn help ON");
    }

    if (error) {
      div.addPara().addXref(makeURL(help, false), "Turn errors OFF");
    } else {
      div.addPara().addXref(makeURL(help, true), "Turn errors ON");
    }

    Division suited = body.addDivision("suited");
    suited.setHead("Fields suited towards being used inline");

    suited.addPara(
        "Below are a list of embedded fields that are normally considered usefully in an inline context.");

    // Text field
    Para p = suited.addPara();
    p.addContent("This is a plain 'Text' field, ");
    Text text = p.addText("text");
    text.setLabel("Text");
    if (help) {
      text.setHelp("This is helpfull text.");
    }
    if (error) {
      text.addError("This field is in error.");
    }
    text.setValue("Current raw value");
    p.addContent(", embedded in a paragraph.");

    // Single Checkbox field
    p = suited.addPara();
    p.addContent("This is a singe 'CheckBox' field, ");
    CheckBox checkBox = p.addCheckBox("yes-or-no");
    if (help) {
      checkBox.setHelp("Select either yes or no.");
    }
    if (error) {
      checkBox.addError("You are incorrect, try again.");
    }
    checkBox.setLabel("Yes or no");
    checkBox.addOption("yes");
    p.addContent(", embedded in a paragraph.");

    // File
    p = suited.addPara();
    p.addContent("This is a 'File' field, ");
    File file = p.addFile("file");
    file.setLabel("File");
    if (help) {
      file.setHelp("Upload a file.");
    }
    if (error) {
      file.addError("This field is in error.");
    }
    p.addContent(", embedded in a paragraph.");

    // Select (single)
    p = suited.addPara();
    p.addContent("This is single 'Select' (aka dropdown) field, ");
    Select select = p.addSelect("select");
    select.setLabel("Select (single)");
    if (help) {
      select.setHelp("Select one of the options");
    }
    if (error) {
      select.addError("This field is in error.");
    }
    select.addOption("one", "uno");
    select.addOption("two", "dos");
    select.addOption("three", "tres");
    select.addOption("four", "cuatro");
    select.addOption("five", "cinco");
    select.setOptionSelected("one");
    p.addContent(", embedded in a paragraph.");

    // Button
    p = suited.addPara();
    p.addContent("This is a 'Button' field, ");
    Button button = p.addButton("button");
    button.setLabel("Button");
    button.setValue("When you touch me I do things, lots of things");
    if (help) {
      button.setHelp("Submit buttons allow the user to submit the form.");
    }
    if (error) {
      button.addError("This button is in error.");
    }
    p.addContent(", embedded in a paragraph.");

    Division unsuited = body.addDivision("unsuited");
    unsuited.setHead("Fields typicaly unsuited towards being used inline");

    unsuited.addPara(
        "Below are a list of embedded fields that are normally considered useless in an inline context. This is because there widgets normally cross multiple lines making them hard to render inline. However these are all legal, but perhaps not advisable, and in some circumstances may be needed.");

    // Text Area Field
    p = unsuited.addPara();
    p.addContent("This is a 'Text Area' field, ");
    TextArea textArea = p.addTextArea("textarea");
    textArea.setLabel("Text Area");
    if (help) {
      textArea.setHelp("This is helpfull text.");
    }
    if (error) {
      textArea.addError("This field is in error.");
    }
    textArea.setValue("This is the raw value");
    p.addContent(", embedded in a paragraph.");

    // Multi-option Checkbox field
    p = unsuited.addPara();
    p.addContent("This is a multi-option 'CheckBox' field, ");
    checkBox = p.addCheckBox("fruit");
    if (help) {
      checkBox.setHelp("Select all the fruits that you like to eat");
    }
    if (error) {
      checkBox.addError("You are incorrect you actualy do like Tootse Rolls.");
    }
    checkBox.setLabel("fruits");
    checkBox.addOption("apple", "Apples");
    checkBox.addOption(true, "orange", "Oranges");
    checkBox.addOption("pear", "Pears");
    checkBox.addOption("tootsie", "Tootsie Roll");
    checkBox.addOption(true, "cherry", "Cherry");
    p.addContent(", embedded in a paragraph.");

    // multi-option Radio field
    p = unsuited.addPara();
    p.addContent("This is a multi-option 'Radio' field, ");
    Radio radio = p.addRadio("sex");
    radio.setLabel("Football colors");
    if (help) {
      radio.setHelp("Select the colors of the best (college) football team.");
    }
    if (error) {
      radio.addError("Error, Maroon & White is the only acceptable answer.");
    }
    radio.addOption("ut", "Burnt Orange & White");
    radio.addOption(true, "tamu", "Maroon & White");
    radio.addOption("ttu", "Tech Red & Black");
    radio.addOption("baylor", "Green & Gold");
    radio.addOption("rice", "Blue & Gray");
    radio.addOption("uh", "Scarlet Red & Albino White");
    p.addContent(", embedded in a paragraph.");

    // Select (multiple)
    p = unsuited.addPara();
    p.addContent("This is multiple 'Select' field, ");
    select = p.addSelect("multi-select");
    select.setLabel("Select (multiple)");
    select.setMultiple();
    select.setSize(4);
    if (help) {
      select.setHelp("Select one or more options");
    }
    if (error) {
      select.addError("This field is in error.");
    }
    select.addOption("one", "uno");
    select.addOption("two", "dos");
    select.addOption("three", "tres");
    select.addOption("four", "cuatro");
    select.addOption("five", "cinco");
    select.setOptionSelected("one");
    select.setOptionSelected("three");
    select.setOptionSelected("five");
    p.addContent(", embedded in a paragraph.");

    // Composite
    p = unsuited.addPara();
    p.addContent("This is a 'Composite' field of two text fields, ");
    Composite composite = p.addComposite("composite-2text");
    composite.setLabel("Composite (two text fields)");
    if (help) {
      composite.setHelp("I am the help for the entire composite");
    }
    if (error) {
      composite.addError("Just the composite is in error");
    }
    text = composite.addText("partA");
    text.setLabel("Part A");
    text.setValue("Value for part A");
    if (help) {
      text.setHelp("Part A");
    }
    text = composite.addText("partB");
    text.setLabel("Part B");
    text.setValue("Value for part B");
    if (help) {
      text.setHelp("Part B");
    }
    p.addContent(", embedded in a paragraph.");
  }
  /**
   * Add the controls to changing sorting and display options.
   *
   * @param div
   * @param info
   * @param params
   * @throws WingException
   */
  private void addBrowseControls(Division div, BrowseInfo info, BrowseParams params)
      throws WingException {
    // Prepare a Map of query parameters required for all links
    Map<String, String> queryParams = new HashMap<String, String>();

    queryParams.putAll(params.getCommonParameters());

    Division controls =
        div.addInteractiveDivision(
            "browse-controls", BROWSE_URL_BASE, Division.METHOD_POST, "browse controls");

    // Add all the query parameters as hidden fields on the form
    for (String key : queryParams.keySet()) controls.addHidden(key).setValue(queryParams.get(key));

    Para controlsForm = controls.addPara();

    // If we are browsing a list of items
    if (isItemBrowse(info)) //  && info.isSecondLevel()
    {
      try {
        // Create a drop down of the different sort columns available
        Set<SortOption> sortOptions = SortOption.getSortOptions();

        // Only generate the list if we have multiple columns
        if (sortOptions.size() > 1) {
          controlsForm.addContent(T_sort_by);
          Select sortSelect = controlsForm.addSelect(BrowseParams.SORT_BY);

          for (SortOption so : sortOptions) {
            sortSelect.addOption(
                so.equals(info.getSortOption()),
                so.getNumber(),
                message("xmlui.ArtifactBrowser.ConfigurableBrowse.sort_by." + so.getName()));
          }
        }
      } catch (BrowseException be) {
        throw new WingException("Unable to get sort options", be);
      }
    }

    // Create a control to changing ascending / descending order
    controlsForm.addContent(T_order);
    Select orderSelect = controlsForm.addSelect(BrowseParams.ORDER);
    orderSelect.addOption("ASC".equals(params.scope.getOrder()), "ASC", T_order_asc);
    orderSelect.addOption("DESC".equals(params.scope.getOrder()), "DESC", T_order_desc);

    // Create a control for the number of records to display
    controlsForm.addContent(T_rpp);
    Select rppSelect = controlsForm.addSelect(BrowseParams.RESULTS_PER_PAGE);
    for (int i = 5; i <= 100; i += 5) {
      rppSelect.addOption((i == info.getResultsPerPage()), i, Integer.toString(i));
    }

    // Create a control for the number of authors per item to display
    // FIXME This is currently disabled, as the supporting functionality
    // is not currently present in xmlui
    // if (isItemBrowse(info))
    // {
    //    controlsForm.addContent(T_etal);
    //    Select etalSelect = controlsForm.addSelect(BrowseParams.ETAL);
    //
    //    etalSelect.addOption((info.getEtAl() < 0), 0, T_etal_all);
    //    etalSelect.addOption(1 == info.getEtAl(), 1, Integer.toString(1));
    //
    //    for (int i = 5; i <= 50; i += 5)
    //    {
    //        etalSelect.addOption(i == info.getEtAl(), i, Integer.toString(i));
    //    }
    // }

    controlsForm.addButton("update").setValue(T_update);
  }
  /**
   * Makes the jump-list navigation for the results
   *
   * @param div
   * @param info
   * @param params
   * @throws WingException
   */
  private void addBrowseJumpNavigation(Division div, BrowseInfo info, BrowseParams params)
      throws WingException {
    // Get the name of the index
    String type = info.getBrowseIndex().getName();

    // Prepare a Map of query parameters required for all links
    Map<String, String> queryParams = new HashMap<String, String>();
    queryParams.putAll(params.getCommonParameters());
    queryParams.putAll(params.getControlParameters());

    // Navigation aid (really this is a poor version of pagination)
    Division jump =
        div.addInteractiveDivision(
            "browse-navigation", BROWSE_URL_BASE, Division.METHOD_POST, "secondary navigation");

    // Add all the query parameters as hidden fields on the form
    for (String key : queryParams.keySet()) jump.addHidden(key).setValue(queryParams.get(key));

    // If this is a date based browse, render the date navigation
    if (isSortedByDate(info)) {
      Para jumpForm = jump.addPara();

      // Create a select list to choose a month
      jumpForm.addContent(T_jump_select);
      Select month = jumpForm.addSelect(BrowseParams.MONTH);
      month.addOption(false, "-1", T_choose_month);
      for (int i = 1; i <= 12; i++) {
        month.addOption(false, String.valueOf(i), DCDate.getMonthName(i, Locale.getDefault()));
      }

      // Create a select list to choose a year
      Select year = jumpForm.addSelect(BrowseParams.YEAR);
      year.addOption(false, "-1", T_choose_year);
      int currentYear = DCDate.getCurrent().getYear();
      int i = currentYear;

      // Calculate where to move from 1, 5 to 10 year jumps
      int oneYearBreak = ((currentYear - ONE_YEAR_LIMIT) / 5) * 5;
      int fiveYearBreak = ((currentYear - FIVE_YEAR_LIMIT) / 10) * 10;
      int tenYearBreak = (currentYear - TEN_YEAR_LIMIT);
      do {
        year.addOption(false, String.valueOf(i), String.valueOf(i));

        if (i <= fiveYearBreak) i -= 10;
        else if (i <= oneYearBreak) i -= 5;
        else i--;
      } while (i > tenYearBreak);

      // Create a free text entry box for the year
      jumpForm = jump.addPara();
      jumpForm.addContent(T_jump_year);
      jumpForm.addText("start_with").setHelp(T_jump_year_help);

      jumpForm.addButton("submit").setValue(T_go);
    } else {
      // Create a clickable list of the alphabet
      List jumpList = jump.addList("jump-list", List.TYPE_SIMPLE, "alphabet");
      for (char c = 'A'; c <= 'Z'; c++) {
        Map<String, String> cQuery = new HashMap<String, String>(queryParams);
        cQuery.put(BrowseParams.STARTS_WITH, Character.toString(c));
        jumpList.addItemXref(super.generateURL(BROWSE_URL_BASE, cQuery), Character.toString(c));
      }

      // Create a free text field for the initial characters
      Para jumpForm = jump.addPara();
      jumpForm.addContent(T_starts_with);
      jumpForm.addText(BrowseParams.STARTS_WITH).setHelp(T_starts_with_help);

      jumpForm.addButton("submit").setValue(T_go);
    }
  }