myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jak...@apache.org
Subject svn commit: r960867 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces: application/ApplicationImpl.java application/ViewHandlerImpl.java context/servlet/PartialViewContextImpl.java view/facelets/FaceletViewDeclarationLanguage.java
Date Tue, 06 Jul 2010 10:57:27 GMT
Author: jakobk
Date: Tue Jul  6 10:57:26 2010
New Revision: 960867

URL: http://svn.apache.org/viewvc?rev=960867&view=rev
Log:
MYFACES-2787 Application objects which can be wrapped must not access public methods internally
(+ some code cleanup)

Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java?rev=960867&r1=960866&r2=960867&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
Tue Jul  6 10:57:26 2010
@@ -930,7 +930,6 @@ public class ApplicationImpl extends App
         return _viewHandler;
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public void addBehavior(String behaviorId, String behaviorClass)
     {
@@ -952,7 +951,6 @@ public class ApplicationImpl extends App
 
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public final void addComponent(final String componentType, final String componentClassName)
     {
@@ -973,7 +971,6 @@ public class ApplicationImpl extends App
         }
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public final void addConverter(final String converterId, final String converterClass)
     {
@@ -1024,7 +1021,6 @@ public class ApplicationImpl extends App
         _converterClassNameToConfigurationMap.put(converterClassName, configuration);
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public final void addValidator(final String validatorId, final String validatorClass)
     {
@@ -1762,8 +1758,11 @@ public class ApplicationImpl extends App
     }
 
     private void _handleAnnotations(FacesContext context, Object inspected, UIComponent component)
-    {        
-        boolean isProduction = getProjectStage().equals(ProjectStage.Production);
+    {   
+        // determine the ProjectStage setting via the given FacesContext
+        // note that a local getProjectStage() could cause problems in wrapped environments
+        boolean isProduction = context.isProjectStage(ProjectStage.Production);
+        
         Class<?> inspectedClass = inspected.getClass();
         _handleListenerForAnnotations(context, inspected, inspectedClass, component, isProduction);
 
@@ -1841,6 +1840,11 @@ public class ApplicationImpl extends App
             // ComponentSystemEventListener, "target" is the Application instance.
             else if (component instanceof SystemEventListener)
             {
+                // use the Application object from the FacesContext (note that a
+                // direct use of subscribeToEvent() could cause problems if the
+                // Application is wrapped)
+                Application application = context.getApplication();
+                
                 // If "target" is the Application instance, inspect the value of the sourceClass()
annotation attribute
                 // value.
                 if (Void.class.equals(annotation.sourceClass()))
@@ -1851,7 +1855,7 @@ public class ApplicationImpl extends App
                      * which this annotation is attached (which must implement SystemEventListener)
as the second
                      * argument.
                      */
-                    subscribeToEvent(annotation.systemEventClass(), (SystemEventListener)
inspected);
+                    application.subscribeToEvent(annotation.systemEventClass(), (SystemEventListener)
inspected);
                 }
                 else
                 {
@@ -1861,7 +1865,7 @@ public class ApplicationImpl extends App
                      * argument, and the instance of the class to which this annotation is
attached (which must
                      * implement SystemEventListener) as the third argument.
                      */
-                    subscribeToEvent(annotation.systemEventClass(), annotation.sourceClass(),
+                    application.subscribeToEvent(annotation.systemEventClass(), annotation.sourceClass(),
                                      (SystemEventListener) inspected);
                 }
             }
@@ -1936,7 +1940,8 @@ public class ApplicationImpl extends App
 
             // Obtain the renderer-type for the resource name by passing name to
             // ResourceHandler.getRendererTypeForResourceName(java.lang.String).
-            String rendererType = getResourceHandler().getRendererTypeForResourceName(name);
+            // (note that we can not use this.getResourceHandler(), because the Application
might be wrapped)
+            String rendererType = context.getApplication().getResourceHandler().getRendererTypeForResourceName(name);
 
             // Call setRendererType on the UIOutput instance, passing the renderer-type.
             output.setRendererType(rendererType);

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java?rev=960867&r1=960866&r2=960867&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java
Tue Jul  6 10:57:26 2010
@@ -64,6 +64,19 @@ public class ViewHandlerImpl extends Vie
     public static final String FORM_STATE_MARKER = "<!--@@JSF_FORM_STATE_MARKER@@-->";
     private ViewHandlerSupport _viewHandlerSupport;
     private ViewDeclarationLanguageFactory _vdlFactory;
+    
+    /**
+     * Gets the current ViewHandler via FacesContext.getApplication().getViewHandler().
+     * We have to use this method to invoke any other specified ViewHandler-method
+     * in the code, because direct access (this.method()) will cause problems if
+     * the ViewHandler is wrapped.
+     * @param facesContext
+     * @return
+     */
+    public static ViewHandler getViewHandler(FacesContext facesContext)
+    {
+        return facesContext.getApplication().getViewHandler();
+    }
 
     public ViewHandlerImpl()
     {
@@ -94,7 +107,6 @@ public class ViewHandlerImpl extends Vie
             Map<String, List<String>> parameters, boolean includeViewParams)
     {
         Map<String, List<String>> viewParameters;
-        ExternalContext externalContext = context.getExternalContext();
         if (includeViewParams)
         {
             viewParameters = getViewParameterList(context, viewId, parameters);
@@ -104,7 +116,11 @@ public class ViewHandlerImpl extends Vie
             viewParameters = parameters;
         }
         
-        String actionEncodedViewId = getActionURL(context, viewId);
+        // note that we cannot use this.getActionURL(), because this will
+        // cause problems if the ViewHandler is wrapped
+        String actionEncodedViewId = getViewHandler(context).getActionURL(context, viewId);
+        
+        ExternalContext externalContext = context.getExternalContext();
         String bookmarkEncodedURL = externalContext.encodeBookmarkableURL(actionEncodedViewId,
viewParameters);
         return externalContext.encodeActionURL(bookmarkEncodedURL);
     }
@@ -114,7 +130,6 @@ public class ViewHandlerImpl extends Vie
             Map<String, List<String>> parameters, boolean includeViewParams)
     {
         Map<String, List<String>> viewParameters;
-        ExternalContext externalContext = context.getExternalContext();
         if (includeViewParams)
         {
             viewParameters = getViewParameterList(context, viewId, parameters);
@@ -124,7 +139,11 @@ public class ViewHandlerImpl extends Vie
             viewParameters = parameters;
         }
         
-        String actionEncodedViewId = getActionURL(context, viewId);
+        // note that we cannot use this.getActionURL(), because this will
+        // cause problems if the ViewHandler is wrapped
+        String actionEncodedViewId = getViewHandler(context).getActionURL(context, viewId);
+        
+        ExternalContext externalContext = context.getExternalContext();
         String redirectEncodedURL = externalContext.encodeRedirectURL(actionEncodedViewId,
viewParameters);
         return externalContext.encodeActionURL(redirectEncodedURL);
     }
@@ -200,7 +219,11 @@ public class ViewHandlerImpl extends Vie
     {
        checkNull(context, "facesContext");
        String calculatedViewId = getViewHandlerSupport().calculateViewId(context, viewId);
-       return getViewDeclarationLanguage(context,calculatedViewId).createView(context,calculatedViewId);
+       
+       // we cannot use this.getVDL() directly (see getViewHandler())
+       return getViewHandler(context)
+               .getViewDeclarationLanguage(context, calculatedViewId)
+                   .createView(context, calculatedViewId);
     }
 
     @Override
@@ -229,7 +252,10 @@ public class ViewHandlerImpl extends Vie
         checkNull(context, "context");
         checkNull(viewToRender, "viewToRender");
 
-        getViewDeclarationLanguage(context,viewToRender.getViewId()).renderView(context,
viewToRender);
+        // we cannot use this.getVDL() directly (see getViewHandler())
+        String viewId = viewToRender.getViewId();
+        getViewHandler(context).getViewDeclarationLanguage(context, viewId)
+                .renderView(context, viewToRender);
     }
 
     @Override
@@ -238,7 +264,11 @@ public class ViewHandlerImpl extends Vie
         checkNull(context, "context");
     
         String calculatedViewId = getViewHandlerSupport().calculateViewId(context, viewId);
-        return getViewDeclarationLanguage(context,calculatedViewId).restoreView(context,
calculatedViewId); 
+        
+        // we cannot use this.getVDL() directly (see getViewHandler())
+        return getViewHandler(context)
+                .getViewDeclarationLanguage(context,calculatedViewId)
+                    .restoreView(context, calculatedViewId); 
     }
     
     @Override
@@ -287,8 +317,6 @@ public class ViewHandlerImpl extends Vie
     private Map<String, List<String>> getViewParameterList(FacesContext context,
             String viewId, Map<String, List<String>> parametersFromArg)
     {
-
-        Map<String, List<String>> viewParameters;
         UIViewRoot viewRoot = context.getViewRoot();
         String currentViewId = viewRoot.getViewId();
         Collection<UIViewParameter> toViewParams = null;
@@ -300,8 +328,10 @@ public class ViewHandlerImpl extends Vie
         }
         else
         {
-            String calculatedViewId = getViewHandlerSupport().calculateViewId(context, viewId);
           
-            ViewDeclarationLanguage vdl = getViewDeclarationLanguage(context,calculatedViewId);
+            String calculatedViewId = getViewHandlerSupport().calculateViewId(context, viewId);
 
+            // we cannot use this.getVDL() directly (see getViewHandler())
+            ViewDeclarationLanguage vdl = getViewHandler(context).
+                    getViewDeclarationLanguage(context, calculatedViewId);
             ViewMetadata viewMetadata = vdl.getViewMetadata(context, viewId);
             // getViewMetadata() returns null on JSP
             if (viewMetadata != null)

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java?rev=960867&r1=960866&r2=960867&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java
Tue Jul  6 10:57:26 2010
@@ -335,7 +335,10 @@ public class PartialViewContextImpl exte
         //    return;
         //}
 
-        PartialResponseWriter writer = getPartialResponseWriter();
+        // note that we cannot use this.getPartialResponseWriter(), because
+        // this could cause problems if PartialResponseWriter is wrapped
+        PartialResponseWriter writer = _facesContext.getPartialViewContext().getPartialResponseWriter();
+        
         ResponseWriter oldWriter = _facesContext.getResponseWriter();
         boolean inDocument = false;
 

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java?rev=960867&r1=960866&r2=960867&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
Tue Jul  6 10:57:26 2010
@@ -1458,7 +1458,7 @@ public class FaceletViewDeclarationLangu
 
         // -= Leonardo Uribe =- Add */* to the contentType is a fix done from FaceletViewHandler
         // to make old RI versions work, but since this is for JSF 2.0 it is not necessary
that code.
-        ResponseWriter writer = writer = renderKit.createResponseWriter(NullWriter.Instance,
contentType, encoding);
+        ResponseWriter writer = renderKit.createResponseWriter(NullWriter.Instance, contentType,
encoding);
         
         //ResponseWriter writer;
         // append */* to the contentType so createResponseWriter will succeed no matter



Mime
View raw message