Ejemplo n.º 1
0
  @SuppressWarnings("unchecked")
  protected void populateCurrentPage(int page) throws Exception {
    if (iter_ == null) {
      iter_ = setQuery(isQuery_, value_);
      setAvailablePage((int) iter_.getSize());
      if (page == 0) currentPage_ = 0; // nasty trick for getAll()
      else checkAndSetPage(page);
      page = currentPage_;
    }
    Node currentNode;
    long pageSize = 0;
    if (page > 0) {
      long position = 0;
      pageSize = getPageSize();
      if (page == 1) position = 0;
      else {
        position = (page - 1) * pageSize;
        iter_.skip(position);
      }
    } else {
      pageSize = iter_.getSize();
    }

    currentListPage_ = new ArrayList<Object>();
    for (int i = 0; i < pageSize; i++) {
      if (iter_.hasNext()) {
        currentNode = iter_.nextNode();
        if (currentNode.isNodeType("exo:post")) {
          currentListPage_.add(getPost(currentNode));
        } else if (currentNode.isNodeType(Utils.TYPE_TOPIC)) {
          currentListPage_.add(getTopic(currentNode));
        } else if (currentNode.isNodeType(Utils.USER_PROFILES_TYPE)) {
          currentListPage_.add(getUserProfile(currentNode));
        } else if (currentNode.isNodeType("exo:privateMessage")) {
          currentListPage_.add(getPrivateMessage(currentNode));
        }
      } else {
        break;
      }
    }
    iter_ = null;
    if (sessionManager.getCurrentSession() != null && sessionManager.getCurrentSession().isLive()) {
      sessionManager.closeSession();
    }
  }
Ejemplo n.º 2
0
 @SuppressWarnings("unchecked")
 protected void populateCurrentPage(String valueString) throws Exception {
   NodeIterator nodeIterator = setQuery(isQuery_, value_);
   if (iter_ == null) {
     iter_ = setQuery(isQuery_, value_);
   }
   int pos = 0;
   for (int i = 0; i < nodeIterator.getSize(); i++) {
     if (getUserProfile(nodeIterator.nextNode()).getUserId().equals(valueString)) {
       pos = i + 1;
       break;
     }
   }
   int pageSize = getPageSize();
   int page = 1;
   if (pos < pageSize) {
     page = 1;
   } else {
     page = pos / pageSize;
     if (pos % pageSize > 0) {
       page = page + 1;
     }
   }
   this.pageSelected = page;
   iter_.skip((page - 1) * pageSize);
   currentListPage_ = new ArrayList<Object>();
   Node currentNode;
   for (int i = 0; i < pageSize; i++) {
     if (iter_.hasNext()) {
       currentNode = iter_.nextNode();
       if (currentNode.isNodeType(Utils.USER_PROFILES_TYPE)) {
         currentListPage_.add(getUserProfile(currentNode));
       }
     } else {
       break;
     }
   }
   iter_ = null;
   if (sessionManager.getCurrentSession() != null && sessionManager.getCurrentSession().isLive()) {
     sessionManager.closeSession();
   }
 }
  /**
   * Query items using JCR SQL2 syntax.
   *
   * @param query Query string
   * @param maxResultSize Max results returned
   * @param pageNumber paging number
   * @return List<Node> List of nodes
   * @throws javax.jcr.RepositoryException
   */
  public static List<Node> getWrappedNodesFromQuery(
      String query, int maxResultSize, int pageNumber, String nodeTypeName, String workspace)
      throws RepositoryException {
    final List<Node> itemsListPaged = new ArrayList<Node>(0);
    final NodeIterator items = QueryUtil.search(workspace, query, Query.JCR_SQL2, nodeTypeName);

    // Paging result set
    final int startRow = (maxResultSize * (pageNumber - 1));
    if (startRow > 0) {
      try {
        items.skip(startRow);
      } catch (NoSuchElementException e) {
        // log.error("No more blog items found beyond this item number: " + startRow);
      }
    }

    int count = 1;
    while (items.hasNext() && count <= maxResultSize) {
      itemsListPaged.add(new I18nNodeWrapper(items.nextNode()));
      count++;
    }

    return itemsListPaged;
  }
 /** @param i The number of rules to skip. */
 public void skip(int i) {
   it.skip(i);
 }