Exemplo 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();
    }
  }
Exemplo n.º 2
0
 private NodeIterator setQuery(boolean isQuery, String value) throws Exception {
   NodeIterator iter;
   Session session = sessionManager.getCurrentSession();
   if (session == null || !session.isLive()) {
     sessionManager.openSession();
     session = sessionManager.getCurrentSession();
   }
   if (isQuery) {
     QueryManager qm = session.getWorkspace().getQueryManager();
     Query query = qm.createQuery(value, Query.XPATH);
     QueryResult result = query.execute();
     iter = result.getNodes();
   } else {
     Node node = (Node) session.getItem(value);
     iter = node.getNodes();
   }
   return iter;
 }
Exemplo n.º 3
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();
   }
 }
Exemplo n.º 4
0
  public ForumPageList(NodeIterator iter, int pageSize, String value, boolean isQuery)
      throws Exception {
    super(pageSize);
    value_ = value;
    isQuery_ = isQuery;

    this.sessionManager = ForumServiceUtils.getSessionManager();
    try {
      if (iter == null) {
        sessionManager.openSession();
        iter = setQuery(isQuery_, value_);
        iter_ = iter;
      }
      if (iter != null) {
        setAvailablePage((int) iter.getSize());
      }
    } finally {
      // sessionManager.closeSession();
    }
  }