public static TermLengthOrPercent createLengthOrPercent ( String spec ) { spec = spec . trim ( ) ; if ( spec . endsWith ( "%" ) ) { try { float val = Float . parseFloat ( spec . substring ( 0 , spec . length ( ) - 1 ) ) ; TermPercent perc = CSSFactory . getTermFactory ( ) . createPercent ( val ) ; return perc ; } catch ( NumberFormatException e ) { return null ; } } else { try { float val = Float . parseFloat ( spec ) ; TermLength len = CSSFactory . getTermFactory ( ) . createLength ( val , TermLength . Unit . px ) ; return len ; } catch ( NumberFormatException e ) { return null ; } } }
Creates a CSS length or percentage from a string .