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, 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.ade.detailpage; 029 030import org.opencms.ade.configuration.CmsADEManager; 031import org.opencms.file.CmsObject; 032import org.opencms.file.CmsResource; 033import org.opencms.main.CmsException; 034import org.opencms.main.OpenCms; 035import org.opencms.workplace.CmsWorkplace; 036 037import java.util.ArrayList; 038import java.util.Collection; 039 040/** 041 * This class uses information from the detail page information stored in the sitemap to find the detail page for 042 * a given resource.<p> 043 * 044 * @since 8.0.0 045 */ 046public class CmsSitemapDetailPageFinder implements I_CmsDetailPageFinder { 047 048 /** 049 * @see org.opencms.ade.detailpage.I_CmsDetailPageFinder#getAllDetailPages(org.opencms.file.CmsObject, int) 050 */ 051 public Collection<String> getAllDetailPages(CmsObject cms, int resType) throws CmsException { 052 053 if (!OpenCms.getADEManager().isInitialized()) { 054 return new ArrayList<String>(); 055 } 056 String typeName = OpenCms.getResourceManager().getResourceType(resType).getTypeName(); 057 return OpenCms.getADEManager().getDetailPages(cms, typeName); 058 } 059 060 /** 061 * @see org.opencms.ade.detailpage.I_CmsDetailPageFinder#getDetailPage(org.opencms.file.CmsObject, java.lang.String, java.lang.String, java.lang.String) 062 */ 063 public String getDetailPage(CmsObject cms, String rootPath, String linkSource, String targetDetailPage) { 064 065 CmsADEManager manager = OpenCms.getADEManager(); 066 if (!manager.isInitialized()) { 067 return null; 068 } 069 070 if (rootPath.endsWith(".jsp") || rootPath.startsWith(CmsWorkplace.VFS_PATH_WORKPLACE)) { 071 // exclude these for performance reasons 072 return null; 073 } 074 String result = manager.getDetailPage(cms, rootPath, linkSource, targetDetailPage); 075 if (result == null) { 076 return null; 077 } 078 if (!CmsResource.isFolder(result)) { 079 result = CmsResource.getFolderPath(result); 080 } 081 return result; 082 } 083 084}