View Javadoc

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  
18  
19  package jsp2.examples.simpletag;
20  
21  import java.io.IOException;
22  
23  import javax.servlet.jsp.JspException;
24  import javax.servlet.jsp.tagext.JspFragment;
25  import javax.servlet.jsp.tagext.SimpleTagSupport;
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  }