You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by jw...@apache.org on 2008/04/23 19:56:32 UTC
svn commit: r650967 - in /myfaces/trinidad/trunk:
trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/
trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/
trinidad-impl/src/main/java/org/apache/myfaces/trinidadinter...
Author: jwaldman
Date: Wed Apr 23 10:56:29 2008
New Revision: 650967
URL: http://svn.apache.org/viewvc?rev=650967&view=rev
Log:
TRINIDAD-1 Add @agent support for skin properties
I followed the implementation of adding @agent support for icon properties that Andy recently added.
on trunk
Added:
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/SkinPropertyNode.java
Removed:
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/parse/SkinPropertyNode.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/parse/SkinPropertyNodeParser.java
Modified:
myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SkinProperties.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/RequestSkinWrapper.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/StyleSheetEntry.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleProvider.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java
myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java
Modified: myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css?rev=650967&r1=650966&r2=650967&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css (original)
+++ myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css Wed Apr 23 10:56:29 2008
@@ -473,8 +473,10 @@
/* use special properties to change the ui **/
/* don't show the last item in breadCrumbs (the default is to show it)*/
-
+@agent gecko
+{
af|breadCrumbs {-tr-show-last-item:false}
+}
af|breadCrumbs::step {color: purple;}
af|breadCrumbs::step:hover {color: green}
@@ -887,6 +889,15 @@
.AFFooIcon:alias {content:url(/skins/purple/images/btns.gif); width:7px; height:18px}
.AFBarIcon {content:url(/skins/purple/images/btns.gif); width:7px; height:18px}
+@agent ie
+{
+af|tree {
+ -tr-show-lines:true;
+}
+}
+@agent gecko
+{
af|tree {
-tr-show-lines:false;
+}
}
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java?rev=650967&r1=650966&r2=650967&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java Wed Apr 23 10:56:29 2008
@@ -167,7 +167,12 @@
{
return null;
}
-
+
+ public ConcurrentMap<Object, Object> getSkinProperties(StyleContext context)
+ {
+ return null;
+ }
+
private static StyleProvider _sInstance;
}
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SkinProperties.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SkinProperties.java?rev=650967&r1=650966&r2=650967&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SkinProperties.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SkinProperties.java Wed Apr 23 10:56:29 2008
@@ -18,6 +18,9 @@
*/
package org.apache.myfaces.trinidadinternal.renderkit.core.xhtml;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* This class contains all valid predefined skin properties used by Trinidad.
* The properties are sorted alphabetically.
@@ -56,4 +59,26 @@
"af|treeTable-tr-spacer-width";
public static final String AF_TREE_SHOW_LINES =
"af|tree-tr-show-lines";
+
+ // Map of property to class type
+ public static final Map<String, Class<?>> PROPERTY_CLASS_TYPE_MAP;
+ static
+ {
+ PROPERTY_CLASS_TYPE_MAP = new HashMap<String, Class<?>>();
+
+ PROPERTY_CLASS_TYPE_MAP.put(
+ AF_NAVIGATIONPATH_SHOW_LAST_ITEM_PROPERTY_KEY, Boolean.class);
+ PROPERTY_CLASS_TYPE_MAP.put(
+ AF_TABLE_SELECTION_BAR_IN_TABLE, Boolean.class);
+ PROPERTY_CLASS_TYPE_MAP.put(
+ AF_TABLE_REPEAT_CONTROL_BAR, Boolean.class);
+ PROPERTY_CLASS_TYPE_MAP.put(
+ AF_TREE_SHOW_LINES, Boolean.class);
+ PROPERTY_CLASS_TYPE_MAP.put(
+ AF_BREAD_CRUMBS_SEPARATOR_ON_NEW_LINE, Boolean.class);
+ PROPERTY_CLASS_TYPE_MAP.put(
+ AF_BREAD_CRUMBS_INDENT_SPACES, Integer.class);
+ }
+
+
}
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/RequestSkinWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/RequestSkinWrapper.java?rev=650967&r1=650966&r2=650967&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/RequestSkinWrapper.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/RequestSkinWrapper.java Wed Apr 23 10:56:29 2008
@@ -38,15 +38,15 @@
/**
* This is a Skin decorator which is used to store request-specific
- * skin state. In particular, the set of icons to use varies from
+ * skin state. For example, the set of icons to use varies from
* request to request, eg. based on the browser/platform. We cannot
* store such request-specific state on our shared Skin instances.
* Instead, SkinFactoryImpl wraps shared Skin instances in RequestSkinWrappers
* so that request-specific state can be stored locally in the wrapper.
*
- * At the moment, the only piece of request-specific state is that
- * icon map, which is retrieved from the StyleProvider one time per
- * request and stored here.
+ * Currently, the request-specific state for a skin is the icon map and the skin property map.
+ * They are retrieved from the StyleProvider one time per request and stored here.
+ * @see org.apache.myfaces.trinidadinternal.style.cache.FileSystemStyleCache
*/
public class RequestSkinWrapper extends Skin implements DocumentProviderSkin
{
@@ -164,7 +164,7 @@
{
// We look for the icon in two places:
//
- // 1. In the the icon map provided by the StyleProvider.
+ // 1. In the icon map provided by the StyleProvider.
// The StyleProvider serves up icons that are
// specific to this particular request, including
// agent-specific icons.
@@ -205,20 +205,6 @@
}
@Override
- public Object getProperty(Object key)
- {
- return _skin.getProperty(key);
- }
-
- @Override
- public void setProperty(
- Object key,
- Object value)
- {
- _skin.setProperty(key, value);
- }
-
- @Override
public void registerIcon(
String iconName,
Icon icon)
@@ -232,7 +218,7 @@
// will look up the non-directional version of the icon and register
// that under the rtl name to avoid repeated lookups.
//
- // 2. RequestSkingWrapper.getIcon() calls registerIcon() to register
+ // 2. RequestSkinWrapper.getIcon() calls registerIcon() to register
// icons which were not found in the StyleProvider's icon map. This
// also is done as a performance optimization - to repeatedly looking
// up icons first in the StyleProvider icon map and then in the
@@ -248,8 +234,52 @@
if (icons != _NULL_ICONS)
icons.put(iconName, (icon == null) ? _NULL_ICON : icon);
}
+
+ @Override
+ public Object getProperty(Object key)
+ {
+ // We look for the skin properties in two places:
+ //
+ // 1. In the skin property map provided by the StyleProvider (see _getRequestSkinProperties).
+ // The StyleProvider serves up skin properties that are
+ // specific to this particular request, including
+ // agent-specific skin properties.
+ // 2. In the wrapped Skin instance. Any skin properties that are
+ // manually registered via a call to setProperty(Object, Object)
+ // will be stored in the wrapped skin.
+
+ // Note: no synchronization needed since we are in a
+ // a request-specific object.
+ Map<Object, Object> properties = _getRequestSkinProperties();
+ assert(properties != null);
+
+ Object propertyValue = properties.get(key);
+
+ if (propertyValue == null)
+ {
+ propertyValue = _skin.getProperty(key);
+ }
+
+ return propertyValue;
+ }
@Override
+ public void setProperty(
+ Object key,
+ Object value)
+ {
+ Map<Object, Object> properties = _getRequestSkinProperties();
+ if (properties != _NULL_PROPERTIES)
+ properties.put(key, value);
+ }
+
+
+
+
+ /**
+ * @deprecated Use addSkinAddition instead
+ * */
+ @Override
public void registerStyleSheet(
String styleSheetName
)
@@ -318,6 +348,43 @@
return _icons;
}
+
+ // Returns request-specific map of skin property key/values
+ private Map<Object, Object> _getRequestSkinProperties()
+ {
+ if (_properties == null)
+ {
+ // We get to the request-specific properties via the
+ // StyleProvider. We need a CoreRenderingContext
+ // instance to get at the StyleProvider. This
+ // implementation assumes that the RenderingContext
+ // is going to be an instanceof CoreRenderingContext.
+ // This is a pretty good bet, since the only
+ // RenderingContext provided by Trinidad is
+ // CoreRenderingContext, and given the complexity of
+ // the CoreRenderingContext implementation, it seems
+ // unlikely that anyone would attempt to replace the
+ // implementation.
+ RenderingContext rc = RenderingContext.getCurrentInstance();
+ assert(rc instanceof CoreRenderingContext);
+
+ CoreRenderingContext crc = (CoreRenderingContext)rc;
+ StyleContext styleContext = crc.getStyleContext();
+ StyleProvider styleProvider = styleContext.getStyleProvider();
+ // skin properties are stored in an Map<Object, Object>
+ _properties = styleProvider.getSkinProperties(styleContext);
+
+ // Under normal circumstances, the StyleProvider will return
+ // a non-null, modifiable map. If the skin/style subsystem
+ // has failed to initialize, however, the map may be null.
+ // Substitute an empty map so we don't need to check for null
+ // later.
+ if (_properties == null)
+ _properties = _NULL_PROPERTIES;
+ }
+
+ return _properties;
+ }
// The wrapped skin
private final Skin _skin;
@@ -326,9 +393,16 @@
// up by the StyleProvider.
private Map<String, Icon> _icons;
+ // The skin properties map specific to this request as served
+ // up by the StyleProvider.
+ private Map<Object, Object> _properties;
+
// Marker used to cache nulls.
private static final Icon _NULL_ICON = new NullIcon();
// Empty map used when StyleProvider.getIcons() fails;
private static final Map<String, Icon> _NULL_ICONS = Collections.emptyMap();
+
+ // Empty map used when StyleProvider.getSkinProperties() fails;
+ private static final Map<Object, Object> _NULL_PROPERTIES = Collections.emptyMap();
}
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java?rev=650967&r1=650966&r2=650967&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java Wed Apr 23 10:56:29 2008
@@ -21,7 +21,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
-import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -47,11 +46,8 @@
import org.apache.myfaces.trinidad.skin.SkinAddition;
import org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderingContext;
-import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SkinProperties;
import org.apache.myfaces.trinidadinternal.share.config.Configuration;
-import org.apache.myfaces.trinidadinternal.share.expl.Coercions;
import org.apache.myfaces.trinidadinternal.skin.icon.ReferenceIcon;
-import org.apache.myfaces.trinidadinternal.skin.parse.SkinPropertyNode;
import org.apache.myfaces.trinidadinternal.style.StyleContext;
import org.apache.myfaces.trinidadinternal.style.StyleProvider;
import org.apache.myfaces.trinidadinternal.style.xml.StyleSheetDocumentUtils;
@@ -516,49 +512,6 @@
return modified;
}
- private void _registerPropertiesFromStyleSheetEntry(
- StyleSheetEntry entry)
- {
- // register the properties if there are any.
- // get a List of IconNodes, and register them.
- if (entry != null)
- {
- // register properties
- List<SkinPropertyNode> skinProperties = entry.getSkinProperties();
-
- if (skinProperties != null)
- {
- for(SkinPropertyNode property : skinProperties)
- {
- Object propValueObj = property.getPropertyValue();
- // Store the property selector + property Name as the Skin Property Key.
- // e.g., use af|breadCrumbs-tr-show-last-item
-
- String key = property.getPropertySelector() +
- property.getPropertyName();
- // look up in map to get conversion
- Class<?> type = _PROPERTY_CLASS_TYPE_MAP.get(key);
- if (type != null)
- {
- try
- {
- // coerce the value to the type
- propValueObj = Coercions.coerce(null, (String)propValueObj,
- type);
- }
- catch (IllegalArgumentException ex)
- {
- if (_LOG.isWarning())
- _LOG.warning(ex);
- }
- }
-
-
- setProperty(key, propValueObj);
- }
- }
- }
- }
// Creates the StyleSheetDocument for this Skin
// (as a side effect, this also registers icons and skin properties
@@ -578,7 +531,6 @@
if (styleSheetName != null)
{
_skinStyleSheet = StyleSheetEntry.createEntry(context, styleSheetName);
- _registerPropertiesFromStyleSheetEntry(_skinStyleSheet);
}
// Now create entries for skin-addition-specific style sheets.
@@ -601,11 +553,8 @@
StyleSheetEntry entry = _skinAdditionStyleSheets[i];
if (entry != null)
{
- // add the icons and properties that are in the
- // skin-addition's StyleSheetEntry
- _registerPropertiesFromStyleSheetEntry(entry);
-
- // now merge the css properties
+ // Merge the skin-addition's StyleSheetDocument on top of
+ // the current StyleSheetDocument.
StyleSheetDocument additionDocument = entry.getDocument();
if (additionDocument != null)
@@ -1144,25 +1093,6 @@
// HashMap of Skin properties
private ConcurrentHashMap<Object, Object> _properties= new ConcurrentHashMap<Object, Object>();
- // Map of property to class type
- private static final Map<String, Class<?>> _PROPERTY_CLASS_TYPE_MAP;
- static
- {
- _PROPERTY_CLASS_TYPE_MAP = new HashMap<String, Class<?>>();
-
- _PROPERTY_CLASS_TYPE_MAP.put(
- SkinProperties.AF_NAVIGATIONPATH_SHOW_LAST_ITEM_PROPERTY_KEY, Boolean.class);
- _PROPERTY_CLASS_TYPE_MAP.put(
- SkinProperties.AF_TABLE_SELECTION_BAR_IN_TABLE, Boolean.class);
- _PROPERTY_CLASS_TYPE_MAP.put(
- SkinProperties.AF_TABLE_REPEAT_CONTROL_BAR, Boolean.class);
- _PROPERTY_CLASS_TYPE_MAP.put(
- SkinProperties.AF_TREE_SHOW_LINES, Boolean.class);
- _PROPERTY_CLASS_TYPE_MAP.put(
- SkinProperties.AF_BREAD_CRUMBS_SEPARATOR_ON_NEW_LINE, Boolean.class);
- _PROPERTY_CLASS_TYPE_MAP.put(
- SkinProperties.AF_BREAD_CRUMBS_INDENT_SPACES, Integer.class);
- }
private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(SkinImpl.class);
}
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java?rev=650967&r1=650966&r2=650967&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java Wed Apr 23 10:56:29 2008
@@ -38,6 +38,8 @@
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
import org.apache.myfaces.trinidad.skin.Icon;
+import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SkinProperties;
+import org.apache.myfaces.trinidadinternal.share.expl.Coercions;
import org.apache.myfaces.trinidadinternal.share.io.InputStreamProvider;
import org.apache.myfaces.trinidadinternal.share.io.NameResolver;
import org.apache.myfaces.trinidadinternal.share.xml.ParseContext;
@@ -47,6 +49,7 @@
import org.apache.myfaces.trinidadinternal.style.xml.parse.IconNode;
import org.apache.myfaces.trinidadinternal.style.xml.parse.IncludeStyleNode;
import org.apache.myfaces.trinidadinternal.style.xml.parse.PropertyNode;
+import org.apache.myfaces.trinidadinternal.style.xml.parse.SkinPropertyNode;
import org.apache.myfaces.trinidadinternal.style.xml.parse.StyleNode;
import org.apache.myfaces.trinidadinternal.style.xml.parse.StyleSheetDocument;
import org.apache.myfaces.trinidadinternal.style.xml.parse.StyleSheetNode;
@@ -54,7 +57,6 @@
import org.apache.myfaces.trinidadinternal.skin.icon.NullIcon;
import org.apache.myfaces.trinidadinternal.skin.icon.TextIcon;
import org.apache.myfaces.trinidadinternal.skin.icon.URIImageIcon;
-import org.apache.myfaces.trinidadinternal.skin.parse.SkinPropertyNode;
import org.apache.myfaces.trinidadinternal.style.util.CSSUtils;
import org.apache.myfaces.trinidadinternal.style.util.StyleUtils;
import org.apache.myfaces.trinidadinternal.util.nls.LocaleUtils;
@@ -162,15 +164,15 @@
}
/**
- * Given a List of StyleSheetNodes, create StyleSheetEntry.
+ * Given a List of SkinStyleSheetNode, create StyleSheetEntry.
* A StyleSheetEntry is an object that contains:
- * styleSheetName, StyleSheetDocument, List<IconNode>, List<SkinPropertyNode>
+ * styleSheetName, StyleSheetDocument
* A StyleSheetDocument contains StyleSheetNodes. A StyleSheetNode contains
* a list css style selectors and their properties and additional info like
* the direction, locale, etc. for this list of selectors.
* @param context
* @param sourceName
- * @param styleSheetNodes
+ * @param skinSSNodeList
* @return
*/
private static StyleSheetEntry _createStyleSheetEntry(
@@ -185,10 +187,10 @@
// styleNodeList. Also, build one iconNodeList and one skinPropertyNodeList.
// initialize
- List<SkinPropertyNode> skinPropertyNodeList = new ArrayList<SkinPropertyNode>();
List<StyleSheetNode> ssNodeList = new ArrayList<StyleSheetNode>();
String baseSourceURI = CSSUtils.getBaseSkinStyleSheetURI(sourceName);
+ // loop through the selectors and its properties
for (SkinStyleSheetNode skinSSNode : skinSSNodeList)
{
@@ -200,11 +202,15 @@
// initialize
List <StyleNode> styleNodeList = new ArrayList<StyleNode>();
List<IconNode> iconNodeList = new ArrayList<IconNode>();
+ // trSkinPropertyNodeList, e.g., af|foo {-tr-show-last-item: true}
+ List<SkinPropertyNode> trSkinPropertyNodeList = new ArrayList<SkinPropertyNode>();
+ // process each selector and all its name+values
for (SkinSelectorPropertiesNode cssSelector : selectorNodeList)
{
String selectorName = cssSelector.getSelectorName();
+ // PropertyNode is the name+value, like font-size: 8px
List<PropertyNode> propertyList = cssSelector.getPropertyNodes();
int direction = skinSSNode.getDirection();
@@ -212,7 +218,8 @@
_resolveProperties(selectorName,
propertyList);
- skinPropertyNodeList.addAll(resolvedProperties.getSkinPropertyNodeList());
+
+ trSkinPropertyNodeList.addAll(resolvedProperties.getSkinPropertyNodeList());
List<PropertyNode> noTrPropertyList =
resolvedProperties.getNoTrPropertyList();
@@ -257,7 +264,8 @@
}
}
- if ((styleNodeList.size() > 0) || (iconNodeList.size() > 0))
+ if ((styleNodeList.size() > 0) || (iconNodeList.size() > 0)
+ || (trSkinPropertyNodeList.size() > 0))
{
// we need to deal with the styleNodeList by building a StyleSheetNode
// with this information.
@@ -266,6 +274,7 @@
StyleSheetNode ssNode =
new StyleSheetNode(styleNodeArray,
iconNodeList,
+ trSkinPropertyNodeList,
null,/*locales, not yet supported*/
skinSSNode.getDirection(),
skinSSNode.getAgents(),
@@ -283,8 +292,7 @@
_createStyleSheetDocument(context, ssNodeList);
return new StyleSheetEntry(sourceName,
- ssDocument,
- skinPropertyNodeList);
+ ssDocument);
@@ -359,10 +367,9 @@
}
else
{
- SkinPropertyNode node =
- new SkinPropertyNode(selectorName,
- propertyName,
- propertyValue);
+ // create the SkinPropertyNode
+ SkinPropertyNode node =
+ _createSkinPropertyNode(selectorName, propertyName, propertyValue);
skinPropertyNodeList.add(node);
}
@@ -628,6 +635,40 @@
styleNodeList.add(styleNode);
}
+
+ private static SkinPropertyNode _createSkinPropertyNode(
+ String selector,
+ String name,
+ String value)
+ {
+ // Store the property selector + property Name as the Skin Property Key.
+ // e.g., use af|breadCrumbs-tr-show-last-item
+ StringBuilder keyBuilder = new StringBuilder(selector.length() + name.length());
+ keyBuilder.append(selector);
+ keyBuilder.append(name);
+ String key = keyBuilder.toString();
+
+ // look up in map to get conversion
+ Class<?> type = SkinProperties.PROPERTY_CLASS_TYPE_MAP.get(key);
+ Object propValueObj = null;
+ if (type != null)
+ {
+ try
+ {
+ // coerce the value to the type
+ propValueObj = Coercions.coerce(null, value, type);
+ }
+ catch (IllegalArgumentException ex)
+ {
+ if (_LOG.isWarning())
+ _LOG.warning(ex);
+ }
+ }
+
+ SkinPropertyNode node = new SkinPropertyNode(key,
+ propValueObj != null ? propValueObj : value);
+ return node;
+ }
// This is for -tr-rule-ref properties on styles.
private static void _addIncludeStyleNodes(
@@ -884,6 +925,7 @@
private static final Pattern _SPACE_PATTERN = Pattern.compile("\\s");
private static final Pattern _SELECTOR_PATTERN = Pattern.compile("selector\\(");
+
static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/StyleSheetEntry.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/StyleSheetEntry.java?rev=650967&r1=650966&r2=650967&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/StyleSheetEntry.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/StyleSheetEntry.java Wed Apr 23 10:56:29 2008
@@ -30,8 +30,6 @@
import org.apache.myfaces.trinidadinternal.share.xml.ParseContextImpl;
import org.apache.myfaces.trinidadinternal.share.xml.XMLProvider;
-import org.apache.myfaces.trinidadinternal.skin.parse.SkinPropertyNode;
-
import org.apache.myfaces.trinidadinternal.style.StyleContext;
import org.apache.myfaces.trinidadinternal.style.xml.StyleSheetDocumentUtils;
import org.apache.myfaces.trinidadinternal.style.xml.parse.StyleSheetDocument;
@@ -82,7 +80,6 @@
if (context.checkStylesModified())
return new CheckModifiedEntry(styleSheetName,
skinStyleSheet.getDocument(),
- skinStyleSheet.getSkinProperties(),
resolver);
return skinStyleSheet;
@@ -98,20 +95,17 @@
// in CheckModifiedEntry. changing it to package private
StyleSheetEntry(
String styleSheetName,
- StyleSheetDocument document,
- List<SkinPropertyNode> skinProperties
-
+ StyleSheetDocument document
)
{
_name = styleSheetName;
_document = document;
- _skinProperties = skinProperties;
}
StyleSheetEntry(String styleSheetName)
{
- this(styleSheetName, null, null);
+ this(styleSheetName, null);
}
// Use full constructor
@@ -138,18 +132,6 @@
}
/**
- * Returns the SkinProperties List for this
- * StyleSheetEntry. This is a list of SkinProperyNodes
- * a node contains the selector, the -tr- property, and the value.
- * e.g, selector: af|breadCrumbs, property: -tr-show-last-item,
- * value: true
- */
- public List <SkinPropertyNode> getSkinProperties()
- {
- return _skinProperties;
- }
-
- /**
* Checks whether the underlying style sheet source file
* has been modified and if so, reloads the StyleSheetDocument.
* Returns true if the document has been modified (and the
@@ -166,12 +148,6 @@
_document = document;
}
- // Called by CheckModifiedEntry when the style sheet has changed
- void __setSkinProperties(List <SkinPropertyNode> skinProperties)
- {
- _skinProperties = skinProperties;
- }
-
// Creates the SkinStyleSheet (a private static inner class that
// contains StyleSheetDocument plus a list
// of properties) from a CSS file
@@ -195,8 +171,7 @@
else
{
skinStyleSheet = new StyleSheetEntry(styleSheetName,
- document,
- null);
+ document);
}
}
@@ -297,11 +272,10 @@
public CheckModifiedEntry(
String styleSheetName,
StyleSheetDocument document,
- List<SkinPropertyNode> properties,
NameResolver resolver
)
{
- super(styleSheetName, document, properties);
+ super(styleSheetName, document);
// We need the InputStreamProvider in order to check
// for modifications. Get it from the NameResolver.
@@ -321,7 +295,6 @@
// Throw away the old InputStreamProvider and StyleSheetDocument
_provider = null;
__setDocument(null);
- __setSkinProperties(null);
// Get a new NameResolver
NameResolver resolver = _getNameResolver(context);
@@ -342,7 +315,6 @@
{
_provider = _getInputStreamProvider(resolver);
__setDocument(skinStyleSheet.getDocument());
- __setSkinProperties(skinStyleSheet.getSkinProperties());
}
return true;
@@ -386,9 +358,6 @@
private String _name;
private StyleSheetDocument _document;
- // List of -tr- properties that the skin can be set on the skin.
- // This is a List of SkinPropertyNodes
- private List <SkinPropertyNode> _skinProperties;
private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(StyleSheetEntry.class);
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleProvider.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleProvider.java?rev=650967&r1=650966&r2=650967&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleProvider.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleProvider.java Wed Apr 23 10:56:29 2008
@@ -91,4 +91,17 @@
* specified context.
*/
public ConcurrentMap<String, Icon> getIcons(StyleContext context);
+
+ /**
+ * Returns a map of skin property keys to skin property Object instances.
+ *
+ * The returned map is both mutable and threadsafe. This allows
+ * request/context-specific skin properties to be cached on the skin property map.
+ *
+ * @param context The context which describes the target end user
+ * environment
+ * @return A ConcurrentMap which exposes the skin properties for the
+ * specified context.
+ */
+ public ConcurrentMap<Object, Object> getSkinProperties(StyleContext context);
}
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java?rev=650967&r1=650966&r2=650967&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java Wed Apr 23 10:56:29 2008
@@ -72,6 +72,7 @@
import org.apache.myfaces.trinidadinternal.style.xml.StyleSheetDocumentUtils;
import org.apache.myfaces.trinidadinternal.style.xml.parse.IconNode;
import org.apache.myfaces.trinidadinternal.style.xml.parse.PropertyNode;
+import org.apache.myfaces.trinidadinternal.style.xml.parse.SkinPropertyNode;
import org.apache.myfaces.trinidadinternal.style.xml.parse.StyleNode;
import org.apache.myfaces.trinidadinternal.style.xml.parse.StyleSheetDocument;
import org.apache.myfaces.trinidadinternal.style.xml.parse.StyleSheetNode;
@@ -180,7 +181,21 @@
return entry.map;
}
+
+ /**
+ * Implementation of StyleProvider.getSkinProperties()
+ */
+ public ConcurrentMap<Object, Object> getSkinProperties(StyleContext context)
+ {
+
+ Entry entry = _getEntry(context);
+
+ if (entry == null)
+ return null;
+ return entry.skinProperties;
+ }
+
/**
* Implementation of StyleProvider.getIcons()
*/
@@ -487,13 +502,20 @@
checkModified);
_LOG.fine("Finished processing stylesheet {0}", uri);
-
- ConcurrentMap<String, Icon> icons = _getStyleContextResolvedIcons(context, document);
+
+
+ // Next, get the fully resolved icons and skin properties for this context.
+ // This will be those Icons and Skin Properties that match the locale, direction,
+ // browser, etc -- the info that is in the StyleContext
+ ConcurrentMap<String, Icon> icons =
+ _getStyleContextResolvedIcons(context, document);
+ ConcurrentMap<Object, Object> skinProperties =
+ _getStyleContextResolvedSkinProperties(context, document);
// Create a new entry and cache it in the "normal" cache. The "normal" cache is one
// where the key is the Key object which is built based on information from the StyleContext,
// like browser, agent, locale, direction.
- Entry entry = new Entry(uri, new StyleMapImpl(), icons);
+ Entry entry = new Entry(uri, new StyleMapImpl(), icons, skinProperties);
cache.put(key, entry);
// Also, cache the new entry in the entry cache
@@ -622,15 +644,43 @@
return v.toArray(new StyleNode[v.size()]);
}
+ // Returns a Map of skin property names to values for the specified
+ // styleSheetNodes that have been filtered from the StyleContext and StyleSheetDocument.
+ private ConcurrentMap<Object, Object> _getStyleContextResolvedSkinProperties(
+ StyleContext context,
+ StyleSheetDocument document
+ )
+ {
+ Iterator<StyleSheetNode> styleSheetNodes = document.getStyleSheets(context);
+
+ ConcurrentMap<Object, Object> skinProperties = new ConcurrentHashMap<Object, Object>();
+ while (styleSheetNodes.hasNext())
+ {
+ StyleSheetNode styleSheetNode = styleSheetNodes.next();
+ Collection<SkinPropertyNode> skinPropertyNodes = styleSheetNode.getSkinProperties();
+
+ if (skinPropertyNodes != null)
+ {
+ for (SkinPropertyNode skinPropertyNode : skinPropertyNodes)
+ {
+ skinProperties.put(skinPropertyNode.getKey(), skinPropertyNode.getValue());
+ }
+ }
+ }
+
+ return skinProperties;
+ }
+
// Returns a Map of icon names to Icons for the specified
- // StyleContext and StyleSheetDocument.
+ // styleSheetNodes that have been filtered from the StyleContext and StyleSheetDocument.
private ConcurrentMap<String, Icon> _getStyleContextResolvedIcons(
StyleContext context,
StyleSheetDocument document
)
{
- ConcurrentMap<String, Icon> icons = new ConcurrentHashMap<String, Icon>();
Iterator<StyleSheetNode> styleSheetNodes = document.getStyleSheets(context);
+
+ ConcurrentMap<String, Icon> icons = new ConcurrentHashMap<String, Icon>();
while (styleSheetNodes.hasNext())
{
StyleSheetNode styleSheetNode = styleSheetNodes.next();
@@ -1157,12 +1207,18 @@
public final String uri;
public final StyleMap map;
public final ConcurrentMap<String, Icon> icons;
+ public final ConcurrentMap<Object, Object> skinProperties;
- public Entry(String uri, StyleMap map, ConcurrentMap<String, Icon> icons)
+ public Entry(
+ String uri,
+ StyleMap map,
+ ConcurrentMap<String, Icon> icons,
+ ConcurrentMap<Object, Object> skinProperties)
{
this.uri = uri;
this.map = map;
this.icons = icons;
+ this.skinProperties = skinProperties;
}
}
Added: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/SkinPropertyNode.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/SkinPropertyNode.java?rev=650967&view=auto
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/SkinPropertyNode.java (added)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/SkinPropertyNode.java Wed Apr 23 10:56:29 2008
@@ -0,0 +1,73 @@
+/*
+ * 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.trinidadinternal.style.xml.parse;
+
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+/**
+ * A SkinProperyNode is a node that
+ * contains the selector, the -tr- property, and the value
+ * e.g., af|breadCrumbs, -tr-show-last-item, true
+ *
+ * @version $Name: $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/style/xml/parse/SkinPropertyNode.java#0 $) $Date: 10-nov-2005.18:50:45 $
+ */
+public class SkinPropertyNode
+{
+ /**
+ * Creates a SkinPropertyNode
+ *
+ * @param key The key of the skin property, like af|breadCrumbs-tr-show-last-item
+ * @param value The value of the skin property
+ */
+ public SkinPropertyNode(
+ Object key,
+ Object value
+ )
+ {
+
+ assert(key != null);
+ assert(value != null);
+
+ _key = key;
+ _value = value;
+ }
+
+
+ /**
+ * Returns the value of the skin property that is defined
+ * by this SkinPropertyNode.
+ */
+ public Object getValue()
+ {
+ return _value;
+ }
+
+
+ /**
+ * Returns the key of the SkinPropertyNode
+ */
+ public Object getKey()
+ {
+ return _key;
+ }
+
+ private Object _value;
+ // The key is the SkinProperty key, which is usually the selector + name.
+ private Object _key;
+
+}
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java?rev=650967&r1=650966&r2=650967&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java Wed Apr 23 10:56:29 2008
@@ -60,6 +60,7 @@
public StyleSheetNode(
StyleNode[] styles,
Collection<IconNode> icons,
+ Collection<SkinPropertyNode> skinProperties,
Locale[] locales,
int direction,
Map<Integer, Set<Integer>> browsers,
@@ -79,6 +80,13 @@
else
_icons = Collections.emptyList();
+
+ if (skinProperties != null)
+ _skinProperties = Collections.unmodifiableList(
+ new ArrayList<SkinPropertyNode>(skinProperties));
+ else
+ _skinProperties = Collections.emptyList();
+
// locales, browsers, versions, platforms order does not matter, so these are Sets.
if (locales != null)
{
@@ -134,6 +142,18 @@
}
/**
+ * Returns the SkinProperties List for this
+ * StyleSheetEntry. This is a list of SkinProperyNodes
+ * a node contains the selector, the -tr- property, and the value.
+ * e.g, selector: af|breadCrumbs, property: -tr-show-last-item,
+ * value: true
+ */
+ public Collection<SkinPropertyNode> getSkinProperties()
+ {
+ return _skinProperties;
+ }
+
+ /**
* Implementation of StyleSheetNode.getReadingDirection();
*/
public int getReadingDirection()
@@ -549,6 +569,9 @@
private final List<StyleNode> _styles; // The styles contained within this node
private final List<IconNode> _icons; // The icons contained within this node
+ // List of -tr- properties that the skin can be set on the skin.
+ // This is a List of SkinPropertyNodes
+ private List <SkinPropertyNode> _skinProperties;
// Order does not matter for locales, browsers, versions, platforms
private final Set<Locale> _locales; // The locale variants
private final int _direction; // The reading direction
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java?rev=650967&r1=650966&r2=650967&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java Wed Apr 23 10:56:29 2008
@@ -101,6 +101,7 @@
return new StyleSheetNode(
styles,
null, // icons only supported in skin CSS - not XSS
+ null, // properties only supported in skin CSS - not XSS
_locales,
_direction,
browsers,
Modified: myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java?rev=650967&r1=650966&r2=650967&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java Wed Apr 23 10:56:29 2008
@@ -165,6 +165,7 @@
StyleSheetNode styleSheetNode =
new StyleSheetNode(styleSheetOneNodes,
iconNodes,
+ null,
localesArray,
0,
browsers,
@@ -173,7 +174,8 @@
accProps);
StyleSheetNode anotherStyleSheetNode =
new StyleSheetNode(anotherStyleSheetOneNodes,
- anotherIconNodes,
+ anotherIconNodes,
+ null,
anotherLocalesArray,
0,
anotherBrowsersDiffOrder,
@@ -183,6 +185,7 @@
StyleSheetNode sameDiffOrderStyleSheetNode =
new StyleSheetNode(anotherStyleSheetOneNodes,
anotherIconNodes,
+ null,
diffOrderLocalesArray,
0,
anotherBrowsersDiffOrder,
@@ -333,5 +336,6 @@
return iconNodes;
}
}
+