001    package org.apache.myfaces.tobago.layout;
002    
003    import org.apache.commons.lang.StringUtils;
004    
005    /*
006     * User: lofwyr
007     * Date: 23.01.2008 20:12:30
008     */
009    public abstract class Measure {
010    
011      // todo: refactor and consolidate with LayoutToken
012    
013      public static Measure parse(String value) {
014        if (StringUtils.isEmpty(value)) {
015          return new PixelMeasure(0); // fixme: may return a "default measure", or is Pixel the default?
016        }
017        if (value.toLowerCase().matches("\\d+px")) {// XXX no regexp here: user LayoutTokens.parse !!!
018          return new PixelMeasure(Integer.parseInt(value.substring(0, value.length() - 2)));
019        }
020        throw new IllegalArgumentException("Can't parse to any measure: '" + value + "'");
021      }
022    
023      public abstract Measure add(Measure m);
024    
025      public abstract Measure substractNotNegative(Measure m);
026    
027      public abstract int getPixel();
028    }