This is an automated email from the ASF dual-hosted git repository.

doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git


The following commit(s) were added to refs/heads/master by this push:
     new f6c5588d EMPIREDB-422 ControlTag added disabled state to input style 
class
f6c5588d is described below

commit f6c5588db12721d0eedb4f6cb1bd4ead7219c876
Author: Rainer Döbele <[email protected]>
AuthorDate: Sun May 26 16:18:28 2024 +0200

    EMPIREDB-422
    ControlTag added disabled state to input style class
---
 .../apache/empire/jsf2/components/ControlTag.java  |  5 +-
 .../empire/jsf2/utils/TagEncodingHelper.java       | 18 +++--
 .../org/apache/empire/commons/StringUtils.java     | 85 +++++++++++++++++++++-
 3 files changed, 97 insertions(+), 11 deletions(-)

diff --git 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
index 9b7491a3..5b5179f1 100644
--- 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
+++ 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
@@ -161,7 +161,8 @@ public class ControlTag extends UIInput implements 
NamingContainer
         {
             // style Class
             String inputClass = helper.getTagAttributeStringEx("inputClass");
-            helper.writeStyleClass(writer, TagStyleClass.CONTROL_INPUT.get(), 
inputClass);
+            String inputState =(helper.isRenderValueComponent() ? 
TagStyleClass.INPUT_DIS.get() : null); 
+            helper.writeStyleClass(writer, TagStyleClass.CONTROL_INPUT.get(), 
inputClass, inputState);
             // colspan
             String colSpan = 
tagName.equalsIgnoreCase(InputControl.HTML_TAG_TD) ? 
helper.getTagAttributeStringEx("colspan") : null;            
             if (colSpan!=null)
@@ -375,7 +376,7 @@ public class ControlTag extends UIInput implements 
NamingContainer
             helper.writeComponentId(writer, false);
             // style class
             String controlClass = 
helper.getTagAttributeStringEx("controlClass"); 
-            String styleClass   = helper.getControlContextStyleClass(); 
+            String styleClass   = helper.getControlContextStyleClass();
             helper.writeStyleClass(writer, TagStyleClass.CONTROL.get(), 
controlClass, styleClass);
         }
         
diff --git 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
index c9c62084..bd25712f 100644
--- 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
+++ 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
@@ -1596,13 +1596,19 @@ public class TagEncodingHelper implements 
NamingContainer
     public void writeStyleClass(ResponseWriter writer, String... styleClasses)
         throws IOException
     {
+        // Check if there is only one
+        int i=0;
         String styleClass = null;
-        if (styleClasses.length>2)
-            styleClass = assembleStyleClassString(styleClasses[0], null, 
styleClasses[1], styleClasses[2]);
-        else if (styleClasses.length>1)
-            styleClass = assembleStyleClassString(styleClasses[0], null, 
styleClasses[1], null);
-        else if (styleClasses.length==1)
-            styleClass = styleClasses[0];
+        for (; i<styleClasses.length; i++) {
+            if (styleClasses[i]!=null) {
+                if (styleClass!=null) {
+                    break; // more than one!
+                }
+                styleClass = styleClasses[i];
+            }
+        }
+        if (i<styleClasses.length)
+            styleClass = StringUtils.arrayToString(styleClasses, 
StringUtils.SPACE, null, true);
         if (styleClass != null)
             writer.writeAttribute(InputControl.HTML_ATTR_CLASS, styleClass, 
null);
     }
diff --git a/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java 
b/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java
index 4602ee23..9fa34069 100644
--- a/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java
+++ b/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java
@@ -20,12 +20,18 @@ package org.apache.empire.commons;
 
 import java.util.Collection;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
  * This class contains common functions for comparing and converting values of 
type String. 
  * 
  */
 public class StringUtils
 {
+    // Logger
+    private static final Logger log = 
LoggerFactory.getLogger(StringUtils.class);
+    
     private StringUtils()
     {
         // Static Function only
@@ -227,7 +233,7 @@ public class StringUtils
         }
         return -1; // Not found
     }
-
+    
     /**
      * Converts an array of objects to a string.
      * 
@@ -247,7 +253,11 @@ public class StringUtils
         {   // build the list
             int tend =(tbeg>=0 ? template.lastIndexOf(TEMPLATE_SEP_CHAR) : -1);
             String separator = ((tbeg>0) ? (tend>tbeg ? 
template.substring(tbeg+1, tend) : DEFAULT_ITEM_SEPARATOR) : template);
-            StringBuilder buf = new StringBuilder();
+            // create StringBuilder
+            int bufferLen = estimateArrayBufferSize(array, (separator!=null ? 
separator.length() : 0));
+            if (template!=null && template.length()>separator.length())
+                bufferLen += template.length()-separator.length(); 
+            StringBuilder buf = new StringBuilder(bufferLen);
             if (tend>0)
                 buf.append(template.substring(0, tbeg)); // add template prefix
             boolean isEmpty = true;
@@ -267,6 +277,8 @@ public class StringUtils
                 buf.setLength(buf.length()-separator.length()); // remove last 
separator
             if (tend>0)
                 buf.append(template.substring(tend+1)); // add template suffix
+            if (buf.length()!=bufferLen)
+                log.debug("estimateArrayBufferSize returned {} but string 
length is {}", bufferLen, buf.length());
             return buf.toString();
         }
         // Only one member
@@ -300,6 +312,37 @@ public class StringUtils
     {
         return arrayToString(array, separator, EMPTY);
     }
+
+    /**
+     * Estimates the buffer size needed to convert an Array into a String
+     * @param array the array
+     * @return the estimated length of the array parts
+     */
+    public static int estimateArrayBufferSize(Object[] array, int 
seperatorLength)
+    {
+        int estimate = 0;
+        for (int i = 0; i < array.length; i++) 
+        {
+            Object item = array[i];
+            int len = 0;
+            if (item instanceof String) 
+                len = ((String)item).length();
+            else if (item instanceof Number)
+                len = 10; // assume 10
+            else if (item instanceof Object[])
+                len = estimateArrayBufferSize((Object[])item, seperatorLength);
+            else if (item instanceof Collection<?>)
+                len = estimateListBufferSize((Collection<?>)item, 
seperatorLength);
+            else if (item!=null)
+                len = 20; // unknown
+            if (len>0) {
+                if (estimate > 0)
+                    estimate += seperatorLength;
+                estimate += len;
+            }
+        }
+        return estimate; 
+    }
     
     /**
      * Converts a list (Collection) of objects to a string.
@@ -320,7 +363,11 @@ public class StringUtils
         {   // build the list
             int tend =(tbeg>=0 ? template.lastIndexOf(TEMPLATE_SEP_CHAR) : -1);
             String separator = ((tbeg>0) ? (tend>tbeg ? 
template.substring(tbeg+1, tend) : DEFAULT_ITEM_SEPARATOR) : template);
-            StringBuilder buf = new StringBuilder();
+            // create StringBuilder
+            int bufferLen = estimateListBufferSize(list, (separator!=null ? 
separator.length() : 0));
+            if (template!=null && template.length()>separator.length())
+                bufferLen += template.length()-separator.length(); 
+            StringBuilder buf = new StringBuilder(bufferLen);
             if (tend>0)
                 buf.append(template.substring(0, tbeg)); // add template prefix
             boolean isEmpty = true;
@@ -340,6 +387,8 @@ public class StringUtils
                 buf.setLength(buf.length()-separator.length()); // remove last 
separator
             if (tend>0)
                 buf.append(template.substring(tend+1)); // add template suffix
+            if (buf.length()!=bufferLen)
+                log.debug("estimateListBufferSize returned {} but string 
length is {}", bufferLen, buf.length());
             return buf.toString();
         }
         // Only one member
@@ -374,6 +423,36 @@ public class StringUtils
         return listToString(list, separator, EMPTY);
     }
 
+    /**
+     * Estimates the buffer size needed to convert a Collection into a String
+     * @param array the array
+     * @return the estimated length of the collection parts
+     */
+    public static int estimateListBufferSize(Collection<?> list, int 
seperatorLength)
+    {
+        int estimate = 0;
+        for (Object item : list)
+        {
+            int len = 0;
+            if (item instanceof String) 
+                len = ((String)item).length();
+            else if (item instanceof Number)
+                len = 10; // assume 10
+            else if (item instanceof Object[])
+                len = estimateArrayBufferSize((Object[])item, seperatorLength);
+            else if (item instanceof Collection<?>)
+                len = estimateListBufferSize((Collection<?>)item, 
seperatorLength);
+            else if (item!=null)
+                len = 20; // unknown
+            if (len>0) {
+                if (estimate > 0)
+                    estimate += seperatorLength;
+                estimate += len;
+            }
+        }
+        return estimate; 
+    }
+
     /**
      * Assembles a string from parts with a separator
      * 

Reply via email to