Author: nbelaevski
Date: 2008-03-05 18:13:02 -0500 (Wed, 05 Mar 2008)
New Revision: 6578
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
Log:
http://jira.jboss.com/jira/browse/RF-2404
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java 2008-03-05
20:26:30 UTC (rev 6577)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java 2008-03-05
23:13:02 UTC (rev 6578)
@@ -34,6 +34,8 @@
import java.util.Set;
import java.util.regex.Pattern;
+import javax.el.ExpressionFactory;
+import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.FactoryFinder;
import javax.faces.application.Application;
@@ -62,6 +64,7 @@
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.ajax4jsf.resource.InternetResourceBuilder;
import org.ajax4jsf.resource.ResourceNotFoundException;
+import org.ajax4jsf.util.ELUtils;
import org.ajax4jsf.webapp.BaseFilter;
import org.ajax4jsf.webapp.FilterServletResponseWrapper;
import org.apache.commons.logging.Log;
@@ -85,6 +88,11 @@
//as they have their own advanced styling
private static final Pattern USER_AGENTS = Pattern.compile(" AppleWebKit/|^Opera/|
Opera ");
+ private static final String INIT_PARAMETER_PREFIX = "_init_parameter_";
+
+ //Object to put into application map as a value of cached parameter if it is null
+ private static final Object NULL = new Object();
+
private static final Log log = LogFactory.getLog(AjaxContext.class);
private static ComponentInvoker invoker;
@@ -418,15 +426,15 @@
boolean useStdControlsSkinning = false;
- String stdControlsSkinning =
externalContext.getInitParameter(InternetResourceBuilder.STD_CONTROLS_SKINNING_PARAM);
- if (stdControlsSkinning != null && stdControlsSkinning.length() != 0) {
+ String stdControlsSkinning = getInitParameterValue(context,
InternetResourceBuilder.STD_CONTROLS_SKINNING_PARAM);
+ if (stdControlsSkinning != null) {
useStdControlsSkinning =
InternetResourceBuilder.ENABLE.equals(stdControlsSkinning);
}
boolean useStdControlsSkinningClasses = true;
- String stdControlsSkinningClasses =
externalContext.getInitParameter(InternetResourceBuilder.STD_CONTROLS_SKINNING_CLASSES_PARAM);
- if (stdControlsSkinningClasses != null && stdControlsSkinningClasses.length()
!= 0) {
+ String stdControlsSkinningClasses = getInitParameterValue(context,
InternetResourceBuilder.STD_CONTROLS_SKINNING_CLASSES_PARAM);
+ if (stdControlsSkinningClasses != null) {
useStdControlsSkinningClasses =
InternetResourceBuilder.ENABLE.equals(stdControlsSkinningClasses);
}
@@ -890,4 +898,55 @@
return true;
}
}
+
+ private String evaluate(FacesContext context, Object parameterValue) {
+ if (parameterValue == NULL || parameterValue == null) {
+ return null;
+ } else if (parameterValue instanceof ValueExpression) {
+ ValueExpression expression = (ValueExpression) parameterValue;
+
+ return (String) expression.getValue(context.getELContext());
+ } else {
+ return parameterValue.toString();
+ }
+ }
+
+ private String getInitParameterValue(FacesContext context, String parameterName) {
+
+ String key = INIT_PARAMETER_PREFIX + parameterName;
+
+ ExternalContext externalContext = context.getExternalContext();
+ Map<String, Object> applicationMap = externalContext.getApplicationMap();
+ Object mutex = externalContext.getRequest();
+ Object parameterValue = null;
+
+ synchronized (mutex) {
+ parameterValue = applicationMap.get(key);
+
+ if (parameterValue == null) {
+
+ String initParameter = externalContext.getInitParameter(parameterName);
+ if (initParameter != null) {
+
+ if (ELUtils.isValueReference(initParameter)) {
+ Application application = context.getApplication();
+ ExpressionFactory expressionFactory = application.getExpressionFactory();
+
+ parameterValue = expressionFactory.createValueExpression(context.getELContext(),
+ initParameter,
+ String.class);
+ } else {
+ parameterValue = initParameter;
+ }
+
+ } else {
+ parameterValue = NULL;
+ }
+
+ applicationMap.put(key, parameterValue);
+ }
+ }
+
+ return evaluate(context, parameterValue);
+ }
}