001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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.file.CmsResource; 031 032/** 033 * The result of resolving a detail page URI: the container page that renders the request, and the 034 * detail content it shows (or, for a named function, the function default page).<p> 035 * 036 * Instances are created by {@link CmsDetailPageUtil#resolveDetail(org.opencms.file.CmsObject, java.lang.String)}.<p> 037 * 038 * @since 21.0.0 039 */ 040public final class CmsDetailResolution { 041 042 /** The detail content, or <code>null</code> if this is a detail function request. */ 043 private CmsResource m_detailContent; 044 045 /** The detail name, i.e. the last URI segment the request was resolved from. */ 046 private String m_detailName; 047 048 /** The detail page that renders the request. */ 049 private CmsResource m_detailPage; 050 051 /** The function default page, or <code>null</code> if this is a detail content request. */ 052 private CmsResource m_functionPage; 053 054 /** 055 * Creates a new detail resolution.<p> 056 * 057 * @param detailPage the detail page that renders the request 058 * @param detailContent the detail content, or <code>null</code> for a detail function request 059 * @param functionPage the function default page, or <code>null</code> for a detail content request 060 * @param detailName the detail name the request was resolved from 061 */ 062 private CmsDetailResolution( 063 CmsResource detailPage, 064 CmsResource detailContent, 065 CmsResource functionPage, 066 String detailName) { 067 068 m_detailPage = detailPage; 069 m_detailContent = detailContent; 070 m_functionPage = functionPage; 071 m_detailName = detailName; 072 } 073 074 /** 075 * Creates the resolution of a detail content request.<p> 076 * 077 * @param detailPage the detail page that renders the content 078 * @param detailContent the detail content 079 * @param detailName the detail name the request was resolved from 080 * 081 * @return the detail resolution 082 */ 083 static CmsDetailResolution forContent(CmsResource detailPage, CmsResource detailContent, String detailName) { 084 085 return new CmsDetailResolution(detailPage, detailContent, null, detailName); 086 } 087 088 /** 089 * Creates the resolution of a named function request.<p> 090 * 091 * @param detailPage the detail page that renders the function 092 * @param functionPage the function default page 093 * @param detailName the detail name the request was resolved from 094 * 095 * @return the detail resolution 096 */ 097 static CmsDetailResolution forFunction(CmsResource detailPage, CmsResource functionPage, String detailName) { 098 099 return new CmsDetailResolution(detailPage, null, functionPage, detailName); 100 } 101 102 /** 103 * Returns the detail content, or <code>null</code> if this is a detail function request.<p> 104 * 105 * @return the detail content 106 */ 107 public CmsResource getDetailContent() { 108 109 return m_detailContent; 110 } 111 112 /** 113 * Returns the detail name, i.e. the last URI segment the request was resolved from.<p> 114 * 115 * A detail name which is a valid UUID means the URI addressed the detail content by its 116 * structure id rather than by a mapped URL name.<p> 117 * 118 * @return the detail name 119 */ 120 public String getDetailName() { 121 122 return m_detailName; 123 } 124 125 /** 126 * Returns the detail page that renders the request.<p> 127 * 128 * @return the detail page 129 */ 130 public CmsResource getDetailPage() { 131 132 return m_detailPage; 133 } 134 135 /** 136 * Returns the function default page, or <code>null</code> if this is a detail content request.<p> 137 * 138 * @return the function default page 139 */ 140 public CmsResource getFunctionPage() { 141 142 return m_functionPage; 143 } 144 145 /** 146 * Returns <code>true</code> if this is a named function request rather than a detail content request.<p> 147 * 148 * @return <code>true</code> for a named function request 149 */ 150 public boolean isFunctionDetail() { 151 152 return m_functionPage != null; 153 } 154 155 /** 156 * @see java.lang.Object#toString() 157 */ 158 @Override 159 public String toString() { 160 161 return "CmsDetailResolution[" 162 + m_detailName 163 + " -> " 164 + (m_detailPage == null ? "null" : m_detailPage.getRootPath()) 165 + ", " 166 + (isFunctionDetail() 167 ? m_functionPage.getRootPath() 168 : (m_detailContent == null ? "null" : m_detailContent.getRootPath())) 169 + "]"; 170 } 171}