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: cache resource identifier
Date Mon, 03 Dec 2018 19:42:52 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 e6de197  cache resource identifier
e6de197 is described below

commit e6de197a69e8dd02106d59fb8529ec9378a0f718
Author: Thomas Andraschko <tandraschko@apache.org>
AuthorDate: Mon Dec 3 20:42:50 2018 +0100

    cache resource identifier
---
 .../myfaces/application/ResourceHandlerImpl.java   | 31 +++-----
 .../myfaces/resource/AliasResourceMetaImpl.java    | 86 +++++++++++-----------
 2 files changed, 54 insertions(+), 63 deletions(-)

diff --git a/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java b/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java
index 8c89ab8..35a899f 100644
--- a/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java
@@ -624,7 +624,6 @@ public class ResourceHandlerImpl extends ResourceHandler
         {
             InputStream in = resource.getInputStream();
             OutputStream out = httpServletResponse.getOutputStream();
-            //byte[] buffer = new byte[_BUFFER_SIZE];
             byte[] buffer = new byte[this.getResourceBufferSize()];
 
             try
@@ -677,8 +676,7 @@ public class ResourceHandlerImpl extends ResourceHandler
      * Reads the specified input stream into the provided byte array storage and
      * writes it to the output stream.
      */
-    private static int pipeBytes(InputStream in, OutputStream out, byte[] buffer)
-            throws IOException
+    private static int pipeBytes(InputStream in, OutputStream out, byte[] buffer) throws
IOException
     {
         int count = 0;
         int length;
@@ -743,8 +741,7 @@ public class ResourceHandlerImpl extends ResourceHandler
             
             if (isResourceRequest || context.getViewRoot() == null)
             {
-                locale = context.getApplication().getViewHandler()
-                                .calculateLocale(context);
+                locale = context.getApplication().getViewHandler().calculateLocale(context);
             }
             else
             {
@@ -753,8 +750,8 @@ public class ResourceHandlerImpl extends ResourceHandler
 
             try
             {
-                ResourceBundle bundle = ResourceBundle
-                        .getBundle(bundleName, locale, ClassUtils.getContextClassLoader());
+                ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale,
+                        ClassUtils.getContextClassLoader());
 
                 if (bundle != null)
                 {
@@ -859,8 +856,7 @@ public class ResourceHandlerImpl extends ResourceHandler
             {
                 for (String contract : contracts)
                 {
-                    for (ContractResourceLoader loader : getResourceHandlerSupport()
-                            .getContractResourceLoaders())
+                    for (ContractResourceLoader loader : getResourceHandlerSupport().getContractResourceLoaders())
                     {
                         if (loader.libraryExists(pathToLib, contract))
                         {
@@ -871,8 +867,7 @@ public class ResourceHandlerImpl extends ResourceHandler
                 }
             }
             
-            for (ResourceLoader loader : getResourceHandlerSupport()
-                    .getResourceLoaders())
+            for (ResourceLoader loader : getResourceHandlerSupport().getResourceLoaders())
             {
                 if (loader.libraryExists(pathToLib))
                 {
@@ -887,8 +882,7 @@ public class ResourceHandlerImpl extends ResourceHandler
         {
             for (String contract : contracts)
             {
-                for (ContractResourceLoader loader : getResourceHandlerSupport()
-                        .getContractResourceLoaders())
+                for (ContractResourceLoader loader : getResourceHandlerSupport().getContractResourceLoaders())
                 {
                     if (loader.libraryExists(libraryName, contract))
                     {
@@ -899,8 +893,7 @@ public class ResourceHandlerImpl extends ResourceHandler
             }
         }
 
-        for (ResourceLoader loader : getResourceHandlerSupport()
-                .getResourceLoaders())
+        for (ResourceLoader loader : getResourceHandlerSupport().getResourceLoaders())
         {
             if (loader.libraryExists(libraryName))
             {
@@ -925,8 +918,7 @@ public class ResourceHandlerImpl extends ResourceHandler
      * @param resourceHandlerSupport
      *            the resourceHandlerSupport to set
      */
-    public void setResourceHandlerSupport(
-            ResourceHandlerSupport resourceHandlerSupport)
+    public void setResourceHandlerSupport(ResourceHandlerSupport resourceHandlerSupport)
     {
         _resourceHandlerSupport = resourceHandlerSupport;
     }
@@ -1045,8 +1037,7 @@ public class ResourceHandlerImpl extends ResourceHandler
         // a contract.
         if (contractPreferred != null)
         {
-            resourceValue = getResourceLoaderCache().getResource(
-                    resourceId, contractPreferred);
+            resourceValue = getResourceLoaderCache().getResource(resourceId, contractPreferred);
         }
         if (resourceValue == null && !contracts.isEmpty())
         {
@@ -1066,7 +1057,7 @@ public class ResourceHandlerImpl extends ResourceHandler
             resourceValue = getResourceLoaderCache().getResource(resourceId);
         }
         
-        if(resourceValue != null)
+        if (resourceValue != null)
         {        
             //Resolve contentType using ExternalContext.getMimeType
             String contentType = facesContext.getExternalContext().getMimeType(
diff --git a/impl/src/main/java/org/apache/myfaces/resource/AliasResourceMetaImpl.java b/impl/src/main/java/org/apache/myfaces/resource/AliasResourceMetaImpl.java
index 2cae556..871476c 100644
--- a/impl/src/main/java/org/apache/myfaces/resource/AliasResourceMetaImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/resource/AliasResourceMetaImpl.java
@@ -23,9 +23,10 @@ package org.apache.myfaces.resource;
  */
 public class AliasResourceMetaImpl extends ResourceMetaImpl
 {
-    private String _realResourceName;
+    private final String _realResourceName;
+    private final boolean _couldContainValueExpressions;
     
-    private boolean _couldContainValueExpressions;
+    private String resourceIdentifier = null;
 
     public AliasResourceMetaImpl(String prefix, String libraryName, String libraryVersion,
             String resourceName, String resourceVersion, String realResourceName, boolean
couldContainValueExpressions)
@@ -48,61 +49,60 @@ public class AliasResourceMetaImpl extends ResourceMetaImpl
     {
         return _realResourceName;
     }
-
-    public void setRealResourceName(String realResourceName)
-    {
-        _realResourceName = realResourceName;
-    }
     
     @Override
     public String getResourceIdentifier()
     {
-        StringBuilder builder = new StringBuilder();
-        boolean firstSlashAdded = false;
-        if (getLocalePrefix() != null && getLocalePrefix().length() > 0)
+        if (resourceIdentifier == null)
         {
-            builder.append(getLocalePrefix());
-            firstSlashAdded = true;
-        }
-        if (getLibraryName() != null)
-        {
-            if (firstSlashAdded)
+            StringBuilder builder = new StringBuilder();
+            boolean firstSlashAdded = false;
+            if (getLocalePrefix() != null && getLocalePrefix().length() > 0)
             {
-                builder.append('/');
+                builder.append(getLocalePrefix());
+                firstSlashAdded = true;
             }
-            builder.append(getLibraryName());
-            firstSlashAdded = true;
-        }
-        if (getLibraryVersion() != null)
-        {
-            if (firstSlashAdded)
+            if (getLibraryName() != null)
             {
-                builder.append('/');
+                if (firstSlashAdded)
+                {
+                    builder.append('/');
+                }
+                builder.append(getLibraryName());
+                firstSlashAdded = true;
             }
-            builder.append(getLibraryVersion());
-            firstSlashAdded = true;
-        }
-        if (getRealResourceName() != null)
-        {
-            if (firstSlashAdded)
+            if (getLibraryVersion() != null)
             {
-                builder.append('/');
+                if (firstSlashAdded)
+                {
+                    builder.append('/');
+                }
+                builder.append(getLibraryVersion());
+                firstSlashAdded = true;
             }
-            builder.append(getRealResourceName());
-            firstSlashAdded = true;
-        }
-        if (getResourceVersion() != null)
-        {
-            if (firstSlashAdded)
+            if (getRealResourceName() != null)
+            {
+                if (firstSlashAdded)
+                {
+                    builder.append('/');
+                }
+                builder.append(getRealResourceName());
+                firstSlashAdded = true;
+            }
+            if (getResourceVersion() != null)
             {
-                builder.append('/');
+                if (firstSlashAdded)
+                {
+                    builder.append('/');
+                }
+                builder.append(getResourceVersion());
+                builder.append(getRealResourceName().substring(getRealResourceName().lastIndexOf('.')));
+                firstSlashAdded = true;
             }
-            builder.append(getResourceVersion());
-            builder.append(
-                    getRealResourceName().substring(getRealResourceName().lastIndexOf('.')));
-            firstSlashAdded = true;
+            resourceIdentifier = builder.toString();
         }
-        return builder.toString();
+        
+        return resourceIdentifier;
     }
 
     @Override


Mime
View raw message