From 2a81c7b8db3ef16f2012f07a97f50298b9363a7d Mon Sep 17 00:00:00 2001 From: Jeremy Grelle Date: Fri, 7 Mar 2008 15:04:39 +0000 Subject: [PATCH] Added better checking for el-api version --- .../LegacyJSFELExpressionParser.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/spring-faces/src/main/java/org/springframework/faces/expression/LegacyJSFELExpressionParser.java b/spring-faces/src/main/java/org/springframework/faces/expression/LegacyJSFELExpressionParser.java index 0eb38e79..43a49851 100644 --- a/spring-faces/src/main/java/org/springframework/faces/expression/LegacyJSFELExpressionParser.java +++ b/spring-faces/src/main/java/org/springframework/faces/expression/LegacyJSFELExpressionParser.java @@ -4,15 +4,18 @@ import java.util.ArrayList; import java.util.List; import javax.el.ELContext; +import javax.el.ELException; import javax.el.ELResolver; import javax.el.ExpressionFactory; import javax.el.FunctionMapper; import javax.el.VariableMapper; +import org.springframework.beans.BeanUtils; import org.springframework.binding.expression.el.DefaultELResolver; import org.springframework.binding.expression.el.ELContextFactory; import org.springframework.binding.expression.el.ELExpressionParser; import org.springframework.util.ClassUtils; +import org.springframework.util.ReflectionUtils; import org.springframework.webflow.core.collection.MutableAttributeMap; import org.springframework.webflow.execution.RequestContext; import org.springframework.webflow.expression.el.ActionMethodELResolver; @@ -30,6 +33,10 @@ import org.springframework.webflow.expression.el.SpringSecurityELResolver; */ public class LegacyJSFELExpressionParser extends ELExpressionParser { + private static final String EXPRESSION_FACTORY_PROPERTY = "javax.el.ExpressionFactory"; + + private static final String DEFAULT_EXPRESSION_FACTORY = "org.jboss.el.ExpressionFactoryImpl"; + public LegacyJSFELExpressionParser(ExpressionFactory expressionFactory) { super(expressionFactory); putContextFactory(RequestContext.class, new RequestContextELContextFactory()); @@ -41,10 +48,18 @@ public class LegacyJSFELExpressionParser extends ELExpressionParser { } private static ExpressionFactory getDefaultExpressionFactory() { - if (!System.getProperties().containsKey("javax.el.ExpressionFactory")) { - System.setProperty("javax.el.ExpressionFactory", "org.jboss.el.ExpressionFactoryImpl"); + if (!System.getProperties().containsKey(EXPRESSION_FACTORY_PROPERTY)) { + System.setProperty(EXPRESSION_FACTORY_PROPERTY, DEFAULT_EXPRESSION_FACTORY); + } + if (ReflectionUtils.findMethod(ExpressionFactory.class, "newInstance") != null) { + return ExpressionFactory.newInstance(); + } else { // Fallback in case using an older version of el-api + try { + return (ExpressionFactory) BeanUtils.instantiateClass(Class.forName(DEFAULT_EXPRESSION_FACTORY)); + } catch (Exception e) { + throw new ELException("Could not create the default ExpressionFactory", e); + } } - return ExpressionFactory.newInstance(); } private static class RequestContextELContextFactory implements ELContextFactory {