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 javax.servlet.jsp.PageContext; 031import javax.servlet.jsp.jstl.core.Config; 032import javax.servlet.jsp.jstl.fmt.LocalizationContext; 033 034import org.apache.taglibs.standard.tag.common.core.Util; 035import org.apache.taglibs.standard.tag.el.fmt.SetBundleTag; 036 037/** Set bundle tag using OpenCms' bundle loader mechanism. */ 038public class CmsJspTagSetBundle extends SetBundleTag { 039 040 /** Serial version UID required for safe serialization. */ 041 private static final long serialVersionUID = 3260512204391338383L; 042 /** Scope attribute. */ 043 private int m_scope; 044 /** Variable attribute. */ 045 private String m_var; 046 047 /** 048 * Public constructor doing the initialization. 049 */ 050 public CmsJspTagSetBundle() { 051 052 super(); 053 init(); 054 } 055 056 /** 057 * @see org.apache.taglibs.standard.tag.common.fmt.SetBundleSupport#doEndTag() 058 */ 059 @Override 060 public int doEndTag() { 061 062 LocalizationContext locCtxt = CmsJspTagBundle.getLocalizationContext(pageContext, basename); 063 064 if (m_var != null) { 065 pageContext.setAttribute(m_var, locCtxt, m_scope); 066 } else { 067 Config.set(pageContext, Config.FMT_LOCALIZATION_CONTEXT, locCtxt, m_scope); 068 } 069 070 return EVAL_PAGE; 071 } 072 073 /** 074 * @see org.apache.taglibs.standard.tag.el.fmt.SetBundleTag#release() 075 */ 076 @Override 077 public void release() { 078 079 super.release(); 080 init(); 081 } 082 083 /** 084 * @see org.apache.taglibs.standard.tag.common.fmt.SetBundleSupport#setScope(java.lang.String) 085 */ 086 @Override 087 public void setScope(String scope) { 088 089 this.m_scope = Util.getScope(scope); 090 super.setScope(scope); 091 } 092 093 /** 094 * @see org.apache.taglibs.standard.tag.common.fmt.SetBundleSupport#setVar(java.lang.String) 095 */ 096 @Override 097 public void setVar(String var) { 098 099 this.m_var = var; 100 super.setVar(var); 101 } 102 103 /** 104 * Sets the initial state. 105 */ 106 private void init() { 107 108 m_scope = PageContext.PAGE_SCOPE; 109 m_var = null; 110 } 111 112}