コード例 #1
0
ファイル: ContentViewImpl.java プロジェクト: mindis/nuxeo
  /**
   * Returns cached page provider if it exists or build a new one if parameters have changed.
   *
   * <p>The search document, current page and page size are set on the page provider anyway. Sort
   * infos are not set again if page provider was not built again (e.g if parameters did not change)
   * to avoid erasing sort infos already held by it.
   */
  @Override
  public PageProvider<?> getPageProvider(
      DocumentModel searchDocument,
      List<SortInfo> sortInfos,
      Long pageSize,
      Long currentPage,
      Object... params) {
    // do not return any page provider if filter has not been done yet
    if (isWaitForExecution() && !isExecuted()) {
      return null;
    }

    // resolve search doc so that it can be used in EL expressions defined
    // in XML configuration
    boolean setSearchDoc = false;
    DocumentModel finalSearchDocument = null;
    if (searchDocument != null) {
      setSearchDoc = true;
      finalSearchDocument = searchDocument;
    } else if (searchDocumentModel == null) {
      setSearchDoc = true;
      if (pageProvider != null) {
        // try to retrieve it on current page provider
        finalSearchDocument = pageProvider.getSearchDocumentModel();
      }
      if (finalSearchDocument == null) {
        // initialize it and set it => do not need to set it again
        finalSearchDocument = getSearchDocumentModel();
        setSearchDoc = false;
      }
    } else {
      finalSearchDocument = searchDocumentModel;
    }
    if (setSearchDoc) {
      // set it on content view so that it can be used when resolving EL
      // expressions
      setSearchDocumentModel(finalSearchDocument);
    }

    // fallback on local parameters if defined in the XML configuration
    if (params == null) {
      params = getQueryParameters();
    }
    if (sortInfos == null) {
      sortInfos = resolveSortInfos();
    }
    // allow to pass negative integers instead of null: EL transforms
    // numbers into value 0 for numbers
    if (pageSize != null && pageSize.longValue() < 0) {
      pageSize = null;
    }
    if (currentPage != null && currentPage.longValue() < 0) {
      currentPage = null;
    }
    if (pageSize == null) {
      if (currentPageSize != null && currentPageSize.longValue() >= 0) {
        pageSize = currentPageSize;
      }
      if (pageSize == null) {
        pageSize = resolvePageSize();
      }
    }

    // parameters changed => reset provider.
    // do not force setting of sort infos as they can be set directly on
    // the page provider and this method will be called after so they could
    // be lost.
    if (pageProvider == null || pageProvider.hasChangedParameters(params)) {
      // make the service build the provider
      ContentViewService service = Framework.getLocalService(ContentViewService.class);
      pageProvider =
          service.getPageProvider(
              getName(), sortInfos, pageSize, currentPage, finalSearchDocument, params);
    } else {
      if (pageSize != null) {
        pageProvider.setPageSize(pageSize.longValue());
      }
      if (currentPage != null) {
        pageProvider.setCurrentPage(currentPage.longValue());
      }
    }

    // Register listener to be notified when the page has changed on the
    // page provider
    pageProvider.setPageProviderChangedListener(this);
    return pageProvider;
  }