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 2009/04/07 20:26:41 UTC

svn commit: r762891 - in /myfaces/trinidad/branches/jwaldman_StyleMap: trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/ trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/ trinidad-impl/src/main/java/org/a...

Author: jwaldman
Date: Tue Apr  7 18:26:41 2009
New Revision: 762891

URL: http://svn.apache.org/viewvc?rev=762891&view=rev
Log:
Add Selector class

Modified:
    myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Style.java
    myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Styles.java
    myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java
    myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/BaseStyle.java
    myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/CoreStyle.java
    myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
    myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java
    myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/XhtmlLafUtils.java

Modified: myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Style.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Style.java?rev=762891&r1=762890&r2=762891&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Style.java (original)
+++ myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Style.java Tue Apr  7 18:26:41 2009
@@ -8,9 +8,9 @@
  *  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
@@ -28,18 +28,20 @@
  * key and the property value as the value.
  *
  */
-public interface Style
+public abstract class Style
 {
 
   /**
    * Returns a Map of the properties (name/value) defined by this style.
    */
-  public Map<String, String> getProperties();
+  abstract public Map<String, String> getProperties();
+
 
   /**
    * Converts the style to a String suitable for use as an inline style
    * attribute value.
    */
-  public String toInlineString();
+  abstract public String toInlineString();
+
 }
 

Modified: myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Styles.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Styles.java?rev=762891&r1=762890&r2=762891&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Styles.java (original)
+++ myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Styles.java Tue Apr  7 18:26:41 2009
@@ -21,7 +21,6 @@
 
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.regex.Pattern;
@@ -38,9 +37,12 @@
    * to get all the selector keys, or to get the Style Object for a Selector, or to 
    * get all the selectors that match some criteria, like they contain a certain simple selector.
    * 
-   * @return unmodifiableMamp of the resolved Selector -> Style map.
+   * @return unmodifiableMap of the resolved Selector -> Style map.
    */
-  public abstract Map<String, Style> getSelectorStyleMap();
+  public abstract Map<Selector, Style> getSelectorStyleMap();
+  
+  // Returns the Selector in String form, converted to a css-2 style.
+  public abstract String getNativeSelector(Selector selector);
   
   /**
    * Given a simple selector (as opposed to a complex selector) like "af|inputText", this method
@@ -51,26 +53,27 @@
    * @param simpleSelector
    * @return
    */
-  public Set<String> getSelectorsForSimpleSelector(String simpleSelector)
+  public Set<Selector> getSelectorsForSimpleSelector(String simpleSelector)
   {
-    Map<String, Style> selectorStyleMap = getSelectorStyleMap();
-    Set<String> set = null;
+    Map<Selector, Style> selectorStyleMap = getSelectorStyleMap();
+    Set<Selector> set = null;
     
     // loop through each entry and find all simple selectors
-    for (Map.Entry<String, Style> entry : selectorStyleMap.entrySet())
+    for (Map.Entry<Selector, Style> entry : selectorStyleMap.entrySet())
     {
-      String completeSelector = entry.getKey();
-      if (completeSelector.indexOf(simpleSelector) > -1)
+      Selector completeSelector = entry.getKey();
+      String completeSelectorString = completeSelector.toString();
+      if (completeSelectorString.indexOf(simpleSelector) > -1)
       {
         // split based on . and space and :?
-        String[] selectorsSplit = _SPACE_PATTERN.split(completeSelector);
+        String[] selectorsSplit = _SPACE_PATTERN.split(completeSelectorString);
         
         for(String selector : selectorsSplit)
         {
           if (selector.indexOf(simpleSelector) > -1)
           {
             if (set == null)
-              set = new HashSet<String>(); 
+              set = new HashSet<Selector>(); 
             set.add(completeSelector);
             break;
           }

Modified: myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java?rev=762891&r1=762890&r2=762891&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java (original)
+++ myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java Tue Apr  7 18:26:41 2009
@@ -33,6 +33,7 @@
 import org.apache.myfaces.trinidad.bean.FacesBean;
 import org.apache.myfaces.trinidad.component.core.CoreStyleSheet;
 import org.apache.myfaces.trinidad.context.RenderingContext;
+import org.apache.myfaces.trinidad.style.Selector;
 import org.apache.myfaces.trinidad.style.Style;
 import org.apache.myfaces.trinidad.style.Styles;
 import org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderingContext;
@@ -89,7 +90,8 @@
 
     StyleContext sContext = ((CoreRenderingContext) arc).getStyleContext();
     StyleProvider provider = sContext.getStyleProvider();
-    _testGetSelectorStyleMap(context, arc);
+    //System.out.println("TEST THE GET SELECTOR STYLE MAP");
+    //_testGetSelectorStyleMap(context, arc);
     if (provider != null)
     {
       List<String> uris = provider.getStyleSheetURIs(sContext);
@@ -195,7 +197,7 @@
                               "AFDefaultFont"};// name
           
         System.out.println("getSelectorStyleMap NEW. Gets all the selectors, then find the one you want");
-        Map<String, Style> selectorStyleMap = styles.getSelectorStyleMap();
+        Map<Selector, Style> selectorStyleMap = styles.getSelectorStyleMap();
         
         for (int i=0; i< selectors.length; i++)
         {
@@ -223,12 +225,13 @@
         writer.startElement("style", null);
         for (int i=0; i< simpleSelectorsToInline.length; i++)
         {
-          System.out.println("Get styles for " + simpleSelectorsToInline[i]);
-          Set<String> selectorSet = styles.getSelectorsForSimpleSelector(simpleSelectorsToInline[i]);
-          for (String eachSelector : selectorSet)
+          System.out.println("xGet styles for " + simpleSelectorsToInline[i]);
+          Set<Selector> selectorSet = styles.getSelectorsForSimpleSelector(simpleSelectorsToInline[i]);
+          for (Selector eachSelector : selectorSet)
           {
-            System.out.print(eachSelector + "{");
-            writer.write(eachSelector);
+            String validSelector = styles.getNativeSelector(eachSelector);
+            System.out.print(validSelector + "{");
+            writer.write(validSelector);
             writer.write("{");
             String cssInlineProperties = selectorStyleMap.get(eachSelector).toInlineString();
             System.out.print(cssInlineProperties);

Modified: myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/BaseStyle.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/BaseStyle.java?rev=762891&r1=762890&r2=762891&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/BaseStyle.java (original)
+++ myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/BaseStyle.java Tue Apr  7 18:26:41 2009
@@ -32,7 +32,7 @@
  * TODO Then remove CoreStyle and implement the public Style object instead.
  * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/style/BaseStyle.java#0 $) $Date: 10-nov-2005.18:57:54 $
  */
-abstract public class BaseStyle implements CoreStyle, Serializable
+abstract public class BaseStyle extends CoreStyle implements Serializable 
 {
   /**
    * Creates an empty BaseStyle. For better performance, 

Modified: myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/CoreStyle.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/CoreStyle.java?rev=762891&r1=762890&r2=762891&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/CoreStyle.java (original)
+++ myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/CoreStyle.java Tue Apr  7 18:26:41 2009
@@ -34,7 +34,7 @@
  * that is not used.
  * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/style/Style.java#0 $) $Date: 10-nov-2005.18:57:56 $
  */
-public interface CoreStyle extends Style
+public abstract class CoreStyle extends Style
 {
   /**
    * Key for obtaining the Color object which corresponds to the
@@ -130,7 +130,7 @@
    * @param throws PropertyParseException Thrown if the property value
    *   can not be parsed.
    */
-  public Object getParsedProperty(ParsedPropertyKey key)
+  abstract public Object getParsedProperty(ParsedPropertyKey key)
     throws PropertyParseException;
 
 }

Modified: myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java?rev=762891&r1=762890&r2=762891&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java (original)
+++ myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java Tue Apr  7 18:26:41 2009
@@ -49,6 +49,7 @@
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 import org.apache.myfaces.trinidad.skin.Icon;
 import org.apache.myfaces.trinidad.skin.Skin;
+import org.apache.myfaces.trinidad.style.Selector;
 import org.apache.myfaces.trinidad.style.Style;
 import org.apache.myfaces.trinidad.style.Styles;
 import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
@@ -555,7 +556,7 @@
     // 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(uris, new StylesImpl(styles), icons, skinProperties);
+    Entry entry = new Entry(uris, new StylesImpl(styles, namespacePrefixes, _STYLE_KEY_MAP), icons, skinProperties);
     cache.put(key, entry);
 
     // Also, cache the new entry in the entry cache
@@ -1408,21 +1409,32 @@
      * etc.
      * @param resolvedStyles
      */
-    public StylesImpl(StyleNode[] resolvedStyles) 
-    {
-      _resolvedStyles = resolvedStyles;   
-      // TODO create a map right here (aggressively versus lazily)
-      // else I could make a List out of this and then I could create
-      // it lazily from then on.
+    public StylesImpl(
+        StyleNode[]         resolvedStyles,
+        String[]            namespacePrefixArray,
+        Map<String, String> afSelectorMap
+      ) 
+    {
+      _resolvedStyles = resolvedStyles; 
+      _namespacePrefixArray = namespacePrefixArray;
+      _afSelectorMap = afSelectorMap;
+
+      // create a map right here (aggressively versus lazily)
+
       // Loop through each StyleNode and use it to add to the StyleMap.
       for (int i=0; i < _resolvedStyles.length; i++)
       {
         String selector = _resolvedStyles[i].getSelector();
         if (selector != null)
         {
-          // create a Style Object from the StyleNode object
-          Style style = _convertStyleNode(_resolvedStyles[i]);
-          _resolvedSelectorStyleMap.put(selector, style);
+          Style style = _convertStyleNodeToStyle(_resolvedStyles[i]);
+          _resolvedSelectorStyleMap.put(Selector.createSelector(selector), style);
+
+          // TODO create a map for native selectors. Given a selector, return
+          // the native selector?
+          // I might need a map of native selectors to styles, but for now I
+          // think I only need to given a selector, return the native selector.
+          // store the _namespacePrefixArray and the _afSelectorMap.
 
  
         }
@@ -1455,13 +1467,38 @@
      * 
      * @return unmodifiableMamp of the resolved Selector -> Style map.
      */
-    public Map<String, Style> getSelectorStyleMap()
+    @Override
+    public Map<Selector, Style> getSelectorStyleMap()
     {
       return Collections.unmodifiableMap(_resolvedSelectorStyleMap);
     }  
+    
+    // Given a Selector, return the uncompressed valid css2-formatted selectors.
+    // TODO is it necessary to return shortened styles if there is a shortened 
+    // map??
+    // Right now we plan to use this to write out selectors in the html
+    // page for emailable page, and that is uncompressed, but I suppose 
+    // it could be compressed somehow.
+    // TODO This will need to move to the public API when we need it.
+    // TODO should we build up a Map as we go along?
+    // Right now we plan to get the style selectors in their css-3 skin format
+    // and we'll need to convert it to something that is writeable to the page.
+    public String getNativeSelector(Selector selector)
+    {
+      // convert the selector to a valid css2 selector like the ones we write
+      // to the generated css file.
+      if (selector == null)
+        throw new IllegalArgumentException("selector cannot be null");
+      // run the selector through a conversion map so the selector is closer to
+      // what we write out to the css. e.g., af|inputText:error::content becomes
+      // af|inputText.p_AFError af|inputText::content. This way we don't have to 
+      // do this when we write the css inline. We have the information now.
+      return CSSGenerationUtils.getMappedSelector(
+        _afSelectorMap, _namespacePrefixArray, selector.toString());
+    }
 
     // TODO Do I need ConcurrentHashMap??
-    public Style _convertStyleNode(StyleNode styleNode)
+    public Style _convertStyleNodeToStyle(StyleNode styleNode)
     {
       Map<String, String> styleProperties = new ConcurrentHashMap<String, String>();
       // Add in the properties for the style
@@ -1481,12 +1518,12 @@
 
     }
     
-    private ConcurrentMap<String, Style> _resolvedSelectorStyleMap = 
-      new ConcurrentHashMap<String, Style>();
+    private ConcurrentMap<Selector, Style> _resolvedSelectorStyleMap = 
+      new ConcurrentHashMap<Selector, Style>();
     
     private StyleNode[] _resolvedStyles;
-
-
+    private Map<String, String> _afSelectorMap;
+    private String[] _namespacePrefixArray;
   }
   
   private class StyleWriterFactoryImpl

Modified: myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java?rev=762891&r1=762890&r2=762891&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java (original)
+++ myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java Tue Apr  7 18:26:41 2009
@@ -207,9 +207,9 @@
           // We should always have a selector at this point
           assert (selectors[j] != null);
 
-          mappedSelectors[j] = _getMappedSelector(afSelectorMap,
-                                                     namespacePrefixArray,
-                                                     selectors[j]);
+          mappedSelectors[j] = getMappedSelector(afSelectorMap,
+                                                 namespacePrefixArray,
+                                                 selectors[j]);
 
           if (compressStyles && (mappedSelectors[j].indexOf('|') == -1))
           {
@@ -246,7 +246,7 @@
           if (!compressStyles || (mappedSelectors[j].indexOf('|') == -1))
           {
             validFullNameSelector =
-              _getValidFullNameSelector(mappedSelectors[j], namespacePrefixArray);
+              getValidFullNameSelector(mappedSelectors[j], namespacePrefixArray);
 
             if (validFullNameSelector != null)
             {
@@ -294,7 +294,7 @@
             if (shortSelector != null)
             {
               String validShortSelector =
-                _getValidFullNameSelector(shortSelector, namespacePrefixArray);
+                getValidFullNameSelector(shortSelector, namespacePrefixArray);
 
               // if we wrote out a full style, check to see if we need to write out the short, too.
               // if it is something different, write out the short, too.
@@ -745,6 +745,7 @@
     // return the original selector if this isn't shorter.
     return isShorter ? buffer.toString() : selector;
   }
+  
   /**
    * Runs a selector through a map. It returns the selector unchanged (except for converted
    * pseudo-classes) if there is no namespace in the selector.
@@ -756,16 +757,17 @@
    * We call this method first with the public->internal map, and then
    * to shorten it.
    * Only the pieces of the selector that start with the namespace are mapped.
-   * @param map         if shortenPass is true, then this map shortens the
-   *                    af| selector. else, it maps the public af| selector
-   *                    to the internal selector.
-   * @param namespace   most likely, "af|". The selectors with this namespace
-   *                    are the ones we map.
+   * @param afSelectorMap if shortenPass is true, then this map shortens the
+   *                 af| selector. else, it maps the public af| selector
+   *                 to the internal selector (a selector that is closer to what is written to the
+*                    CSS file. 
+*                    e.g., af|inputText:error::content becomes 
+*                    af|inputText.p_AFError af|inputText::content
+   * @param namespacePrefixArray   most likely, "af|". The selectors with this namespace
+   *                               are the ones we map.
    * @param selector    selector to map.
-   * @param shorten     if true, then we'll add the "." to the mapped selector.
-   * @return            the selector, mapped.
    */
-  private static String _getMappedSelector (
+  public static String getMappedSelector (
     Map<String, String> afSelectorMap,
     String[]            namespacePrefixArray,
     String              selector)
@@ -1104,7 +1106,7 @@
    * @param selector
    * @return
    */
-  private static String _getValidFullNameSelector(
+  public static String getValidFullNameSelector(
     String selector,
     String[] namespacePrefixArray)
   {

Modified: myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/XhtmlLafUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/XhtmlLafUtils.java?rev=762891&r1=762890&r2=762891&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/XhtmlLafUtils.java (original)
+++ myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/XhtmlLafUtils.java Tue Apr  7 18:26:41 2009
@@ -33,6 +33,7 @@
 import org.apache.myfaces.trinidad.context.RenderingContext;
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 import org.apache.myfaces.trinidad.skin.Icon;
+import org.apache.myfaces.trinidad.style.Selector;
 import org.apache.myfaces.trinidad.style.Style;
 import org.apache.myfaces.trinidad.style.Styles;
 import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
@@ -221,9 +222,9 @@
       Styles styles = context.getStyleContext().getStyles();
       if (styles != null)
       {
-        Map<String, Style> map = styles.getSelectorStyleMap();
+        Map<Selector, Style> map = styles.getSelectorStyleMap();
         if (map != null)
-          return (CoreStyle)map.get(className.toString());
+          return (CoreStyle)map.get(Selector.createSelector(className.toString()));
       }
     }