myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject [myfaces] branch master updated: refactored
Date Wed, 14 Aug 2019 17:14:24 GMT
This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/master by this push:
     new 9c291f9  refactored
9c291f9 is described below

commit 9c291f97d8a76a12d0d9198de41c9d407c50828a
Author: Thomas Andraschko <tandraschko@apache.org>
AuthorDate: Wed Aug 14 19:14:22 2019 +0200

    refactored
---
 .../search/MyFacesSearchExpressionHints.java       | 35 ++++++++++++++++++++++
 .../search/SearchExpressionHandlerImpl.java        | 35 +++++++++++-----------
 .../renderkit/html/HtmlAjaxBehaviorRenderer.java   | 13 ++++----
 .../renderkit/html/HtmlCommandScriptRenderer.java  | 10 ++-----
 .../myfaces/renderkit/html/HtmlLabelRenderer.java  | 10 ++-----
 .../html/base/HtmlMessageRendererBase.java         |  7 ++---
 .../html/base/HtmlMessagesRendererBase.java        |  7 ++---
 7 files changed, 68 insertions(+), 49 deletions(-)

diff --git a/impl/src/main/java/org/apache/myfaces/component/search/MyFacesSearchExpressionHints.java
b/impl/src/main/java/org/apache/myfaces/component/search/MyFacesSearchExpressionHints.java
new file mode 100644
index 0000000..f417f21
--- /dev/null
+++ b/impl/src/main/java/org/apache/myfaces/component/search/MyFacesSearchExpressionHints.java
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+package org.apache.myfaces.component.search;
+
+import java.util.EnumSet;
+import java.util.Set;
+import javax.faces.component.search.SearchExpressionHint;
+
+public class MyFacesSearchExpressionHints
+{
+    public static final Set<SearchExpressionHint> SET_IGNORE_NO_RESULT =
+            EnumSet.of(SearchExpressionHint.IGNORE_NO_RESULT);
+    
+    public static final Set<SearchExpressionHint> SET_RESOLVE_CLIENT_SIDE_RESOLVE_SINGLE_COMPONENT
=
+            EnumSet.of(SearchExpressionHint.RESOLVE_CLIENT_SIDE, SearchExpressionHint.RESOLVE_SINGLE_COMPONENT);
+    
+    public static final Set<SearchExpressionHint> SET_RESOLVE_SINGLE_COMPONENT_IGNORE_NO_RESULT
=
+            EnumSet.of(SearchExpressionHint.RESOLVE_SINGLE_COMPONENT, SearchExpressionHint.IGNORE_NO_RESULT);
+}
diff --git a/impl/src/main/java/org/apache/myfaces/component/search/SearchExpressionHandlerImpl.java
b/impl/src/main/java/org/apache/myfaces/component/search/SearchExpressionHandlerImpl.java
index 633aa5f..b288eb9 100644
--- a/impl/src/main/java/org/apache/myfaces/component/search/SearchExpressionHandlerImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/component/search/SearchExpressionHandlerImpl.java
@@ -86,19 +86,19 @@ public class SearchExpressionHandlerImpl extends SearchExpressionHandler
         }
         else
         {
-            CollectClientIdCallback callback = new CollectClientIdCallback();
-            
+            CollectClientIdCallback callback = null;
             if (!expression.isEmpty())
             {
+                callback = new CollectClientIdCallback();
                 handler.invokeOnComponent(
                         searchExpressionContext, searchExpressionContext.getSource(), expression,
callback);
             }
 
-            if (!callback.isClientIdFound())
+            if (callback == null || !callback.isClientIdFound())
             {
                 if (isHintSet(searchExpressionContext, SearchExpressionHint.IGNORE_NO_RESULT))
                 {
-                    //Ignore
+                    return null;
                 }
                 else
                 {
@@ -150,10 +150,10 @@ public class SearchExpressionHandlerImpl extends SearchExpressionHandler
         FacesContext facesContext = searchExpressionContext.getFacesContext();
         SearchExpressionHandler handler = facesContext.getApplication().getSearchExpressionHandler();
 
-        CollectClientIdsCallback callback = new CollectClientIdsCallback();
-
+        CollectClientIdsCallback callback = null;
         if (!expressions.isEmpty())
         {
+            callback = new CollectClientIdsCallback();
             for (String expression : handler.splitExpressions(facesContext, expressions))
             {
                 if (handler.isPassthroughExpression(searchExpressionContext, expression))
@@ -169,11 +169,11 @@ public class SearchExpressionHandlerImpl extends SearchExpressionHandler
             }
         }
 
-        if (!callback.isClientIdFound())
+        if (callback == null || !callback.isClientIdFound())
         {
             if (isHintSet(searchExpressionContext, SearchExpressionHint.IGNORE_NO_RESULT))
             {
-                //Ignore
+                return Collections.emptyList();
             }
             else
             {
@@ -194,7 +194,7 @@ public class SearchExpressionHandlerImpl extends SearchExpressionHandler
         {
             if (clientIds == null)
             {
-                clientIds = new ArrayList<String>();
+                clientIds = new ArrayList<>();
             }
             clientIds.add(target.getClientId(context));
         }
@@ -213,7 +213,7 @@ public class SearchExpressionHandlerImpl extends SearchExpressionHandler
         {
             if (clientIds == null)
             {
-                clientIds = new ArrayList<String>();
+                clientIds = new ArrayList<>();
             }
             clientIds.add(clientId);
         }
@@ -234,18 +234,18 @@ public class SearchExpressionHandlerImpl extends SearchExpressionHandler
         
         FacesContext facesContext = searchExpressionContext.getFacesContext();
         SearchExpressionHandler handler = facesContext.getApplication().getSearchExpressionHandler();
-        
-        SingleInvocationCallback checkCallback = new SingleInvocationCallback(callback);
-        
+
         addHint(searchExpressionContext, SearchExpressionHint.RESOLVE_SINGLE_COMPONENT);
 
+        SingleInvocationCallback checkCallback = null;
         if (!expression.isEmpty())
         {
+            checkCallback = new SingleInvocationCallback(callback);
             handler.invokeOnComponent(searchExpressionContext, searchExpressionContext.getSource(),
                     expression, checkCallback);
         }
 
-        if (!checkCallback.isInvoked())
+        if (checkCallback == null || !checkCallback.isInvoked())
         {
             if (isHintSet(searchExpressionContext, SearchExpressionHint.IGNORE_NO_RESULT))
             {
@@ -310,10 +310,11 @@ public class SearchExpressionHandlerImpl extends SearchExpressionHandler
         FacesContext facesContext = searchExpressionContext.getFacesContext();
         SearchExpressionHandler handler = facesContext.getApplication().getSearchExpressionHandler();
         
-        MultipleInvocationCallback checkCallback = new MultipleInvocationCallback(callback);
+        MultipleInvocationCallback checkCallback = null;
 
         if (!expressions.isEmpty())
         {
+            checkCallback = new MultipleInvocationCallback(callback);
             for (String expression : handler.splitExpressions(facesContext, expressions))
             {
                 handler.invokeOnComponent(searchExpressionContext, searchExpressionContext.getSource(),
@@ -321,7 +322,7 @@ public class SearchExpressionHandlerImpl extends SearchExpressionHandler
             }
         }
 
-        if (!checkCallback.isInvoked())
+        if (checkCallback == null || !checkCallback.isInvoked())
         {
             if (isHintSet(searchExpressionContext, SearchExpressionHint.IGNORE_NO_RESULT))
             {
@@ -801,7 +802,7 @@ public class SearchExpressionHandlerImpl extends SearchExpressionHandler
             return null;
         }
 
-        List<String> tokens = new ArrayList<String>(5);
+        List<String> tokens = new ArrayList<>(5);
         StringBuilder buffer = SharedStringBuilder.get(context, SB_SPLIT);
 
         int parenthesesCounter = 0;
diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlAjaxBehaviorRenderer.java
b/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlAjaxBehaviorRenderer.java
index 2805918..15610fb 100644
--- a/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlAjaxBehaviorRenderer.java
+++ b/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlAjaxBehaviorRenderer.java
@@ -21,10 +21,8 @@ package org.apache.myfaces.renderkit.html;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.EnumSet;
 import java.util.List;
 import java.util.RandomAccess;
-import java.util.Set;
 
 import javax.faces.FacesException;
 import javax.faces.component.ActionSource;
@@ -35,11 +33,11 @@ import javax.faces.component.behavior.ClientBehavior;
 import javax.faces.component.behavior.ClientBehaviorContext;
 import javax.faces.component.search.SearchExpressionContext;
 import javax.faces.component.search.SearchExpressionHandler;
-import javax.faces.component.search.SearchExpressionHint;
 import javax.faces.context.FacesContext;
 import javax.faces.event.AjaxBehaviorEvent;
 import javax.faces.event.PhaseId;
 import javax.faces.render.ClientBehaviorRenderer;
+import org.apache.myfaces.component.search.MyFacesSearchExpressionHints;
 import org.apache.myfaces.util.lang.StringUtils;
 import org.apache.myfaces.util.SharedStringBuilder;
 
@@ -420,7 +418,8 @@ public class HtmlAjaxBehaviorRenderer extends ClientBehaviorRenderer
                     if (searchExpressionContext == null)
                     {
                         searchExpressionContext = SearchExpressionContext.createSearchExpressionContext(
-                                context.getFacesContext(), context.getComponent(), EXPRESSION_HINTS,
null);
+                                context.getFacesContext(), context.getComponent(),
+                                MyFacesSearchExpressionHints.SET_RESOLVE_CLIENT_SIDE_RESOLVE_SINGLE_COMPONENT,
null);
                     }
                     
                     String strVal = list.get(cnt);
@@ -434,7 +433,8 @@ public class HtmlAjaxBehaviorRenderer extends ClientBehaviorRenderer
                     if (searchExpressionContext == null)
                     {
                         searchExpressionContext = SearchExpressionContext.createSearchExpressionContext(
-                                context.getFacesContext(), context.getComponent(), EXPRESSION_HINTS,
null);
+                                context.getFacesContext(), context.getComponent(),
+                                MyFacesSearchExpressionHints.SET_RESOLVE_CLIENT_SIDE_RESOLVE_SINGLE_COMPONENT,
null);
                     }
                     
                     cnt++;
@@ -449,9 +449,6 @@ public class HtmlAjaxBehaviorRenderer extends ClientBehaviorRenderer
 
     }
 
-    private static final Set<SearchExpressionHint> EXPRESSION_HINTS =
-            EnumSet.of(SearchExpressionHint.RESOLVE_CLIENT_SIDE, SearchExpressionHint.RESOLVE_SINGLE_COMPONENT);
-    
     public void build(ClientBehaviorContext context,
             int size, StringBuilder retVal, int cnt,
             String strVal, SearchExpressionContext searchExpressionContext)
diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlCommandScriptRenderer.java
b/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlCommandScriptRenderer.java
index ada067a..9f534e8 100644
--- a/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlCommandScriptRenderer.java
+++ b/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlCommandScriptRenderer.java
@@ -22,11 +22,9 @@ package org.apache.myfaces.renderkit.html;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.EnumSet;
 import java.util.List;
 import java.util.Map;
 import java.util.RandomAccess;
-import java.util.Set;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIForm;
 import javax.faces.component.UIParameter;
@@ -35,11 +33,11 @@ import javax.faces.component.behavior.ClientBehaviorHolder;
 import javax.faces.component.html.HtmlCommandScript;
 import javax.faces.component.search.SearchExpressionContext;
 import javax.faces.component.search.SearchExpressionHandler;
-import javax.faces.component.search.SearchExpressionHint;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 import javax.faces.event.ActionEvent;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFRenderer;
+import org.apache.myfaces.component.search.MyFacesSearchExpressionHints;
 import org.apache.myfaces.renderkit.html.util.HTML;
 import org.apache.myfaces.renderkit.html.base.HtmlRenderer;
 import org.apache.myfaces.renderkit.html.base.HtmlRendererUtils;
@@ -53,9 +51,6 @@ import org.apache.myfaces.util.SharedStringBuilder;
 @JSFRenderer(renderKitId = "HTML_BASIC", family = "javax.faces.Command", type = "javax.faces.Script")
 public class HtmlCommandScriptRenderer extends HtmlRenderer
 {
-    private static final Set<SearchExpressionHint> EXPRESSION_HINTS =
-            EnumSet.of(SearchExpressionHint.RESOLVE_CLIENT_SIDE, SearchExpressionHint.RESOLVE_SINGLE_COMPONENT);
-    
     private static final String AJAX_KEY_ONERROR = "onerror";
     private static final String AJAX_KEY_ONEVENT = "onevent";
     private static final String AJAX_KEY_EXECUTE = "execute";
@@ -203,7 +198,8 @@ public class HtmlCommandScriptRenderer extends HtmlRenderer
         StringBuilder paramBuffer = SharedStringBuilder.get(context.getFacesContext(), AJAX_PARAM_SB,
20);
     
         SearchExpressionContext searchExpressionContext = SearchExpressionContext.createSearchExpressionContext(
-                            context.getFacesContext(), context.getComponent(), EXPRESSION_HINTS,
null);
+                context.getFacesContext(), context.getComponent(),
+                MyFacesSearchExpressionHints.SET_RESOLVE_CLIENT_SIDE_RESOLVE_SINGLE_COMPONENT,
null);
         
         String executes = resolveExpressionsAsParameter(paramBuffer, AJAX_KEY_EXECUTE, commandScript.getExecute(),
                 searchExpressionContext);
diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlLabelRenderer.java b/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlLabelRenderer.java
index 2337376..6d0d883 100755
--- a/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlLabelRenderer.java
+++ b/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlLabelRenderer.java
@@ -19,10 +19,8 @@
 package org.apache.myfaces.renderkit.html;
 
 import java.io.IOException;
-import java.util.EnumSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -32,11 +30,11 @@ import javax.faces.component.behavior.ClientBehavior;
 import javax.faces.component.behavior.ClientBehaviorHolder;
 import javax.faces.component.html.HtmlOutputLabel;
 import javax.faces.component.search.SearchExpressionContext;
-import javax.faces.component.search.SearchExpressionHint;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFRenderer;
+import org.apache.myfaces.component.search.MyFacesSearchExpressionHints;
 import org.apache.myfaces.renderkit.html.util.JSFAttr;
 import org.apache.myfaces.renderkit.RendererUtils;
 import org.apache.myfaces.renderkit.html.util.CommonEventUtils;
@@ -58,9 +56,6 @@ import org.apache.myfaces.util.ComponentUtils;
 public class HtmlLabelRenderer extends HtmlRenderer
 {
     private static final Logger log = Logger.getLogger(HtmlLabelRenderer.class.getName());
-
-    private static final Set<SearchExpressionHint> EXPRESSION_HINTS =
-            EnumSet.of(SearchExpressionHint.RESOLVE_SINGLE_COMPONENT, SearchExpressionHint.IGNORE_NO_RESULT);
     
     @Override
     protected boolean isCommonPropertiesOptimizationEnabled(FacesContext facesContext)
@@ -237,7 +232,8 @@ public class HtmlLabelRenderer extends HtmlRenderer
     protected String getClientId(FacesContext facesContext, UIComponent uiComponent, String
forAttr)
     {
         SearchExpressionContext searchExpressionContext = SearchExpressionContext.createSearchExpressionContext(
-                facesContext, uiComponent, EXPRESSION_HINTS, null);
+                facesContext, uiComponent,
+                MyFacesSearchExpressionHints.SET_RESOLVE_SINGLE_COMPONENT_IGNORE_NO_RESULT,
null);
 
         return facesContext.getApplication().getSearchExpressionHandler().resolveClientId(
                 searchExpressionContext, forAttr);
diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/html/base/HtmlMessageRendererBase.java
b/impl/src/main/java/org/apache/myfaces/renderkit/html/base/HtmlMessageRendererBase.java
index c9e0679..f251a92 100644
--- a/impl/src/main/java/org/apache/myfaces/renderkit/html/base/HtmlMessageRendererBase.java
+++ b/impl/src/main/java/org/apache/myfaces/renderkit/html/base/HtmlMessageRendererBase.java
@@ -21,11 +21,9 @@ package org.apache.myfaces.renderkit.html.base;
 import org.apache.myfaces.renderkit.html.util.CommonPropertyUtils;
 import org.apache.myfaces.renderkit.html.util.CommonEventUtils;
 import java.io.IOException;
-import java.util.EnumSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.logging.Logger;
 
 import javax.faces.application.FacesMessage;
@@ -37,9 +35,9 @@ import javax.faces.component.behavior.ClientBehaviorHolder;
 import javax.faces.component.html.HtmlMessage;
 import javax.faces.component.search.SearchExpressionContext;
 import javax.faces.component.search.SearchExpressionHandler;
-import javax.faces.component.search.SearchExpressionHint;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
+import org.apache.myfaces.component.search.MyFacesSearchExpressionHints;
 
 import org.apache.myfaces.renderkit.html.util.JSFAttr;
 import org.apache.myfaces.renderkit.RendererUtils;
@@ -92,11 +90,10 @@ public abstract class HtmlMessageRendererBase
         }
 
         SearchExpressionHandler searchExpressionHandler = facesContext.getApplication().getSearchExpressionHandler();
-        Set<SearchExpressionHint> expressionHints = EnumSet.of(SearchExpressionHint.IGNORE_NO_RESULT);
 
         String clientId = searchExpressionHandler.resolveClientId(
                 SearchExpressionContext.createSearchExpressionContext(
-                        facesContext, message, expressionHints, null), forAttr);
+                        facesContext, message, MyFacesSearchExpressionHints.SET_IGNORE_NO_RESULT,
null), forAttr);
         if (clientId == null)
         {
             log.severe("Could not render Message. Unable to find component '" 
diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/html/base/HtmlMessagesRendererBase.java
b/impl/src/main/java/org/apache/myfaces/renderkit/html/base/HtmlMessagesRendererBase.java
index d4524e7..c1d5b5a 100644
--- a/impl/src/main/java/org/apache/myfaces/renderkit/html/base/HtmlMessagesRendererBase.java
+++ b/impl/src/main/java/org/apache/myfaces/renderkit/html/base/HtmlMessagesRendererBase.java
@@ -20,12 +20,10 @@ package org.apache.myfaces.renderkit.html.base;
 
 import java.io.IOException;
 import java.util.Collections;
-import java.util.EnumSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
-import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -37,9 +35,9 @@ import javax.faces.component.behavior.ClientBehaviorHolder;
 import javax.faces.component.html.HtmlMessages;
 import javax.faces.component.search.SearchExpressionContext;
 import javax.faces.component.search.SearchExpressionHandler;
-import javax.faces.component.search.SearchExpressionHint;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
+import org.apache.myfaces.component.search.MyFacesSearchExpressionHints;
 
 import org.apache.myfaces.renderkit.html.util.JSFAttr;
 import org.apache.myfaces.renderkit.RendererUtils;
@@ -75,11 +73,10 @@ public abstract class HtmlMessagesRendererBase extends HtmlMessageRendererBase
         {
             SearchExpressionHandler searchExpressionHandler = 
                     facesContext.getApplication().getSearchExpressionHandler();
-            Set<SearchExpressionHint> expressionHints = EnumSet.of(SearchExpressionHint.IGNORE_NO_RESULT);
 
             clientId = searchExpressionHandler.resolveClientId(
                     SearchExpressionContext.createSearchExpressionContext(
-                            facesContext, messages, expressionHints, null), forAttr);
+                            facesContext, messages, MyFacesSearchExpressionHints.SET_IGNORE_NO_RESULT,
null), forAttr);
             if (clientId == null)
             {
                 log.severe("Could not render Message. Unable to find component '" 


Mime
View raw message