a_cmslistresourcecollector.java

来自「找了很久才找到到源代码」· Java 代码 · 共 695 行 · 第 1/2 页

JAVA
695
字号
                }
            }
        }
        return res;
    }

    /**
     * Returns all, unsorted and unfiltered, resources.<p>
     * 
     * Be sure to cache the resources.<p>
     * 
     * @param cms the cms object
     * @param params the parameter map
     * 
     * @return a list of {@link CmsResource} objects
     * 
     * @throws CmsException if something goes wrong
     */
    public abstract List getResources(CmsObject cms, Map params) throws CmsException;

    /**
     * @see org.opencms.file.collectors.I_CmsResourceCollector#getResults(org.opencms.file.CmsObject)
     */
    public List getResults(CmsObject cms) throws CmsException {

        return getResults(cms, getDefaultCollectorName(), m_collectorParameter);
    }

    /**
     * The parameter must follow the syntax "page:nr" where nr is the number of the page to be displayed.
     * 
     * @see org.opencms.file.collectors.I_CmsResourceCollector#getResults(org.opencms.file.CmsObject, java.lang.String, java.lang.String)
     */
    public List getResults(CmsObject cms, String collectorName, String parameter) throws CmsException {

        synchronized (this) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(Messages.get().getBundle().key(Messages.LOG_COLLECTOR_GET_RESULTS_START_0));
            }
            if (parameter == null) {
                parameter = m_collectorParameter;
            }
            List resources = new ArrayList();
            if (getWp().getList() != null) {
                Iterator itItems = getListItems(parameter).iterator();
                while (itItems.hasNext()) {
                    CmsListItem item = (CmsListItem)itItems.next();
                    resources.add(getResource(cms, item));
                }
            } else {
                Map params = CmsStringUtil.splitAsMap(
                    parameter,
                    I_CmsListResourceCollector.SEP_PARAM,
                    I_CmsListResourceCollector.SEP_KEYVAL);
                resources = getInternalResources(cms, params);
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug(Messages.get().getBundle().key(
                    Messages.LOG_COLLECTOR_GET_RESULTS_END_1,
                    new Integer(resources.size())));
            }
            return resources;
        }
    }

    /**
     * Returns the workplace object.<p>
     *
     * @return the workplace object
     */
    public A_CmsListExplorerDialog getWp() {

        return m_wp;
    }

    /**
     * @see org.opencms.file.collectors.I_CmsResourceCollector#setDefaultCollectorName(java.lang.String)
     */
    public void setDefaultCollectorName(String collectorName) {

        // ignore
    }

    /**
     * The parameter must follow the syntax "mode|projectId" where mode is either "new", "changed", "deleted" 
     * or "modified" and projectId is the id of the project to be displayed.
     * 
     * @see org.opencms.file.collectors.I_CmsResourceCollector#setDefaultCollectorParam(java.lang.String)
     */
    public void setDefaultCollectorParam(String param) {

        m_collectorParameter = param;
    }

    /**
     * @see org.opencms.file.collectors.I_CmsResourceCollector#setOrder(int)
     */
    public void setOrder(int order) {

        // ignore
    }

    /**
     * Sets the current display page.<p>
     * 
     * @param page the new display page
     */
    public void setPage(int page) {

        if (m_collectorParameter != null) {
            int pos = m_collectorParameter.indexOf(I_CmsListResourceCollector.PARAM_PAGE);
            if (pos >= 0) {
                String params = "";
                int endPos = m_collectorParameter.indexOf(I_CmsListResourceCollector.SEP_PARAM, pos);
                if (pos > 0) {
                    pos -= I_CmsListResourceCollector.SEP_PARAM.length(); // remove also the SEP_PARAM 
                    params += m_collectorParameter.substring(0, pos);
                }
                if (endPos >= 0) {
                    if (pos == 0) {
                        endPos += I_CmsListResourceCollector.SEP_PARAM.length(); // remove also the SEP_PARAM
                    }
                    params += m_collectorParameter.substring(endPos, m_collectorParameter.length());
                }
                m_collectorParameter = params;
            }
        }
        if (m_collectorParameter == null) {
            m_collectorParameter = "";
        } else if (m_collectorParameter.length() > 0) {
            m_collectorParameter += I_CmsListResourceCollector.SEP_PARAM;
        }
        m_collectorParameter += I_CmsListResourceCollector.PARAM_PAGE + I_CmsListResourceCollector.SEP_KEYVAL + page;
        synchronized (this) {
            m_resources = null;
        }
    }

    /**
     * Returns a list item created from the resource information, differs between valid resources and invalid resources.<p>
     * 
     * @param resource the resource to create the list item from
     * @param list the list
     * @param showPermissions if to show permissions
     * @param showDateLastMod if to show the last modification date
     * @param showUserLastMod if to show the last modification user
     * @param showDateCreate if to show the creation date
     * @param showUserCreate if to show the creation date
     * @param showDateRel if to show the date released
     * @param showDateExp if to show the date expired
     * @param showState if to show the state
     * @param showLockedBy if to show the lock user
     * @param showSite if to show the site
     * 
     * @return a list item created from the resource information
     */
    protected CmsListItem createResourceListItem(
        CmsResource resource,
        CmsHtmlList list,
        boolean showPermissions,
        boolean showDateLastMod,
        boolean showUserLastMod,
        boolean showDateCreate,
        boolean showUserCreate,
        boolean showDateRel,
        boolean showDateExp,
        boolean showState,
        boolean showLockedBy,
        boolean showSite) {

        CmsListItem item = list.newItem(resource.getStructureId().toString());
        // get an initialized resource utility
        CmsResourceUtil resUtil = getWp().getResourceUtil();
        resUtil.setResource(resource);
        item.set(A_CmsListExplorerDialog.LIST_COLUMN_NAME, resUtil.getPath());
        item.set(A_CmsListExplorerDialog.LIST_COLUMN_ROOT_PATH, resUtil.getFullPath());
        item.set(A_CmsListExplorerDialog.LIST_COLUMN_TITLE, resUtil.getTitle());
        item.set(A_CmsListExplorerDialog.LIST_COLUMN_TYPE, resUtil.getResourceTypeName());
        item.set(A_CmsListExplorerDialog.LIST_COLUMN_SIZE, resUtil.getSizeString());
        if (showPermissions) {
            item.set(A_CmsListExplorerDialog.LIST_COLUMN_PERMISSIONS, resUtil.getPermissionString());
        }
        if (showDateLastMod) {
            item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATELASTMOD, new Date(resource.getDateLastModified()));
        }
        if (showUserLastMod) {
            item.set(A_CmsListExplorerDialog.LIST_COLUMN_USERLASTMOD, resUtil.getUserLastModified());
        }
        if (showDateCreate) {
            item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATECREATE, new Date(resource.getDateCreated()));
        }
        if (showUserCreate) {
            item.set(A_CmsListExplorerDialog.LIST_COLUMN_USERCREATE, resUtil.getUserCreated());
        }
        if (showDateRel) {
            item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATEREL, new Date(resource.getDateReleased()));
        }
        if (showDateExp) {
            item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATEEXP, new Date(resource.getDateExpired()));
        }
        if (showState) {
            item.set(A_CmsListExplorerDialog.LIST_COLUMN_STATE, resUtil.getStateName());
        }
        if (showLockedBy) {
            item.set(A_CmsListExplorerDialog.LIST_COLUMN_LOCKEDBY, resUtil.getLockedByName());
        }
        if (showSite) {
            item.set(A_CmsListExplorerDialog.LIST_COLUMN_SITE, resUtil.getSiteTitle());
        }
        setAdditionalColumns(item, resUtil);
        return item;
    }

    /**
     * Returns a dummy list item.<p>
     * 
     * @param list the list object to create the entry for
     * 
     * @return a dummy list item
     */
    protected CmsListItem getDummyListItem(CmsHtmlList list) {

        CmsListItem item = list.newItem(CmsUUID.getNullUUID().toString());
        item.set(A_CmsListExplorerDialog.LIST_COLUMN_NAME, "");
        item.set(A_CmsListExplorerDialog.LIST_COLUMN_TITLE, "");
        item.set(A_CmsListExplorerDialog.LIST_COLUMN_TYPE, "");
        item.set(A_CmsListExplorerDialog.LIST_COLUMN_SIZE, "");
        item.set(A_CmsListExplorerDialog.LIST_COLUMN_PERMISSIONS, "");
        item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATELASTMOD, new Date());
        item.set(A_CmsListExplorerDialog.LIST_COLUMN_USERLASTMOD, "");
        item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATECREATE, new Date());
        item.set(A_CmsListExplorerDialog.LIST_COLUMN_USERCREATE, "");
        item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATEREL, new Date());
        item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATEEXP, new Date());
        item.set(A_CmsListExplorerDialog.LIST_COLUMN_STATE, "");
        item.set(A_CmsListExplorerDialog.LIST_COLUMN_LOCKEDBY, "");
        return item;
    }

    /**
     * Wrapper method for caching the result of {@link #getResources(CmsObject, Map)}.<p>
     * 
     * @param cms the cms object
     * @param params the parameter map
     * 
     * @return the result of {@link #getResources(CmsObject, Map)}
     * 
     * @throws CmsException if something goes wrong 
     */
    protected List getInternalResources(CmsObject cms, Map params) throws CmsException {

        synchronized (this) {
            if (m_resources == null) {
                m_resources = getResources(cms, params);
                Iterator it = m_resources.iterator();
                while (it.hasNext()) {
                    CmsResource resource = (CmsResource)it.next();
                    m_resCache.put(resource.getStructureId().toString(), resource);
                }
            }
        }
        return m_resources;
    }

    /**
     * Returns the list of resource names from the parameter map.<p>
     * 
     * @param params the parameter map
     * 
     * @return the list of resource names
     * 
     * @see I_CmsListResourceCollector#PARAM_RESOURCES
     */
    protected List getResourceNamesFromParam(Map params) {

        String resourcesParam = "/";
        if (params.containsKey(I_CmsListResourceCollector.PARAM_RESOURCES)) {
            resourcesParam = (String)params.get(I_CmsListResourceCollector.PARAM_RESOURCES);
        }
        if (resourcesParam.length() == 0) {
            return Collections.EMPTY_LIST;
        }
        return CmsStringUtil.splitAsList(resourcesParam, "#");
    }

    /**
     * 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 params) {

        CmsListState state = new CmsListState();
        try {
            state.setPage(Integer.parseInt((String)params.get(I_CmsListResourceCollector.PARAM_PAGE)));
        } catch (Throwable e) {
            // ignore
        }
        try {
            state.setOrder(CmsListOrderEnum.valueOf((String)params.get(I_CmsListResourceCollector.PARAM_ORDER)));
        } catch (Throwable e) {
            // ignore
        }
        try {
            state.setFilter((String)params.get(I_CmsListResourceCollector.PARAM_FILTER));
        } catch (Throwable e) {
            // ignore
        }
        try {
            state.setColumn((String)params.get(I_CmsListResourceCollector.PARAM_SORTBY));
        } catch (Throwable e) {
            // ignore
        }
        return state;
    }

    /**
     * Set additional column entries for a resource.<p>
     * 
     * Overwrite this method to set additional column entries.<p>
     * 
     * @param item the current list item 
     * @param resUtil the resource util object for getting the info from
     */
    protected abstract void setAdditionalColumns(CmsListItem item, CmsResourceUtil resUtil);

    /**
     * Sets the resources parameter.<p>
     * 
     * @param resources the list of resource names to use
     */
    protected void setResourcesParam(List resources) {

        m_collectorParameter += I_CmsListResourceCollector.SEP_PARAM
            + I_CmsListResourceCollector.PARAM_RESOURCES
            + I_CmsListResourceCollector.SEP_KEYVAL;
        if (resources == null) {
            // search anywhere
            m_collectorParameter += "/";
        } else {
            m_collectorParameter += CmsStringUtil.collectionAsString(resources, "#");
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?