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 2010/04/19 21:59:13 UTC

svn commit: r935718 - in /myfaces/trinidad/trunk: src/site/xdoc/devguide/ trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/ trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/

Author: jwaldman
Date: Mon Apr 19 19:59:13 2010
New Revision: 935718

URL: http://svn.apache.org/viewvc?rev=935718&view=rev
Log:
TRINIDAD-1680 Introduce include-property in CSS
Thanks to Marius Petoi for taking ownership of this one.

Modified:
    myfaces/trinidad/trunk/src/site/xdoc/devguide/skinning.xml
    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/skin/SkinStyleSheetParserUtils.java

Modified: myfaces/trinidad/trunk/src/site/xdoc/devguide/skinning.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/src/site/xdoc/devguide/skinning.xml?rev=935718&r1=935717&r2=935718&view=diff
==============================================================================
--- myfaces/trinidad/trunk/src/site/xdoc/devguide/skinning.xml (original)
+++ myfaces/trinidad/trunk/src/site/xdoc/devguide/skinning.xml Mon Apr 19 19:59:13 2010
@@ -804,6 +804,15 @@ public class SkinTranslationMapDemo
         section. Application developers probably won't use this. This is meant for component developers to use when
         they are setting up the base skin for their components. 
         </li>
+        <li>
+        <strong>-tr-property-ref</strong> - > This is used to include properties from other styles in your style.
+        The syntax of -tr-include-property is: background-color: -tr-property-ref("af|foo","color"), where the first
+        parameter is the style from which the property is included and the second one is the name of the included property
+        in that style. When the property included has the same name as in the including selector, the following syntax
+        can also be used: background-color: -tr-property-ref("af|foo") instead of: background-color: -tr-property-ref("af|foo",
+        "background-color"). This is useful when only some properties from another style are needed to be included.
+        In this case, we won't need to include the entire style via a -tr-rule-ref rule, but only the needed property.
+        </li>
         </ul>
         <P>
         You might not want your selector's css properties to be applied to all browsers, all platforms, 

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=935718&r1=935717&r2=935718&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 Mon Apr 19 19:59:13 2010
@@ -34,6 +34,20 @@ af|foo af|bar {color: purple; background
   font-size: medium;
 }
 
+
+af|foo {font-style:italic; font-size: large;}
+af|commandButton
+{
+  max-width: 100px;
+  background-color: -tr-property-ref(".AFTestBackgroundColor:alias"); 
+  font-style: -tr-property-ref("af|foo");
+}
+
+/* test the new include property functionality */
+.AFTestForegroundColor:alias {color: yellow; font-style:italic}
+.AFTestBackgroundColor:alias {background-color: -tr-property-ref(".AFTestForegroundColor:alias","color")}
+
+
 .AFDarkForeground:alias {color:#035D5C;}
 .AFDarkBackground:alias {background-color:Purple;}
 /** In the base styles, AFDarkBorder uses the background-color of 

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=935718&r1=935717&r2=935718&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 Mon Apr 19 19:59:13 2010
@@ -51,6 +51,7 @@ import org.apache.myfaces.trinidadintern
 import org.apache.myfaces.trinidadinternal.style.util.CSSUtils;
 import org.apache.myfaces.trinidadinternal.style.util.StyleUtils;
 import org.apache.myfaces.trinidadinternal.style.xml.parse.IconNode;
+import org.apache.myfaces.trinidadinternal.style.xml.parse.IncludePropertyNode;
 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;
@@ -70,10 +71,10 @@ class SkinStyleSheetParserUtils
 {
   /**
    * Parses a Skin style-sheet that is in the CSS-3 format.
-   * @param context the current ParseContext
-   * @param resolver a NameResolver to locate the target
-   *                ( Given a name, returns an InputStreamProvider.)
-   * @param sourceName the name of the target, relative to the current file
+   * @param context      the current ParseContext
+   * @param resolver     a NameResolver to locate the target
+   *                     ( Given a name, returns an InputStreamProvider.)
+   * @param sourceName   the name of the target, relative to the current file
    * @param expectedType the expected Java type of the target.
    */
   static public StyleSheetEntry parseCSSSource(
@@ -241,6 +242,7 @@ class SkinStyleSheetParserUtils
             _addStyleNode(selectorName,
                           noTrPropertyList,
                           resolvedProperties.getTrRuleRefList(),
+                          resolvedProperties.getIncludedPropertiesList(),
                           resolvedProperties.getInhibitedProperties(),
                           resolvedProperties.isTrTextAntialias(),
                           styleNodeList);
@@ -252,6 +254,7 @@ class SkinStyleSheetParserUtils
           _addStyleNode(selectorName,
                         noTrPropertyList,
                         resolvedProperties.getTrRuleRefList(),
+                        resolvedProperties.getIncludedPropertiesList(),
                         resolvedProperties.getInhibitedProperties(),
                         resolvedProperties.isTrTextAntialias(),
                         styleNodeList);
@@ -259,8 +262,8 @@ class SkinStyleSheetParserUtils
         }
       }
 
-      if ((styleNodeList.size() > 0) || (iconNodeList.size() > 0)
-          || (trSkinPropertyNodeList.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.
@@ -290,7 +293,6 @@ class SkinStyleSheetParserUtils
                                ssDocument);
 
 
-
   }
 
   /**
@@ -308,6 +310,8 @@ class SkinStyleSheetParserUtils
     List<PropertyNode> noTrPropertyList = new ArrayList<PropertyNode>();
     List<String> trRuleRefList = new ArrayList<String>();
     Set<String> inhibitedPropertySet = new TreeSet<String>();
+    List<IncludePropertyNode> includedPropertiesList =
+      new ArrayList<IncludePropertyNode>();
     List<SkinPropertyNode> skinPropertyNodeList =
       new ArrayList<SkinPropertyNode>();
 
@@ -323,6 +327,7 @@ class SkinStyleSheetParserUtils
     //                      (or -ora-text-antialias for backwards compatibility)
     // skinPropertyNodeList (all other properties that start with -tr-
     //                       (or -ora- for backwards compatibility))
+    // includedPropertiesList (all the included property 'values')
     // These properties are stored in the ResolvedSkinProperties inner class.
 
     for(PropertyNode propertyNode : propertyNodeList)
@@ -332,51 +337,63 @@ class SkinStyleSheetParserUtils
 
       if(propertyName != null && propertyValue != null)
       {
-        boolean oraProperty = propertyName.startsWith(_ORA_PROPERTY_PREFIX);
-        boolean trProperty = propertyName.startsWith(_TR_PROPERTY_PREFIX);
-        if( oraProperty || trProperty)
-        {
-          int suffixIndex = (oraProperty) ?
-                              _ORA_PROPERTY_PREFIX.length() :
-                              _TR_PROPERTY_PREFIX.length();
-          String propertyNameSuffix = propertyName.substring(suffixIndex);
-          if (propertyNameSuffix.equals(_PROPERTY_RULE_REF))
-          {
-            // add the rule ref value to the list
-            trRuleRefList.add(propertyValue);
-          }
-          else if (propertyNameSuffix.equals(_PROPERTY_TEXT_ANTIALIAS))
-          {
-            if ("true".equals(propertyValue))
-              trTextAntialias = true;
+        // Check for special propertyNames (-tr-rule-ref, -tr- skin properties)
+        // or propertyValue (-tr-property-ref)
 
-          }
-          else if (propertyNameSuffix.equals(_PROPERTY_INHIBIT))
+        boolean includedProperty = propertyValue.startsWith(_INCLUDE_PROPERTY);
+        if (includedProperty)
+        {
+          IncludePropertyNode node = _createIncludePropertyNode(
+            propertyName, propertyValue.substring(_INCLUDE_PROPERTY.length()));
+          includedPropertiesList.add(node);
+        }
+        else
+        {
+          boolean oraProperty = propertyName.startsWith(_ORA_PROPERTY_PREFIX);
+          boolean trProperty = propertyName.startsWith(_TR_PROPERTY_PREFIX);
+          if( oraProperty || trProperty)
           {
-            for (String value : _SPACE_PATTERN.split(propertyValue))
+            int suffixIndex = (oraProperty)?_ORA_PROPERTY_PREFIX.length(): _TR_PROPERTY_PREFIX.length();
+            String propertyNameSuffix = propertyName.substring(suffixIndex);
+            if (propertyNameSuffix.equals(_PROPERTY_RULE_REF))
+            {
+              // add the rule ref value to the list
+              trRuleRefList.add(propertyValue);
+            }
+            else if (propertyNameSuffix.equals(_PROPERTY_TEXT_ANTIALIAS))
+            {
+              if ("true".equals(propertyValue))
+                trTextAntialias = true;
+
+            }
+            else if (propertyNameSuffix.equals(_PROPERTY_INHIBIT))
+            {
+              for (String value : _SPACE_PATTERN.split(propertyValue))
+              {
+                inhibitedPropertySet.add(value);
+              }
+            }
+            else
             {
-              inhibitedPropertySet.add(value);
+              // create the SkinPropertyNode
+              SkinPropertyNode node =
+                _createSkinPropertyNode(selectorName, propertyName, propertyValue);
+
+              skinPropertyNodeList.add(node);
             }
           }
           else
           {
-            // create the SkinPropertyNode
-            SkinPropertyNode node =
-              _createSkinPropertyNode(selectorName, propertyName, propertyValue);
-
-            skinPropertyNodeList.add(node);
+            noTrPropertyList.add(propertyNode);
           }
         }
-        else
-        {
-          noTrPropertyList.add(propertyNode);
-        }
       }
     }
 
     return new ResolvedSkinProperties(
       noTrPropertyList,
       trRuleRefList,
+      includedPropertiesList,
       inhibitedPropertySet,
       skinPropertyNodeList,
       trTextAntialias);
@@ -519,7 +536,7 @@ class SkinStyleSheetParserUtils
         if ((heightValue != null || widthValue != null) && inlineStyle == null)
           inlineStyle = new CSSStyle();
         if (heightValue != null)
-         inlineStyle.setProperty("height", heightValue);
+          inlineStyle.setProperty("height", heightValue);
         if (widthValue != null)
           inlineStyle.setProperty("width", widthValue);
         icon = new TextIcon(text, text, null, inlineStyle);
@@ -561,8 +578,8 @@ class SkinStyleSheetParserUtils
         /// neither text or image icon.
         if (inlineStyle != null)
         {
-         // create a styleNode, too with the inlineStyles.
-         createStyleNode = true;
+          // create a styleNode, too with the inlineStyles.
+          createStyleNode = true;
         }
       }
     }
@@ -588,12 +605,13 @@ class SkinStyleSheetParserUtils
    * @param styleNodeList
    */
   private static void _addStyleNode(
-    String             selectorName,
-    List<PropertyNode> propertyNodeList,
-    List<String>       trRuleRefList,
-    Set<String>        inhibitedProperties,
-    boolean            trTextAntialias,
-    List<StyleNode>    styleNodeList)
+    String                    selectorName,
+    List<PropertyNode>        propertyNodeList,
+    List<String>              trRuleRefList,
+    List<IncludePropertyNode> includePropertyNodes,
+    Set<String>               inhibitedProperties,
+    boolean                   trTextAntialias,
+    List<StyleNode>           styleNodeList)
   {
 
     // these are the styles.
@@ -648,13 +666,64 @@ class SkinStyleSheetParserUtils
                     selector,
                     propertyArray,
                     includeStyleNodes.toArray(new IncludeStyleNode[0]),
-                    null,
+                    includePropertyNodes.isEmpty() ? null : includePropertyNodes.toArray(new IncludePropertyNode[0]),
                     inhibitedProperties);
 
     styleNodeList.add(styleNode);
 
   }
 
+  /**
+   * Create an IncludePropertyNode.
+   * The syntax for including a property from another selector is
+   * af|commandButton { background-color: -tr-property-ref(".AFTestBackgroundColor:alias"); }
+   * .AFTestForegroundColor:alias {color: yellow; font-style:italic}
+   * .AFTestBackgroundColor:alias {background-color: -tr-property-ref(".AFTestForegroundColor:alias","color")}
+   * @param propertyName name of the property like background-color, color
+   * @param propertyValue value that want to include. This is stripped of the
+   * -tr-property-ref, so it is of the form ("...")
+   */
+  private static IncludePropertyNode _createIncludePropertyNode(
+    String propertyName, 
+    String propertyValue)
+  {
+    // do a quick sanity check
+    if (propertyValue == null || propertyValue.length() < 2)
+      return null;
+    if (propertyValue.startsWith("(") && propertyValue.endsWith(")"))
+    {
+      String valueString = propertyValue.substring(1, propertyValue.length() - 1);
+      String values[] = valueString.split(",");
+      String selectorValue = trimQuotes(values[0]);
+      String includedProperty;
+      if (values.length == 1)
+      {
+        includedProperty = propertyName;
+      }
+      else
+      {
+        includedProperty = trimQuotes(values[1]);
+      }
+
+      String selector = null;
+      String name = null;
+      if (selectorValue.endsWith(":alias"))
+      {
+        int aliasEndIndex = selectorValue.indexOf(":alias");
+        int aliasStartIndex = 0;
+        if (selectorValue.startsWith("."))
+          aliasStartIndex = 1;
+        name = selectorValue.substring(aliasStartIndex, aliasEndIndex);
+      }
+      else
+      {
+        selector = selectorValue;
+      }
+      return new IncludePropertyNode(name, selector, includedProperty, propertyName);
+    }
+    return null;
+  }
+
   private static SkinPropertyNode _createSkinPropertyNode(
     String selector,
     String name,
@@ -745,8 +814,8 @@ class SkinStyleSheetParserUtils
   }
 
   private static StyleSheetDocument _createStyleSheetDocument(
-    ParseContext       context,
-    List <StyleSheetNode> ssNodeList)
+    ParseContext context,
+    List<StyleSheetNode> ssNodeList)
   {
 
     long timestamp = _getDocumentTimestamp(context);
@@ -791,34 +860,35 @@ class SkinStyleSheetParserUtils
     return timestamp;
   }
 
-/** unused for now. we want to do this for icons, properties and styles at once
-  // substitute the prefix (the part that comes before the |) with
-  // its namespace
-  // e.g., selectorName = af|breadCrumbs
-  // af maps to http://myfaces.apache.org/adf/faces
-  // return
-  // http://myfaces.apache.org/adf/faces|navigationPath
-  private static String _getNamespacedSelector(
-    Map    namespaceMap,
-    String selectorName)
-  {
-
-    int barIndex = selectorName.indexOf("|");
-
-    if (barIndex <= 0)
-      return selectorName;
-    else
-    {
-      String namespace =
-        (String)namespaceMap.get(selectorName.substring(0, barIndex));
-      if (namespace == null)
-        return selectorName;
-      return namespace.concat(selectorName.substring(barIndex));
-    }
-  }
-  **/
+  /**
+   * unused for now. we want to do this for icons, properties and styles at once
+   * // substitute the prefix (the part that comes before the |) with
+   * // its namespace
+   * // e.g., selectorName = af|breadCrumbs
+   * // af maps to http://myfaces.apache.org/adf/faces
+   * // return
+   * // http://myfaces.apache.org/adf/faces|navigationPath
+   * private static String _getNamespacedSelector(
+   * Map    namespaceMap,
+   * String selectorName)
+   * {
+   * <p/>
+   * int barIndex = selectorName.indexOf("|");
+   * <p/>
+   * if (barIndex <= 0)
+   * return selectorName;
+   * else
+   * {
+   * String namespace =
+   * (String)namespaceMap.get(selectorName.substring(0, barIndex));
+   * if (namespace == null)
+   * return selectorName;
+   * return namespace.concat(selectorName.substring(barIndex));
+   * }
+   * }
+   */
 
-  private static List <SkinStyleSheetNode> _parseCSSStyleSheet(Reader reader)
+  private static List<SkinStyleSheetNode> _parseCSSStyleSheet(Reader reader)
   {
     SkinCSSParser parser = new SkinCSSParser();
     SkinCSSDocumentHandler documentHandler = new SkinCSSDocumentHandler();
@@ -887,12 +957,14 @@ class SkinStyleSheetParserUtils
     ResolvedSkinProperties(
       List<PropertyNode> noTrPropertyList,
       List<String> trRuleRefList,
+      List<IncludePropertyNode> includedPropertiesList,
       Set<String> inhibitedPropertySet,
       List<SkinPropertyNode> skinPropertyNodeList,
       boolean trTextAntialias)
     {
       _noTrPropertyList = noTrPropertyList;
       _trRuleRefList = trRuleRefList;
+      _includedPropertiesList = includedPropertiesList;
       _inhibitedPropertySet = inhibitedPropertySet;
       _skinPropertyNodeList = skinPropertyNodeList;
       _trTextAntialias = trTextAntialias;
@@ -908,6 +980,11 @@ class SkinStyleSheetParserUtils
       return _trRuleRefList;
     }
 
+    public List<IncludePropertyNode> getIncludedPropertiesList()
+    {
+      return _includedPropertiesList;
+    }
+
     public List<SkinPropertyNode> getSkinPropertyNodeList()
     {
       return _skinPropertyNodeList;
@@ -923,11 +1000,12 @@ class SkinStyleSheetParserUtils
       return _trTextAntialias;
     }
 
-    private Set<String>            _inhibitedPropertySet;
-    private List<PropertyNode>     _noTrPropertyList;
-    private List<String>           _trRuleRefList;
-    private List<SkinPropertyNode> _skinPropertyNodeList;
-    private boolean                _trTextAntialias;
+    private Set<String>               _inhibitedPropertySet;
+    private List<PropertyNode>        _noTrPropertyList;
+    private List<String>              _trRuleRefList;
+    private List<IncludePropertyNode> _includedPropertiesList;
+    private List<SkinPropertyNode>    _skinPropertyNodeList;
+    private boolean                   _trTextAntialias;
   }
 
   // Custom Trinidad css properties:
@@ -938,6 +1016,7 @@ class SkinStyleSheetParserUtils
   private static final String _ORA_PROPERTY_PREFIX = "-ora-";
   private static final String _PROPERTY_RULE_REF = "rule-ref";
   private static final String _PROPERTY_INHIBIT = "inhibit";
+  private static final String _INCLUDE_PROPERTY = "-tr-property-ref";
   private static final String _PROPERTY_TEXT_ANTIALIAS = "text-antialias";
   private static final Pattern _INTEGER_PATTERN = Pattern.compile("\\d+(px)?");
 
@@ -946,4 +1025,4 @@ class SkinStyleSheetParserUtils
 
   static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(
     SkinStyleSheetParserUtils.class);
-}
+}
\ No newline at end of file