1 | <html><body><pre> |
---|
2 | /* |
---|
3 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
4 | * contributor license agreements. See the NOTICE file distributed with |
---|
5 | * this work for additional information regarding copyright ownership. |
---|
6 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
7 | * (the "License"); you may not use this file except in compliance with |
---|
8 | * the License. You may obtain a copy of the License at |
---|
9 | * |
---|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
11 | * |
---|
12 | * Unless required by applicable law or agreed to in writing, software |
---|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
15 | * See the License for the specific language governing permissions and |
---|
16 | * limitations under the License. |
---|
17 | */ |
---|
18 | |
---|
19 | |
---|
20 | package jsp2.examples.simpletag; |
---|
21 | |
---|
22 | import javax.servlet.jsp.JspException; |
---|
23 | import javax.servlet.jsp.tagext.JspFragment; |
---|
24 | import javax.servlet.jsp.tagext.SimpleTagSupport; |
---|
25 | import java.io.IOException; |
---|
26 | |
---|
27 | /** |
---|
28 | * SimpleTag handler that accepts takes three attributes of type |
---|
29 | * JspFragment and invokes then in a random order. |
---|
30 | */ |
---|
31 | public class ShuffleSimpleTag extends SimpleTagSupport { |
---|
32 | private JspFragment fragment1; |
---|
33 | private JspFragment fragment2; |
---|
34 | private JspFragment fragment3; |
---|
35 | |
---|
36 | public void doTag() throws JspException, IOException { |
---|
37 | switch( (int)(Math.random() * 6) ) { |
---|
38 | case 0: |
---|
39 | fragment1.invoke( null ); |
---|
40 | fragment2.invoke( null ); |
---|
41 | fragment3.invoke( null ); |
---|
42 | break; |
---|
43 | case 1: |
---|
44 | fragment1.invoke( null ); |
---|
45 | fragment3.invoke( null ); |
---|
46 | fragment2.invoke( null ); |
---|
47 | break; |
---|
48 | case 2: |
---|
49 | fragment2.invoke( null ); |
---|
50 | fragment1.invoke( null ); |
---|
51 | fragment3.invoke( null ); |
---|
52 | break; |
---|
53 | case 3: |
---|
54 | fragment2.invoke( null ); |
---|
55 | fragment3.invoke( null ); |
---|
56 | fragment1.invoke( null ); |
---|
57 | break; |
---|
58 | case 4: |
---|
59 | fragment3.invoke( null ); |
---|
60 | fragment1.invoke( null ); |
---|
61 | fragment2.invoke( null ); |
---|
62 | break; |
---|
63 | case 5: |
---|
64 | fragment3.invoke( null ); |
---|
65 | fragment2.invoke( null ); |
---|
66 | fragment1.invoke( null ); |
---|
67 | break; |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | public void setFragment1( JspFragment fragment1 ) { |
---|
72 | this.fragment1 = fragment1; |
---|
73 | } |
---|
74 | |
---|
75 | public void setFragment2( JspFragment fragment2 ) { |
---|
76 | this.fragment2 = fragment2; |
---|
77 | } |
---|
78 | |
---|
79 | public void setFragment3( JspFragment fragment3 ) { |
---|
80 | this.fragment3 = fragment3; |
---|
81 | } |
---|
82 | } |
---|
83 | </pre></body></html> |
---|