01: /*
02: * Copyright 2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 examples;
17:
18: import javax.servlet.jsp.*;
19: import javax.servlet.jsp.tagext.*;
20: import java.util.Hashtable;
21: import java.io.Writer;
22: import java.io.IOException;
23:
24: /**
25: * Example1: the simplest tag
26: * Collect attributes and call into some actions
27: *
28: * <foo att1="..." att2="...." att3="...." />
29: */
30:
31: public class FooTag extends ExampleTagBase {
32: private String atts[] = new String[3];
33: int i = 0;
34:
35: private final void setAtt(int index, String value) {
36: atts[index] = value;
37: }
38:
39: public void setAtt1(String value) {
40: setAtt(0, value);
41: }
42:
43: public void setAtt2(String value) {
44: setAtt(1, value);
45: }
46:
47: public void setAtt3(String value) {
48: setAtt(2, value);
49: }
50:
51: /**
52: * Process start tag
53: *
54: * @return EVAL_BODY_INCLUDE
55: */
56: public int doStartTag() throws JspException {
57: i = 0;
58: return EVAL_BODY_TAG;
59: }
60:
61: public void doInitBody() throws JspException {
62: pageContext.setAttribute("member", atts[i]);
63: i++;
64: }
65:
66: public int doAfterBody() throws JspException {
67: try {
68: if (i == 3) {
69: bodyOut.writeOut(bodyOut.getEnclosingWriter());
70: return SKIP_BODY;
71: } else
72: pageContext.setAttribute("member", atts[i]);
73: i++;
74: return EVAL_BODY_TAG;
75: } catch (IOException ex) {
76: throw new JspTagException(ex.toString());
77: }
78: }
79: }
|