1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.renderkit.html;
21
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 import java.util.HashMap;
26 import java.util.Map;
27
28
29
30
31
32 @Deprecated
33 public class HtmlStyleMap extends HashMap<String, Object> {
34
35 private static final Logger LOG = LoggerFactory.getLogger(HtmlStyleMap.class);
36 private static final long serialVersionUID = 342607693971417143L;
37
38 public Object put(String s, Object o) {
39 if (o instanceof String && (s.equals("height") || s.equals("width"))) {
40 String str = (String) o;
41 if (str.endsWith("px")) {
42 LOG.error("", new Exception());
43 o = Integer.parseInt(str.substring(0, str.length() - 2));
44 }
45 }
46 return super.put(s, o);
47 }
48
49 public Integer getInt(Object o) {
50 Object obj = get(o);
51 if (obj instanceof Integer) {
52 return (Integer) obj;
53 }
54 if (obj == null) {
55 return null;
56 }
57 LOG.error("", new Exception());
58 return Integer.parseInt(obj.toString());
59 }
60
61 public String toString() {
62 if (entrySet().isEmpty()) {
63 return null;
64 }
65 StringBuilder buf = new StringBuilder();
66 for (Map.Entry<String, Object> style : entrySet()) {
67 buf.append(style.getKey());
68 buf.append(":");
69 buf.append(style.getValue());
70 if (style.getValue() instanceof Integer && !"z-index".equals(style.getKey())) {
71 buf.append("px; ");
72 } else {
73 buf.append("; ");
74 }
75 }
76 return buf.toString();
77 }
78 }