/** Add the browse-title division. */
  public void addBody(Body body)
      throws SAXException, WingException, UIException, SQLException, IOException,
          AuthorizeException {
    BrowseParams params = getUserParams();
    BrowseInfo info = getBrowseInfo();

    String type = info.getBrowseIndex().getName();

    // Build the DRI Body
    Division div = body.addDivision("browse-by-" + type, "primary");

    div.setHead(getTitleMessage(info));

    // Build the internal navigation (jump lists)
    addBrowseJumpNavigation(div, info, params);

    // Build the sort and display controls
    addBrowseControls(div, info, params);

    // This div will hold the browsing results
    Division results = div.addDivision("browse-by-" + type + "-results", "primary");

    // Add the pagination
    results.setSimplePagination(
        info.getTotal(),
        browseInfo.getOverallPosition() + 1,
        browseInfo.getOverallPosition() + browseInfo.getResultCount(),
        getPreviousPageURL(params, info),
        getNextPageURL(params, info));

    // Reference all the browsed items
    ReferenceSet referenceSet =
        results.addReferenceSet("browse-by-" + type, ReferenceSet.TYPE_SUMMARY_LIST, type, null);

    // Are we browsing items, or unique metadata?
    if (isItemBrowse(info)) {
      // Add the items to the browse results
      for (BrowseItem item : (java.util.List<BrowseItem>) info.getResults()) {
        referenceSet.addReference(item);
      }
    } else // browsing a list of unique metadata entries
    {
      // Create a table for the results
      Table singleTable =
          results.addTable("browse-by-" + type + "-results", browseInfo.getResultCount() + 1, 1);

      // Add the column heading
      singleTable
          .addRow(Row.ROLE_HEADER)
          .addCell()
          .addContent(
              message("xmlui.ArtifactBrowser.ConfigurableBrowse." + type + ".column_heading"));

      // Iterate each result
      for (String singleEntry : browseInfo.getStringResults()) {
        // Create a Map of the query parameters for the link
        Map<String, String> queryParams = new HashMap<String, String>();
        queryParams.put(BrowseParams.TYPE, URLEncode(type));
        queryParams.put(BrowseParams.FILTER_VALUE, URLEncode(singleEntry));

        // Create an entry in the table, and a linked entry
        Cell cell = singleTable.addRow().addCell();
        cell.addXref(super.generateURL(BROWSE_URL_BASE, queryParams), singleEntry);
      }
    }
  }
Beispiel #2
0
  /**
   * Attach a division to the given search division named "search-results" which contains results
   * for this search query.
   *
   * @param search The search division to contain the search-results division.
   */
  protected void buildSearchResultsDivision(Division search)
      throws IOException, SQLException, WingException {
    if (getQuery().length() > 0) {

      // Perform the actual search
      performSearch();
      DSpaceObject searchScope = getScope();

      Para para = search.addPara("result-query", "result-query");

      String query = getQuery();
      int hitCount = queryResults.getHitCount();
      para.addContent(T_result_query.parameterize(query, hitCount));

      Division results = search.addDivision("search-results", "primary");

      if (searchScope instanceof Community) {
        Community community = (Community) searchScope;
        String communityName = community.getMetadata("name");
        results.setHead(T_head1_community.parameterize(communityName));
      } else if (searchScope instanceof Collection) {
        Collection collection = (Collection) searchScope;
        String collectionName = collection.getMetadata("name");
        results.setHead(T_head1_collection.parameterize(collectionName));
      } else {
        results.setHead(T_head1_none);
      }

      if (queryResults.getHitCount() > 0) {
        // Pagination variables.
        int itemsTotal = queryResults.getHitCount();
        int firstItemIndex = queryResults.getStart() + 1;
        int lastItemIndex = queryResults.getStart() + queryResults.getPageSize();
        if (itemsTotal < lastItemIndex) {
          lastItemIndex = itemsTotal;
        }
        int currentPage = (queryResults.getStart() / queryResults.getPageSize()) + 1;
        int pagesTotal = ((queryResults.getHitCount() - 1) / queryResults.getPageSize()) + 1;
        Map<String, String> parameters = new HashMap<String, String>();
        parameters.put("page", "{pageNum}");
        String pageURLMask = generateURL(parameters);

        results.setMaskedPagination(
            itemsTotal, firstItemIndex, lastItemIndex, currentPage, pagesTotal, pageURLMask);

        // Look for any communities or collections in the mix
        ReferenceSet referenceSet = null;
        boolean resultsContainsBothContainersAndItems = false;

        @SuppressWarnings("unchecked") // This cast is correct
        java.util.List<String> containerHandles = queryResults.getHitHandles();
        for (String handle : containerHandles) {
          DSpaceObject resultDSO = HandleManager.resolveToObject(context, handle);

          if (resultDSO instanceof Community || resultDSO instanceof Collection) {
            if (referenceSet == null) {
              referenceSet =
                  results.addReferenceSet(
                      "search-results-repository",
                      ReferenceSet.TYPE_SUMMARY_LIST,
                      null,
                      "repository-search-results");
              // Set a heading showing that we will be listing containers that matched:
              referenceSet.setHead(T_head2);
              resultsContainsBothContainersAndItems = true;
            }
            referenceSet.addReference(resultDSO);
          }
        }

        // Look for any items in the result set.
        referenceSet = null;

        @SuppressWarnings("unchecked") // This cast is correct
        java.util.List<String> itemHandles = queryResults.getHitHandles();
        for (String handle : itemHandles) {
          DSpaceObject resultDSO = HandleManager.resolveToObject(context, handle);

          if (resultDSO instanceof Item) {
            if (referenceSet == null) {
              referenceSet =
                  results.addReferenceSet(
                      "search-results-repository",
                      ReferenceSet.TYPE_SUMMARY_LIST,
                      null,
                      "repository-search-results");
              // Only set a heading if there are both containers and items.
              if (resultsContainsBothContainersAndItems) {
                referenceSet.setHead(T_head3);
              }
            }
            referenceSet.addReference(resultDSO);
          }
        }

      } else {
        results.addPara(T_no_results);
      }
    } // Empty query
  }
  /** Display a single collection */
  public void addBody(Body body)
      throws SAXException, WingException, UIException, SQLException, IOException,
          AuthorizeException {
    DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
    if (!(dso instanceof Collection)) return;

    // Set up the major variables
    Collection collection = (Collection) dso;

    // Build the collection viewer division.
    Division home = body.addDivision("collection-home", "primary repository collection");
    home.setHead(collection.getMetadata("name"));

    // The search / browse box.
    {
      Division search = home.addDivision("collection-search-browse", "secondary search-browse");

      // Search query
      Division query =
          search.addInteractiveDivision(
              "collection-search",
              contextPath + "/handle/" + collection.getHandle() + "/search",
              Division.METHOD_POST,
              "secondary search");

      Para para = query.addPara("search-query", null);
      para.addContent(T_full_text_search);
      para.addContent(" ");
      para.addText("query");
      para.addContent(" ");
      para.addButton("submit").setValue(T_go);

      // Browse by list
      Division browseDiv = search.addDivision("collection-browse", "secondary browse");
      List browse = browseDiv.addList("collection-browse", List.TYPE_SIMPLE, "collection-browse");
      browse.setHead(T_head_browse);
      String url = contextPath + "/handle/" + collection.getHandle();
      browse.addItemXref(url + "/browse-title", T_browse_titles);
      browse.addItemXref(url + "/browse-author", T_browse_authors);
      browse.addItemXref(url + "/browse-date", T_browse_dates);
    }

    // Add the refrence
    {
      Division viewer = home.addDivision("collection-view", "secondary");
      ReferenceSet mainInclude =
          viewer.addReferenceSet("collection-view", ReferenceSet.TYPE_DETAIL_VIEW);
      mainInclude.addReference(collection);
    }

    // Reciently submitted items
    {
      java.util.List<BrowseItem> items = getRecientlySubmittedIems(collection);

      Division lastSubmittedDiv =
          home.addDivision("collection-recent-submission", "secondary recent-submission");
      lastSubmittedDiv.setHead(T_head_recent_submissions);
      ReferenceSet lastSubmitted =
          lastSubmittedDiv.addReferenceSet(
              "collection-last-submitted",
              ReferenceSet.TYPE_SUMMARY_LIST,
              null,
              "recent-submissions");
      for (BrowseItem item : items) {
        lastSubmitted.addReference(item);
      }
    }
  }