Ejemplo n.º 1
0
  /**
   * Obtain the sort option
   *
   * @return the sort option
   * @throws BrowseException
   */
  public SortOption getSortOption() throws BrowseException {
    // If a sortOption hasn't been set, work out the default
    if (sortOption == null) {
      // We need a browse index first though
      if (browseIndex != null) {
        // If a sorting hasn't been specified, and it's a metadata browse
        if (sortBy <= 0 && browseIndex.isMetadataIndex()) {
          // Create a dummy sortOption for the metadata sort
          String dataType = browseIndex.getDataType();
          String type = ("date".equals(dataType) ? "date" : "text");
          sortOption =
              new SortOption(
                  0,
                  browseIndex.getName(),
                  browseIndex.getMetadata(),
                  type,
                  browseIndex.getDefaultOrder());
        } else {
          // If a sorting hasn't been specified
          if (sortBy <= 0) {
            // Get the sort option from the index
            sortOption = browseIndex.getSortOption();

            if (sortOption == null) {
              // No sort option, so default to the first one defined in the config
              for (SortOption so : SortOption.getSortOptions()) {
                sortOption = so;
                break;
              }
            }
          } else {
            // A sorting has been specified, so get it from the configured sort columns
            for (SortOption so : SortOption.getSortOptions()) {
              if (so.getNumber() == sortBy) sortOption = so;
            }
          }
        }
      }
    }

    return sortOption;
  }
Ejemplo n.º 2
0
  /**
   * Utility method for obtaining a string representation of the browse. This is useful only for
   * debug
   */
  public String toString() {
    try {
      StringBuffer sb = new StringBuffer();

      // calculate the range for display
      String from = Integer.toString(overallPosition + 1);
      String to = Integer.toString(overallPosition + results.size());
      String of = Integer.toString(total);

      // report on the positional information of the browse
      sb.append("BrowseInfo String Representation: ");
      sb.append("Browsing " + from + " to " + to + " of " + of + " ");

      // insert the information about which index
      sb.append(
          "in index: "
              + browseIndex.getName()
              + " (data type: "
              + browseIndex.getDataType()
              + ", display type: "
              + browseIndex.getDisplayType()
              + ") ");

      sb.append("||");

      // report on the browse scope container
      String container = "all of DSpace";
      DSpaceObject theContainer = null;
      if (inCollection()) {
        container = "collection";
        theContainer = this.collection;
      } else if (inCommunity()) {
        container = "community";
        theContainer = this.community;
      }

      String containerID = "no id available/necessary";
      if (theContainer != null) {
        containerID =
            Integer.toString(theContainer.getID()) + " (" + theContainer.getHandle() + ")";
      }

      sb.append("Browsing in " + container + ": " + containerID);
      sb.append("||");

      // load the item list display configuration
      ItemListConfig config = new ItemListConfig();

      // some information about the columns to be displayed
      if (browseIndex.isItemIndex()) {
        sb.append("Listing over " + Integer.toString(config.numCols()) + " columns: ");
        for (int k = 1; k <= config.numCols(); k++) {
          if (k > 1) {
            sb.append(",");
          }
          String[] meta = config.getMetadata(k);
          sb.append(meta[0] + "." + meta[1] + "." + meta[2]);
        }

        if (value != null) {
          sb.append(" on value: ").append(value);
        }

        if (isStartsWith()) {
          sb.append(" sort column starting with: ").append(focus);
        } else if (hasFocus()) {
          sb.append(" sort column focus: ").append(focus);
        }
      } else if (browseIndex.isMetadataIndex()) {
        sb.append("Listing single column: ").append(browseIndex.getMetadata());
        if (isStartsWith()) {
          sb.append(" sort column starting with: ").append(focus);
        } else if (hasFocus()) {
          sb.append(" sort column focus: ").append(focus);
        }
      }

      sb.append("||");

      // some information about how the data is sorted
      String direction = (ascending ? "ASC" : "DESC");
      sb.append(
          "Sorting by: "
              + sortOption.getMetadata()
              + " "
              + direction
              + " (option "
              + Integer.toString(sortOption.getNumber())
              + ")");
      sb.append("||");

      // output the results
      if (browseIndex.isMetadataIndex() && !isSecondLevel()) {
        sb.append(valueListingString());
      } else if (browseIndex.isItemIndex() || isSecondLevel()) {
        sb.append(fullListingString(config));
      }

      sb.append("||");

      // tell us what the next and previous values are going to be
      sb.append("Top of next page: ");
      if (hasNextPage()) {
        sb.append("offset: ").append(Integer.toString(this.nextOffset));
      } else {
        sb.append("n/a");
      }
      sb.append(";");

      sb.append("Top of previous page: ");
      if (hasPrevPage()) {
        sb.append("offset: ").append(Integer.toString(this.prevOffset));
      } else {
        sb.append("n/a");
      }

      sb.append("||");

      return sb.toString();
    } catch (SQLException e) {
      return e.getMessage();
    } catch (BrowseException e) {
      return e.getMessage();
    }
  }