Author: nbelaevski
Date: 2008-08-26 14:55:35 -0400 (Tue, 26 Aug 2008)
New Revision: 10201
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxViewHandler.java
trunk/framework/impl/src/main/java/org/ajax4jsf/context/ViewResources.java
Log:
Refactoring: initialization code moved from AjaxViewHandler to ViewResources
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxViewHandler.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxViewHandler.java 2008-08-26
18:05:23 UTC (rev 10200)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxViewHandler.java 2008-08-26
18:55:35 UTC (rev 10201)
@@ -68,9 +68,6 @@
public static final String VIEW_ID_KEY = "org.ajax4jsf.VIEW_ID";
- private static final String INIT_PARAMETER_PREFIX = "_init_parameter_";
- private static final Object NULL = new Object();
-
/**
* @param parent
*/
@@ -213,46 +210,7 @@
ViewResources viewResources = new ViewResources();
- boolean extendedSkinningAllowed = true;
- String skinningLevel = getInitParameterValue(context,
InternetResourceBuilder.CONTROL_SKINNING_LEVEL);
- if (skinningLevel != null && skinningLevel.length() > 0) {
- if (InternetResourceBuilder.BASIC.equals(skinningLevel)) {
- extendedSkinningAllowed = false;
- } else if (!InternetResourceBuilder.EXTENDED.equals(skinningLevel)) {
- throw new IllegalArgumentException("Value: " + skinningLevel +
- " of " + InternetResourceBuilder.CONTROL_SKINNING_LEVEL
- + " init parameter is invalid! Only " +
InternetResourceBuilder.EXTENDED
- + ", " + InternetResourceBuilder.BASIC + " can be used");
- }
- }
-
- viewResources.setExtendedSkinningAllowed(extendedSkinningAllowed);
-
- viewResources.setScriptStrategy(getInitParameterValue(context,
- InternetResourceBuilder.LOAD_SCRIPT_STRATEGY_PARAM));
-
- boolean useStdControlsSkinning = false;
-
- String stdControlsSkinning = getInitParameterValue(context,
InternetResourceBuilder.STD_CONTROLS_SKINNING_PARAM);
- if (stdControlsSkinning != null) {
- useStdControlsSkinning =
InternetResourceBuilder.ENABLE.equals(stdControlsSkinning);
- }
-
- viewResources.setUseStdControlsSkinning(useStdControlsSkinning);
-
- boolean useStdControlsSkinningClasses = true;
-
- String stdControlsSkinningClasses = getInitParameterValue(context,
InternetResourceBuilder.STD_CONTROLS_SKINNING_CLASSES_PARAM);
- if (stdControlsSkinningClasses != null) {
- useStdControlsSkinningClasses =
InternetResourceBuilder.ENABLE.equals(stdControlsSkinningClasses);
- }
-
- viewResources.setUseStdControlsSkinningClasses(useStdControlsSkinningClasses);
-
- viewResources.setStyleStrategy(getInitParameterValue(context,
- InternetResourceBuilder.LOAD_STYLE_STRATEGY_PARAM));
-
-
+ viewResources.initialize(context);
viewResources.processHeadResources(context);
requestMap.put(AjaxContext.HEAD_EVENTS_PARAMETER, viewResources.getHeadEvents());
@@ -277,55 +235,4 @@
ajaxRoot.broadcastAjaxEvents(context);
}
- private static 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);
- }
-
- private static 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();
- }
- }
-
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/context/ViewResources.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/context/ViewResources.java 2008-08-26
18:05:23 UTC (rev 10200)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/context/ViewResources.java 2008-08-26
18:55:35 UTC (rev 10201)
@@ -29,9 +29,13 @@
import java.util.Map;
import java.util.Set;
+import javax.el.ExpressionFactory;
+import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
import javax.faces.component.UIComponent;
+import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.render.RenderKit;
@@ -52,6 +56,7 @@
import org.ajax4jsf.resource.ResourceNotFoundException;
import org.ajax4jsf.resource.ResourceRenderer;
import org.ajax4jsf.resource.URIInternetResource;
+import org.ajax4jsf.util.ELUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.richfaces.skin.Skin;
@@ -64,6 +69,9 @@
public class ViewResources {
+ private static final String INIT_PARAMETER_PREFIX = "_init_parameter_";
+ private static final Object NULL = new Object();
+
private String scriptStrategy;
private String styleStrategy;
@@ -532,4 +540,99 @@
}
}
}
+
+ private static 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);
+ }
+
+ private static 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();
+ }
+ }
+
+ public void initialize(FacesContext context) {
+ boolean extendedSkinningAllowed = true;
+ String skinningLevel = getInitParameterValue(context,
InternetResourceBuilder.CONTROL_SKINNING_LEVEL);
+ if (skinningLevel != null && skinningLevel.length() > 0) {
+ if (InternetResourceBuilder.BASIC.equals(skinningLevel)) {
+ extendedSkinningAllowed = false;
+ } else if (!InternetResourceBuilder.EXTENDED.equals(skinningLevel)) {
+ throw new IllegalArgumentException("Value: " + skinningLevel +
+ " of " + InternetResourceBuilder.CONTROL_SKINNING_LEVEL
+ + " init parameter is invalid! Only " + InternetResourceBuilder.EXTENDED
+ + ", " + InternetResourceBuilder.BASIC + " can be used");
+ }
+ }
+
+ this.setExtendedSkinningAllowed(extendedSkinningAllowed);
+
+ this.setScriptStrategy(getInitParameterValue(context,
+ InternetResourceBuilder.LOAD_SCRIPT_STRATEGY_PARAM));
+
+ boolean useStdControlsSkinning = false;
+
+ String stdControlsSkinning = getInitParameterValue(context,
InternetResourceBuilder.STD_CONTROLS_SKINNING_PARAM);
+ if (stdControlsSkinning != null) {
+ useStdControlsSkinning = InternetResourceBuilder.ENABLE.equals(stdControlsSkinning);
+ }
+
+ this.setUseStdControlsSkinning(useStdControlsSkinning);
+
+ boolean useStdControlsSkinningClasses = true;
+
+ String stdControlsSkinningClasses = getInitParameterValue(context,
InternetResourceBuilder.STD_CONTROLS_SKINNING_CLASSES_PARAM);
+ if (stdControlsSkinningClasses != null) {
+ useStdControlsSkinningClasses =
InternetResourceBuilder.ENABLE.equals(stdControlsSkinningClasses);
+ }
+
+ this.setUseStdControlsSkinningClasses(useStdControlsSkinningClasses);
+
+ this.setStyleStrategy(getInitParameterValue(context,
+ InternetResourceBuilder.LOAD_STYLE_STRATEGY_PARAM));
+
+
+ }
+
}
Show replies by date