KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > jsp > CmsJspTagParam


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/jsp/CmsJspTagParam.java,v $
3  * Date : $Date: 2006/03/27 14:52:19 $
4  * Version: $Revision: 1.18 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  *
31  * This file is based on:
32  * org.apache.taglibs.standard.tag.common.core.ParamSupport
33  * from the Apache JSTL 1.0 implmentation.
34  *
35  * The Apache Software License, Version 1.1
36  *
37  * Copyright (c) 1999 The Apache Software Foundation. All rights
38  * reserved.
39  *
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions
42  * are met:
43  *
44  * 1. Redistributions of source code must retain the above copyright
45  * notice, this list of conditions and the following disclaimer.
46  *
47  * 2. Redistributions in binary form must reproduce the above copyright
48  * notice, this list of conditions and the following disclaimer in
49  * the documentation and/or other materials provided with the
50  * distribution.
51  *
52  * 3. The end-user documentation included with the redistribution, if
53  * any, must include the following acknowlegement:
54  * "This product includes software developed by the
55  * Apache Software Foundation (http://www.apache.org/)."
56  * Alternately, this acknowlegement may appear in the software itself,
57  * if and wherever such third-party acknowlegements normally appear.
58  *
59  * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
60  * Foundation" must not be used to endorse or promote products derived
61  * from this software without prior written permission. For written
62  * permission, please contact apache@apache.org.
63  *
64  * 5. Products derived from this software may not be called "Apache"
65  * nor may "Apache" appear in their names without prior written
66  * permission of the Apache Group.
67  *
68  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
69  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
70  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
71  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
72  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
73  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
74  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
75  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
76  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
77  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
78  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
79  * SUCH DAMAGE.
80  * ====================================================================
81  *
82  * This software consists of voluntary contributions made by many
83  * individuals on behalf of the Apache Software Foundation. For more
84  * information on the Apache Software Foundation, please see
85  * <http://www.apache.org/>.
86  *
87  */

88
89 package org.opencms.jsp;
90
91 import org.opencms.i18n.CmsEncoder;
92 import org.opencms.main.OpenCms;
93 import org.opencms.util.CmsStringUtil;
94
95 import javax.servlet.jsp.JspException JavaDoc;
96 import javax.servlet.jsp.JspTagException JavaDoc;
97 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
98 import javax.servlet.jsp.tagext.Tag JavaDoc;
99
100 /**
101  * A handler for &lt;param&gt; that accepts attributes as Strings
102  * and evaluates them as expressions at runtime.<p>
103  *
104  * @author Shawn Bayern
105  *
106  * @version $Revision: 1.18 $
107  *
108  * @since 6.0.0
109  */

110 public class CmsJspTagParam extends BodyTagSupport JavaDoc {
111
112     /** Serial version UID required for safe serialization. */
113     private static final long serialVersionUID = -1057768160264355211L;
114
115     /**
116      * There used to be an 'encode' attribute; I've left this as a
117      * vestige in case custom subclasses want to use our functionality
118      * but NOT encode parameters.
119      */

120     protected boolean m_encode;
121
122     /** The name of the parameter. */
123     protected String JavaDoc m_name;
124
125     /** The value of the parameter. */
126     protected String JavaDoc m_value;
127
128     /**
129      * Public constructor.<p>
130      */

131     public CmsJspTagParam() {
132
133         super();
134         init();
135     }
136
137     /**
138      * Simply send our name and value to our appropriate ancestor.<p>
139      *
140      * @throws JspException (never thrown, required by interface)
141      * @return EVAL_PAGE
142      */

143     public int doEndTag() throws JspException JavaDoc {
144
145         Tag JavaDoc t = findAncestorWithClass(this, I_CmsJspTagParamParent.class);
146         if (t == null) {
147             throw new JspTagException JavaDoc(Messages.get().getBundle(pageContext.getRequest().getLocale()).key(
148                 Messages.ERR_PARENTLESS_TAG_1,
149                 new Object JavaDoc[] {"param"}));
150         }
151         // take no action for null or empty names
152
if (CmsStringUtil.isEmpty(m_name)) {
153             return EVAL_PAGE;
154         }
155
156         // send the parameter to the appropriate ancestor
157
I_CmsJspTagParamParent parent = (I_CmsJspTagParamParent)t;
158         String JavaDoc value = m_value;
159         if (value == null) {
160             if (bodyContent == null || bodyContent.getString() == null) {
161                 value = "";
162             } else {
163                 value = bodyContent.getString().trim();
164             }
165         }
166         if (m_encode) {
167             parent.addParameter(
168                 CmsEncoder.encode(m_name, OpenCms.getSystemInfo().getDefaultEncoding()),
169                 CmsEncoder.encode(value, OpenCms.getSystemInfo().getDefaultEncoding()));
170         } else {
171             parent.addParameter(m_name, value);
172         }
173
174         return EVAL_PAGE;
175     }
176
177     /**
178      * Releases any resources we may have (or inherit).<p>
179      */

180     public void release() {
181
182         init();
183     }
184
185     /**
186      * Sets the attribute name.<p>
187      *
188      * @param name the name to set
189      */

190     public void setName(String JavaDoc name) {
191
192         m_name = name;
193     }
194
195     /**
196      * Sets the attribute value.<p>
197      *
198      * @param value the name to set
199      */

200     public void setValue(String JavaDoc value) {
201
202         m_value = value;
203     }
204
205     /**
206      * Initializes the internal values.<p>
207      */

208     private void init() {
209
210         m_name = null;
211         m_value = null;
212     }
213 }
Popular Tags