myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1790060 - in /myfaces/core/branches/2.3.x: api/src/main/java/javax/faces/application/ shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/
Date Tue, 04 Apr 2017 01:43:38 GMT
Author: lu4242
Date: Tue Apr  4 01:43:38 2017
New Revision: 1790060

URL: http://svn.apache.org/viewvc?rev=1790060&view=rev
Log:
MYFACES-4106 - Implement ResourceHandler.markResourceRendered(...) and ResourceHandler.isResourceRendered(...)

Modified:
    myfaces/core/branches/2.3.x/api/src/main/java/javax/faces/application/ResourceHandler.java
    myfaces/core/branches/2.3.x/api/src/main/java/javax/faces/application/ResourceHandlerWrapper.java
    myfaces/core/branches/2.3.x/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/ResourceUtils.java

Modified: myfaces/core/branches/2.3.x/api/src/main/java/javax/faces/application/ResourceHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/api/src/main/java/javax/faces/application/ResourceHandler.java?rev=1790060&r1=1790059&r2=1790060&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/api/src/main/java/javax/faces/application/ResourceHandler.java
(original)
+++ myfaces/core/branches/2.3.x/api/src/main/java/javax/faces/application/ResourceHandler.java
Tue Apr  4 01:43:38 2017
@@ -19,6 +19,8 @@
 package javax.faces.application;
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.stream.Stream;
 
 import javax.faces.context.FacesContext;
@@ -64,6 +66,12 @@ public abstract class ResourceHandler
      * @since 2.3
      */
     public static final String JSF_SCRIPT_LIBRARY_NAME = "javax.faces";
+    
+    private final static String MYFACES_JS_RESOURCE_NAME = "oamSubmit.js";
+    private final static String MYFACES_JS_RESOURCE_NAME_UNCOMPRESSED = "oamSubmit-uncompressed.js";
+    private final static String RENDERED_RESOURCES_SET = "org.apache.myfaces.RENDERED_RESOURCES_SET";
+    private final static String MYFACES_LIBRARY_NAME = "org.apache.myfaces";
+    private final static String RENDERED_MYFACES_JS = "org.apache.myfaces.RENDERED_MYFACES_JS";
 
     public abstract Resource createResource(String resourceName);
     
@@ -111,15 +119,85 @@ public abstract class ResourceHandler
         return url.contains(RESOURCE_IDENTIFIER);
     }
     
+    /**
+     * @since 2.3
+     * @param facesContext
+     * @param path
+     * @param options
+     * @return 
+     */
     public Stream<java.lang.String> getViewResources(
             FacesContext facesContext, String path, ResourceVisitOption... options)
     {
         return getViewResources(facesContext, path, Integer.MAX_VALUE, options);
     }
     
+    /**
+     * @since 2.3
+     * @param facesContext
+     * @param path
+     * @param maxDepth
+     * @param options
+     * @return 
+     */
     public Stream<java.lang.String> getViewResources(FacesContext facesContext, 
             String path, int maxDepth, ResourceVisitOption... options)
     {
         return null;
     }
+    
+    /**
+     * @since 2.3
+     * @param facesContext
+     * @param resourceName
+     * @param libraryName
+     * @return 
+     */
+    public boolean isResourceRendered(FacesContext facesContext, String resourceName, String
libraryName)
+    {
+        return getRenderedResources(facesContext).containsKey(
+                libraryName != null ? libraryName+'/'+resourceName : resourceName);
+    }
+    
+    /**
+     * @since 2.3
+     * @param context
+     * @param resourceName
+     * @param libraryName 
+     */
+    public void markResourceRendered(FacesContext facesContext, String resourceName, String
libraryName)
+    {
+        getRenderedResources(facesContext).put(
+                libraryName != null ? libraryName+'/'+resourceName : resourceName, Boolean.TRUE);
+        if (ResourceHandler.JSF_SCRIPT_LIBRARY_NAME.equals(libraryName) &&
+            ResourceHandler.JSF_SCRIPT_RESOURCE_NAME.equals(resourceName))
+        {
+            // If we are calling this method, it is expected myfaces core is being used as
runtime and note
+            // oamSubmit script is included inside jsf.js, so mark this one too.
+            getRenderedResources(facesContext).put(
+                    MYFACES_LIBRARY_NAME+'/'+MYFACES_JS_RESOURCE_NAME, Boolean.TRUE);
+        }
+    }
+    
+    /**
+     * Return a set of already rendered resources by this renderer on the current
+     * request. 
+     * 
+     * @param facesContext
+     * @return
+     */
+    @SuppressWarnings("unchecked")
+    private static Map<String, Boolean> getRenderedResources(FacesContext facesContext)
+    {
+        Map<String, Boolean> map = (Map<String, Boolean>) facesContext.getAttributes().get(
+                RENDERED_RESOURCES_SET);
+        if (map == null)
+        {
+            map = new HashMap<String, Boolean>();
+            facesContext.getAttributes().put(RENDERED_RESOURCES_SET,map);
+        }
+        return map;
+    }
+    
+    
 }

Modified: myfaces/core/branches/2.3.x/api/src/main/java/javax/faces/application/ResourceHandlerWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/api/src/main/java/javax/faces/application/ResourceHandlerWrapper.java?rev=1790060&r1=1790059&r2=1790060&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/api/src/main/java/javax/faces/application/ResourceHandlerWrapper.java
(original)
+++ myfaces/core/branches/2.3.x/api/src/main/java/javax/faces/application/ResourceHandlerWrapper.java
Tue Apr  4 01:43:38 2017
@@ -107,6 +107,14 @@ public abstract class ResourceHandlerWra
         return delegate;
     }
 
+    /**
+     * @since 2.3
+     * @param facesContext
+     * @param path
+     * @param maxDepth
+     * @param options
+     * @return 
+     */
     @Override
     public Stream<String> getViewResources(
             FacesContext facesContext, String path, int maxDepth, ResourceVisitOption...
options)
@@ -114,9 +122,41 @@ public abstract class ResourceHandlerWra
         return getWrapped().getViewResources(facesContext, path, maxDepth, options);
     }
 
+    /**
+     * @since 2.3
+     * @param facesContext
+     * @param path
+     * @param options
+     * @return 
+     */
     @Override
     public Stream<String> getViewResources(FacesContext facesContext, String path,
ResourceVisitOption... options)
     {
         return getWrapped().getViewResources(facesContext, path, options);
     }
+
+    /**
+     * @since 2.3
+     * @param facesContext
+     * @param resourceName
+     * @param libraryName 
+     */
+    @Override
+    public void markResourceRendered(FacesContext facesContext, String resourceName, String
libraryName)
+    {
+        getWrapped().markResourceRendered(facesContext, resourceName, libraryName);
+    }
+
+    /**
+     * @since 2.3
+     * @param facesContext
+     * @param resourceName
+     * @param libraryName
+     * @return 
+     */
+    @Override
+    public boolean isResourceRendered(FacesContext facesContext, String resourceName, String
libraryName)
+    {
+        return getWrapped().isResourceRendered(facesContext, resourceName, libraryName);
+    }
 }

Modified: myfaces/core/branches/2.3.x/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/ResourceUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/ResourceUtils.java?rev=1790060&r1=1790059&r2=1790060&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/ResourceUtils.java
(original)
+++ myfaces/core/branches/2.3.x/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/ResourceUtils.java
Tue Apr  4 01:43:38 2017
@@ -19,8 +19,6 @@
 package org.apache.myfaces.shared.renderkit.html.util;
 
 import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
 import javax.faces.FacesWrapper;
 
 import javax.faces.application.Resource;
@@ -61,9 +59,6 @@ public class ResourceUtils
     public final static String JSF_MYFACES_JSFJS_EXPERIMENTAL = "jsf-experimental.js";
     public final static String JSF_MYFACES_JSFJS_LEGACY = "jsf-legacy.js";
 
-    private final static String RENDERED_STYLESHEET_RESOURCES_SET = 
-        "org.apache.myfaces.RENDERED_STYLESHEET_RESOURCES_SET";
-    private final static String RENDERED_SCRIPT_RESOURCES_SET = "org.apache.myfaces.RENDERED_SCRIPT_RESOURCES_SET";
     private final static String RENDERED_JSF_JS = "org.apache.myfaces.RENDERED_JSF_JS";
     public final static String HEAD_TARGET = "head";
     public final static String BODY_TARGET = "body";
@@ -74,76 +69,28 @@ public class ResourceUtils
     public static final String DEFAULT_SCRIPT_RENDERER_TYPE = "javax.faces.resource.Script";
     public static final String DEFAULT_STYLESHEET_RENDERER_TYPE = "javax.faces.resource.Stylesheet";
 
-    /**
-     * Return a set of already rendered resources by this renderer on the current
-     * request. 
-     * 
-     * @param facesContext
-     * @return
-     */
-    @SuppressWarnings("unchecked")
-    private static Map<String, Boolean> getRenderedStylesheetResources(FacesContext
facesContext)
-    {
-        Map<String, Boolean> map = (Map<String, Boolean>) facesContext.getAttributes().get(
-                RENDERED_STYLESHEET_RESOURCES_SET);
-        if (map == null)
-        {
-            map = new HashMap<String, Boolean>();
-            facesContext.getAttributes().put(RENDERED_STYLESHEET_RESOURCES_SET,map);
-        }
-        return map;
-    }
-    
-    /**
-     * Return a set of already rendered resources by this renderer on the current
-     * request. 
-     * 
-     * @param facesContext
-     * @return
-     */
-    @SuppressWarnings("unchecked")
-    private static Map<String, Boolean> getRenderedScriptResources(FacesContext facesContext)
-    {
-        Map<String, Boolean> map = (Map<String, Boolean>) facesContext.getAttributes().get(
-                RENDERED_SCRIPT_RESOURCES_SET);
-        if (map == null)
-        {
-            map = new HashMap<String, Boolean>();
-            facesContext.getAttributes().put(RENDERED_SCRIPT_RESOURCES_SET,map);
-        }
-        return map;
-    }
-    
     public static void markScriptAsRendered(FacesContext facesContext, String libraryName,
String resourceName)
     {
-        getRenderedScriptResources(facesContext).put(
-                libraryName != null ? libraryName+'/'+resourceName : resourceName, Boolean.TRUE);
-        if (ResourceHandler.JSF_SCRIPT_LIBRARY_NAME.equals(libraryName) &&
-            ResourceHandler.JSF_SCRIPT_RESOURCE_NAME.equals(resourceName))
-        {
-            // If we are calling this method, it is expected myfaces core is being used as
runtime and note
-            // oamSubmit script is included inside jsf.js, so mark this one too.
-            getRenderedScriptResources(facesContext).put(
-                    MYFACES_LIBRARY_NAME+'/'+MYFACES_JS_RESOURCE_NAME, Boolean.TRUE);
-        }
+        facesContext.getApplication().getResourceHandler().markResourceRendered(
+                facesContext, resourceName, libraryName);
     }
     
     public static void markStylesheetAsRendered(FacesContext facesContext, String libraryName,
String resourceName)
     {
-        getRenderedStylesheetResources(facesContext).put(
-                libraryName != null ? libraryName+'/'+resourceName : resourceName, Boolean.TRUE);
+        facesContext.getApplication().getResourceHandler().markResourceRendered(
+                facesContext, resourceName, libraryName);
     }
     
     public static boolean isRenderedScript(FacesContext facesContext, String libraryName,
String resourceName)
     {
-        return getRenderedScriptResources(facesContext).containsKey(
-                libraryName != null ? libraryName+'/'+resourceName : resourceName);
+        return facesContext.getApplication().getResourceHandler().isResourceRendered(
+                facesContext, resourceName, libraryName);
     }
     
     public static boolean isRenderedStylesheet(FacesContext facesContext, String libraryName,
String resourceName)
     {
-        return getRenderedStylesheetResources(facesContext).containsKey(
-                libraryName != null ? libraryName+'/'+resourceName : resourceName);
+        return facesContext.getApplication().getResourceHandler().isResourceRendered(
+                facesContext, resourceName, libraryName);
     }
     
     public static void writeScriptInline(FacesContext facesContext, ResponseWriter writer,
String libraryName, 



Mime
View raw message