You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by id...@apache.org on 2009/02/04 18:55:19 UTC

svn commit: r740812 - in /myfaces/tobago/branches/tobago-1.0.x: core/src/main/java/org/apache/myfaces/tobago/component/ core/src/main/java/org/apache/myfaces/tobago/layout/ core/src/main/java/org/apache/myfaces/tobago/renderkit/ core/src/main/java/org/...

Author: idus
Date: Wed Feb  4 17:55:18 2009
New Revision: 740812

URL: http://svn.apache.org/viewvc?rev=740812&view=rev
Log:
 TOBAGO-639: replaced String.replace(String, String), String.replaceAll, String.split, String.matches to avoid regular expressions

Added:
    myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/component/SorterTest.java
Modified:
    myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
    myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/LayoutTokens.java
    myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
    myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/UICommand.java
    myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
    myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/layout/Measure.java
    myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutableRendererBase.java
    myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/CommandRendererHelper.java
    myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java
    myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/ContentType.java
    myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/LayoutUtil.java
    myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/component/LayoutTokensUnitTest.java
    myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/component/UIDataUnitTest.java
    myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/util/LayoutUtilTest.java
    myfaces/tobago/branches/tobago-1.0.x/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/sandbox/standard/tag/InputNumberSliderRenderer.java
    myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuBarRenderer.java
    myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java
    myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectManyListboxRenderer.java
    myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectOneListboxRenderer.java
    myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java
    myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeOldRenderer.java
    myfaces/tobago/branches/tobago-1.0.x/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SeparatorRenderer.java

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java Wed Feb  4 17:55:18 2009
@@ -24,6 +24,8 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.math.NumberUtils;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ACTION_LINK;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ACTION_ONCLICK;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ALIGN;
@@ -371,7 +373,7 @@
       if (UIComponentTag.isValueReference(renderers)) {
         command.setValueBinding(ATTR_RENDERED_PARTIALLY, createValueBinding(renderers));
       } else {
-        String[] components = renderers.split(",");
+        String[] components = StringUtils.split(renderers, ",");
         command.setRenderedPartially(components);
       }
     }
@@ -382,7 +384,7 @@
       if (UIComponentTag.isValueReference(styleClasses)) {
         component.setValueBinding(ATTR_STYLE_CLASS, createValueBinding(styleClasses));
       } else {
-        String[] classes = styleClasses.split("[,  ]");
+        String[] classes = StringUtils.split(styleClasses, ", ");
         if (classes.length > 0) {
           StyleClasses styles = StyleClasses.ensureStyleClasses(component);
           for (String clazz : classes) {
@@ -399,7 +401,7 @@
         if (UIComponentTag.isValueReference(markup)) {
           markupComponent.setValueBinding(ATTR_MARKUP, createValueBinding(markup));
         } else {
-          String[] markups = markup.split(",");
+          String[] markups = StringUtils.split(markup, ",");
           ((SupportsMarkup) markupComponent).setMarkup(markups);
         }
       } else {
@@ -1239,7 +1241,7 @@
       if (markups instanceof String[]) {
         return (String[]) markups;
       } else if (markups instanceof String) {
-        String[] strings = ((String) markups).split("[, ]");
+        String[] strings = StringUtils.split((String) markups, ", ");
         List<String> result = new ArrayList<String>(strings.length);
         for (String string : strings) {
           if (string.trim().length() != 0) {
@@ -1357,17 +1359,22 @@
     if (LOG.isInfoEnabled()) {
       LOG.info("idRemainder = \"" + idRemainder + "\"");
     }
-    if (idRemainder.matches("^:\\d+:.*")) {
+    if (idRemainder.startsWith(String.valueOf(NamingContainer.SEPARATOR_CHAR))) {
       idRemainder = idRemainder.substring(1);
-      int idx = idRemainder.indexOf(":");
-      try {
-        int rowIndex = Integer.parseInt(idRemainder.substring(0, idx));
-        if (LOG.isInfoEnabled()) {
-          LOG.info("set rowIndex = \"" + rowIndex + "\"");
+      int idx = idRemainder.indexOf(NamingContainer.SEPARATOR_CHAR);
+      if (idx > 0) {
+        String firstPart = idRemainder.substring(0, idx);
+        if (NumberUtils.isDigits(firstPart)) {
+          try {
+            int rowIndex = Integer.parseInt(firstPart);
+            if (LOG.isInfoEnabled()) {
+              LOG.info("set rowIndex = \"" + rowIndex + "\"");
+            }
+            uiData.setRowIndex(rowIndex);
+          } catch (NumberFormatException e) {
+            LOG.error("idRemainder = \"" + idRemainder + "\"", e);
+          }
         }
-        uiData.setRowIndex(rowIndex);
-      } catch (NumberFormatException e) {
-        LOG.error("idRemainder = \"" + idRemainder + "\"", e);
       }
     } else {
       if (LOG.isInfoEnabled()) {

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/LayoutTokens.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/LayoutTokens.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/LayoutTokens.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/LayoutTokens.java Wed Feb  4 17:55:18 2009
@@ -19,7 +19,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.commons.lang.math.NumberUtils;
+import org.apache.myfaces.tobago.util.LayoutUtil;
 
 import java.util.StringTokenizer;
 import java.util.List;
@@ -110,11 +110,11 @@
       } else if (token.equals("minimum")) {
         return new MinimumLayoutToken();
       } else if (isPixelToken(token)) {
-        return new PixelLayoutToken(Integer.parseInt(removeSuffix(token, PixelLayoutToken.SUFFIX)));
+        return new PixelLayoutToken(Integer.parseInt(LayoutUtil.removeSuffix(token, PixelLayoutToken.SUFFIX)));
       } else if (isPercentToken(token)) {
-        return new PercentLayoutToken(Integer.parseInt(removeSuffix(token, PercentLayoutToken.SUFFIX)));
+        return new PercentLayoutToken(Integer.parseInt(LayoutUtil.removeSuffix(token, PercentLayoutToken.SUFFIX)));
       } else if (isRelativeToken(token)) {
-        return new RelativeLayoutToken(Integer.parseInt(removeSuffix(token, RelativeLayoutToken.SUFFIX)));
+        return new RelativeLayoutToken(Integer.parseInt(LayoutUtil.removeSuffix(token, RelativeLayoutToken.SUFFIX)));
       } else {
         LOG.error("Ignoring unknown layout token '" + token + "'");
       }
@@ -125,24 +125,15 @@
   }
 
   static boolean isPixelToken(String token) {
-    return isNumberAndSuffix(token, PixelLayoutToken.SUFFIX);
+    return LayoutUtil.isNumberAndSuffix(token, PixelLayoutToken.SUFFIX);
   }
 
   static boolean isPercentToken(String token) {
-    return isNumberAndSuffix(token, PercentLayoutToken.SUFFIX);
+    return LayoutUtil.isNumberAndSuffix(token, PercentLayoutToken.SUFFIX);
   }
 
   static boolean isRelativeToken(String token) {
-    return isNumberAndSuffix(token, RelativeLayoutToken.SUFFIX);
-  }
-
-  static boolean isNumberAndSuffix(String token, String suffix) {
-    return token.endsWith(suffix)
-        && NumberUtils.isDigits(removeSuffix(token, suffix));
-  }
-
-  private static String removeSuffix(String token, String suffix) {
-    return token.substring(0, token.length() - suffix.length());
+    return LayoutUtil.isNumberAndSuffix(token, RelativeLayoutToken.SUFFIX);
   }
 
   public String toString() {

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java Wed Feb  4 17:55:18 2009
@@ -19,6 +19,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.StringUtils;
 import org.apache.myfaces.tobago.TobagoConstants;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SORTABLE;
 import org.apache.myfaces.tobago.event.SortActionEvent;
@@ -179,8 +180,20 @@
     return null;
   }
 
-  private boolean isSimpleProperty(String expressionString) {
-    return expressionString.matches("^#\\{(\\w+(\\.\\w)*)\\}$");
+  // XXX needs to be tested
+  // XXX was based on ^#\{(\w+(\.\w)*)\}$ which is wrong, because there is a + missing after the last \w
+  boolean isSimpleProperty(String expressionString) {
+    if (expressionString.startsWith("#{") && expressionString.endsWith("}")) {
+      String inner = expressionString.substring(2, expressionString.length() - 1);
+      String[] parts = StringUtils.split(inner, ".");
+      for (String part : parts) {
+        if (!StringUtils.isAlpha(part)) {
+          return false;
+        }
+      }
+      return true;
+    }
+    return false;
   }
 
   private void unsetSortableAttribute(UIColumn uiColumn) {

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/UICommand.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/UICommand.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/UICommand.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/UICommand.java Wed Feb  4 17:55:18 2009
@@ -24,6 +24,7 @@
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TRANSITION;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.StringUtils;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -78,7 +79,7 @@
         if (value instanceof String[]) {
           return (String[]) value;
         } else if (value instanceof String) {
-          return ((String) value).split(",");
+          return StringUtils.split((String) value, ",");
         } else {
           LOG.error("Ignoring RenderedPartially value binding. Unknown instance " + value.getClass().getName());
         }
@@ -89,7 +90,7 @@
 
   public void setRenderedPartially(String renderedPartially) {
     if (renderedPartially != null) {
-      String[] components = renderedPartially.split(",");
+      String[] components = StringUtils.split(renderedPartially, ",");
       setRenderedPartially(components);
     }
   }

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java Wed Feb  4 17:55:18 2009
@@ -83,7 +83,6 @@
   public static final String MULTI = "multi";
   public static final int DEFAULT_DIRECT_LINK_COUNT = 9;
   public static final int DEFAULT_ROW_COUNT = 100;
-  public static final String ROW_IDX_REGEX = "^\\d+" + SEPARATOR_CHAR + ".*";
   private static final String DEFAULT_SELECTABLE = MULTI;
 
   private MethodBinding stateChangeListener;
@@ -725,11 +724,23 @@
     return scrollPosition;
   }
 
-
   public UIComponent findComponent(String searchId) {
-    if (searchId.matches(ROW_IDX_REGEX)) {
-      searchId = searchId.substring(searchId.indexOf(SEPARATOR_CHAR) + 1);
+    return super.findComponent(stripRowIndex(searchId));
+  }
+
+  String stripRowIndex(String searchId) {
+    if (searchId.length() > 0 && Character.isDigit(searchId.charAt(0))) {
+      for (int i = 1; i < searchId.length(); ++i) {
+        char c = searchId.charAt(i);
+        if (c == SEPARATOR_CHAR) {
+          searchId = searchId.substring(i + 1);
+          break;
+        }
+        if (!Character.isDigit(c)) {
+          break;
+        }
+      }
     }
-    return super.findComponent(searchId);
+    return searchId;
   }
 }

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/layout/Measure.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/layout/Measure.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/layout/Measure.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/layout/Measure.java Wed Feb  4 17:55:18 2009
@@ -1,6 +1,7 @@
 package org.apache.myfaces.tobago.layout;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.myfaces.tobago.util.LayoutUtil;
 
 /*
  * User: lofwyr
@@ -14,8 +15,9 @@
     if (StringUtils.isEmpty(value)) {
       return new PixelMeasure(0); // fixme: may return a "default measure", or is Pixel the default?
     }
-    if (value.toLowerCase().matches("\\d+px")) {// XXX no regexp here: user LayoutTokens.parse !!!
-      return new PixelMeasure(Integer.parseInt(value.substring(0, value.length() - 2)));
+    // XXX improve code sharing with LayoutTokens.parse
+    if (LayoutUtil.isNumberAndSuffix(value.toLowerCase(), "px")) {
+      return new PixelMeasure(Integer.parseInt(LayoutUtil.removeSuffix(value, "px")));
     }
     throw new IllegalArgumentException("Can't parse to any measure: '" + value + "'");
   }

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutableRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutableRendererBase.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutableRendererBase.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutableRendererBase.java Wed Feb  4 17:55:18 2009
@@ -132,7 +132,7 @@
     }
     if (space != null) {
       try {
-        intSpace = Integer.parseInt(space.replaceAll("\\D", ""));
+        intSpace = Integer.parseInt(LayoutUtil.stripNonNumericChars(space));
       } catch (NumberFormatException e) {
         LOG.error("Caught: " + e.getMessage(), e);
       }

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/CommandRendererHelper.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/CommandRendererHelper.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/CommandRendererHelper.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/CommandRendererHelper.java Wed Feb  4 17:55:18 2009
@@ -19,6 +19,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.StringUtils;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ACTION_LINK;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ACTION_ONCLICK;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DEFAULT_COMMAND;
@@ -156,7 +157,7 @@
     String onclick;
     onclick = (String) component.getAttributes().get(ATTR_ACTION_ONCLICK);
     if (onclick.contains("@autoId")) {
-      onclick = onclick.replace("@autoId", component.getClientId(facesContext));
+      onclick = StringUtils.replace(onclick, "@autoId", component.getClientId(facesContext));
     }
     return onclick;
   }
@@ -220,7 +221,7 @@
   }
 
   public String getOnclickDoubleQuoted() {
-    return onclick.replaceAll("'", "\"");
+    return onclick.replace('\'', '\"');
   }
 
   public boolean isDisabled() {

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java Wed Feb  4 17:55:18 2009
@@ -284,12 +284,18 @@
     return style;
   }
 
+  /**
+   * @deprecated
+   */
   public static String replaceStyleAttribute(String style, String name,
       String value) {
     style = removeStyleAttribute(style != null ? style : "", name);
     return style + " " + name + ": " + value + ";";
   }
 
+  /**
+   * @deprecated
+   */
   public static String removeStyleAttribute(String style, String name) {
     if (style == null) {
       return null;

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/ContentType.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/ContentType.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/ContentType.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/ContentType.java Wed Feb  4 17:55:18 2009
@@ -17,6 +17,8 @@
  * limitations under the License.
  */
 
+import org.apache.commons.lang.StringUtils;
+
 /*
  * Date: Oct 30, 2006
  * Time: 10:26:27 PM
@@ -31,7 +33,7 @@
 
   private void parse(String contentType) {
     // TODO parse Parameter
-    String[] values = contentType.split("/");
+    String[] values = StringUtils.split(contentType, "/");
     if (values.length == 2) {
       primaryType = values[0];
       subType = values[1];

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/LayoutUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/LayoutUtil.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/LayoutUtil.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/LayoutUtil.java Wed Feb  4 17:55:18 2009
@@ -19,6 +19,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.math.NumberUtils;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_HEIGHT;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_INLINE;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_INNER_HEIGHT;
@@ -279,7 +280,8 @@
     return LayoutTokens.parseToken(columnToken) != null;
   }
 
-  static String stripNonNumericChars(String token) {
+  // XXX perhaps move to StringUtil
+  public static String stripNonNumericChars(String token) {
     if (token == null || token.isEmpty()) {
       return token;
     }
@@ -293,4 +295,13 @@
     return builder.toString();
   }
 
+  public static boolean isNumberAndSuffix(String token, String suffix) {
+    return token.endsWith(suffix)
+        && NumberUtils.isDigits(removeSuffix(token, suffix));
+  }
+
+  public static String removeSuffix(String token, String suffix) {
+    return token.substring(0, token.length() - suffix.length());
+  }
+
 }

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/component/LayoutTokensUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/component/LayoutTokensUnitTest.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/component/LayoutTokensUnitTest.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/component/LayoutTokensUnitTest.java Wed Feb  4 17:55:18 2009
@@ -33,9 +33,4 @@
     assertTrue(LayoutTokens.isRelativeToken("3*"));
   }
 
-  public void testIsNumberAndSuffix() {
-    assertTrue(LayoutTokens.isNumberAndSuffix("34cm", "cm"));
-    assertFalse(LayoutTokens.isNumberAndSuffix("acm", "cm"));
-    assertFalse(LayoutTokens.isNumberAndSuffix("cm", "cm"));
-  }
 }

Added: myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/component/SorterTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/component/SorterTest.java?rev=740812&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/component/SorterTest.java (added)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/component/SorterTest.java Wed Feb  4 17:55:18 2009
@@ -0,0 +1,17 @@
+package org.apache.myfaces.tobago.component;
+
+import junit.framework.TestCase;
+
+/**
+ * Created 04.02.2009 18:00:40
+ */
+public class SorterTest extends TestCase {
+
+  public void testIsSimpleProperty() {
+    assertTrue(new Sorter().isSimpleProperty("#{bean}"));
+    assertTrue(new Sorter().isSimpleProperty("#{bean.a.b}"));
+    assertTrue(new Sorter().isSimpleProperty("#{bean.prop}"));
+    assertTrue(new Sorter().isSimpleProperty("#{bean.prop.prop}"));
+  }
+
+}

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/component/UIDataUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/component/UIDataUnitTest.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/component/UIDataUnitTest.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/component/UIDataUnitTest.java Wed Feb  4 17:55:18 2009
@@ -19,25 +19,24 @@
 
 import junit.framework.TestCase;
 
-
 import javax.faces.model.ListDataModel;
 import java.util.List;
 import java.util.ArrayList;
+import java.util.Arrays;
 
 /**
  * @author bommel (latest modification by $Author$)
  * @version $Revision$ $Date$
  */
 public class UIDataUnitTest extends TestCase {
+
   String [] nineRows =
       { "one", "two", "three", "four", "five",
           "six", "seven" , "eight", "nine" };
 
   public void testPage() {
-    List list = new ArrayList();
-    for (String nineRow : nineRows) {
-      list.add(nineRow);
-    }
+    List<String> list = new ArrayList<String>();
+    list.addAll(Arrays.asList(nineRows));
     UIData data = new UIData();
     data.setValue(new ListDataModel(list));
     data.setRows(5);
@@ -103,4 +102,10 @@
     assertEquals(8, data.getPages());
       */
   }
+
+  public void testStripRowIndex() {
+    assertEquals("comp1:comp2", new UIData().stripRowIndex("123:comp1:comp2"));
+    assertEquals("comp1:comp2", new UIData().stripRowIndex("comp1:comp2"));
+  }
+
 }

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/util/LayoutUtilTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/util/LayoutUtilTest.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/util/LayoutUtilTest.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/test/java/org/apache/myfaces/tobago/util/LayoutUtilTest.java Wed Feb  4 17:55:18 2009
@@ -1,6 +1,7 @@
 package org.apache.myfaces.tobago.util;
 
 import junit.framework.TestCase;
+import org.apache.commons.lang.StringUtils;
 
 /**
  * Created 04.02.2009 10:48:34
@@ -32,4 +33,14 @@
     assertEquals("", LayoutUtil.stripNonNumericChars("*"));
   }
 
+  public void testIsNumberAndSuffix() {
+    assertTrue(LayoutUtil.isNumberAndSuffix("34cm", "cm"));
+    assertFalse(LayoutUtil.isNumberAndSuffix("acm", "cm"));
+    assertFalse(LayoutUtil.isNumberAndSuffix("cm", "cm"));
+  }
+
+  public void testSplit() {
+    assertEquals("ab", StringUtils.split("ab, sd", " ,")[0]);
+  }
+
 }

Modified: myfaces/tobago/branches/tobago-1.0.x/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/sandbox/standard/tag/InputNumberSliderRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/sandbox/standard/tag/InputNumberSliderRenderer.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/sandbox/standard/tag/InputNumberSliderRenderer.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/sandbox/standard/tag/InputNumberSliderRenderer.java Wed Feb  4 17:55:18 2009
@@ -206,7 +206,7 @@
     String trackId = getIdForSliderTrack(context, component);
     String handleId = getIdForSliderHandle(context, component);
     String inputId = getIdForInputField(context, component);
-    String jsId = component.getClientId(context).replace(":", "_");
+    String jsId = component.getClientId(context).replace(':', '_');
     Integer min = ComponentUtil.getIntAttribute(component, "min");
     Integer max = ComponentUtil.getIntAttribute(component, "max");
     String script = "    var slider_" + jsId + " = new Control.Slider('" + handleId + "', '" + trackId + "', {\n"

Modified: myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuBarRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuBarRenderer.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuBarRenderer.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuBarRenderer.java Wed Feb  4 17:55:18 2009
@@ -24,6 +24,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.StringUtils;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_IMAGE;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_MENU_POPUP;
@@ -162,10 +163,7 @@
   protected String createSetupFunction(FacesContext facesContext,
       UIComponent component, final String clientId, List<String> accKeyFunctions, StringBuilder sb)
       throws IOException {
-    String setupFunction = "setupMenu"
-        +
-        clientId.replaceAll(":", "_").replaceAll("\\.", "_").replaceAll("-",
-            "_");
+    String setupFunction = "setupMenu" + StringUtils.replaceChars(clientId, ":.-", "___");
 
     sb.append("function ");
     sb.append(setupFunction);
@@ -515,7 +513,7 @@
   }
 
   private String prepareForScript(String s) {
-    return s.replaceAll("\n", " ").replaceAll("'", "\\\\'");
+    return StringUtils.replace(s.replace('\n', ' '), "'", "\\\\'");
   }
 
   public void encodeChildren(FacesContext facesContext, UIComponent component)

Modified: myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java Wed Feb  4 17:55:18 2009
@@ -24,6 +24,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.StringUtils;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DELAY;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DOCTYPE;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ENCTYPE;
@@ -593,15 +594,17 @@
     StringBuilder sb = new StringBuilder("LOG.info(\"FacesMessage: [");
     sb.append(id != null ? id : "null");
     sb.append("][");
-    sb.append(message.getSummary() == null ? "null"
-        : message.getSummary().replace("\\", "\\\\").replace("\"", "\\\""));
+    sb.append(message.getSummary() == null ? "null" : escape(message.getSummary()));
     sb.append("/");
-    sb.append(message.getDetail() == null ? "null"
-        : message.getDetail().replace("\\", "\\\\").replace("\"", "\\\""));
+    sb.append(message.getDetail() == null ? "null" : escape(message.getDetail()));
     sb.append("]\");");
     return sb.toString();
   }
 
+  private String escape(String s) {
+    return StringUtils.replace(StringUtils.replace(s, "\\", "\\\\"), "\"", "\\\"");
+  }
+
   private String getMethod(UIPage page) {
     String method = (String) page.getAttributes().get(ATTR_METHOD);
     return method == null ? "post" : method;

Modified: myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectManyListboxRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectManyListboxRenderer.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectManyListboxRenderer.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectManyListboxRenderer.java Wed Feb  4 17:55:18 2009
@@ -34,6 +34,7 @@
 import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
 import org.apache.myfaces.tobago.renderkit.html.HtmlRendererUtil;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
+import org.apache.myfaces.tobago.util.LayoutUtil;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -63,7 +64,7 @@
     String height = (String) component.getAttributes().get(ATTR_HEIGHT);
     if (height != null) {
       try {
-        fixedHeight = Integer.parseInt(height.replaceAll("\\D", ""));
+        fixedHeight = Integer.parseInt(LayoutUtil.stripNonNumericChars(height));
       } catch (NumberFormatException e) {
         LOG.warn("Can't parse " + height + " to int");
       }

Modified: myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectOneListboxRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectOneListboxRenderer.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectOneListboxRenderer.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectOneListboxRenderer.java Wed Feb  4 17:55:18 2009
@@ -34,6 +34,7 @@
 import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
 import org.apache.myfaces.tobago.renderkit.html.HtmlRendererUtil;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
+import org.apache.myfaces.tobago.util.LayoutUtil;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -58,7 +59,7 @@
     String height = (String) component.getAttributes().get(ATTR_HEIGHT);
     if (height != null) {
       try {
-        fixedHeight = Integer.parseInt(height.replaceAll("\\D", ""));
+        fixedHeight = Integer.parseInt(LayoutUtil.stripNonNumericChars(height));
       } catch (NumberFormatException e) {
         LOG.warn("Can't parse " + height + " to int");
       }

Modified: myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java Wed Feb  4 17:55:18 2009
@@ -108,7 +108,7 @@
       writer.writeJavascript(scriptText);
     } else {
       HtmlRendererUtil.writeScriptLoader(facesContext, scripts,
-          new String[] {scriptText.replaceAll("\n", " ")});
+          new String[] {scriptText.replace('\n', ' ')});
     }
 
   }

Modified: myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeOldRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeOldRenderer.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeOldRenderer.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeOldRenderer.java Wed Feb  4 17:55:18 2009
@@ -32,6 +32,7 @@
 import org.apache.myfaces.tobago.renderkit.html.HtmlRendererUtil;
 import org.apache.myfaces.tobago.util.FastStringWriter;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
+import org.apache.commons.lang.StringUtils;
 
 import javax.faces.component.NamingContainer;
 import javax.faces.component.UICommand;
@@ -294,7 +295,7 @@
       if (helper.getOnclick() != null) {
         String onclick = helper.getOnclick();
         String treeNodeCommandClientId = treeNodeCommand.getClientId(facesContext);
-        onclick = onclick.replaceAll("'" + treeNodeCommandClientId + "'", "this.id");
+        onclick = StringUtils.replace(onclick, "'" + treeNodeCommandClientId + "'", "this.id");
         treeNodeCommandVar += "\"" + onclick + "\";\n";
       } else {
         treeNodeCommandVar += "null;\n";

Modified: myfaces/tobago/branches/tobago-1.0.x/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SeparatorRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SeparatorRenderer.java?rev=740812&r1=740811&r2=740812&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SeparatorRenderer.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SeparatorRenderer.java Wed Feb  4 17:55:18 2009
@@ -27,6 +27,7 @@
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
 import org.apache.myfaces.tobago.context.ClientProperties;
 import org.apache.myfaces.tobago.TobagoConstants;
+import org.apache.commons.lang.StringUtils;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -66,7 +67,7 @@
       UILabel label = (UILabel) component.getFacet(FACET_LABEL);
       String text = String.valueOf(label.getValue());
       if (ClientProperties.getInstance(facesContext.getViewRoot()).getUserAgent().isMsie()) {
-        text = text.replace(" ", TobagoConstants.CHAR_NON_BEAKING_SPACE);
+        text = StringUtils.replace(text, " ", TobagoConstants.CHAR_NON_BEAKING_SPACE);
       }
       writer.writeText(text);
       writer.endElement(HtmlConstants.TD);