1 package org.displaytag.decorator; 2 3 import org.apache.commons.lang.StringUtils; 4 import org.displaytag.exception.DecoratorException; 5 6 7 /** 8 * A column decorator which returns 100/value with padding of spaces. 9 * @author Fabrizio Giustina 10 * @version $Revision: 727 $ ($Author: fgiust $) 11 */ 12 public class PercentualColumnDecorator implements ColumnDecorator 13 { 14 15 /** 16 * @see org.displaytag.decorator.ColumnDecorator#decorate(java.lang.Object) 17 */ 18 public String decorate(Object columnValue) throws DecoratorException 19 { 20 int intValue = ((Number) columnValue).intValue(); 21 if (intValue == 0) 22 { 23 intValue = 1; 24 } 25 return StringUtils.leftPad(Integer.toString(100 / intValue), 3); 26 } 27 28 }