001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/projects/CmsProjectFilesCollector.java,v $
003: * Date : $Date: 2008-02-27 12:05:51 $
004: * Version: $Revision: 1.5 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.tools.projects;
033:
034: import org.opencms.db.CmsResourceState;
035: import org.opencms.file.CmsObject;
036: import org.opencms.file.CmsProject;
037: import org.opencms.file.CmsResource;
038: import org.opencms.main.CmsException;
039: import org.opencms.main.CmsLog;
040: import org.opencms.util.CmsUUID;
041: import org.opencms.workplace.CmsWorkplace;
042: import org.opencms.workplace.explorer.CmsResourceUtil;
043: import org.opencms.workplace.list.A_CmsListExplorerDialog;
044: import org.opencms.workplace.list.A_CmsListResourceCollector;
045: import org.opencms.workplace.list.CmsListItem;
046: import org.opencms.workplace.list.I_CmsListResourceCollector;
047:
048: import java.util.ArrayList;
049: import java.util.Iterator;
050: import java.util.List;
051: import java.util.Map;
052:
053: import org.apache.commons.logging.Log;
054:
055: /**
056: * Collector for {@link org.opencms.file.CmsResource} objects from a project.<p>
057: *
058: * @author Michael Moossen
059: * @author Michael Emmerich
060: *
061: * @version $Revision: 1.5 $
062: *
063: * @since 6.1.0
064: */
065: public class CmsProjectFilesCollector extends
066: A_CmsListResourceCollector {
067:
068: /** Parameter of the default collector name. */
069: public static final String COLLECTOR_NAME = "projectresources";
070:
071: /** Project Parameter name constant. */
072: public static final String PARAM_PROJECT = "project";
073:
074: /** Resource state Parameter name constant. */
075: public static final String PARAM_STATE = "state";
076:
077: /** The log object for this class. */
078: private static final Log LOG = CmsLog
079: .getLog(CmsProjectFilesCollector.class);
080:
081: /**
082: * Constructor, creates a new instance.<p>
083: *
084: * @param wp the workplace object
085: * @param projectId the id of the project
086: * @param state the state of the resources to filter
087: */
088: public CmsProjectFilesCollector(A_CmsListExplorerDialog wp,
089: CmsUUID projectId, CmsResourceState state) {
090:
091: super (wp);
092: m_collectorParameter += I_CmsListResourceCollector.SEP_PARAM
093: + PARAM_STATE + I_CmsListResourceCollector.SEP_KEYVAL
094: + state;
095: m_collectorParameter += I_CmsListResourceCollector.SEP_PARAM
096: + PARAM_PROJECT + I_CmsListResourceCollector.SEP_KEYVAL
097: + projectId;
098: }
099:
100: /**
101: * @see org.opencms.file.collectors.I_CmsResourceCollector#getCollectorNames()
102: */
103: public List getCollectorNames() {
104:
105: List names = new ArrayList();
106: names.add(COLLECTOR_NAME);
107: return names;
108: }
109:
110: /**
111: * @see org.opencms.workplace.list.A_CmsListResourceCollector#getResources(org.opencms.file.CmsObject, java.util.Map)
112: */
113: public List getResources(CmsObject cms, Map params)
114: throws CmsException {
115:
116: CmsUUID projectId = CmsProject.ONLINE_PROJECT_ID;
117: try {
118: projectId = new CmsUUID((String) params.get(PARAM_PROJECT));
119: } catch (Throwable e) {
120: if (LOG.isDebugEnabled()) {
121: LOG.debug(e);
122: }
123: }
124: CmsResourceState state = CmsResource.STATE_KEEP;
125: try {
126: state = CmsResourceState.valueOf(Integer
127: .parseInt((String) params.get(PARAM_STATE)));
128: } catch (Throwable e) {
129: if (LOG.isDebugEnabled()) {
130: LOG.debug(e);
131: }
132: }
133:
134: // show files in the selected project with the selected status
135: List resources = cms.readProjectView(projectId, state);
136:
137: // remove not visible files
138: Iterator itRes = resources.iterator();
139: // dont's show resources that are in a different site root
140: String siteRoot = cms.getRequestContext().getSiteRoot();
141: // this is not sufficient (startsWith) if one siteRoot is prefix of another as siteRoot ends without slash!
142: siteRoot += "/";
143: while (itRes.hasNext()) {
144: CmsResource resource = (CmsResource) itRes.next();
145: if (!resource.getRootPath().startsWith(siteRoot)
146: && !resource.getRootPath().startsWith(
147: CmsWorkplace.VFS_PATH_SYSTEM)) {
148: itRes.remove();
149: }
150: }
151: return resources;
152: }
153:
154: /**
155: * @see org.opencms.workplace.list.A_CmsListResourceCollector#setAdditionalColumns(org.opencms.workplace.list.CmsListItem, org.opencms.workplace.explorer.CmsResourceUtil)
156: */
157: protected void setAdditionalColumns(CmsListItem item,
158: CmsResourceUtil resUtil) {
159:
160: // no-op
161: }
162: }
|