001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (C) Alkacon Software (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.jsp.util; 029 030import org.opencms.file.CmsObject; 031import org.opencms.file.CmsResource; 032import org.opencms.main.CmsException; 033import org.opencms.main.CmsLog; 034import org.opencms.xml.containerpage.CmsDynamicFunctionBean; 035 036import java.util.Collections; 037import java.util.Map; 038 039import org.apache.commons.logging.Log; 040 041/** 042 * Wrapper class for dynamic function formats which can be used from JSP EL.<p> 043 */ 044public class CmsDynamicFunctionFormatWrapper { 045 046 /** The log instance for this class. */ 047 private static final Log LOG = CmsLog.getLog(CmsDynamicFunctionFormatWrapper.class); 048 049 /** The current cms context. */ 050 private CmsObject m_cms; 051 052 /** The dynamic function format. */ 053 private CmsDynamicFunctionBean.Format m_format; 054 055 /** The jsp resource of the dynamic function format. */ 056 private CmsResource m_jspResource; 057 058 /** 059 * Creates a new wrapper instance for a given format.<p> 060 * 061 * The format parameter may be null. 062 * 063 * @param cms the current CMS context 064 * @param format the dynamic function format 065 */ 066 public CmsDynamicFunctionFormatWrapper(CmsObject cms, CmsDynamicFunctionBean.Format format) { 067 068 m_cms = cms; 069 m_format = format; 070 if (format != null) { 071 try { 072 m_jspResource = cms.readResource(format.getJspStructureId()); 073 } catch (CmsException e) { 074 LOG.warn(e.getLocalizedMessage(), e); 075 } 076 } 077 } 078 079 /** 080 * Check if this format is actually valid, i.e. was not created with a null format argument.<p> 081 * 082 * @return true if this format is valid 083 */ 084 public boolean getExists() { 085 086 return m_jspResource != null; 087 } 088 089 /** 090 * Gets the jsp site path for this dynamic function format.<p> 091 * 092 * @return the jsp site path for this dynamic function format 093 */ 094 public String getJsp() { 095 096 if (m_jspResource != null) { 097 return m_cms.getSitePath(m_jspResource); 098 } 099 return ""; 100 } 101 102 /** 103 * Gets the parameters for this dynamic function format.<p> 104 * 105 * @return the map of parameters for the dynamic function 106 */ 107 public Map<String, String> getParam() { 108 109 return getParameters(); 110 } 111 112 /** 113 * Gets the parameters for this dynamic function format.<p> 114 * 115 * @return the map of parameters for the dynamic function 116 */ 117 public Map<String, String> getParameters() { 118 119 if (m_format != null) { 120 return m_format.getParameters(); 121 } 122 return Collections.emptyMap(); 123 } 124 125}