View Javadoc

1   /*
2    * Copyright 2002,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  package org.apache.commons.jelly.tags.xml;
17  
18  import org.apache.commons.jelly.JellyTagException;
19  import org.apache.commons.jelly.TagSupport;
20  import org.apache.commons.jelly.XMLOutput;
21  
22  /*** Sets a parameter in the parent transform tag
23    *
24    * @author Robert Leftwich
25    * @version $Revision: 155420 $
26    */
27  public class ParamTag extends TagSupport {
28  
29      /*** the name of the attribute. */
30      private String name;
31  
32      /*** the value of the attribute. */
33      private Object value;
34  
35  
36      public ParamTag() {
37      }
38  
39      // Tag interface
40      //-------------------------------------------------------------------------
41      public void doTag(XMLOutput output) throws JellyTagException {
42          TransformTag tag = (TransformTag) this.findAncestorWithClass( TransformTag.class );
43          if ( tag == null ) {
44              throw new JellyTagException( "<param> tag must be enclosed inside a <transform> tag" );
45          }
46          Object value = this.getValue();
47          if (value == null) {
48              value = getBodyText();
49          }
50  
51          tag.setParameterValue( getName(), value );
52      }
53  
54      // Properties
55      //-------------------------------------------------------------------------
56  
57      /***
58       * @return the name of the attribute.
59       */
60      public String getName() {
61          return name;
62      }
63      /***
64       * Sets the name of the attribute
65       */
66      public void setName(String name) {
67          this.name = name;
68      }
69  
70      /***
71       * @return the value of the attribute.
72       */
73      public Object getValue() {
74          return value;
75      }
76      /***
77       * Sets the value of the attribute
78       */
79      public void setValue(Object value) {
80          this.value = value;
81      }
82  }