001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.workplace.commons; 029 030import org.opencms.file.CmsObject; 031import org.opencms.file.CmsResource; 032import org.opencms.file.CmsResourceFilter; 033import org.opencms.main.CmsLog; 034import org.opencms.workplace.explorer.CmsResourceUtil; 035import org.opencms.workplace.list.A_CmsListExplorerDialog; 036import org.opencms.workplace.list.A_CmsListResourceCollector; 037import org.opencms.workplace.list.CmsListItem; 038 039import java.util.ArrayList; 040import java.util.Iterator; 041import java.util.List; 042import java.util.Map; 043 044import org.apache.commons.logging.Log; 045 046/** 047 * Collector for locked resources.<p> 048 * 049 * @since 6.5.4 050 */ 051public class CmsLockedResourcesCollector extends A_CmsListResourceCollector { 052 053 /** Parameter of the default collector name. */ 054 public static final String COLLECTOR_NAME = "lockedResources"; 055 056 /** This constant is just a hack to mark related resources in the list. */ 057 private static final int FLAG_RELATED_RESOURCE = 8192; 058 059 /** The log object for this class. */ 060 private static final Log LOG = CmsLog.getLog(CmsLockedResourcesCollector.class); 061 062 /** 063 * Constructor, creates a new instance.<p> 064 * 065 * @param wp the workplace object 066 * @param resources list of locked resources 067 */ 068 public CmsLockedResourcesCollector(A_CmsListExplorerDialog wp, List<String> resources) { 069 070 super(wp); 071 setResourcesParam(resources); 072 } 073 074 /** 075 * @see org.opencms.file.collectors.I_CmsResourceCollector#getCollectorNames() 076 */ 077 public List<String> getCollectorNames() { 078 079 List<String> names = new ArrayList<String>(); 080 names.add(COLLECTOR_NAME); 081 return names; 082 } 083 084 /** 085 * @see org.opencms.workplace.list.A_CmsListResourceCollector#getResources(org.opencms.file.CmsObject, java.util.Map) 086 */ 087 @Override 088 public List<CmsResource> getResources(CmsObject cms, Map<String, String> params) { 089 090 List<CmsResource> resources = new ArrayList<CmsResource>(); 091 Iterator<String> itResourceNames = getResourceNamesFromParam(params).iterator(); 092 while (itResourceNames.hasNext()) { 093 String resName = itResourceNames.next(); 094 boolean relatedResource = resName.endsWith("*"); 095 if (relatedResource) { 096 resName = resName.substring(0, resName.length() - 1); 097 } 098 try { 099 CmsResource resource = cms.readResource(resName, CmsResourceFilter.ALL); 100 if (relatedResource) { 101 resource = new CmsResource( 102 resource.getStructureId(), 103 resource.getResourceId(), 104 resource.getRootPath(), 105 resource.getTypeId(), 106 resource.isFolder(), 107 resource.getFlags() | FLAG_RELATED_RESOURCE, 108 resource.getProjectLastModified(), 109 resource.getState(), 110 resource.getDateCreated(), 111 resource.getUserCreated(), 112 resource.getDateLastModified(), 113 resource.getUserLastModified(), 114 resource.getDateReleased(), 115 resource.getDateExpired(), 116 resource.getSiblingCount(), 117 resource.getLength(), 118 resource.getDateContent(), 119 resource.getVersion()); 120 } 121 resources.add(resource); 122 } catch (Exception e) { 123 LOG.error(e.getLocalizedMessage(), e); 124 } 125 } 126 return resources; 127 } 128 129 /** 130 * @see org.opencms.workplace.list.A_CmsListResourceCollector#setAdditionalColumns(org.opencms.workplace.list.CmsListItem, org.opencms.workplace.explorer.CmsResourceUtil) 131 */ 132 @Override 133 protected void setAdditionalColumns(CmsListItem item, CmsResourceUtil resUtil) { 134 135 item.set( 136 CmsLockedResourcesList.LIST_COLUMN_IS_RELATED, 137 Boolean.valueOf((resUtil.getResource().getFlags() & FLAG_RELATED_RESOURCE) == FLAG_RELATED_RESOURCE)); 138 } 139}