You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2022/12/09 12:39:24 UTC

[myfaces-tobago] branch tobago-2.x updated: refactor: Tobago 2.x fix code scanning (#3518)

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

lofwyr pushed a commit to branch tobago-2.x
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git


The following commit(s) were added to refs/heads/tobago-2.x by this push:
     new 3516d37cbc refactor: Tobago 2.x fix code scanning (#3518)
3516d37cbc is described below

commit 3516d37cbc1530dcf5fad7145f6e73041c31bb62
Author: Udo Schnurpfeil <lo...@apache.org>
AuthorDate: Fri Dec 9 13:39:18 2022 +0100

    refactor: Tobago 2.x fix code scanning (#3518)
    
    * was a warning about the use of regexp
---
 .../tobago/internal/component/AbstractUIPage.java  | 45 +++++++++++++++++++---
 1 file changed, 40 insertions(+), 5 deletions(-)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIPage.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIPage.java
index 0d61780c7d..0c56e2bfa0 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIPage.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIPage.java
@@ -238,19 +238,20 @@ public abstract class AbstractUIPage extends AbstractUIForm
     final UIViewRoot viewRoot = facesContext.getViewRoot();
     UIComponent command = viewRoot.findComponent(currentActionId);
 
-    // TODO: remove this if block if proven this never happens anymore
-    if (command == null
-        && currentActionId != null && currentActionId.matches(".*:\\d+:.*")) {
+    if (command == null && currentActionId != null) {
       // If currentActionId component was inside a sheet the id contains the
       // rowIndex and is therefore not found here.
       // We do not need the row here because we want just to find the
       // related form, so removing the rowIndex will help here.
-      currentActionId = currentActionId.replaceAll(":\\d+:", ":");
+      currentActionId = cutIteratorFromId(currentActionId);
       try {
         command = viewRoot.findComponent(currentActionId);
-        //LOG.info("command = \"" + command + "\"", new Exception());
       } catch (final Exception e) {
         // ignore
+        if (LOG.isTraceEnabled()) {
+          LOG.trace("sourceId='{}'", currentActionId);
+          LOG.trace("Exception in findComponent", e);
+        }
       }
     }
 
@@ -276,6 +277,40 @@ public abstract class AbstractUIPage extends AbstractUIForm
     }
   }
 
+  // TODO: Remove this method if proven this never happens anymore
+  // TODO: This workaround is stil needed for Mojarra
+  // TODO: Otherwise actions in tree/sheet will not be detected
+  protected String cutIteratorFromId(final String sourceId) {
+
+    final char[] chars = sourceId.toCharArray();
+    final int n = chars.length;
+    final char colon = ':';
+    final StringBuilder builder = new StringBuilder(n);
+    char lastInBuilder = ' '; // any non-colon
+    for (char c : chars) {
+      if (c == colon) { // colon
+        if (lastInBuilder != colon) {
+          builder.append(c);
+          lastInBuilder = c;
+        }
+      } else if ('0' <= c && c <= '9') { // number
+
+      } else { // any other
+        builder.append(c);
+        lastInBuilder = c;
+      }
+    }
+
+    if (builder.length() == n) {
+      return sourceId;
+    } else if (lastInBuilder == colon) {
+      builder.deleteCharAt(builder.length() - 1);
+      return builder.toString();
+    } else {
+      return builder.toString();
+    }
+  }
+
   /**
    * @deprecated PageState is deprecated since 1.5.0
    */