View Javadoc
1 package com.mlw.fps.view.taglib; 2 3 import java.io.IOException; 4 import java.text.DecimalFormat; 5 6 import javax.servlet.jsp.JspException; 7 import javax.servlet.jsp.JspWriter; 8 9 import org.apache.struts.util.RequestUtils; 10 11 public class PercentageTag extends javax.servlet.jsp.tagext.BodyTagSupport 12 { 13 private String name; 14 private String property; 15 private String format; 16 private float multiplier = (float)1.0; 17 18 /*** Holds value of property scope. */ 19 private String scope; 20 21 public PercentageTag() 22 { 23 super(); 24 } 25 26 public int doStartTag() throws JspException 27 { 28 return EVAL_BODY_AGAIN; 29 } 30 31 public int doEndTag() throws JspException 32 { 33 DecimalFormat formater = new DecimalFormat( (format==null)?"0.00%":format ); 34 Object percent = RequestUtils.lookup(pageContext, name, property, "page"); 35 StringBuffer sb = new StringBuffer(); 36 int round = Math.round( 100*Float.parseFloat(percent.toString()) ); 37 38 if( round > 50) 39 sb.append("<img border=\"0\" src=\"/fps/images/bar_dark_red.gif\" width=\"").append( Math.max((int)multiplier*round,1) ).append("\" height=\"10\">"); 40 else if( round > 10) 41 sb.append("<img border=\"0\" src=\"/fps/images/bar_dark_green.gif\" width=\"").append( Math.max((int)multiplier*round,1) ).append("\" height=\"10\">"); 42 else 43 sb.append("<img border=\"0\" src=\"/fps/images/bar_dark_yellow.gif\" width=\"").append( Math.max((int)multiplier*round,1) ).append("\" height=\"10\">"); 44 45 sb.append( " " ); 46 47 sb.append( formater.format(percent) ); 48 49 try 50 { 51 JspWriter out = pageContext.getOut(); 52 out.print( sb.toString() ); 53 } 54 catch(IOException e) 55 { 56 } 57 58 return SKIP_BODY; 59 } 60 61 /*** Setter for property name. 62 * @param name New value of property name. 63 */ 64 public void setName(String name) 65 { 66 this.name = name; 67 } 68 69 /*** Setter for property property. 70 * @param property New value of property property. 71 */ 72 public void setProperty(String property) 73 { 74 this.property = property; 75 } 76 77 /*** Getter for property format. 78 * @return Value of property format. 79 */ 80 public String getFormat() 81 { 82 return this.format; 83 } 84 85 /*** Setter for property format. 86 * @param format New value of property format. 87 */ 88 public void setFormat(String format) 89 { 90 this.format = format; 91 } 92 93 /*** Setter for property width. 94 * @param width New value of property width. 95 */ 96 public void setWidth(String width) 97 { 98 multiplier = Float.parseFloat(width); 99 } 100 101 /*** Setter for property scope. 102 * @param scope New value of property scope. 103 */ 104 public void setScope(String scope) 105 { 106 this.scope = scope; 107 } 108 109 }

This page was automatically generated by Maven