myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1296049 - in /myfaces/core/trunk: impl/src/main/java/org/apache/myfaces/application/ impl/src/main/java/org/apache/myfaces/config/ impl/src/main/java/org/apache/myfaces/el/unified/ impl/src/main/java/org/apache/myfaces/view/ impl/src/main/...
Date Fri, 02 Mar 2012 04:48:17 GMT
Author: lu4242
Date: Fri Mar  2 04:48:16 2012
New Revision: 1296049

URL: http://svn.apache.org/viewvc?rev=1296049&view=rev
Log:
MYFACES-3078 performance: allow to disable JSP support (Thanks to Martin Koci for provide
this patch)

Added:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/FaceletsInitilializer.java
  (with props)
Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/ViewDeclarationLanguageFactoryImpl.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializerFactory.java
    myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/el/unified/ResolverBuilderBaseTest.java
    myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.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=1296049&r1=1296048&r2=1296049&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
Fri Mar  2 04:48:16 2012
@@ -102,6 +102,7 @@ import org.apache.myfaces.el.unified.Res
 import org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver;
 import org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.Scope;
 import org.apache.myfaces.lifecycle.LifecycleImpl;
+import org.apache.myfaces.shared.config.MyfacesConfig;
 import org.apache.myfaces.shared.util.ClassUtils;
 import org.apache.myfaces.view.facelets.el.ELText;
 
@@ -353,7 +354,17 @@ public class ApplicationImpl extends App
 
     private ELResolver createFacesResolver()
     {
-        final CompositeELResolver resolver = new FacesCompositeELResolver(Scope.Faces);
+        boolean supportJSPAndFacesEL = MyfacesConfig.getCurrentInstance(
+                                getFaceContext().getExternalContext()).isSupportJSPAndFacesEL();
+        CompositeELResolver resolver;
+        if (supportJSPAndFacesEL)
+        {
+            resolver = new FacesCompositeELResolver(Scope.Faces);
+        }
+        else
+        {
+            resolver = new CompositeELResolver();
+        }
         getResolverBuilderForFaces().build(resolver);
         return resolver;
     }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java?rev=1296049&r1=1296048&r2=1296049&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
Fri Mar  2 04:48:16 2012
@@ -677,14 +677,19 @@ public class FacesConfigurator
 
         RuntimeConfig runtimeConfig = getRuntimeConfig();
 
-        runtimeConfig.setPropertyResolverChainHead(ClassUtils.buildApplicationObject(PropertyResolver.class,
-                dispenser.getPropertyResolverIterator(),
-                new DefaultPropertyResolver()));
-
-        runtimeConfig.setVariableResolverChainHead(ClassUtils.buildApplicationObject(VariableResolver.class,
-                dispenser.getVariableResolverIterator(),
-                new VariableResolverImpl()));
+        if (MyfacesConfig.getCurrentInstance(_externalContext).isSupportJSPAndFacesEL())
+        {
+            // If no JSP and old Faces EL, there is no need to initialize PropertyResolver
+            // and VariableResolver stuff.
+            runtimeConfig.setPropertyResolverChainHead(ClassUtils.buildApplicationObject(PropertyResolver.class,
+                    dispenser.getPropertyResolverIterator(),
+                    new DefaultPropertyResolver()));
+    
+            runtimeConfig.setVariableResolverChainHead(ClassUtils.buildApplicationObject(VariableResolver.class,
+                    dispenser.getVariableResolverIterator(),
+                    new VariableResolverImpl()));
         }
+    }
 
     /**
      * A mapper for the handful of system listener defaults

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java?rev=1296049&r1=1296048&r2=1296049&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java
Fri Mar  2 04:48:16 2012
@@ -24,6 +24,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.el.ELResolver;
+import javax.faces.context.FacesContext;
 import javax.faces.el.PropertyResolver;
 import javax.faces.el.VariableResolver;
 
@@ -34,6 +35,7 @@ import org.apache.myfaces.config.Runtime
 import org.apache.myfaces.el.convert.PropertyResolverToELResolver;
 import org.apache.myfaces.el.convert.VariableResolverToELResolver;
 import org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.Scope;
+import org.apache.myfaces.shared.config.MyfacesConfig;
 
 /**
  * @author Mathias Broekelmann (latest modification by $Author$)
@@ -88,22 +90,49 @@ public class ResolverBuilderBase
             }
         }
 
-        if (_config.getVariableResolver() != null)
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        if (facesContext == null)
         {
-            resolvers.add(createELResolver(_config.getVariableResolver()));
-        }
-        else if (_config.getVariableResolverChainHead() != null)
-        {
-            resolvers.add(createELResolver(_config.getVariableResolverChainHead()));
-        }
+            // Should not happen, but if by some reason happens,
+            // initialize as usual.
+            if (_config.getVariableResolver() != null)
+            {
+                resolvers.add(createELResolver(_config.getVariableResolver()));
+            }
+            else if (_config.getVariableResolverChainHead() != null)
+            {
+                resolvers.add(createELResolver(_config.getVariableResolverChainHead()));
+            }
 
-        if (_config.getPropertyResolver() != null)
-        {
-            resolvers.add(createELResolver(_config.getPropertyResolver()));
+            if (_config.getPropertyResolver() != null)
+            {
+                resolvers.add(createELResolver(_config.getPropertyResolver()));
+            }
+            else if (_config.getPropertyResolverChainHead() != null)
+            {
+                resolvers.add(createELResolver(_config.getPropertyResolverChainHead()));
+            }
         }
-        else if (_config.getPropertyResolverChainHead() != null)
+        else if (facesContext != null && MyfacesConfig.getCurrentInstance(
+                facesContext.getExternalContext()).isSupportJSPAndFacesEL())
         {
-            resolvers.add(createELResolver(_config.getPropertyResolverChainHead()));
+            if (_config.getVariableResolver() != null)
+            {
+                resolvers.add(createELResolver(_config.getVariableResolver()));
+            }
+            else if (_config.getVariableResolverChainHead() != null)
+            {
+                resolvers.add(createELResolver(_config.getVariableResolverChainHead()));
+            }
+
+            if (_config.getPropertyResolver() != null)
+            {
+                resolvers.add(createELResolver(_config.getPropertyResolver()));
+            }
+            else if (_config.getPropertyResolverChainHead() != null)
+            {
+                resolvers.add(createELResolver(_config.getPropertyResolverChainHead()));
+            }
         }
 
         if (_config.getApplicationElResolvers() != null)

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/ViewDeclarationLanguageFactoryImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/ViewDeclarationLanguageFactoryImpl.java?rev=1296049&r1=1296048&r2=1296049&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/ViewDeclarationLanguageFactoryImpl.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/ViewDeclarationLanguageFactoryImpl.java
Fri Mar  2 04:48:16 2012
@@ -27,6 +27,7 @@ import javax.faces.view.ViewDeclarationL
 import javax.faces.view.ViewDeclarationLanguageFactory;
 
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
+import org.apache.myfaces.shared.config.MyfacesConfig;
 import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguageStrategy;
 import org.apache.myfaces.view.jsp.JspViewDeclarationLanguageStrategy;
 
@@ -102,9 +103,18 @@ public class ViewDeclarationLanguageFact
             {
                 logWarningIfLegacyFaceletViewHandlerIsPresent(context);
 
-                _supportedLanguages = new ViewDeclarationLanguageStrategy[2];
-                _supportedLanguages[0] = new FaceletViewDeclarationLanguageStrategy();
-                _supportedLanguages[1] = new JspViewDeclarationLanguageStrategy();
+                if (MyfacesConfig.getCurrentInstance(
+                        context.getExternalContext()).isSupportJSPAndFacesEL())
+                {
+                    _supportedLanguages = new ViewDeclarationLanguageStrategy[2];
+                    _supportedLanguages[0] = new FaceletViewDeclarationLanguageStrategy();
+                    _supportedLanguages[1] = new JspViewDeclarationLanguageStrategy();
+                }
+                else
+                {
+                    _supportedLanguages = new ViewDeclarationLanguageStrategy[1];
+                    _supportedLanguages[0] = new FaceletViewDeclarationLanguageStrategy();
+                }
             }
             else
             {

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/FaceletsInitilializer.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/FaceletsInitilializer.java?rev=1296049&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/FaceletsInitilializer.java
(added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/FaceletsInitilializer.java
Fri Mar  2 04:48:16 2012
@@ -0,0 +1,49 @@
+/*
+ * 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.webapp;
+
+import javax.el.ExpressionFactory;
+import javax.faces.FacesException;
+import javax.faces.context.ExternalContext;
+import javax.servlet.ServletContext;
+
+/**
+ * This initializer initializes only Facelets. Specially checks for
+ * org.apache.myfaces.EXPRESSION_FACTORY parameter.
+ * 
+ * @author Martin Koci
+ */
+public class FaceletsInitilializer extends org.apache.myfaces.webapp.AbstractFacesInitializer
+{
+
+    @Override
+    protected void initContainerIntegration(ServletContext servletContext, ExternalContext
externalContext)
+    {
+
+        ExpressionFactory expressionFactory = getUserDefinedExpressionFactory(externalContext);
+        if (expressionFactory == null)
+        {
+            throw new FacesException("No javax.el.ExpressionFactory found. Please provide"
+
+                    " <context-param> in web.xml: org.apache.myfaces.EXPRESSION_FACTORY");
+        }
+
+        buildConfiguration(servletContext, externalContext, expressionFactory);
+    }
+
+}

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/FaceletsInitilializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializerFactory.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializerFactory.java?rev=1296049&r1=1296048&r2=1296049&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializerFactory.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializerFactory.java
Fri Mar  2 04:48:16 2012
@@ -22,6 +22,7 @@ import javax.faces.FacesException;
 import javax.servlet.ServletContext;
 
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
+import org.apache.myfaces.shared.config.MyfacesConfig;
 import org.apache.myfaces.shared.util.ClassUtils;
 import org.apache.myfaces.util.ContainerUtils;
 
@@ -99,7 +100,13 @@ public class FacesInitializerFactory
      */
     private static FacesInitializer _getDefaultFacesInitializer(ServletContext context)
     {
-        if (ContainerUtils.isJsp21(context)) 
+        // No MyfacesConfig available yet, we must read the parameter directly:
+        String initParameter = context.getInitParameter(MyfacesConfig.INIT_PARAM_SUPPORT_JSP_AND_FACES_EL);
+        if (Boolean.FALSE.toString().equals(initParameter))
+        {
+            return new FaceletsInitilializer();
+        } 
+        else if (ContainerUtils.isJsp21(context)) 
         {
             return new Jsp21FacesInitializer();
         } 

Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/el/unified/ResolverBuilderBaseTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/el/unified/ResolverBuilderBaseTest.java?rev=1296049&r1=1296048&r2=1296049&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/el/unified/ResolverBuilderBaseTest.java
(original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/el/unified/ResolverBuilderBaseTest.java
Fri Mar  2 04:48:16 2012
@@ -31,6 +31,7 @@ import javax.faces.el.VariableResolver;
 import org.apache.myfaces.config.RuntimeConfig;
 import org.apache.myfaces.el.convert.PropertyResolverToELResolver;
 import org.apache.myfaces.el.convert.VariableResolverToELResolver;
+import org.apache.myfaces.test.base.junit4.AbstractJsfTestCase;
 import org.easymock.classextension.EasyMock;
 import org.easymock.classextension.IMocksControl;
 import org.junit.After;
@@ -43,7 +44,7 @@ import org.junit.Test;
  * @version $Revision$ $Date$
  */
 @SuppressWarnings("deprecation")
-public class ResolverBuilderBaseTest
+public class ResolverBuilderBaseTest extends AbstractJsfTestCase
 {
     private IMocksControl _mocksControl;
     private RuntimeConfig _runtimeConfig;
@@ -55,8 +56,9 @@ public class ResolverBuilderBaseTest
     }
 
     @Before
-    public void setUp()
+    public void setUp() throws Exception
     {
+        super.setUp();
         _mocksControl = EasyMock.createNiceControl();
         _runtimeConfig = _mocksControl.createMock(RuntimeConfig.class);
         _testImpl = new ResolverBuilderBase(_runtimeConfig);
@@ -64,8 +66,9 @@ public class ResolverBuilderBaseTest
     }
     
     @After
-    public void tearDown()
+    public void tearDown() throws Exception
     {
+        super.tearDown();
         _mocksControl = null;
         _runtimeConfig = null;
         _testImpl = null;

Modified: myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java?rev=1296049&r1=1296048&r2=1296049&view=diff
==============================================================================
--- myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java
(original)
+++ myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java
Fri Mar  2 04:48:16 2012
@@ -354,6 +354,20 @@ public class MyfacesConfig
         "org.apache.myfaces.DEFAULT_RESPONSE_WRITER_CONTENT_TYPE_MODE";
     public final static String INIT_PARAM_DEFAULT_RESPONSE_WRITER_CONTENT_TYPE_MODE_DEFAULT
= "text/html";
     
+    /**
+    * If set false, myfaces won't support JSP and javax.faces.el. JSP are deprecated in JSF
2.X, javax.faces.el in 
+    * in JSF 1.2. Default value is true. 
+    * 
+    * If this property is set is false, JSF 1.1 VariableResolver and PropertyResolver config
(replaced in JSF 1.2 by
+    * ELResolver) and all related logic for JSP is skipped, making EL evaluation faster.
 
+    */
+    @JSFWebConfigParam(since="2.0.13,2.1.7", expectedValues="true,false", defaultValue="true",
+         desc="If set false, myfaces won't support JSP and javax.faces.el. JSP are deprecated
in " +
+         "JSF 2.X, javax.faces.el in in JSF 1.2. Default value is true.",
+         group="EL", tags="performance ")
+    public final static String INIT_PARAM_SUPPORT_JSP_AND_FACES_EL = "org.apache.myfaces.SUPPORT_JSP_AND_FACES_EL";
+    public final static boolean INIT_PARAM_SUPPORT_JSP_AND_FACES_EL_DEFAULT = true;
+    
     private boolean _prettyHtml;
     private boolean _detectJavascript;
     private boolean _allowJavascript;
@@ -380,6 +394,7 @@ public class MyfacesConfig
     private boolean _strictJsf2RefreshTargetAjax;
     private boolean _strictJsf2CCELResolver;
     private String _defaultResponseWriterContentTypeMode;
+    private boolean _supportJSPAndFacesEL;
 
     private static final boolean TOMAHAWK_AVAILABLE;
     private static final boolean MYFACES_IMPL_AVAILABLE;
@@ -475,6 +490,7 @@ public class MyfacesConfig
         setStrictJsf2RefreshTargetAjax(INIT_PARAM_STRICT_JSF_2_REFRESH_TARGET_AJAX_DEFAULT);
         setStrictJsf2CCELResolver(INIT_PARAM_STRICT_JSF_2_CC_EL_RESOLVER_DEFAULT);
         setDefaultResponseWriterContentTypeMode(INIT_PARAM_DEFAULT_RESPONSE_WRITER_CONTENT_TYPE_MODE_DEFAULT);
+        setSupportJSPAndFacesEL(INIT_PARAM_SUPPORT_JSP_AND_FACES_EL_DEFAULT);
     }
 
     private static MyfacesConfig createAndInitializeMyFacesConfig(ExternalContext extCtx)
@@ -568,6 +584,10 @@ public class MyfacesConfig
                 extCtx, INIT_PARAM_DEFAULT_RESPONSE_WRITER_CONTENT_TYPE_MODE,
                 INIT_PARAM_DEFAULT_RESPONSE_WRITER_CONTENT_TYPE_MODE_DEFAULT));
 
+        
+        myfacesConfig.setSupportJSPAndFacesEL(WebConfigParamUtils.getBooleanInitParameter(extCtx,

+                INIT_PARAM_SUPPORT_JSP_AND_FACES_EL, INIT_PARAM_SUPPORT_JSP_AND_FACES_EL_DEFAULT));
+        
         if (TOMAHAWK_AVAILABLE)
         {
             myfacesConfig.setDetectJavascript(getBooleanInitParameter(extCtx, INIT_PARAM_DETECT_JAVASCRIPT,
@@ -1034,4 +1054,15 @@ public class MyfacesConfig
     {
         this._defaultResponseWriterContentTypeMode = defaultResponseWriterContentTypeMode;
     }
+    
+    public boolean isSupportJSPAndFacesEL()
+    {
+        return _supportJSPAndFacesEL;
+    }
+
+    public void setSupportJSPAndFacesEL(
+            boolean supportJSPANDFacesEL)
+    {
+        _supportJSPAndFacesEL = supportJSPANDFacesEL;
+    } 
 }



Mime
View raw message