View Javadoc

1   /*
2   * Copyright 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  
18  package jsp2.examples.simpletag;
19  
20  import javax.servlet.jsp.JspException;
21  import javax.servlet.jsp.tagext.JspFragment;
22  import javax.servlet.jsp.tagext.SimpleTagSupport;
23  import java.util.HashMap;
24  import java.io.IOException;
25  
26  /**
27   * SimpleTag handler that accepts takes three attributes of type
28   * JspFragment and invokes then in a random order.
29   */
30  public class ShuffleSimpleTag extends SimpleTagSupport {
31      private JspFragment fragment1;
32      private JspFragment fragment2;
33      private JspFragment fragment3;
34  
35      public void doTag() throws JspException, IOException {
36          switch( (int)(Math.random() * 6) ) {
37              case 0:
38                  fragment1.invoke( null );
39                  fragment2.invoke( null );
40                  fragment3.invoke( null );
41                  break;
42              case 1:
43                  fragment1.invoke( null );
44                  fragment3.invoke( null );
45                  fragment2.invoke( null );
46                  break;
47              case 2:
48                  fragment2.invoke( null );
49                  fragment1.invoke( null );
50                  fragment3.invoke( null );
51                  break;
52              case 3:
53                  fragment2.invoke( null );
54                  fragment3.invoke( null );
55                  fragment1.invoke( null );
56                  break;
57              case 4:
58                  fragment3.invoke( null );
59                  fragment1.invoke( null );
60                  fragment2.invoke( null );
61                  break;
62              case 5:
63                  fragment3.invoke( null );
64                  fragment2.invoke( null );
65                  fragment1.invoke( null );
66                  break;
67          }
68      }
69  
70      public void setFragment1( JspFragment fragment1 ) {
71          this.fragment1 = fragment1;
72      }
73      
74      public void setFragment2( JspFragment fragment2 ) {
75          this.fragment2 = fragment2;
76      }
77      
78      public void setFragment3( JspFragment fragment3 ) {
79          this.fragment3 = fragment3;
80      }
81  }