コード例 #1
0
  /**
   * Returns the state of the parameter map.
   *
   * <p>
   *
   * @param params the parameter map
   * @return the state of the list from the parameter map
   */
  protected CmsListState getState(Map<String, String> params) {

    CmsListState state = new CmsListState();
    try {
      state.setPage(Integer.parseInt(params.get(I_CmsListResourceCollector.PARAM_PAGE)));
    } catch (Throwable e) {
      // ignore
    }
    try {
      state.setOrder(CmsListOrderEnum.valueOf(params.get(I_CmsListResourceCollector.PARAM_ORDER)));
    } catch (Throwable e) {
      // ignore
    }
    try {
      state.setFilter(params.get(I_CmsListResourceCollector.PARAM_FILTER));
    } catch (Throwable e) {
      // ignore
    }
    try {
      state.setColumn(params.get(I_CmsListResourceCollector.PARAM_SORTBY));
    } catch (Throwable e) {
      // ignore
    }
    return state;
  }
コード例 #2
0
  /**
   * Constructor, creates a new list collector.
   *
   * <p>
   *
   * @param wp the workplace object where the collector is used from
   */
  protected A_CmsListResourceCollector(A_CmsListExplorerDialog wp) {

    m_wp = wp;
    CmsListState state = (wp != null ? wp.getListStateForCollector() : new CmsListState());
    if (state.getPage() < 1) {
      state.setPage(1);
    }
    if (CmsStringUtil.isEmptyOrWhitespaceOnly(state.getColumn())) {
      state.setColumn(A_CmsListExplorerDialog.LIST_COLUMN_NAME);
    }
    if (state.getOrder() == null) {
      state.setOrder(CmsListOrderEnum.ORDER_ASCENDING);
    }
    if (state.getFilter() == null) {
      state.setFilter("");
    }
    m_collectorParameter =
        I_CmsListResourceCollector.PARAM_PAGE
            + I_CmsListResourceCollector.SEP_KEYVAL
            + state.getPage();
    m_collectorParameter +=
        I_CmsListResourceCollector.SEP_PARAM
            + I_CmsListResourceCollector.PARAM_SORTBY
            + I_CmsListResourceCollector.SEP_KEYVAL
            + state.getColumn();
    m_collectorParameter +=
        I_CmsListResourceCollector.SEP_PARAM
            + I_CmsListResourceCollector.PARAM_ORDER
            + I_CmsListResourceCollector.SEP_KEYVAL
            + state.getOrder();
    m_collectorParameter +=
        I_CmsListResourceCollector.SEP_PARAM
            + I_CmsListResourceCollector.PARAM_FILTER
            + I_CmsListResourceCollector.SEP_KEYVAL
            + state.getFilter();
  }
コード例 #3
0
  /**
   * Returns a list of list items from a list of resources.
   *
   * <p>
   *
   * @param parameter the collector parameter or <code>null</code> for default.
   *     <p>
   * @return a list of {@link CmsListItem} objects
   * @throws CmsException if something goes wrong
   */
  public List<CmsListItem> getListItems(String parameter) throws CmsException {

    synchronized (this) {
      if (parameter == null) {
        parameter = m_collectorParameter;
      }
      Map<String, String> params =
          CmsStringUtil.splitAsMap(
              parameter,
              I_CmsListResourceCollector.SEP_PARAM,
              I_CmsListResourceCollector.SEP_KEYVAL);
      CmsListState state = getState(params);
      List<CmsResource> resources = getInternalResources(getWp().getCms(), params);
      List<CmsListItem> ret = new ArrayList<CmsListItem>();
      if (LOG.isDebugEnabled()) {
        LOG.debug(
            Messages.get()
                .getBundle()
                .key(Messages.LOG_COLLECTOR_PROCESS_ITEMS_START_1, new Integer(resources.size())));
      }
      getWp().applyColumnVisibilities();
      CmsHtmlList list = getWp().getList();

      // check if progress should be set in the thread
      CmsProgressThread thread = null;
      int progressOffset = 0;
      if (Thread.currentThread() instanceof CmsProgressThread) {
        thread = (CmsProgressThread) Thread.currentThread();
        progressOffset = thread.getProgress();
      }

      CmsListColumnDefinition colPermissions =
          list.getMetadata().getColumnDefinition(A_CmsListExplorerDialog.LIST_COLUMN_PERMISSIONS);
      boolean showPermissions = (colPermissions.isVisible() || colPermissions.isPrintable());
      CmsListColumnDefinition colDateLastMod =
          list.getMetadata().getColumnDefinition(A_CmsListExplorerDialog.LIST_COLUMN_DATELASTMOD);
      boolean showDateLastMod = (colDateLastMod.isVisible() || colDateLastMod.isPrintable());
      CmsListColumnDefinition colUserLastMod =
          list.getMetadata().getColumnDefinition(A_CmsListExplorerDialog.LIST_COLUMN_USERLASTMOD);
      boolean showUserLastMod = (colUserLastMod.isVisible() || colUserLastMod.isPrintable());
      CmsListColumnDefinition colDateCreate =
          list.getMetadata().getColumnDefinition(A_CmsListExplorerDialog.LIST_COLUMN_DATECREATE);
      boolean showDateCreate = (colDateCreate.isVisible() || colDateCreate.isPrintable());
      CmsListColumnDefinition colUserCreate =
          list.getMetadata().getColumnDefinition(A_CmsListExplorerDialog.LIST_COLUMN_USERCREATE);
      boolean showUserCreate = (colUserCreate.isVisible() || colUserCreate.isPrintable());
      CmsListColumnDefinition colDateRel =
          list.getMetadata().getColumnDefinition(A_CmsListExplorerDialog.LIST_COLUMN_DATEREL);
      boolean showDateRel = (colDateRel.isVisible() || colDateRel.isPrintable());
      CmsListColumnDefinition colDateExp =
          list.getMetadata().getColumnDefinition(A_CmsListExplorerDialog.LIST_COLUMN_DATEEXP);
      boolean showDateExp = (colDateExp.isVisible() || colDateExp.isPrintable());
      CmsListColumnDefinition colState =
          list.getMetadata().getColumnDefinition(A_CmsListExplorerDialog.LIST_COLUMN_STATE);
      boolean showState = (colState.isVisible() || colState.isPrintable());
      CmsListColumnDefinition colLockedBy =
          list.getMetadata().getColumnDefinition(A_CmsListExplorerDialog.LIST_COLUMN_LOCKEDBY);
      boolean showLockedBy = (colLockedBy.isVisible() || colLockedBy.isPrintable());
      CmsListColumnDefinition colSite =
          list.getMetadata().getColumnDefinition(A_CmsListExplorerDialog.LIST_COLUMN_SITE);
      boolean showSite = (colSite.isVisible() || colSite.isPrintable());

      // get content
      Iterator<CmsResource> itRes = resources.iterator();
      int count = 0;
      while (itRes.hasNext()) {
        // set progress in thread
        if (thread != null) {
          count++;
          if (thread.isInterrupted()) {
            throw new CmsIllegalStateException(
                org.opencms.workplace.commons.Messages.get()
                    .container(org.opencms.workplace.commons.Messages.ERR_PROGRESS_INTERRUPTED_0));
          }
          thread.setProgress(((count * 40) / resources.size()) + progressOffset);
          thread.setDescription(
              org.opencms.workplace.commons.Messages.get()
                  .getBundle(thread.getLocale())
                  .key(
                      org.opencms.workplace.commons.Messages.GUI_PROGRESS_PUBLISH_STEP2_2,
                      new Integer(count),
                      new Integer(resources.size())));
        }

        Object obj = itRes.next();
        if (!(obj instanceof CmsResource)) {
          ret.add(getDummyListItem(list));
          continue;
        }
        CmsResource resource = (CmsResource) obj;
        CmsListItem item = m_liCache.get(resource.getStructureId().toString());
        if (item == null) {
          item =
              createResourceListItem(
                  resource,
                  list,
                  showPermissions,
                  showDateLastMod,
                  showUserLastMod,
                  showDateCreate,
                  showUserCreate,
                  showDateRel,
                  showDateExp,
                  showState,
                  showLockedBy,
                  showSite);
          m_liCache.put(resource.getStructureId().toString(), item);
        }
        ret.add(item);
      }
      CmsListMetadata metadata = list.getMetadata();
      if (metadata != null) {
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(state.getFilter())) {
          // filter
          ret = metadata.getSearchAction().filter(ret, state.getFilter());
        }
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(state.getColumn())) {
          if ((metadata.getColumnDefinition(state.getColumn()) != null)
              && metadata.getColumnDefinition(state.getColumn()).isSorteable()) {
            // sort
            I_CmsListItemComparator c =
                metadata.getColumnDefinition(state.getColumn()).getListItemComparator();
            Collections.sort(ret, c.getComparator(state.getColumn(), getWp().getLocale()));
            if (state.getOrder().equals(CmsListOrderEnum.ORDER_DESCENDING)) {
              Collections.reverse(ret);
            }
          }
        }
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug(
            Messages.get()
                .getBundle()
                .key(Messages.LOG_COLLECTOR_PROCESS_ITEMS_END_1, new Integer(ret.size())));
      }
      return ret;
    }
  }