Author: nbelaevski
Date: 2007-07-19 12:12:55 -0400 (Thu, 19 Jul 2007)
New Revision: 1702
Modified:
trunk/framework/api/src/main/java/org/richfaces/skin/SkinFactory.java
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/ElementBase.java
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/HtmlCompiler.java
trunk/framework/impl/src/main/java/org/richfaces/skin/SkinFactoryImpl.java
Log:
http://jira.jboss.com/jira/browse/RF-269 - baseSkin parameter handling added
Modified: trunk/framework/api/src/main/java/org/richfaces/skin/SkinFactory.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/skin/SkinFactory.java 2007-07-19
16:04:56 UTC (rev 1701)
+++ trunk/framework/api/src/main/java/org/richfaces/skin/SkinFactory.java 2007-07-19
16:12:55 UTC (rev 1702)
@@ -177,4 +177,13 @@
*/
public static final String SKIN_PARAMETER = "org.ajax4jsf.SKIN";
+ public static final String BASE_SKIN_PARAMETER = "org.ajax4jsf.BASE_SKIN";
+
+ /**
+ * Get base {@link Skin} implementation
+ * @param facesContext
+ * @return
+ */
+ public abstract Skin getBaseSkin(FacesContext facesContext);
+
}
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/ElementBase.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/ElementBase.java 2007-07-19
16:04:56 UTC (rev 1701)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/ElementBase.java 2007-07-19
16:12:55 UTC (rev 1702)
@@ -59,6 +59,7 @@
private Object _context = null;
private String _property = null;
private String _skin ;
+ private String _baseSkin ;
// private String _skinConfiguration ;
private String _call = null;
private PreparedTemplate parent;
@@ -288,22 +289,21 @@
/**
* @param skin The skin to set.
*/
+ public void setBaseSkin(String baseSkin) {
+ _baseSkin = baseSkin;
+// if( null == _skinConfiguration ){
+ // Only Skin parameter is used.
+ valueGetter = new SkinValueGetter();
+ }
+
+ /**
+ * @param skin The skin to set.
+ */
public void setSkin(String skin) {
_skin = skin;
// if( null == _skinConfiguration ){
// Only Skin parameter is used.
- valueGetter = new ValueGetter(){
-
- /* (non-Javadoc)
- * @see
org.ajax4jsf.renderkit.compiler.RootElement.ValueGetter#getValue(javax.faces.context.FacesContext,
javax.faces.component.UIComponent)
- */
- Object getValue(TemplateContext context) {
- FacesContext facesContext = context.getFacesContext();
- Object parameter =
SkinFactory.getInstance().getSkin(facesContext).getParameter(facesContext,_skin,_default);
- return parameter;
- }
-
- };
+ valueGetter = new SkinValueGetter();
// } else {
// valueGetter = new ConfigurationAndSkinValueGetter();
// }
@@ -435,4 +435,20 @@
}
}
+ protected class SkinValueGetter extends ValueGetter {
+ Object getValue(TemplateContext context) {
+ FacesContext facesContext = context.getFacesContext();
+ SkinFactory skinFactory = SkinFactory.getInstance();
+ Object result =
skinFactory.getSkin(facesContext).getParameter(facesContext,_skin,_default);
+ if (_baseSkin != null && (result == null || result.toString().length()==0)) {
+ if ("inherit".equals(_baseSkin)) {
+ result =
skinFactory.getBaseSkin(facesContext).getParameter(facesContext,_skin,_default);
+ } else {
+ result =
skinFactory.getBaseSkin(facesContext).getParameter(facesContext,_baseSkin,_default);
+ }
+ }
+ return result;
+ }
+ }
+
}
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/HtmlCompiler.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/HtmlCompiler.java 2007-07-19
16:04:56 UTC (rev 1701)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/HtmlCompiler.java 2007-07-19
16:12:55 UTC (rev 1702)
@@ -106,6 +106,7 @@
* <ul>
* <li><b>value</b> as string or EL-expression</li>
* <li><b>property</b> name for property of current
component</li>
+ * <li><b>baseSkin</b> name for property of base skin</li>
* <li><b>skin</b> name for property of current skin</li>
* <li><b>context</b> name for property of {@link TemplateContext} for
trmplate encoding</li>
* <li><b>default</b> use as value if main property
<code>null</code></li>
@@ -113,13 +114,13 @@
* Supported :
* <ul>
* <li>Call renderer or utils method <f:call name='xxx'
/></li>
- * <li>Call method parameter <f:parameter name='xxx'
(value='....' | property='style' | skin='paramName' |
context='propertyName ) /></li>
- * <li>Encode plain text <f:verbatim [value='....' |
property='style' | skin='paramName' | context='propertyName ]
>Some Text</f:text></li>
- * <li>Encode as text in HTML CSS parameter format <u:style
name='background' (value='....' | property='style' |
skin='paramName' | context='propertyName )/></li>
+ * <li>Call method parameter <f:parameter name='xxx'
(value='....' | property='style' | baseSkin='paramName' |
skin='paramName' | context='propertyName ) /></li>
+ * <li>Encode plain text <f:verbatim [value='....' |
property='style' | baseSkin='paramName' | skin='paramName' |
context='propertyName ] >Some Text</f:text></li>
+ * <li>Encode as text in HTML CSS parameter format <u:style
name='background' (value='....' | property='style' |
baseSkin='paramName' | skin='paramName' | context='propertyName
)/></li>
* <li>Get and encode resource <f:resource
f:key='images/spacer.gif' [ ... any attributes ... ] /></li>
- * <li>Encode custom attribute <f:attribute name='style'
(value='....' | property='style' | skin='paramName' |
context='propertyName ) [endorsed='true'] /></li>
+ * <li>Encode custom attribute <f:attribute name='style'
(value='....' | property='style' | baseSkin='paramName' |
skin='paramName' | context='propertyName ) [endorsed='true']
/></li>
* <li>Template breakpoint <f:break name='xxxxx'
/></li>
- * <li>Encode named facet <u:facet ( name='head |
property='style' | skin='paramName' | context='propertyName )'
/></li>
+ * <li>Encode named facet <u:facet ( name='head |
property='style' | baseSkin='paramName' | skin='paramName' |
context='propertyName )' /></li>
* <li>Encode children components for current <u:children
/></li>
* <li>Encode one child component for enclosed u:facet or u:children
<u:child /'></li>
* </ul>
@@ -156,11 +157,11 @@
digestr.addObjectCreate(pattern,ResourceElement.class);
digestr.addSetNext(pattern,CHILD_METHOD);
{
- Rule rule = new PutAttributesRule(digestr,new
String[]{NS_PREFIX+"key",NS_PREFIX+"property",NS_PREFIX+"skin",NS_PREFIX+"context"});
+ Rule rule = new PutAttributesRule(digestr,new
String[]{NS_PREFIX+"key",NS_PREFIX+"property",NS_PREFIX+"baseSkin",NS_PREFIX+"skin",NS_PREFIX+"context"});
digestr.addRule(pattern,rule);
}
{
- SetPropertiesRule rule = new SetPropertiesRule(new
String[]{NS_PREFIX+"key",NS_PREFIX+"property",NS_PREFIX+"skin",NS_PREFIX+"context"},new
String[]{"value","property","skin","context"});
+ SetPropertiesRule rule = new SetPropertiesRule(new
String[]{NS_PREFIX+"key",NS_PREFIX+"property",NS_PREFIX+"baseSkin",NS_PREFIX+"skin",NS_PREFIX+"context"},new
String[]{"value","property","baseSkin","skin","context"});
digestr.addRule(pattern,rule);
}
// custom attribute <f:attribute name='style' (value='....' |
property='style' | skin='paramName' | call='methodName' |
utilCall='methodName') [notNull='true'] />
Modified: trunk/framework/impl/src/main/java/org/richfaces/skin/SkinFactoryImpl.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/skin/SkinFactoryImpl.java 2007-07-19
16:04:56 UTC (rev 1701)
+++ trunk/framework/impl/src/main/java/org/richfaces/skin/SkinFactoryImpl.java 2007-07-19
16:12:55 UTC (rev 1702)
@@ -85,6 +85,8 @@
private Properties defaultSkinProperties = null;
private String skinName = null;
private ValueBinding skinBinding = null;
+ private String baseSkinName = null;
+ private ValueBinding baseSkinBinding = null;
private static final Log log = LogFactory.getLog(SkinFactoryImpl.class);
protected Skin getSkinByName(Object currentSkinOrName) {
@@ -119,10 +121,15 @@
public Skin getSkin(FacesContext context) {
// TODO - cache skin for current thread ? or for current Faces Lifecycle
// Phase ?
- Object currentSkinOrName = getSkinOrName(context);
+ Object currentSkinOrName = getSkinOrName(context, false);
return getSkinByName(currentSkinOrName);
}
+ public Skin getBaseSkin(FacesContext context) {
+ Object currentSkinOrName = getSkinOrName(context, true);
+ return getSkinByName(currentSkinOrName);
+ }
+
protected Properties getDefaultSkinProperties() {
if (defaultSkinProperties == null) {
defaultSkinProperties = loadDefaultProperties(DEFAULT_SKIN_PROPERTIES_RESOURCE);
@@ -170,34 +177,55 @@
* binding for speed calculations.
*
* @param context
+ * @param useBase
* @return name of currens skin from init parameter ( "DEFAULT" if no
* parameter ) or {@link Skin } as result of evaluation EL
* expression.
*/
- protected Object getSkinOrName(FacesContext context) {
+ protected Object getSkinOrName(FacesContext context, boolean useBase) {
// Detect skin name
+ ValueBinding binding;
+ String skin;
+
synchronized (this) {
- if (skinName == null && skinBinding == null) {
+ if (useBase) {
+ binding = baseSkinBinding;
+ skin = baseSkinName;
+ } else {
+ binding = skinBinding;
+ skin = skinName;
+ }
+
+ if (binding == null && skin == null) {
String currentSkinName = context.getExternalContext()
- .getInitParameter(SKIN_PARAMETER);
+ .getInitParameter(useBase ? BASE_SKIN_PARAMETER : SKIN_PARAMETER);
if (currentSkinName == null) {
// not set - usr default.
return DEFAULT_SKIN_NAME;
}
if (SkinFactory.isValueReference(currentSkinName)) {
// For EL expression as skin name
- skinBinding = context.getApplication().createValueBinding(
+ binding = context.getApplication().createValueBinding(
currentSkinName);
} else {
- skinName = currentSkinName;
+ skin = currentSkinName;
}
}
+
+ if (useBase) {
+ baseSkinBinding = binding;
+ baseSkinName = skin;
+ } else {
+ skinBinding = binding;
+ skinName = skin;
+ }
+
// }
}
- if (skinBinding != null) {
- return skinBinding.getValue(context);
+ if (binding != null) {
+ return binding.getValue(context);
} else {
- return skinName;
+ return skin;
}
}