001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 019 package jsp2.examples.simpletag; 020 021 import java.io.IOException; 022 023 import javax.servlet.jsp.JspException; 024 import javax.servlet.jsp.tagext.JspFragment; 025 import javax.servlet.jsp.tagext.SimpleTagSupport; 026 027 /** 028 * SimpleTag handler that accepts takes three attributes of type 029 * JspFragment and invokes then in a random order. 030 */ 031 public class ShuffleSimpleTag extends SimpleTagSupport { 032 private JspFragment fragment1; 033 private JspFragment fragment2; 034 private JspFragment fragment3; 035 036 public void doTag() throws JspException, IOException { 037 switch ((int) (Math.random() * 6)) { 038 case 0: 039 fragment1.invoke(null); 040 fragment2.invoke(null); 041 fragment3.invoke(null); 042 break; 043 case 1: 044 fragment1.invoke(null); 045 fragment3.invoke(null); 046 fragment2.invoke(null); 047 break; 048 case 2: 049 fragment2.invoke(null); 050 fragment1.invoke(null); 051 fragment3.invoke(null); 052 break; 053 case 3: 054 fragment2.invoke(null); 055 fragment3.invoke(null); 056 fragment1.invoke(null); 057 break; 058 case 4: 059 fragment3.invoke(null); 060 fragment1.invoke(null); 061 fragment2.invoke(null); 062 break; 063 case 5: 064 fragment3.invoke(null); 065 fragment2.invoke(null); 066 fragment1.invoke(null); 067 break; 068 } 069 } 070 071 public void setFragment1(JspFragment fragment1) { 072 this.fragment1 = fragment1; 073 } 074 075 public void setFragment2(JspFragment fragment2) { 076 this.fragment2 = fragment2; 077 } 078 079 public void setFragment3(JspFragment fragment3) { 080 this.fragment3 = fragment3; 081 } 082 }