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.jsp; 029 030import org.opencms.util.CmsStringUtil; 031 032import javax.servlet.jsp.JspException; 033import javax.servlet.jsp.JspTagException; 034import javax.servlet.jsp.tagext.Tag; 035import javax.servlet.jsp.tagext.TagSupport; 036 037/** 038 * The tag 'displayFormatter' can be used to add a formatter resource type pairing to the surrounding 'display' tag.<p> 039 */ 040public class CmsJspTagDisplayFormatter extends TagSupport { 041 042 /** The serial version id. */ 043 private static final long serialVersionUID = -7268191204617852330L; 044 045 /** The formatter key. */ 046 private String m_key; 047 048 /** The path to the formatter configuration file. */ 049 private String m_path; 050 051 /** The resource type name. */ 052 private String m_type; 053 054 /** 055 * @see javax.servlet.jsp.tagext.TagSupport#doStartTag() 056 */ 057 @Override 058 public int doStartTag() throws JspException { 059 060 Tag t = findAncestorWithClass(this, CmsJspTagDisplay.class); 061 if (t == null) { 062 throw new JspTagException( 063 Messages.get().getBundle(pageContext.getRequest().getLocale()).key( 064 Messages.ERR_PARENTLESS_TAG_1, 065 new Object[] {"displayFormatter"})); 066 } 067 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_type) && CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_key)) { 068 ((CmsJspTagDisplay)t).addDisplayFormatterKey(m_type, m_key); 069 } else if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_type) 070 && CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_path)) { 071 // only act if type and path are set 072 ((CmsJspTagDisplay)t).addDisplayFormatter(m_type, m_path); 073 } 074 075 return EVAL_PAGE; 076 } 077 078 /** 079 * Sets the path to the formatter configuration file.<p> 080 * 081 * @param path the path to set 082 */ 083 public void setFormatter(String path) { 084 085 setPath(path); 086 } 087 088 /** 089 * Sets the key of the formatter to use. 090 * 091 * @param key the formatter key 092 */ 093 public void setFormatterKey(String key) { 094 095 m_key = key; 096 } 097 098 /** 099 * Sets the path to the formatter configuration file.<p> 100 * 101 * @param path the path to set 102 */ 103 public void setPath(String path) { 104 105 m_path = path; 106 } 107 108 /** 109 * Sets the type.<p> 110 * 111 * @param type the type to set 112 */ 113 public void setType(String type) { 114 115 m_type = type; 116 } 117 118}