KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > xtags > xslt > ParamTag


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.xtags.xslt;
18
19 import javax.servlet.jsp.JspException JavaDoc;
20 import javax.servlet.jsp.PageContext JavaDoc;
21 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
22 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
23
24 /** A tag which declares a parameter for use in an XSLT stylesheet
25   *
26   * @author James Strachan
27   */

28 public class ParamTag extends BodyTagSupport JavaDoc {
29
30     /** Holds value of property name. */
31     private String JavaDoc name;
32     
33     /** Holds value of property value. */
34     private Object JavaDoc value;
35     
36     
37     public ParamTag() {
38     }
39
40     // Tag interface
41
//-------------------------------------------------------------------------
42
public int doStartTag() throws JspException JavaDoc {
43         if ( name == null ) {
44             throw new JspException JavaDoc( "No value specified for attribute 'name'" );
45         }
46         if ( value != null ) {
47             defineParameter(value);
48             return SKIP_BODY;
49         }
50         return EVAL_BODY_TAG;
51     }
52     
53     public int doAfterBody() throws JspException JavaDoc {
54         if ( value == null ) {
55             BodyContent JavaDoc body = getBodyContent();
56             String JavaDoc text = body.getString();
57             body.clearBody();
58             defineParameter(text);
59         }
60         return SKIP_BODY;
61     }
62
63     public void release() {
64         super.release();
65         name = null;
66         value = null;
67     }
68
69     // Properties
70
//-------------------------------------------------------------------------
71
public String JavaDoc getName() {
72         return name;
73     }
74     
75     public void setName(String JavaDoc name) {
76         this.name = name;
77     }
78     
79     public Object JavaDoc getValue() {
80         return value;
81     }
82     
83     public void setValue(Object JavaDoc value) {
84         this.value = value;
85     }
86
87     // Implementation methods
88
//-------------------------------------------------------------------------
89
protected void defineParameter(Object JavaDoc value) throws JspException JavaDoc {
90         ParameterAcceptingTag tag = (ParameterAcceptingTag) findAncestorWithClass(
91             this, ParameterAcceptingTag.class
92         );
93         if ( tag == null ) {
94             throw new JspException JavaDoc( "<param> tag must be used inside a <style> tag!" );
95         }
96         tag.setParameter( name, value );
97     }
98 }
99
Popular Tags