source: nutchez-0.1/tomcat/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/ShuffleSimpleTag.java @ 66

Last change on this file since 66 was 66, checked in by waue, 15 years ago

NutchEz - an easy way to nutch

File size: 2.7 KB
Line 
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
19package jsp2.examples.simpletag;
20
21import javax.servlet.jsp.JspException;
22import javax.servlet.jsp.tagext.JspFragment;
23import javax.servlet.jsp.tagext.SimpleTagSupport;
24import 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 */
30public 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}
Note: See TracBrowser for help on using the repository browser.