KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > io > GetTag


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.io;
18
19 import javax.servlet.ServletContext JavaDoc;
20 import javax.servlet.jsp.JspException JavaDoc;
21 import javax.servlet.jsp.JspWriter JavaDoc;
22 import javax.servlet.jsp.tagext.Tag JavaDoc;
23
24 /** Allows a named bean, or a property of a named bean to be used as input
25   * to a pipe.
26   *
27   * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan</a>
28   * @version $Revision: 1.2 $
29   */

30 public class GetTag extends AbstractTag {
31
32     /** The name used */
33     private String JavaDoc name;
34
35     /** The property to extract from the bean */
36     private String JavaDoc property;
37     
38     
39     public GetTag() {
40     }
41
42     // Tag interface
43
//-------------------------------------------------------------------------
44
public int doStartTag() throws JspException JavaDoc {
45         Tag JavaDoc parent = getParent();
46         if ( parent instanceof PipeConsumer ) {
47             PipeConsumer consumer = (PipeConsumer) parent;
48             consumer.setReader( PipeHelper.getReader( getValue() ) );
49         }
50         else if ( parent instanceof PipeProducer ) {
51             PipeProducer producer = (PipeProducer) parent;
52             producer.setWriter( PipeHelper.getWriter( getValue() ) );
53         }
54         else {
55             throw new JspException JavaDoc( "<io:get> tag must be included inside either a PipeConsumer or PipeProducer tag" );
56         }
57         return SKIP_BODY;
58     }
59     
60     public void release() {
61         super.release();
62         name = null;
63         property = null;
64     }
65     
66     
67    
68     // Properties
69
//-------------------------------------------------------------------------
70
public Object JavaDoc getValue() throws JspException JavaDoc {
71         Object JavaDoc bean = pageContext.findAttribute( name );
72         if ( bean != null ) {
73             if ( property == null ) {
74                 return bean;
75             }
76             else {
77                 return BeanHelper.getProperty( bean, property );
78             }
79         }
80         return null;
81     }
82     
83     public void setName(String JavaDoc name) {
84         this.name = name;
85     }
86     
87     public void setProperty(String JavaDoc property) {
88         this.property = property;
89     }
90 }
91
Popular Tags