View Javadoc
1   /*
2    * Copyright (C) 2003-2008 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.services.wcm.publication;
18  
19  import java.util.ArrayList;
20  
21  import org.exoplatform.services.wcm.core.NodeLocation;
22  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
23  
24  /**
25   * Created by The eXo Platform SAS
26   * Author : Hoa Pham
27   * hoa.phamvu@exoplatform.com
28   * Oct 17, 2008
29   */
30  @SuppressWarnings({ "deprecation", "unchecked" })
31  public class NodeLocationPaginatedResultIterator extends PaginatedResultIterator {
32  
33    public NodeLocationPaginatedResultIterator(int pageSize) {
34      super(pageSize);
35    }
36  
37    public NodeLocationPaginatedResultIterator(Result result, int pageSize) {
38      super(result, pageSize);
39    }
40  
41    /* (non-Javadoc)
42     * @see org.exoplatform.commons.utils.PageList#populateCurrentPage(int)
43     */
44    protected void populateCurrentPage(int page) throws Exception {
45      if(page == currentPage_) {
46        if(currentListPage_ != null)
47          return;
48      }
49      currentListPage_ = new ArrayList();
50  
51      WCMComposer composer = WCMCoreUtils.getService(WCMComposer.class);
52      result.getFiltersDescriber().put(WCMComposer.FILTER_LIMIT, ""+this.getPageSize());
53      result.getFiltersDescriber().put(WCMComposer.FILTER_OFFSET, ""+(this.getPageSize()*(page-1)));
54      result.getFiltersDescriber().put(WCMComposer.FILTER_TOTAL, ""+this.result.getNumTotal());
55      result = composer.getPaginatedContents(result.getNodeLocationDescriber(),
56                                             result.getFiltersDescriber(),
57                                             WCMCoreUtils.getUserSessionProvider());
58  
59      currentListPage_ = NodeLocation.getLocationsByNodeList(result.getNodes());
60  
61      currentPage_ = page;
62    }
63  
64  }