1 16 17 package org.apache.taglibs.random; 18 19 import javax.servlet.jsp.JspException ; 20 import javax.servlet.jsp.PageContext ; 21 import javax.servlet.jsp.tagext.TagSupport ; 22 23 60 61 public class RandomNumTag extends TagSupport { 62 63 66 private long upper = 100; 67 70 private long lower = 0; 71 74 private String algorithm = null; 75 78 private String provider = null; 79 80 91 public final int doStartTag() throws JspException { 92 93 RandomNum random = new RandomNum(); 94 95 random.setRange(lower, upper); 97 98 if (algorithm != null) 101 random.setAlgorithm(algorithm); 102 if (provider != null) 103 random.setProvider(provider); 104 105 random.generateRandomObject(); 107 108 pageContext.setAttribute(id, random, PageContext.PAGE_SCOPE); 111 112 return SKIP_BODY; 113 } 114 115 124 public final void setRange(String value) throws JspException { 125 try { 126 upper = new Integer (value.substring(value.indexOf('-') + 1)).longValue(); 127 } catch (NumberFormatException nfe) { 128 pageContext.getServletContext().log("upper attribute could not be" + 129 " turned into an Integer default value was used"); 130 } 131 try { 132 lower = new Integer (value.substring(0, value.indexOf('-'))).longValue(); 133 } catch (NumberFormatException nfe) { 134 pageContext.getServletContext().log("lower attribute could not be" + 135 " turned into an Integer default value was used"); 136 } 137 138 if (upper < lower) 141 throw new JspException ("You can't have a range where the lowerbound" + 142 " is higher than the upperbound."); 143 } 144 145 151 public final void setAlgorithm(String value) { 152 algorithm = value; 153 } 154 155 161 public final void setProvider(String value) { 162 provider = value; 163 } 164 } 165 | Popular Tags |