View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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   * @deprecated
30   * @see org.apache.myfaces.tobago.renderkit.css.Style
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(final String s, Object o) {
39      if (o instanceof String && (s.equals("height") || s.equals("width"))) {
40        final 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(final Object o) {
50      final 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      final StringBuilder buf = new StringBuilder();
66      for (final 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  }