CssUtils { public Map<String, String> processBackground(final String background) { Map<String, String> rules = new HashMap<String, String>(); String[] styles = splitComplexCssStyle(background); for(String style : styles) { if (style.contains("url(")) { rules.put(CSS.Property.BACKGROUND_IMAGE, style); } else if (style.equalsIgnoreCase(CSS.Value.REPEAT) || style.equalsIgnoreCase(CSS.Value.NO_REPEAT) || style.equalsIgnoreCase(CSS.Value.REPEAT_X) || style.equalsIgnoreCase(CSS.Value.REPEAT_Y)) { rules.put(CSS.Property.BACKGROUND_REPEAT, style); } else if (style.equalsIgnoreCase(CSS.Value.FIXED) || style.equalsIgnoreCase(CSS.Value.SCROLL)) { rules.put(CSS.Property.BACKGROUND_ATTACHMENT, style); } else if (backgroundPositions.contains(style)) { if(rules.get(CSS.Property.BACKGROUND_POSITION) == null) { rules.put(CSS.Property.BACKGROUND_POSITION, style); } else { style = style.concat(" "+rules.get(CSS.Property.BACKGROUND_POSITION)); rules.put(CSS.Property.BACKGROUND_POSITION, style); } } else if (isNumericValue(style) || isMetricValue(style) || isRelativeValue(style)) { if(rules.get(CSS.Property.BACKGROUND_POSITION) == null) { rules.put(CSS.Property.BACKGROUND_POSITION, style); } else { style = style.concat(" "+rules.get(CSS.Property.BACKGROUND_POSITION)); rules.put(CSS.Property.BACKGROUND_POSITION, style); } } else if(style.contains("rgb(") || style.contains("rgba(") || style.contains("#") || WebColors.NAMES.containsKey(style.toLowerCase())) { rules.put(CSS.Property.BACKGROUND_COLOR, style); } } return rules; } private  CssUtils(); static CssUtils getInstance(); Map<String, String> parseBoxValues(final java.lang.String box,
                                             final java.lang.String pre, final java.lang.String post); Map<String, String> parseBoxValues(final String box,
                                              final String pre, final String post, String preKey); Map<String, String> parseBorder(final String border); Map<String, String> parseBorder(final String border, final String borderKey); String stripDoubleSpacesAndTrim(final String str); String stripDoubleSpacesTrimAndToLowerCase(final String str); Map<String, String> processBackground(final String background); Map<String, String> processListStyle(final String listStyle); Map<String, String> processFont(final String font); float checkMetricStyle(final Tag t, final String style); Float checkMetricStyle(final Map<String,String> css, final String style); boolean isMetricValue(final String value); boolean isRelativeValue(final String value); boolean isNumericValue(final String value); float parseValueToPt(final String value, final float baseValue); float parseRelativeValue(final String relativeValue, final float baseValue); float parsePxInCmMmPcToPt(final String length, final String defaultMetric); float parsePxInCmMmPcToPt(final String length); int determinePositionBetweenValueAndUnit(final String string); float getLeftAndRightMargin(final Tag t, final float pageWidth); String extractUrl(final String url); float validateTextHeight(final Map<String, String> css,
			float textHeight); float calculateMarginTop(final String value, final float largestFont, final MarginMemory configuration); float calculateMarginTop(final float value, final MarginMemory configuration); String trimAndRemoveQuoutes(String s); String[] splitComplexCssStyle(String s); static final int DEFAULT_FONT_SIZE_PT; }
@Test public void splitBackgroundOne() { Map<String, String> background = css.processBackground("#00ff00 url('smiley.gif') no-repeat fixed center top"); Assert.assertEquals("#00ff00", background.get("background-color")); Assert.assertEquals("url('smiley.gif')", background.get("background-image")); Assert.assertEquals("no-repeat", background.get("background-repeat")); Assert.assertEquals("fixed", background.get("background-attachment")); Assert.assertEquals("top center", background.get("background-position")); }
@Test public void splitBackgroundTwo() { Map<String, String> background = css .processBackground("rgdbq(150, 90, 60) url'smiley.gif') repeat-x scroll 20 60%"); Assert.assertEquals(null, background.get("background-color")); Assert.assertEquals(null, background.get("background-image")); Assert.assertEquals("repeat-x", background.get("background-repeat")); Assert.assertEquals("scroll", background.get("background-attachment")); Assert.assertEquals("60% 20", background.get("background-position")); }
@Test public void splitBackgroundThree() { Map<String, String> background = css.processBackground("DarkOliveGreen fixed center"); Assert.assertEquals("DarkOliveGreen", background.get("background-color")); Assert.assertEquals(null, background.get("background-image")); Assert.assertEquals(null, background.get("background-repeat")); Assert.assertEquals("fixed", background.get("background-attachment")); Assert.assertEquals("center", background.get("background-position")); }