incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awi...@apache.org
Subject svn commit: r486916 - in /incubator/adffaces/trunk/trinidad/trinidad-impl/src: main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/ test/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/
Date Thu, 14 Dec 2006 01:06:48 GMT
Author: awiner
Date: Wed Dec 13 17:06:48 2006
New Revision: 486916

URL: http://svn.apache.org/viewvc?view=rev&rev=486916
Log:
ADFFACES-321: styleClass attribute values that include spaces need to be treated as multiple
style classes rather than one huge style class.  Implementation strategy here is to implement
this only for style classes coming from the actual 'styleClass' component attribute

Added:
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/OutputUtilsTest.java
Modified:
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CommandButtonRenderer.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormInputRenderer.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/InputLabelAndMessageRenderer.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/OutputUtils.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlRenderer.java

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CommandButtonRenderer.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CommandButtonRenderer.java?view=diff&rev=486916&r1=486915&r2=486916
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CommandButtonRenderer.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CommandButtonRenderer.java
Wed Dec 13 17:06:48 2006
@@ -193,9 +193,16 @@
     }
     else
     {
+      List<String> parsedStyleClasses = OutputUtils.parseStyleClassList(styleClass);
+      int userStyleClassCount;
+      if (parsedStyleClasses == null)
+        userStyleClassCount = (styleClass == null) ? 0 : 1;
+      else
+        userStyleClassCount = parsedStyleClasses.size();
+
       int numStates =   ((stateStyleClasses != null) ? 
                          stateStyleClasses.size() : 0);
-      int numClasses = ((styleClass != null) ? 1 : 0) +
+      int numClasses = userStyleClassCount +
                         ((defaultStyleClass != null) ? 1 : 0) +
                         numStates;
       if (numClasses > 0)
@@ -205,8 +212,18 @@
         String[] styleClasses = new String[numClasses];
         
         int i=0;
-        if (styleClass != null)
+        if (parsedStyleClasses != null)
+        {
+          while (i < userStyleClassCount)
+          {
+            styleClasses[i] = parsedStyleClasses.get(i);
+            i++;
+          }
+        }
+        else if (styleClass != null)
+        {
           styleClasses[i++] = styleClass;
+        }
         if (defaultStyleClass != null)
           styleClasses[i++] = defaultStyleClass;
          

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormInputRenderer.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormInputRenderer.java?view=diff&rev=486916&r1=486915&r2=486916
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormInputRenderer.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormInputRenderer.java
Wed Dec 13 17:06:48 2006
@@ -16,6 +16,9 @@
 package org.apache.myfaces.trinidadinternal.renderkit.core.xhtml;
 
 import java.io.IOException;
+
+import java.util.List;
+
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 
@@ -153,12 +156,35 @@
       requiredStyleClass = SkinSelectors.STATE_REQUIRED;
     }
    
-    renderStyleClasses(context, arc, new String[]{styleClass,
-                                                  contentStyleClass,
-                                                  disabledStyleClass,
-                                                  readOnlyStyleClass,
-                                                  requiredStyleClass});
-    
+    List<String> parsedStyleClasses =
+      OutputUtils.parseStyleClassList(styleClass);
+    int userStyleClassCount;
+    if (parsedStyleClasses == null)
+      userStyleClassCount = (styleClass == null) ? 0 : 1;
+    else
+      userStyleClassCount = parsedStyleClasses.size();
+
+    String[] styleClasses = new String[userStyleClassCount + 4];
+    int i=0;
+    if (parsedStyleClasses != null)
+    {
+      while (i < userStyleClassCount)
+      {
+        styleClasses[i] = parsedStyleClasses.get(i);
+        i++;
+      }
+    }
+    else if (styleClass != null)
+    {
+      styleClasses[i++] = styleClass;
+    }
+
+    styleClasses[i++] = contentStyleClass;
+    styleClasses[i++] = disabledStyleClass;
+    styleClasses[i++] = readOnlyStyleClass;
+    styleClasses[i++] = requiredStyleClass;
+
+    renderStyleClasses(context, arc, styleClasses);
     renderInlineStyle(context, arc, bean);  
   }
   

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/InputLabelAndMessageRenderer.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/InputLabelAndMessageRenderer.java?view=diff&rev=486916&r1=486915&r2=486916
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/InputLabelAndMessageRenderer.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/InputLabelAndMessageRenderer.java
Wed Dec 13 17:06:48 2006
@@ -16,6 +16,7 @@
 package org.apache.myfaces.trinidadinternal.renderkit.core.xhtml;
 
 import java.io.IOException;
+import java.util.List;
 
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIComponent;
@@ -189,12 +190,35 @@
       requiredStyleClass = SkinSelectors.STATE_REQUIRED;
     }
    
-    renderStyleClasses(context, arc, new String[]{styleClass,
-                                                  contentStyleClass,
-                                                  disabledStyleClass,
-                                                  readOnlyStyleClass,
-                                                  requiredStyleClass});
-    
+    List<String> parsedStyleClasses =
+      OutputUtils.parseStyleClassList(styleClass);
+    int userStyleClassCount;
+    if (parsedStyleClasses == null)
+      userStyleClassCount = (styleClass == null) ? 0 : 1;
+    else
+      userStyleClassCount = parsedStyleClasses.size();
+
+    String[] styleClasses = new String[userStyleClassCount + 4];
+    int i=0;
+    if (parsedStyleClasses != null)
+    {
+      while (i < userStyleClassCount)
+      {
+        styleClasses[i] = parsedStyleClasses.get(i);
+        i++;
+      }
+    }
+    else if (styleClass != null)
+    {
+      styleClasses[i++] = styleClass;
+    }
+
+    styleClasses[i++] = contentStyleClass;
+    styleClasses[i++] = disabledStyleClass;
+    styleClasses[i++] = readOnlyStyleClass;
+    styleClasses[i++] = requiredStyleClass;
+
+    renderStyleClasses(context, arc, styleClasses);
     renderInlineStyle(context, arc, bean);  
   }
     

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/OutputUtils.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/OutputUtils.java?view=diff&rev=486916&r1=486915&r2=486916
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/OutputUtils.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/OutputUtils.java
Wed Dec 13 17:06:48 2006
@@ -19,6 +19,8 @@
 
 import java.io.IOException;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
 import javax.faces.component.UIComponent;
@@ -37,6 +39,44 @@
  */
 public class OutputUtils
 {
+  /**
+   * Parse a styleclass string, which may have spaces, into a list
+   * of style classes.   Returns null if it's just a single class.
+   */
+  public static List<String> parseStyleClassList(String styleClass)
+  {
+    if (styleClass == null)
+      return null;
+
+    // If there's no spaces, it's just a single class - return
+    // AdamWiner: should we care about all Unicode whitspace?
+    // This will catch 99.9% of cases, and this code needs to be
+    // fast
+    int spaceIndex = styleClass.indexOf(' ');
+    if (spaceIndex < 0)
+      return null;
+
+    // Iterate through the string and build up the split list
+    // AdamWiner: Regex split() would be a lot less code, but
+    // it doesn't automatically trim empty strings.
+    int prevSpaceIndex = 0;
+    List<String> styleClasses = new ArrayList<String>();
+    do
+    {
+      if (spaceIndex > prevSpaceIndex)
+        styleClasses.add(styleClass.substring(prevSpaceIndex, spaceIndex));
+      prevSpaceIndex = spaceIndex + 1;
+      spaceIndex = styleClass.indexOf(' ', prevSpaceIndex);
+    }
+    while (spaceIndex >= 0);
+
+    if (prevSpaceIndex < styleClass.length())
+      styleClasses.add(styleClass.substring(prevSpaceIndex));
+
+    return styleClasses;
+  }
+
+
   /**
    * Gets the character encoding of the output.
    */

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlRenderer.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlRenderer.java?view=diff&rev=486916&r1=486915&r2=486916
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlRenderer.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlRenderer.java
Wed Dec 13 17:06:48 2006
@@ -17,6 +17,7 @@
 
 import java.io.IOException;
 
+import java.util.List;
 import java.util.Map;
 
 import javax.faces.component.UIComponent;
@@ -382,30 +383,55 @@
     String              defaultStyleClass) throws IOException
   {
     String styleClass = getStyleClass(bean);
+    List<String> parsedStyleClasses = OutputUtils.parseStyleClassList(styleClass);
+
     if (defaultStyleClass != null)
     {
       if(styleClass!= null )
       {
-        defaultStyleClass = arc.getStyleClass(defaultStyleClass);
-        styleClass = arc.getStyleClass(styleClass);
-        renderStyleClasses( context,
-                            arc,
-                            new String[]{styleClass, defaultStyleClass});
+        // If we've got both a defaultStyleClass and a styleClass,
+        // build up an array containing each - and if the styleClass
+        // is really a list of styleClasses, break it apart so it
+        // can be compressed correctly
+        int styleCount = (parsedStyleClasses == null) ? 1 : parsedStyleClasses.size();
+        String[] styleClasses = new String[1 + styleCount];
+        if (parsedStyleClasses != null)
+        {
+          for (int i = 0; i < styleCount; i++)
+            styleClasses[i] = parsedStyleClasses.get(i);
+        }
+        else
+        {
+          styleClasses[0] = styleClass;
+        }
+
+        styleClasses[styleCount] = defaultStyleClass;
+
+        renderStyleClasses(context,
+                           arc,
+                           styleClasses);
       }
       else
       {
-        defaultStyleClass = arc.getStyleClass(defaultStyleClass);
-        context.getResponseWriter().writeAttribute("class",
-                                                   defaultStyleClass,
-                                                   null);
+        renderStyleClass(context, arc, defaultStyleClass);
       }
     }
     else if (styleClass != null)
     {
-      styleClass = arc.getStyleClass(styleClass);
-      context.getResponseWriter().writeAttribute("class",
-                                                 styleClass,
-                                                 "styleClass");
+      if (parsedStyleClasses == null)
+      {
+        styleClass = arc.getStyleClass(styleClass);
+        context.getResponseWriter().writeAttribute("class",
+                                                   arc.getStyleClass(styleClass),
+                                                   "styleClass");
+      }
+      else
+      {
+        renderStyleClasses(context,
+                           arc,
+                           parsedStyleClasses.toArray(
+                                   new String[parsedStyleClasses.size()]));
+      }
     }
 
     String style = getInlineStyle(bean);

Added: incubator/adffaces/trunk/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/OutputUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/OutputUtilsTest.java?view=auto&rev=486916
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/OutputUtilsTest.java
(added)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/OutputUtilsTest.java
Wed Dec 13 17:06:48 2006
@@ -0,0 +1,28 @@
+package org.apache.myfaces.trinidadinternal.renderkit.core.xhtml;
+
+import junit.framework.TestCase;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class OutputUtilsTest extends TestCase
+{
+  public OutputUtilsTest(String name)
+  {
+    super(name);
+  }
+
+  public void testStyleClassListParsing() throws Exception
+  {
+    assertEquals(OutputUtils.parseStyleClassList("a"), null);
+    assertEquals(OutputUtils.parseStyleClassList(" a "),
+                 Arrays.asList("a"));
+    assertEquals(OutputUtils.parseStyleClassList("a b c"),
+                 Arrays.asList("a", "b", "c"));
+    assertEquals(OutputUtils.parseStyleClassList("a   b   c"),
+                 Arrays.asList("a", "b", "c"));
+    assertEquals(OutputUtils.parseStyleClassList("ab c"),
+                 Arrays.asList("ab", "c"));
+  }
+}
+



Mime
View raw message