1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.css;
16
17 import java.util.HashMap;
18 import java.util.Locale;
19 import java.util.Map;
20
21
22
23
24
25
26 public final class CssColors {
27
28 private static final Map<String, String> CSS_COLORS = new HashMap<>();
29
30 static {
31 CSS_COLORS.put("aqua", "rgb(0, 255, 255)");
32 CSS_COLORS.put("black", "rgb(0, 0, 0)");
33 CSS_COLORS.put("blue", "rgb(0, 0, 255)");
34 CSS_COLORS.put("fuchsia", "rgb(255, 0, 255)");
35 CSS_COLORS.put("gray", "rgb(128, 128, 128)");
36 CSS_COLORS.put("green", "rgb(0, 128, 0)");
37 CSS_COLORS.put("lime", "rgb(0, 255, 0)");
38 CSS_COLORS.put("maroon", "rgb(128, 0, 0)");
39 CSS_COLORS.put("navy", "rgb(0, 0, 128)");
40 CSS_COLORS.put("olive", "rgb(128, 128, 0)");
41 CSS_COLORS.put("purple", "rgb(128, 0, 128)");
42 CSS_COLORS.put("red", "rgb(255, 0, 0)");
43 CSS_COLORS.put("silver", "rgb(192, 192, 192)");
44 CSS_COLORS.put("teal", "rgb(0, 128, 128)");
45 CSS_COLORS.put("white", "rgb(255, 255, 255)");
46 CSS_COLORS.put("yellow", "rgb(255, 255, 0)");
47 }
48
49 private CssColors() {
50
51 }
52
53
54
55
56
57
58 public static boolean isColorKeyword(final String token) {
59 return CSS_COLORS.containsKey(token.toLowerCase(Locale.ROOT));
60 }
61
62
63
64
65
66
67
68 public static String toRGBColor(final String color) {
69 final String rgbValue = CSS_COLORS.get(color.toLowerCase(Locale.ROOT));
70 if (rgbValue != null) {
71 return rgbValue;
72 }
73 return color;
74 }
75 }