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 Sun, 04 Aug 2019 10:27:02 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 68c7a3b  refactored
68c7a3b is described below

commit 68c7a3b5b8bb69fdae0b104d6cf85f231430fbfd
Author: Thomas Andraschko <tandraschko@apache.org>
AuthorDate: Sun Aug 4 12:26:53 2019 +0200

    refactored
---
 .../faces/component/_SelectItemsIterator.java      | 10 ++++----
 .../org/apache/myfaces/config/MyfacesConfig.java   | 12 ++++++++--
 .../renderkit/html/util/SelectItemsIterator.java   | 10 ++++----
 .../myfaces/resource/ResourceHandlerCache.java     | 28 +++++++---------------
 .../org/apache/myfaces/resource/ResourceImpl.java  | 15 ++++++------
 .../DefaultFaceletsStateManagementStrategy.java    |  6 ++---
 .../facelets/FaceletViewDeclarationLanguage.java   |  2 +-
 7 files changed, 37 insertions(+), 46 deletions(-)

diff --git a/api/src/main/java/javax/faces/component/_SelectItemsIterator.java b/api/src/main/java/javax/faces/component/_SelectItemsIterator.java
index 2be92d6..7d6e140 100644
--- a/api/src/main/java/javax/faces/component/_SelectItemsIterator.java
+++ b/api/src/main/java/javax/faces/component/_SelectItemsIterator.java
@@ -41,9 +41,7 @@ class _SelectItemsIterator implements Iterator<SelectItem>
 {
     
     private static final Logger log = Logger.getLogger(_SelectItemsIterator.class.getName());
-    
-    private static final Iterator<UIComponent> _EMPTY_UICOMPONENT_ITERATOR = Collections.<UIComponent>emptyIterator();
-    
+
     // org.apache.myfaces.util.SelectItemsIterator uses JSFAttr
     private static final String VAR_ATTR = "var";
     private static final String ITEM_VALUE_ATTR = "itemValue";
@@ -64,7 +62,7 @@ class _SelectItemsIterator implements Iterator<SelectItem>
     {
         _children = selectItemsParent.getChildCount() > 0
                         ? selectItemsParent.getChildren().iterator()
-                        : _EMPTY_UICOMPONENT_ITERATOR;
+                        : Collections.<UIComponent>emptyIterator();
         _facesContext = facesContext;
     }
 
@@ -155,7 +153,7 @@ class _SelectItemsIterator implements Iterator<SelectItem>
                     // value is any kind of array (primitive or non-primitive)
                     // --> we have to use class Array to get the values
                     int length = Array.getLength(value);
-                    Collection<Object> items = new ArrayList<Object>(length);
+                    Collection<Object> items = new ArrayList<>(length);
                     for (int i = 0; i < length; i++)
                     {
                         items.add(Array.get(value, i));
@@ -172,7 +170,7 @@ class _SelectItemsIterator implements Iterator<SelectItem>
                 else if (value instanceof Map)
                 {
                     Map<Object, Object> map = ((Map<Object, Object>) value);
-                    Collection<SelectItem> items = new ArrayList<SelectItem>(map.size());
+                    Collection<SelectItem> items = new ArrayList<>(map.size());
                     for (Map.Entry<Object, Object> entry : map.entrySet())
                     {
                         items.add(new SelectItem(entry.getValue(), entry.getKey().toString()));
diff --git a/impl/src/main/java/org/apache/myfaces/config/MyfacesConfig.java b/impl/src/main/java/org/apache/myfaces/config/MyfacesConfig.java
index 1713ec8..4920e0c 100755
--- a/impl/src/main/java/org/apache/myfaces/config/MyfacesConfig.java
+++ b/impl/src/main/java/org/apache/myfaces/config/MyfacesConfig.java
@@ -774,10 +774,10 @@ public class MyfacesConfig
      * Defines if the last-modified should be cached of the resources when the ProjectStage
is Production.
      * If the cache is disabled, each last-modified request will read the last-modified from
the file.
      */
-    @JSFWebConfigParam(since="3.0.0" , defaultValue="false", expectedValues="true, false")
+    @JSFWebConfigParam(since="3.0.0" , defaultValue="true", expectedValues="true, false")
     public static final String RESOURCE_CACHE_LAST_MODIFIED
             = "org.apache.myfaces.RESOURCE_CACHE_LAST_MODIFIED";
-    private static final boolean RESOURCE_CACHE_LAST_MODIFIED_DEFAULT = false;
+    private static final boolean RESOURCE_CACHE_LAST_MODIFIED_DEFAULT = true;
 
     /**
      * Indicate if log all web config params should be done before initialize the webapp.

@@ -1146,6 +1146,10 @@ public class MyfacesConfig
         
         cfg.resourceHandlerCacheEnabled = getBoolean(extCtx, RESOURCE_HANDLER_CACHE_ENABLED,
                 RESOURCE_HANDLER_CACHE_ENABLED_DEFAULT);
+        if (cfg.projectStage != ProjectStage.Production)
+        {
+            cfg.resourceHandlerCacheEnabled = false;
+        }
         
         cfg.resourceHandlerCacheSize = getInt(extCtx, RESOURCE_HANDLER_CACHE_SIZE,
                 RESOURCE_HANDLER_CACHE_SIZE_DEFAULT);
@@ -1298,6 +1302,10 @@ public class MyfacesConfig
         
         cfg.resourceCacheLastModified = getBoolean(extCtx, RESOURCE_CACHE_LAST_MODIFIED,
                 RESOURCE_CACHE_LAST_MODIFIED_DEFAULT);
+        if (cfg.projectStage == ProjectStage.Development)
+        {
+            cfg.resourceCacheLastModified = false;
+        }
         
         String logWebContextParams = getString(extCtx, LOG_WEB_CONTEXT_PARAMS,
                 LOG_WEB_CONTEXT_PARAMS_DEFAULT);    
diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/html/util/SelectItemsIterator.java
b/impl/src/main/java/org/apache/myfaces/renderkit/html/util/SelectItemsIterator.java
index e8363d2..88df444 100644
--- a/impl/src/main/java/org/apache/myfaces/renderkit/html/util/SelectItemsIterator.java
+++ b/impl/src/main/java/org/apache/myfaces/renderkit/html/util/SelectItemsIterator.java
@@ -53,9 +53,7 @@ public class SelectItemsIterator implements Iterator<SelectItem>
     private static final String ITEM_DISABLED_PROP = JSFAttr.ITEM_DISABLED_ATTR;
     private static final String ITEM_LABEL_ESCAPED_PROP = JSFAttr.ITEM_LABEL_ESCAPED_ATTR;
     private static final String NO_SELECTION_VALUE_PROP = JSFAttr.NO_SELECTION_VALUE_ATTR;
-    
-    private static final Iterator<UIComponent> _EMPTY_UICOMPONENT_ITERATOR = Collections.<UIComponent>emptyIterator();
-    
+
     private final Iterator<UIComponent> _children;
     private Iterator<? extends Object> _nestedItems;
     private SelectItem _nextItem;
@@ -68,7 +66,7 @@ public class SelectItemsIterator implements Iterator<SelectItem>
     {
         _children = selectItemsParent.getChildCount() > 0
                 ? selectItemsParent.getChildren().iterator()
-                : _EMPTY_UICOMPONENT_ITERATOR;
+                : Collections.<UIComponent>emptyIterator();
         _facesContext = facesContext;
     }
 
@@ -162,7 +160,7 @@ public class SelectItemsIterator implements Iterator<SelectItem>
                     // value is any kind of array (primitive or non-primitive)
                     // --> we have to use class Array to get the values
                     final int length = Array.getLength(value);
-                    Collection<Object> items = new ArrayList<Object>(length);
+                    Collection<Object> items = new ArrayList<>(length);
                     for (int i = 0; i < length; i++)
                     {
                         items.add(Array.get(value, i));
@@ -179,7 +177,7 @@ public class SelectItemsIterator implements Iterator<SelectItem>
                 else if (value instanceof Map)
                 {
                     Map<Object, Object> map = ((Map<Object, Object>) value);
-                    Collection<SelectItem> items = new ArrayList<SelectItem>(map.size());
+                    Collection<SelectItem> items = new ArrayList<>(map.size());
                     for (Map.Entry<Object, Object> entry : map.entrySet())
                     {
                         items.add(new SelectItem(entry.getValue(), entry.getKey().toString()));
diff --git a/impl/src/main/java/org/apache/myfaces/resource/ResourceHandlerCache.java b/impl/src/main/java/org/apache/myfaces/resource/ResourceHandlerCache.java
index 8269700..cfd89fa 100644
--- a/impl/src/main/java/org/apache/myfaces/resource/ResourceHandlerCache.java
+++ b/impl/src/main/java/org/apache/myfaces/resource/ResourceHandlerCache.java
@@ -21,8 +21,6 @@ package org.apache.myfaces.resource;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javax.faces.application.ProjectStage;
-import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 
 import org.apache.myfaces.config.MyfacesConfig;
@@ -32,7 +30,7 @@ public class ResourceHandlerCache
 {
     private static final Logger log = Logger.getLogger(ResourceHandlerCache.class.getName());
 
-    private boolean _resourceCacheEnabled = false;
+    private boolean _resourceCacheEnabled;
 
     private volatile ConcurrentLRUCache<Object, ResourceValue> _resourceCacheMap =
null;
     private volatile ConcurrentLRUCache<Object, ResourceValue> _viewResourceCacheMap
= null;
@@ -40,29 +38,19 @@ public class ResourceHandlerCache
 
     public ResourceHandlerCache()
     {
-        if (log.isLoggable(Level.FINE))
-        {
-            log.log(Level.FINE, "Initializing ResourceHandlerCache");
-        }
-     
         FacesContext facesContext = FacesContext.getCurrentInstance();
-        ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
+        MyfacesConfig myfacesConfig = MyfacesConfig.getCurrentInstance(facesContext);
 
-        // skip cache when ProjectStage != Production
-        if (facesContext.isProjectStage(ProjectStage.Production))
+        _resourceCacheEnabled = myfacesConfig.isResourceHandlerCacheEnabled();
+        
+        if (log.isLoggable(Level.FINE))
         {
-            //if in production, make sure that the cache is not explicitly disabled via context
param
-            _resourceCacheEnabled = MyfacesConfig.getCurrentInstance(externalContext).isResourceHandlerCacheEnabled();
-
-            if (log.isLoggable(Level.FINE))
-            {
-                log.log(Level.FINE, "MyFaces ResourceHandlerCache enabled = " + _resourceCacheEnabled);
-            }
+            log.log(Level.FINE, "Initializing ResourceHandlerCache; Enabled = " + _resourceCacheEnabled);
         }
-        
+
         if (_resourceCacheEnabled)
         {
-            int maxSize = MyfacesConfig.getCurrentInstance(externalContext).getResourceHandlerCacheSize();
+            int maxSize = myfacesConfig.getResourceHandlerCacheSize();
 
             _resourceCacheMap = new ConcurrentLRUCache<>((maxSize * 4 + 3) / 3, maxSize);
             _viewResourceCacheMap = new ConcurrentLRUCache<>((maxSize * 4 + 3) / 3,
maxSize);
diff --git a/impl/src/main/java/org/apache/myfaces/resource/ResourceImpl.java b/impl/src/main/java/org/apache/myfaces/resource/ResourceImpl.java
index ad3be82..1da6cba 100644
--- a/impl/src/main/java/org/apache/myfaces/resource/ResourceImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/resource/ResourceImpl.java
@@ -178,13 +178,13 @@ public class ResourceImpl extends Resource implements ContractResource
             // Here we have two cases: If the file could contain EL Expressions
             // the last modified time is the greatest value between application startup and
             // the value from file.
-            if (this.couldResourceContainValueExpressions() &&
-                    lastModified < _resourceHandlerSupport.getStartupTime())
+            if (this.couldResourceContainValueExpressions()
+                    && lastModified < _resourceHandlerSupport.getStartupTime())
             {
                 lastModified = _resourceHandlerSupport.getStartupTime();
             }            
-            else if (_resourceMeta instanceof AliasResourceMetaImpl &&
-                lastModified < _resourceHandlerSupport.getStartupTime())
+            else if (_resourceMeta instanceof AliasResourceMetaImpl
+                    && lastModified < _resourceHandlerSupport.getStartupTime())
             {
                 // If the resource meta is aliased, the last modified time is the greatest

                 // value between application startup and the value from file.
@@ -260,8 +260,8 @@ public class ResourceImpl extends Resource implements ContractResource
         long lastModified = getLastModified(context);
         if (lastModified >= 0)
         {
-            if (this.couldResourceContainValueExpressions() &&
-                    lastModified < _resourceHandlerSupport.getStartupTime())
+            if (this.couldResourceContainValueExpressions()
+                    && lastModified < _resourceHandlerSupport.getStartupTime())
             {
                 lastModified = _resourceHandlerSupport.getStartupTime();
             }
@@ -306,8 +306,7 @@ public class ResourceImpl extends Resource implements ContractResource
     
     protected long getLastModified(FacesContext facesContext)
     {
-        if (facesContext.isProjectStage(ProjectStage.Production)
-                && MyfacesConfig.getCurrentInstance(facesContext).isResourceCacheLastModified())
+        if (MyfacesConfig.getCurrentInstance(facesContext).isResourceCacheLastModified())
         {
             Long lastModified = _resourceMeta.getLastModified();
             if (lastModified == null)
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
b/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
index 7d91812..f5be63c 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
@@ -718,7 +718,7 @@ public class DefaultFaceletsStateManagementStrategy extends StateManagementStrat
                 ensureClearInitialState(view);
                 Object rlcStates = !context.getResourceLibraryContracts().isEmpty() ? 
                     UIComponentBase.saveAttachedState(context, 
-                                new ArrayList<String>(context.getResourceLibraryContracts()))
: null;
+                                new ArrayList<>(context.getResourceLibraryContracts()))
: null;
                 states = new Object[]{
                             internalBuildTreeStructureToSave(view),
                             view.processSaveState(context), rlcStates};
@@ -916,7 +916,7 @@ public class DefaultFaceletsStateManagementStrategy extends StateManagementStrat
         if (clientIdsAdded == null)
         {
             //Create a set that preserve insertion order
-            clientIdsAdded = new ArrayList<String>();
+            clientIdsAdded = new ArrayList<>();
         }
         clientIdsAdded.add(clientId);
 
@@ -926,7 +926,7 @@ public class DefaultFaceletsStateManagementStrategy extends StateManagementStrat
         if (clientIdsRemoved == null)
         {
             //Create a set that preserve insertion order
-            clientIdsRemoved = new ArrayList<String>();
+            clientIdsRemoved = new ArrayList<>();
         }
 
         clientIdsRemoved.add(clientId);
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
b/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
index 94176b6..2e28110 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
@@ -2089,7 +2089,7 @@ public class FaceletViewDeclarationLanguage extends FaceletViewDeclarationLangua
 
         // resource resolver
         ResourceResolver resolver = new DefaultResourceResolver();
-        ArrayList<String> classNames = new ArrayList<String>();
+        ArrayList<String> classNames = new ArrayList<>();
 
         String faceletsResourceResolverClassName = config.getResourceResolver();
         if (faceletsResourceResolverClassName != null)


Mime
View raw message