cmscategoryresourcecollector.java
来自「找了很久才找到到源代码」· Java 代码 · 共 413 行 · 第 1/2 页
JAVA
413 行
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/file/collectors/CmsCategoryResourceCollector.java,v $
* Date : $Date: 2007-08-24 15:53:08 $
* Version: $Revision: 1.4 $
*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) 2002 - 2007 Alkacon Software GmbH (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software GmbH, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.file.collectors;
import org.opencms.file.CmsDataAccessException;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.file.types.I_CmsResourceType;
import org.opencms.loader.CmsLoaderException;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.relations.CmsCategory;
import org.opencms.relations.CmsCategoryService;
import org.opencms.util.CmsStringUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
/**
* A collector to fetch XML contents in a folder or the current site filtered by one or more given category types.<p>
*
* The return list will also be filtered by given key value pairs which are given as a collector parameter.<p>
*
* Usage:
* <code>
* <cms:contentload collector="allKeyValuePairFiltered" param="resource=[filename]|resourceType=[resource type]|categoryTypes=[category1,category2,...]|subTree=[boolean]|sortBy=[category|date]|sortAsc=[boolean]">
* </code>
*
* @author Raphael Schnuck
*
* @version $Revision: 1.4 $
*
* @since 7.0.0
*/
public class CmsCategoryResourceCollector extends A_CmsResourceCollector {
/**
* Data structure for the collector, parsed from the collector parameters.<p>
*
* In addition to the superclass this implementation accepts parameters that build key value pairs separated by
* pipes '|', which allows arbitrary order of parameters and free numbers of parameters.<p>
*
* Usage:
* <code>
* "resource=[filename]|resourceType=[resource type]|categoryTypes=[category1,category2,...]|subTree=[boolean]|sortBy=[category|date]|sortAsc=[boolean]"
* </code>
*/
private static final class CmsCategoryCollectorData extends CmsCollectorData {
/** The collector parameter key for the resource type. */
public static final String PARAM_KEY_CATEGORY_TYPES = "categoryTypes";
/** The collector parameter key for the count. */
public static final String PARAM_KEY_COUNT = "count";
/** The collector parameter key for the resource (folder / file). */
public static final String PARAM_KEY_RESOURCE = "resource";
/** The collector parameter key for the resource type. */
public static final String PARAM_KEY_RESOURCE_TYPE = "resourceType";
/** The collector parameter key for sort ascending. */
public static final String PARAM_KEY_SORT_ASC = "sortAsc";
/** The collector parameter key for sort by. */
public static final String PARAM_KEY_SORT_BY = "sortBy";
/** The collector parameter key for the sub tree. */
public static final String PARAM_KEY_SUB_TREE = "subTree";
/** The list of category types. */
private List m_categoryTypes;
/** Indicates if the returned list will be sorted ascending or not (descending). */
private boolean m_sortAsc;
/** The returned list will be sort by this ('category' or 'date' are excepted). */
private String m_sortBy;
/** Indicates if the sub tree of the given resource will be searched for appropriate resources too. */
private boolean m_subTree;
/**
* Creates a new collector data set.<p>
*
* @param data the data to parse.
*
* @throws CmsLoaderException if the given configuration is not valid.
*/
public CmsCategoryCollectorData(String data)
throws CmsLoaderException {
parseExtendedData(data);
}
/**
* Returns the list of requested categories.<p>
*
* @return the list of requested categories
*/
public List getCategoryTypes() {
return m_categoryTypes;
}
/**
* Returns the sort by string (only 'date' or 'category' excepted).<p>
*
* @return the sort by string
*/
public String getSortBy() {
return m_sortBy;
}
/**
* Returns <code>true</code> if the list has to be sorted in ascending order.<p>
*
* @return <code>true</code> if the list has to be sorted in ascending order
*/
public boolean isSortAsc() {
return m_sortAsc;
}
/**
* Returns <code>true</code> if the sub tree of the given resource will be searched too.<p>
*
* @return <code>true</code> if the sub tree of the given resource will be searched too.
*/
public boolean isSubTree() {
return m_subTree;
}
/**
* Parses the additional configuration data from the collector param.<p>
*
* @param data the configuration data.
*
* @throws CmsLoaderException if something goes wrong
*/
private void parseExtendedData(String data) throws CmsLoaderException {
String[] keyValueTokens = CmsStringUtil.splitAsArray(data, '|');
for (int i = keyValueTokens.length - 1; i >= 0; i--) {
String relation = keyValueTokens[i];
String[] keyValuePair = CmsStringUtil.splitAsArray(relation, '=');
String key = keyValuePair[0];
String value = keyValuePair[1];
if (PARAM_KEY_CATEGORY_TYPES.equals(key)) {
m_categoryTypes = CmsStringUtil.splitAsList(value, ',');
} else if (PARAM_KEY_RESOURCE.equals(key)) {
setFileName(value);
} else if (PARAM_KEY_RESOURCE_TYPE.equals(key)) {
I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(value);
if (type != null) {
setType(type.getTypeId());
}
} else if (PARAM_KEY_SORT_ASC.equals(key)) {
m_sortAsc = Boolean.valueOf(value).booleanValue();
} else if (PARAM_KEY_SORT_BY.equals(key)) {
m_sortBy = value;
} else if (PARAM_KEY_SUB_TREE.equals(key)) {
m_subTree = Boolean.valueOf(value).booleanValue();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?