KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > examples > taglib > CustomerFmtTag


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.standard.examples.taglib;
18
19 import java.io.IOException JavaDoc;
20
21 import javax.servlet.jsp.*;
22 import javax.servlet.jsp.tagext.*;
23 import javax.servlet.jsp.jstl.core.*;
24
25 import org.apache.taglibs.standard.examples.beans.Customer;
26
27 /**
28  * <p>Tag handler for &lt;customerFmt&gt;
29  *
30  * @author Pierre Delisle
31  * @version $Revision: 1.3 $ $Date: 2004/02/28 01:01:41 $
32  */

33 public class CustomerFmtTag extends TagSupport {
34     
35     //*********************************************************************
36
// Instance variables
37

38     /** Holds value of property customer. */
39     private Customer customer;
40     
41     /** Holds value of property fmt. */
42     private String JavaDoc fmt;
43     
44     //*********************************************************************
45
// Constructors
46

47     public CustomerFmtTag() {
48         super();
49         init();
50     }
51     
52     private void init() {
53         customer = null;
54         fmt = null;
55     }
56     
57     //*********************************************************************
58
// TagSupport methods
59

60     public int doStartTag() throws JspException {
61         JspWriter out = pageContext.getOut();
62         try {
63             if (fmt.equalsIgnoreCase("short")) {
64                 out.println(customer.getFirstName() + " " +
65                 customer.getLastName());
66             } else if (fmt.equalsIgnoreCase("long")) {
67                 out.println(customer.getFirstName() + " " +
68                 customer.getLastName() + " " + customer.getAddress());
69             } else {
70                 out.println("invalid format");
71             }
72         } catch (IOException JavaDoc ex) {}
73         
74         return SKIP_BODY;
75     }
76     
77     // Releases any resources we may have (or inherit)
78
public void release() {
79         super.release();
80         init();
81     }
82     
83     //*********************************************************************
84
// Accessors
85

86     /**
87      * Getter for property customer.
88      * @return Value of property customer.
89      */

90     public Customer getCustomer() {
91         return customer;
92     }
93     
94     /**
95      * Setter for property customer.
96      * @param customer New value of property customer.
97      */

98     public void setCustomer(Customer customer) {
99         this.customer = customer;
100     }
101     
102     /**
103      * Getter for property fmt.
104      * @return Value of property fmt.
105      */

106     public String JavaDoc getFmt() {
107         return fmt;
108     }
109     
110     /**
111      * Setter for property fmt.
112      * @param fmt New value of property fmt.
113      */

114     public void setFmt(String JavaDoc fmt) {
115         this.fmt = fmt;
116     }
117 }
118
Popular Tags