001    package org.apache.myfaces.tobago.renderkit.html;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more
005     * contributor license agreements.  See the NOTICE file distributed with
006     * this work for additional information regarding copyright ownership.
007     * The ASF licenses this file to You under the Apache License, Version 2.0
008     * (the "License"); you may not use this file except in compliance with
009     * the License.  You may obtain a copy of the License at
010     *
011     *      http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing, software
014     * distributed under the License is distributed on an "AS IS" BASIS,
015     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016     * See the License for the specific language governing permissions and
017     * limitations under the License.
018     */
019    
020    import org.slf4j.Logger;
021    import org.slf4j.LoggerFactory;
022    
023    import java.util.HashMap;
024    import java.util.Map;
025    
026    /**
027     * @deprecated
028     * @see org.apache.myfaces.tobago.renderkit.css.Style
029     */
030    @Deprecated
031    public class HtmlStyleMap extends HashMap<String, Object> {
032    
033      private static final Logger LOG = LoggerFactory.getLogger(HtmlStyleMap.class);
034      private static final long serialVersionUID = 342607693971417143L;
035    
036      public Object put(String s, Object o) {
037        if (o instanceof String && (s.equals("height") || s.equals("width"))) {
038          String str = (String) o;
039          if (str.endsWith("px")) {
040            LOG.error("", new Exception());
041            o = Integer.parseInt(str.substring(0, str.length() - 2));
042          }
043        }
044        return super.put(s, o);
045      }
046    
047      public Integer getInt(Object o) {
048        Object obj = get(o);
049        if (obj instanceof Integer) {
050          return (Integer) obj;
051        }
052        if (obj == null) {
053          return null;
054        }
055        LOG.error("", new Exception());
056        return Integer.parseInt(obj.toString());
057      }
058    
059      public String toString() {
060        if (entrySet().isEmpty()) {
061          return null;
062        }
063        StringBuilder buf = new StringBuilder();
064        for (Map.Entry<String, Object> style : entrySet()) {
065          buf.append(style.getKey());
066          buf.append(":");
067          buf.append(style.getValue());
068          if (style.getValue() instanceof Integer && !"z-index".equals(style.getKey())) {
069            buf.append("px; ");
070          } else {
071            buf.append("; ");
072          }
073        }
074        return buf.toString();
075      }
076    }