You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2006/11/27 00:05:55 UTC

svn commit: r479448 - in /myfaces/tobago/trunk: core/src/main/java/org/apache/myfaces/tobago/component/ core/src/main/java/org/apache/myfaces/tobago/renderkit/ core/src/main/java/org/apache/myfaces/tobago/renderkit/html/ theme/scarborough/src/main/java...

Author: bommel
Date: Sun Nov 26 15:05:54 2006
New Revision: 479448

URL: http://svn.apache.org/viewvc?view=rev&rev=479448
Log:
TOBAGO-200 Changed internal style attribute from String to a Map based implementation

Added:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlStyleMap.java
Removed:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/StyleAttribute.java
Modified:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIGridLayout.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java
    myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/BoxRenderer.java
    myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/GridLayoutRenderer.java
    myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
    myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java
    myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ToolBarRenderer.java
    myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/BoxRenderer.java
    myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/TabGroupRenderer.java

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIGridLayout.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIGridLayout.java?view=diff&rev=479448&r1=479447&r2=479448
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIGridLayout.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIGridLayout.java Sun Nov 26 15:05:54 2006
@@ -72,7 +72,7 @@
     if (vb != null) {
       return (String) vb.getValue(getFacesContext());
     } else {
-      return marginTop;
+      return getMargin();
     }
   }
 
@@ -84,7 +84,7 @@
     if (vb != null) {
       return (String) vb.getValue(getFacesContext());
     } else {
-      return marginRight;
+      return getMargin();
     }
   }
 
@@ -96,7 +96,7 @@
     if (vb != null) {
       return (String) vb.getValue(getFacesContext());
     } else {
-      return marginBottom;
+      return getMargin();
     }
   }
 
@@ -108,7 +108,7 @@
     if (vb != null) {
       return (String) vb.getValue(getFacesContext());
     } else {
-      return marginLeft;
+      return getMargin();
     }
   }
 

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java?view=diff&rev=479448&r1=479447&r2=479448
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java Sun Nov 26 15:05:54 2006
@@ -216,7 +216,12 @@
     }
     return sb.toString();
   }
-
+  public static Integer getStyleAttributeIntValue(HtmlStyleMap style, String name) {
+    if (style == null) {
+      return null;
+    }
+    return style.getInt(name);
+  }
   public static String getStyleAttributeValue(String style, String name) {
     if (style == null) {
       return null;
@@ -232,11 +237,40 @@
     return value;
   }
 
+
   public static void replaceStyleAttribute(UIComponent component, String styleAttribute, String value) {
+    HtmlStyleMap style = ensureStyleAttributeMap(component);
+    style.put(styleAttribute, value);
+  }
+
+  public static void replaceStyleAttribute(UIComponent component, String attribute, String styleAttribute, String value) {
+    HtmlStyleMap style = ensureStyleAttributeMap(component, attribute);
+    style.put(styleAttribute, value);
+  }
+
+  public static void replaceStyleAttribute(UIComponent component, String styleAttribute, int value) {
+    HtmlStyleMap style = ensureStyleAttributeMap(component);
+    style.put(styleAttribute, value);
+  }
+
+  public static void replaceStyleAttribute(UIComponent component, String attribute, String styleAttribute, int value) {
+    HtmlStyleMap style = ensureStyleAttributeMap(component, attribute);
+    style.put(styleAttribute, value);
+
+  }
+
+  private static HtmlStyleMap ensureStyleAttributeMap(UIComponent component) {
+    return ensureStyleAttributeMap(component, ATTR_STYLE);
+  }
+
+  private static HtmlStyleMap ensureStyleAttributeMap(UIComponent component, String attribute) {
     final Map attributes = component.getAttributes();
-    String style = (String) attributes.get(ATTR_STYLE);
-    style = replaceStyleAttribute(style, styleAttribute, value);
-    attributes.put(ATTR_STYLE, style);
+    HtmlStyleMap style = (HtmlStyleMap) attributes.get(attribute);
+    if (style == null) {
+      style = new HtmlStyleMap();
+      attributes.put(attribute, style);
+    }
+    return style;
   }
 
   public static String replaceStyleAttribute(String style, String name,
@@ -319,7 +353,7 @@
           }
         }
 
-        replaceStyleAttribute(component, styleAttribute, styleSpace + "px");
+        replaceStyleAttribute(component, styleAttribute, styleSpace);
 
       }
       UIComponent layout = component.getFacet(FACET_LAYOUT);
@@ -340,14 +374,14 @@
 
   public static void createHeaderAndBodyStyles(FacesContext facesContext, UIComponent component, boolean width) {
     RendererBase renderer = ComponentUtil.getRenderer(facesContext, component);
-    String style = (String) component.getAttributes().get(ATTR_STYLE);
-    int styleSpace = -1;
+    HtmlStyleMap style = (HtmlStyleMap) component.getAttributes().get(ATTR_STYLE);
+    Integer styleSpace = null;
     try {
-      styleSpace = Integer.parseInt(getStyleAttributeValue(style, width ? "width" : "height").replaceAll("\\D", ""));
+      styleSpace = style.getInt(width ? "width" : "height");
     } catch (Exception e) {
       /* ignore */
     }
-    if (styleSpace != -1) {
+    if (styleSpace != null) {
       int bodySpace = 0;
       int headerSpace = 0;
       if (!width) {
@@ -356,34 +390,15 @@
         }
         bodySpace = styleSpace - headerSpace;
       }
-
-      String headerStyle;
-      String bodyStyle;
+      HtmlStyleMap headerStyle = ensureStyleAttributeMap(component, ATTR_STYLE_HEADER);
+      HtmlStyleMap bodyStyle = ensureStyleAttributeMap(component, ATTR_STYLE_BODY); 
       if (width) {
-        headerStyle = "width: " + styleSpace + "px;";
-        bodyStyle = "width: " + styleSpace + "px;";
+        headerStyle.put("width", styleSpace);
+        bodyStyle.put("width",  styleSpace);
       } else {
-        headerStyle =
-            (String)
-            component.getAttributes().get(ATTR_STYLE_HEADER);
-        if (headerStyle == null) {
-          LOG.warn("headerStyle attribute == null, set to empty String");
-          headerStyle = "";
-        }
-        headerStyle
-            = headerStyle.replaceAll("height:\\s\\d+px;", "").trim();
-        headerStyle += " height: " + headerSpace + "px;";
-        bodyStyle
-            = (String) component.getAttributes().get(ATTR_STYLE_BODY);
-        if (bodyStyle == null) {
-          LOG.warn("bodyStyle attribute == null, set to empty String");
-          bodyStyle = "";
-        }
-        bodyStyle = bodyStyle.replaceAll("height:\\s\\d+px;", "").trim();
-        bodyStyle += " height: " + bodySpace + "px;";
+        headerStyle.put("height", headerSpace);
+        bodyStyle.put("height", bodySpace);
       }
-      component.getAttributes().put(ATTR_STYLE_HEADER, headerStyle);
-      component.getAttributes().put(ATTR_STYLE_BODY, bodyStyle);
     }
   }
 
@@ -681,5 +696,23 @@
   public static String getEmptyHref(FacesContext facesContext) {
     ClientProperties clientProperties = ClientProperties.getInstance(facesContext);
     return clientProperties.getUserAgent().isMsie() ? "#" : "javascript:;";
+  }
+
+  public static String toStyleString(String key, Integer value) {
+    StringBuilder buf = new StringBuilder();
+    buf.append(key);
+    buf.append(":");
+    buf.append(value);
+    buf.append("px; ");
+    return buf.toString();
+  }
+
+  public static String toStyleString(String key, String value) {
+    StringBuilder buf = new StringBuilder();
+    buf.append(key);
+    buf.append(":");
+    buf.append(value);
+    buf.append("; ");
+    return buf.toString();
   }
 }

Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlStyleMap.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlStyleMap.java?view=auto&rev=479448
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlStyleMap.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlStyleMap.java Sun Nov 26 15:05:54 2006
@@ -0,0 +1,73 @@
+package org.apache.myfaces.tobago.renderkit.html;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/*
+ * Created by IntelliJ IDEA.
+ * User: bommel
+ * Date: Nov 24, 2006
+ * Time: 10:07:33 PM
+ */
+public class HtmlStyleMap extends HashMap<String, Object> {
+
+  private static final Log LOG = LogFactory.getLog(HtmlStyleMap.class);
+
+  public Object put(String s, Object o) {
+    if (o instanceof String && ( s.equals("height")|| s.equals("width"))) {
+      String str = (String) o;
+      if (str.endsWith("px")) {
+        LOG.error("", new Exception());
+        o = Integer.parseInt(str.substring(0, str.length() - 2));
+      }
+    }
+    return super.put(s, o);
+  }
+
+  public Integer getInt(Object o) {
+    Object obj = get(o);
+    if (obj instanceof Integer) {
+      return (Integer) obj;
+    }
+    if (obj == null) {
+      return null;
+    }
+    LOG.error("", new Exception());
+    return Integer.parseInt(obj.toString());
+  }
+
+  public String toString() {
+    StringBuilder buf = new StringBuilder();
+    for(Map.Entry<String,Object> style :entrySet()) {
+      buf.append(style.getKey());
+      buf.append(":");
+      buf.append(style.getValue());
+      if (style.getValue() instanceof Integer) {
+        buf.append("px; ");
+      } else {
+        buf.append("; ");
+      }
+    }
+    return buf.toString();
+  }
+}

Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/BoxRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/BoxRenderer.java?view=diff&rev=479448&r1=479447&r2=479448
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/BoxRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/BoxRenderer.java Sun Nov 26 15:05:54 2006
@@ -57,23 +57,18 @@
     UIComponent label = component.getFacet(FACET_LABEL);
     String labelString
         = (String) component.getAttributes().get(ATTR_LABEL);
-    String style = (String) component.getAttributes().get(getAttrStyleKey());
     UIPanel toolbar = (UIPanel) component.getFacet(FACET_TOOL_BAR);
     if (toolbar != null) {
-      final int padding
-          = getConfiguredValue(facesContext, component, "paddingTopWhenToolbar");
-      style = HtmlRendererUtil.replaceStyleAttribute(style, "padding-top",
-          Integer.toString(padding) + "px");
-      style = HtmlRendererUtil.replaceStyleAttribute(style, "padding-bottom", "0px");
+      final int padding = getConfiguredValue(facesContext, component, "paddingTopWhenToolbar");
+      HtmlRendererUtil.replaceStyleAttribute(component, getAttrStyleKey(), "padding-top", padding);
+      HtmlRendererUtil.replaceStyleAttribute(component, getAttrStyleKey(), "padding-bottom", 0);
     }
 
     TobagoResponseWriter writer = (TobagoResponseWriter) facesContext.getResponseWriter();
 
     writer.startElement(HtmlConstants.FIELDSET, component);
     writer.writeComponentClass();
-    if (style != null) {
-      writer.writeAttribute(HtmlAttributes.STYLE, style, null);
-    }
+    writer.writeAttribute(HtmlAttributes.STYLE, null, getAttrStyleKey());
 
     if (label != null || labelString != null) {
       writer.startElement(HtmlConstants.LEGEND, component);

Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/GridLayoutRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/GridLayoutRenderer.java?view=diff&rev=479448&r1=479447&r2=479448
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/GridLayoutRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/GridLayoutRenderer.java Sun Nov 26 15:05:54 2006
@@ -30,12 +30,6 @@
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_INNER_HEIGHT;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_INNER_WIDTH;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LAYOUT_HEIGHT;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_MARGIN;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_MARGIN_BOTTOM;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_MARGIN_LEFT;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_MARGIN_RIGHT;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_MARGIN_TOP;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LAYOUT_TABLE_STYLE;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LAYOUT_WIDTH;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ROWS;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SCROLLBARS;
@@ -53,6 +47,7 @@
 import org.apache.myfaces.tobago.renderkit.html.HtmlRendererUtil;
 import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
 import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
+import org.apache.myfaces.tobago.renderkit.html.HtmlStyleMap;
 import org.apache.myfaces.tobago.util.LayoutInfo;
 import org.apache.myfaces.tobago.util.LayoutUtil;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
@@ -116,6 +111,8 @@
     int size = Math.min(rows.size(), layoutTokens.length);
 
     int height = 0;
+  //  height += getMarginAsInt(layout.getMarginTop());
+  //  height += getMarginAsInt(layout.getMarginBottom());
     for (int i = 0; i < size; i++) {
       if (!rowIsRendered(rows.get(i))) {
         continue;
@@ -172,7 +169,7 @@
     writer.startElement(HtmlConstants.TABLE, layout);
     writer.writeAttribute(HtmlAttributes.BORDER, null, ATTR_BORDER);
     writer.writeComponentClass();
-    writer.writeAttribute(HtmlAttributes.STYLE, null, ATTR_LAYOUT_TABLE_STYLE);
+    writer.writeAttribute(HtmlAttributes.STYLE, null, ATTR_STYLE);
     writer.writeAttribute(HtmlAttributes.CELLSPACING, "0", null);
     writer.writeAttribute(HtmlAttributes.CELLPADDING, "0", null);
     writer.writeAttribute(HtmlAttributes.SUMMARY, "", null);
@@ -180,8 +177,7 @@
     if (columnWidths != null) {
       writer.startElement(HtmlConstants.COLGROUP, null);
       for (int i = 0; i < columnWidths.size(); i++) {
-        int cellWidth
-            = ((Integer) columnWidths.get(i)).intValue();
+        int cellWidth = ((Integer) columnWidths.get(i)).intValue();
         if (cellWidth != LayoutInfo.HIDE) {
           cellWidth += getCellPadding(facesContext, layout, i);
           writer.startElement(HtmlConstants.COL, null);
@@ -375,8 +371,7 @@
   }
 
   private int getCellSpacing(FacesContext facesContext, UIComponent component) {
-    String cellspacing = (String) component.getAttributes().get(
-        ATTR_CELLSPACING);
+    String cellspacing = (String) component.getAttributes().get(ATTR_CELLSPACING);
     if (cellspacing instanceof String) {
       try {
         return Integer.parseInt(cellspacing);
@@ -421,10 +416,7 @@
           = innerWidth.intValue() - getWidthSpacingSum(layout, facesContext);
       if (needVerticalScroolbar) {
         value -= getConfiguredValue(facesContext, component, "scrollbarWidth");
-        String style = (String) layout.getAttributes().get(ATTR_STYLE);
-        style = HtmlRendererUtil.replaceStyleAttribute(style, "width",
-            Integer.toString(value) + "px");
-        layout.getAttributes().put(ATTR_STYLE, style);
+        HtmlRendererUtil.replaceStyleAttribute(layout, "width", value);
       }
       layoutWidth(new Integer(value), layout, facesContext);
     }
@@ -694,7 +686,6 @@
     }
   }
 
-// ///////////////////////////////////////////// LayoutManager implementation
 
   public void layoutBegin(FacesContext facesContext, UIComponent component) {
     LOG.info("############################## layoutBegin +++++++++++++++++++++++++++++++++++++++++");
@@ -707,60 +698,38 @@
   }
 
   private void layoutMargins(UIGridLayout layout) {
-    String margin
-        = (String) layout.getAttributes().get(
-            ATTR_MARGIN);
-    String marginTop
-        = getMargin(layout, ATTR_MARGIN_TOP, margin);
-    String marginRight
-        = getMargin(layout, ATTR_MARGIN_RIGHT, margin);
-    String marginBottom
-        = getMargin(layout, ATTR_MARGIN_BOTTOM, margin);
-    String marginLeft
-        = getMargin(layout, ATTR_MARGIN_LEFT, margin);
 
-    String style = (String) layout.getAttributes().get(
-        ATTR_STYLE);
+    HtmlStyleMap style = (HtmlStyleMap) layout.getAttributes().get(ATTR_STYLE);
 
     if (style != null) {
-      style = addStyle(style, "margin-top", marginTop);
-      style = addStyle(style, "margin-right", marginRight);
-      style = addStyle(style, "margin-bottom", marginBottom);
-      style = addStyle(style, "margin-left", marginLeft);
-
-      layout.getAttributes().put(ATTR_LAYOUT_TABLE_STYLE,
-          style);
-    }
-  }
-
-  private String addStyle(String style, String attribute, String value) {
-    if (value != null) {
-      style += " " + attribute + ": " + value + ";";
-    }
-    return style;
-  }
+      int marginTop = getMarginAsInt(layout.getMarginTop());
+      int marginRight = getMarginAsInt(layout.getMarginRight());
+      int marginBottom = getMarginAsInt(layout.getMarginBottom());
+      int marginLeft = getMarginAsInt(layout.getMarginLeft());
+      if(marginTop > 0) {
+        style.put("margin-top", marginTop);
+      }
+      if(marginRight > 0) {
+        style.put("margin-right", marginRight);
+      }
+      if(marginBottom > 0) {
+        style.put("margin-bottom", marginBottom);
+      }
+      if(marginLeft > 0) {
+        style.put("margin-left", marginLeft);
+      }
 
-  private String getMargin(UIGridLayout layout, String attribute,
-      String defaultMargin) {
-    String margin = (String) layout.getAttributes().get(attribute);
-    if (margin == null && defaultMargin != null) {
-      margin = defaultMargin;
+      //layout.getAttributes().put(ATTR_LAYOUT_TABLE_STYLE, style);
     }
-    return margin;
   }
 
   public int getComponentExtraWidth(FacesContext facesContext,
       UIComponent component) {
     int extra = 0;
     UIGridLayout layout = (UIGridLayout) component;
-    String margin
-        = (String) layout.getAttributes().get(
-            ATTR_MARGIN);
-
-    extra += getMaginAsInt(
-        getMargin(layout, ATTR_MARGIN_RIGHT, margin));
-    extra += getMaginAsInt(
-        getMargin(layout, ATTR_MARGIN_LEFT, margin));
+
+    extra += getMarginAsInt(layout.getMarginRight());
+    extra += getMarginAsInt(layout.getMarginLeft());
 
     return extra;
   }
@@ -769,22 +738,17 @@
       UIComponent component) {
     int extra = 0;
     UIGridLayout layout = (UIGridLayout) component;
-    String margin
-        = (String) layout.getAttributes().get(
-            ATTR_MARGIN);
-
-    extra += getMaginAsInt(
-        getMargin(layout, ATTR_MARGIN_TOP, margin));
-    extra += getMaginAsInt(
-        getMargin(layout, ATTR_MARGIN_BOTTOM, margin));
+
+    extra += getMarginAsInt(layout.getMarginTop());
+    extra += getMarginAsInt(layout.getMarginBottom());
     return extra;
   }
 
-  private int getMaginAsInt(String margin) {
-    int intValue = 0;
+  private int getMarginAsInt(String margin) {
     if (margin != null) {
+      margin = removePx(margin);
       try {
-        intValue += Integer.parseInt(margin.replaceAll("\\D", ""));
+        return Integer.parseInt(margin);
       } catch (NumberFormatException e) {
         if (LOG.isWarnEnabled()) {
           LOG.warn("Illegal Margin : " + margin
@@ -792,8 +756,14 @@
         }
       }
     }
-    return intValue;
+    return 0;
   }
 
+  private String removePx(String margin) {
+    if (margin!=null&&margin.endsWith("px")) {
+      margin = margin.substring(0, margin.length() - 2);
+    }
+    return margin;
+  }
 }
 

Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java?view=diff&rev=479448&r1=479447&r2=479448
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java Sun Nov 26 15:05:54 2006
@@ -77,6 +77,7 @@
 import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
 import org.apache.myfaces.tobago.renderkit.html.HtmlRendererUtil;
+import org.apache.myfaces.tobago.renderkit.html.HtmlStyleMap;
 import org.apache.myfaces.tobago.util.StringUtil;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
 
@@ -117,7 +118,7 @@
     HtmlRendererUtil.createHeaderAndBodyStyles(facesContext, data);
 
     final String sheetId = data.getClientId(facesContext);
-    String sheetStyle = (String) data.getAttributes().get(ATTR_STYLE);
+    HtmlStyleMap sheetStyle = (HtmlStyleMap) data.getAttributes().get(ATTR_STYLE);
 
     TobagoResponseWriter writer
         = (TobagoResponseWriter) facesContext.getResponseWriter();
@@ -188,22 +189,17 @@
         .getImage(viewRoot, "image/sheetUnchecked.gif");
 
     Map attributes = data.getAttributes();
-    String sheetStyle = (String) attributes.get(ATTR_STYLE);
-    String headerStyle =
-        (String) attributes.get(ATTR_STYLE_HEADER);
+    HtmlStyleMap sheetStyle = (HtmlStyleMap) attributes.get(ATTR_STYLE);
+    //HtmlStyleMap headerStyle = (HtmlStyleMap) attributes.get(ATTR_STYLE_HEADER);
 //    String sheetWidthString = LayoutUtil.getStyleAttributeValue(sheetStyle,
 //        "width");
-    String sheetHeightString
-        = HtmlRendererUtil.getStyleAttributeValue(sheetStyle, "height");
-    int sheetHeight;
-    if (sheetHeightString != null) {
-      sheetHeight = Integer.parseInt(sheetHeightString.replaceAll("\\D", ""));
-    } else {
+    Integer sheetHeight = HtmlRendererUtil.getStyleAttributeIntValue(sheetStyle, "height");
+    if (sheetHeight == null) {
       // FIXME: nullpointer if height not defined
       LOG.error("no height in parent container, setting to 100");
       sheetHeight = 100;
     }
-    String bodyStyle = (String) attributes.get(ATTR_STYLE_BODY);
+    //HtmlStyleMap bodyStyle = (HtmlStyleMap) attributes.get(ATTR_STYLE_BODY);
     int footerHeight = (Integer) attributes.get(ATTR_FOOTER_HEIGHT);
 
     String selectable = data.getSelectable();
@@ -239,7 +235,10 @@
       writer.startElement(HtmlConstants.DIV, null);
       writer.writeIdAttribute(sheetId + "_header_div");
       writer.writeClassAttribute("tobago-sheet-header-div");
-      writer.writeAttribute(HtmlAttributes.STYLE, headerStyle, null);
+      HtmlStyleMap headerStyle = (HtmlStyleMap) attributes.get(ATTR_STYLE_HEADER);
+      if (headerStyle != null) {
+        writer.writeAttribute(HtmlAttributes.STYLE, headerStyle, null);
+      }
 
       int columnCount = 0;
       final int sortMarkerWidth = getAscendingMarkerWidth(facesContext, data);
@@ -264,32 +263,26 @@
     }
 
 // BEGIN RENDER BODY CONTENT
-    bodyStyle = HtmlRendererUtil.replaceStyleAttribute(bodyStyle, "height",
-        (sheetHeight - footerHeight) + "px");
-    String space = HtmlRendererUtil.getStyleAttributeValue(bodyStyle, "width");
-    String sheetBodyStyle;
+    HtmlStyleMap bodyStyle = (HtmlStyleMap) attributes.get(ATTR_STYLE_BODY);
+    HtmlRendererUtil.replaceStyleAttribute(data, ATTR_STYLE_BODY, "height", (sheetHeight - footerHeight));
+    writer.startElement(HtmlConstants.DIV, null);
+    writer.writeIdAttribute(sheetId + "_data_div");
+    writer.writeClassAttribute("tobago-sheet-body-div ");
+    writer.writeAttribute(HtmlAttributes.STYLE, bodyStyle.toString() + (showHeader?"":" padding-top: 0px;"), null);
+    Integer space = HtmlRendererUtil.getStyleAttributeIntValue(bodyStyle, "width");
+    HtmlStyleMap sheetBodyStyle = (HtmlStyleMap) bodyStyle.clone();
+    //String sheetBodyStyle;
     if (space != null) {
-      int intSpace = Integer.parseInt(space.replaceAll("\\D", ""));
 //      intSpace -= columnWidths.get(columnWidths.size() - 1);
-      intSpace -= getContentBorder(facesContext, data);
+      space -= getContentBorder(facesContext, data);
       if (needVerticalScrollbar(facesContext, data)) {
-        intSpace -= getScrollbarWidth(facesContext, data);
+        space -= getScrollbarWidth(facesContext, data);
       }
-      sheetBodyStyle =
-          HtmlRendererUtil.replaceStyleAttribute(bodyStyle, "width", intSpace + "px");
-    } else {
-      sheetBodyStyle = bodyStyle;
+      sheetBodyStyle.put("width", space);
     }
-    sheetBodyStyle = HtmlRendererUtil.removeStyleAttribute(sheetBodyStyle, "height");
+    sheetBodyStyle.remove("height");
 
-    if (!showHeader) {
-      bodyStyle += " padding-top: 0px;";
-    }
 
-    writer.startElement(HtmlConstants.DIV, null);
-    writer.writeIdAttribute(sheetId + "_data_div");
-    writer.writeClassAttribute("tobago-sheet-body-div ");
-    writer.writeAttribute(HtmlAttributes.STYLE, bodyStyle, null);
 
     writer.startElement(HtmlConstants.TABLE, null);
     writer.writeAttribute(HtmlAttributes.CELLSPACING, "0", null);
@@ -352,17 +345,11 @@
       for (UIColumn column : data.getRendererdColumns()) {
         columnIndex++;
 
-        final String style = "width: " + columnWidths.get(columnIndex) + "px;";
-        String tdStyle = "";
-        final String align = (String) column.getAttributes().get(ATTR_ALIGN);
-        if (align != null) {
-          tdStyle = "text-align: " + align;
-        }
         final String cellClass = (String) column.getAttributes().get(ATTR_STYLE_CLASS);
 
         final StringBuilder tdClass = new StringBuilder();
         tdClass.append("tobago-sheet-cell-td ");
-        HtmlRendererUtil.addMarkupClass(column, "sheet-cell", tdClass);
+        HtmlRendererUtil.addMarkupClass(column, "column", tdClass);
         if (columnIndex == 0) {
           tdClass.append("tobago-sheet-cell-first-column ");
         }
@@ -373,13 +360,16 @@
         writer.startElement(HtmlConstants.TD, column);
 
         writer.writeClassAttribute(tdClass.toString());
-        writer.writeAttribute(HtmlAttributes.STYLE, tdStyle, null);
-
+        final String align = (String) column.getAttributes().get(ATTR_ALIGN);
+        if (align != null) {
+          writer.writeAttribute(HtmlAttributes.STYLE, HtmlRendererUtil.toStyleString("text-align", align) , null);
+        }
         writer.startElement(HtmlConstants.DIV, null);
         writer.writeIdAttribute(
             sheetId + "_data_row_" + visibleIndex + "_column" + columnIndex);
         writer.writeClassAttribute("tobago-sheet-cell-outer");
-        writer.writeAttribute(HtmlAttributes.STYLE, style, null);
+        writer.writeAttribute(HtmlAttributes.STYLE,
+            HtmlRendererUtil.toStyleString("width", columnWidths.get(columnIndex)), null);
 
         writer.startElement(HtmlConstants.DIV, null);
         writer.writeClassAttribute("tobago-sheet-cell-inner");
@@ -447,9 +437,12 @@
     if (isValidPagingValue(showRowRange)
         || isValidPagingValue(showPageRange)
         || isValidPagingValue(showDirectLinks)) {
-      final String footerStyle = HtmlRendererUtil.replaceStyleAttribute(bodyStyle,
-          "height", footerHeight + "px")
-          + " top: " + (sheetHeight - footerHeight) + "px;";
+      final HtmlStyleMap footerStyle = (HtmlStyleMap) bodyStyle.clone();
+      footerStyle.put("height", footerHeight);
+      footerStyle.put("top", (sheetHeight - footerHeight));
+
+        //  "height", MessageFormat.format("{0}px", footerHeight));
+        //  + " top: " + (sheetHeight - footerHeight) + "px;";
 
       writer.startElement(HtmlConstants.DIV, data);
       writer.writeClassAttribute("tobago-sheet-footer");
@@ -628,10 +621,9 @@
       }
     }
 
-    String style = (String) data.getAttributes().get(
-        ATTR_STYLE);
-    String heightString = HtmlRendererUtil.getStyleAttributeValue(style, "height");
-    if (heightString != null) {
+    HtmlStyleMap style = (HtmlStyleMap) data.getAttributes().get(ATTR_STYLE);
+    Integer height = HtmlRendererUtil.getStyleAttributeIntValue(style, "height");
+    if (height != null) {
       int first = data.getFirst();
       int rows = Math.min(data.getRowCount(), first + data.getRows()) - first;
       int heightNeeded = getHeaderHeight(facesContext, data)
@@ -639,7 +631,6 @@
           + (rows * (getFixedHeight(facesContext, null)
           + getRowPadding(facesContext, data)));
 
-      int height = Integer.parseInt(heightString.replaceAll("\\D", ""));
       return heightNeeded > height;
     } else {
       return false;

Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java?view=diff&rev=479448&r1=479447&r2=479448
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java Sun Nov 26 15:05:54 2006
@@ -47,10 +47,10 @@
 import org.apache.myfaces.tobago.renderkit.LabelWithAccessKey;
 import org.apache.myfaces.tobago.renderkit.RenderUtil;
 import org.apache.myfaces.tobago.renderkit.RendererBase;
-import org.apache.myfaces.tobago.renderkit.StyleAttribute;
 import org.apache.myfaces.tobago.renderkit.html.HtmlRendererUtil;
 import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
 import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
+import org.apache.myfaces.tobago.renderkit.html.HtmlStyleMap;
 import org.apache.myfaces.tobago.util.AccessKeyMap;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
 
@@ -150,10 +150,10 @@
 
       if (SWITCH_TYPE_CLIENT.equals(switchType) || virtualTab == activeIndex) {
 
-        StyleAttribute oStyle = new StyleAttribute(
-            (String) component.getAttributes().get(ATTR_STYLE));
+
+
         if (virtualTab != activeIndex) {
-          oStyle.add("display", "none");
+          HtmlRendererUtil.replaceStyleAttribute(component, "display", "none");
         }
         writer.startElement(HtmlConstants.DIV, null);
         writer.writeComment("empty div fix problem with mozilla and fieldset");
@@ -161,7 +161,8 @@
 
         writer.startElement(HtmlConstants.DIV, null);
         writer.writeIdAttribute(clientId);
-        renderTabGroupView(facesContext, writer, component, virtualTab, oStyle,
+        renderTabGroupView(facesContext, writer, component, virtualTab,
+            (HtmlStyleMap) component.getAttributes().get(ATTR_STYLE),
             switchType, image1x1);
         writer.endElement(HtmlConstants.DIV);
 
@@ -180,7 +181,7 @@
 
   private void renderTabGroupView(
       FacesContext facesContext, TobagoResponseWriter writer, UITabGroup component,
-      int virtualTab, StyleAttribute oStyle, String switchType, String image1x1)
+      int virtualTab, HtmlStyleMap oStyle, String switchType, String image1x1)
       throws IOException {
     UIPanel[] tabs = component.getTabs();
     writer.startElement(HtmlConstants.TABLE, null);
@@ -190,7 +191,7 @@
     writer.writeAttribute(HtmlAttributes.SUMMARY, "", null);
     final String clientId = component.getClientId(facesContext);
     writer.writeIdAttribute(clientId + '.' + virtualTab);
-    writer.writeAttribute(HtmlAttributes.STYLE, oStyle.toString(), null);
+    writer.writeAttribute(HtmlAttributes.STYLE, oStyle, null);
 
     writer.startElement(HtmlConstants.TR, null);
     writer.writeAttribute(HtmlAttributes.VALIGN, "bottom", null);
@@ -305,7 +306,7 @@
   protected void encodeContent(TobagoResponseWriter writer,
       FacesContext facesContext, UIPanel activeTab) throws IOException {
 
-    String bodyStyle = (String)
+    HtmlStyleMap bodyStyle = (HtmlStyleMap)
         activeTab.getParent().getAttributes().get(ATTR_STYLE_BODY);
     writer.startElement(HtmlConstants.TR, null);
     writer.startElement(HtmlConstants.TD, null);
@@ -324,7 +325,7 @@
         (TobagoResponseWriter) context.getResponseWriter(),
         (UITabGroup) component,
         ((UITabGroup) component).getActiveIndex(),
-        new StyleAttribute((String) component.getAttributes().get(ATTR_STYLE)),
+        (HtmlStyleMap) component.getAttributes().get(ATTR_STYLE),
         SWITCH_TYPE_RELOAD_TAB,
         ResourceManagerUtil.getImageWithPath(context, "image/1x1.gif"));
     context.responseComplete();

Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ToolBarRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ToolBarRenderer.java?view=diff&rev=479448&r1=479447&r2=479448
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ToolBarRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ToolBarRenderer.java Sun Nov 26 15:05:54 2006
@@ -533,10 +533,7 @@
   private void setToolBarHeight(FacesContext facesContext,
       UIComponent component) {
     final int height = getFixedHeight(facesContext, component);
-    final Map attributes = component.getAttributes();
-    String style = HtmlRendererUtil.replaceStyleAttribute((String)
-        attributes.get(ATTR_STYLE), "height", Integer.toString(height) + "px");
-    attributes.put(ATTR_STYLE, style);
+    HtmlRendererUtil.replaceStyleAttribute(component, "height", height);
   }
 
   public int getFixedHeight(FacesContext facesContext, UIComponent component) {

Modified: myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/BoxRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/BoxRenderer.java?view=diff&rev=479448&r1=479447&r2=479448
==============================================================================
--- myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/BoxRenderer.java (original)
+++ myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/BoxRenderer.java Sun Nov 26 15:05:54 2006
@@ -39,6 +39,7 @@
 import org.apache.myfaces.tobago.renderkit.html.HtmlRendererUtil;
 import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
 import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
+import org.apache.myfaces.tobago.renderkit.html.HtmlStyleMap;
 import org.apache.myfaces.tobago.taglib.component.ToolBarTag;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
 
@@ -63,16 +64,12 @@
 
     TobagoResponseWriter writer = (TobagoResponseWriter) facesContext.getResponseWriter();
 
-    String style = (String) component.getAttributes().get(ATTR_STYLE);
+    HtmlStyleMap style = (HtmlStyleMap) component.getAttributes().get(ATTR_STYLE);
 
     if (style != null) {
-
-      // XXX ???
-      String str = HtmlRendererUtil.getStyleAttributeValue(style, "height");
-      if (str != null) {
-        String heightString = str.replaceAll("\\D", "");
-        int height = Integer.parseInt(heightString) - 1;
-        style = HtmlRendererUtil.replaceStyleAttribute(style, "height", height + "px");
+      Integer styleHeight = style.getInt("height");
+      if (styleHeight != null) {
+        style.put("height", styleHeight-1);
       }
     }
 

Modified: myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/TabGroupRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/TabGroupRenderer.java?view=diff&rev=479448&r1=479447&r2=479448
==============================================================================
--- myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/TabGroupRenderer.java (original)
+++ myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/TabGroupRenderer.java Sun Nov 26 15:05:54 2006
@@ -30,10 +30,12 @@
 import org.apache.myfaces.tobago.renderkit.html.HtmlRendererUtil;
 import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
 import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
+import org.apache.myfaces.tobago.renderkit.html.HtmlStyleMap;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
 
 import javax.faces.context.FacesContext;
 import java.io.IOException;
+import java.text.MessageFormat;
 
 public class TabGroupRenderer extends
     org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.TabGroupRenderer{
@@ -43,7 +45,7 @@
   protected void encodeContent(TobagoResponseWriter writer,
       FacesContext facesContext, UIPanel activeTab) throws IOException {
 
-    String bodyStyle = (String)
+    HtmlStyleMap bodyStyle = (HtmlStyleMap)
         activeTab.getParent().getAttributes().get(ATTR_STYLE_BODY);
     writer.startElement(HtmlConstants.TR, null);
     writer.startElement(HtmlConstants.TD, null);
@@ -61,10 +63,10 @@
     writer.startElement(HtmlConstants.DIV, null);
     writer.writeClassAttribute("tobago-tab-content");
 
-    String height = HtmlRendererUtil.getStyleAttributeValue(bodyStyle, "height");
+    Integer height = HtmlRendererUtil.getStyleAttributeIntValue(bodyStyle, "height");
     if (height != null) {
-      writer.writeAttribute(HtmlAttributes.STYLE, "height: "
-          + (Integer.parseInt(height.replaceAll("\\D", ""))-1) + "px; overflow: auto;", null);
+      writer.writeAttribute(HtmlAttributes.STYLE,
+          MessageFormat.format("height: {0}px; overflow: auto;", height - 1), null);
     }
 
     writer.writeText("", null);