1 | /* |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | package examples; |
---|
18 | |
---|
19 | import javax.servlet.jsp.*; |
---|
20 | import java.io.IOException; |
---|
21 | |
---|
22 | /** |
---|
23 | * Example1: the simplest tag |
---|
24 | * Collect attributes and call into some actions |
---|
25 | * |
---|
26 | * <foo att1="..." att2="...." att3="...." /> |
---|
27 | */ |
---|
28 | |
---|
29 | public class FooTag |
---|
30 | extends ExampleTagBase |
---|
31 | { |
---|
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_BUFFERED; |
---|
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_BUFFERED; |
---|
75 | } catch (IOException ex) { |
---|
76 | throw new JspTagException(ex.toString()); |
---|
77 | } |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|