You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by aw...@apache.org on 2006/12/13 22:49:18 UTC
svn commit: r486881 - in /incubator/adffaces/trunk/trinidad:
trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/
trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/
trinidad-impl/src/main/java/org/apache/myfaces/t...
Author: awiner
Date: Wed Dec 13 14:49:17 2006
New Revision: 486881
URL: http://svn.apache.org/viewvc?view=rev&rev=486881
Log:
ADFFACES-116: Detect empty styles and don't render them
Modified:
incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocument.java
Modified: incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java?view=diff&rev=486881&r1=486880&r2=486881
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java Wed Dec 13 14:49:17 2006
@@ -599,7 +599,8 @@
if (styleClasses[i] != null)
{
String styleClass = arc.getStyleClass(styleClasses[i]);
- length += styleClass.length() + 1;
+ if (styleClass != null)
+ length += styleClass.length() + 1;
styleClasses[i] = styleClass;
}
}
Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java?view=diff&rev=486881&r1=486880&r2=486881
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java Wed Dec 13 14:49:17 2006
@@ -57,6 +57,12 @@
public class CoreRenderingContext extends RenderingContext
{
+ /**
+ * String marker used to indicate the style class is empty and can
+ * be ignored.
+ */
+ static public final String EMPTY_STYLE_CLASS = "";
+
public CoreRenderingContext()
{
FacesContext context = FacesContext.getCurrentInstance();
@@ -251,7 +257,12 @@
}
if (shortenedStyle != null)
+ {
+ if (EMPTY_STYLE_CLASS == shortenedStyle)
+ return null;
+
styleClass = shortenedStyle;
+ }
else
{
// if we didn't shorten the style classes, then make sure the
Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java?view=diff&rev=486881&r1=486880&r2=486881
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java Wed Dec 13 14:49:17 2006
@@ -24,11 +24,14 @@
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -36,6 +39,7 @@
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
+import org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderingContext;
import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SkinSelectors;
import org.apache.myfaces.trinidadinternal.share.io.CachingNameResolver;
import org.apache.myfaces.trinidadinternal.share.io.DefaultNameResolver;
@@ -618,16 +622,11 @@
return null;
}
- // -= Simon Lessard =-
- // TODO: Check if synchronization is truly required
- Vector<StyleNode> v = new Vector<StyleNode>();
+ List<StyleNode> v = new ArrayList<StyleNode>();
while (e.hasNext())
- v.addElement(e.next());
+ v.add(e.next());
- StyleNode[] styles = new StyleNode[v.size()];
- v.copyInto(styles);
-
- return styles;
+ return v.toArray(new StyleNode[v.size()]);
}
// Generates the CSS file for the specified context and styles.
@@ -896,6 +895,7 @@
Iterator<StyleSheetNode> styleSheets = document.getStyleSheets(context);
assert (styleSheets != null);
+ Set<String> emptySelectors = new HashSet<String>();
while (styleSheets.hasNext())
{
StyleSheetNode styleSheet = styleSheets.next();
@@ -908,8 +908,6 @@
if (selector != null)
{
-
-
// If we've got a single style class selector, add it
// to the map. Otherwise, we need to search the selector
// for style classes.
@@ -918,6 +916,11 @@
String styleClass = selector.substring(1);
if (!map.containsKey(styleClass))
map.put(styleClass, _getShortStyleClass(map.size()));
+
+ if (style.isEmpty())
+ emptySelectors.add(styleClass);
+ else
+ emptySelectors.remove(styleClass);
}
else
{
@@ -929,14 +932,17 @@
while (styleClasses.hasNext())
{
String styleClass = styleClasses.next();
-
+
if (!map.containsKey(styleClass))
map.put(styleClass, _getShortStyleClass(map.size()));
+
+ // Don't remove any styleclass that is referred to
+ emptySelectors.remove(styleClass);
}
}
-
+
int length = namespacePrefixes.length;
-
+
for (int i=0; i < length; i++)
{
String nsPrefix = namespacePrefixes[i];
@@ -946,12 +952,23 @@
_STYLE_KEY_MAP);
if (afSelectors != null)
{
+ boolean isFirst = true;
while (afSelectors.hasNext())
{
String styleClass = afSelectors.next();
-
+
if (!map.containsKey(styleClass))
map.put(styleClass, _getShortStyleClass(map.size()));
+ if (isFirst && !afSelectors.hasNext() && style.isEmpty())
+ {
+ emptySelectors.add(styleClass);
+ }
+ else
+ {
+ emptySelectors.remove(styleClass);
+ }
+
+ isFirst = false;
}
}
}
@@ -962,13 +979,15 @@
}
}
+ // Replace all empty keys with an empty string as the selector
+ for (String emptyKey : emptySelectors)
+ map.put(emptyKey, CoreRenderingContext.EMPTY_STYLE_CLASS);
+
// We actually need a Map, since this object is exposed
// via public APIs. Also, we need the Map to be immutable,
// or else we would need to create a new copy of the Map
// each time it is requested.
- // =-ags We could just clone the Map and wrap it in a Map
- // if we want to allow clients to modify the Map.
- return new ImmutableMapAdapter<String, String>(map);
+ return Collections.unmodifiableMap(map);
}
// Helper method used by _getShortStyleClassMap(). Returns a new
@@ -1334,70 +1353,6 @@
private Hashtable<String, Style> _classMap;
private Hashtable<String, Style> _nameMap;
}
-
- // Wraps a Map in an immutable Map
- // -= Simon Lessard =-
- // FIXME: WAHHHH! This is BAD... extending HashMap creates a
- // big array that will never be used... Furthermore,
- // Collections.unmodifiableMap does just that!!!
- private static class ImmutableMapAdapter<K, V> extends HashMap<K, V>
- {
- public ImmutableMapAdapter(Map<K, V> map)
- {
- _map = map;
- }
-
- @Override
- public int size()
- {
- return _map.size();
- }
-
- @Override
- public boolean isEmpty()
- {
- return _map.isEmpty();
- }
-
- public Iterator<K> keys()
- {
- Set<K> keys = _map.keySet();
- if (keys == null)
- return null;
-
- return keys.iterator();
- }
-
- public Iterator<V> elements()
- {
- Collection<V> values = _map.values();
- if (values == null)
- return null;
-
- return values.iterator();
- }
-
- @Override
- public V get(Object key)
- {
- return _map.get(key);
- }
-
- @Override
- public V put(K key, V value)
- {
- throw new IllegalArgumentException();
- }
-
- @Override
- public V remove(Object key)
- {
- throw new IllegalArgumentException();
- }
-
- private final Map<K, V> _map;
- }
-
private File _sourceFile; // The source XSS file
private String _targetPath; // The location of the cache
Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java?view=diff&rev=486881&r1=486880&r2=486881
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java Wed Dec 13 14:49:17 2006
@@ -161,6 +161,22 @@
{
return _selector;
}
+
+ /**
+ * Returns true if the style node has no properties.
+ */
+ public boolean isEmpty()
+ {
+ if (_properties != null && _properties.length > 0)
+ return false;
+ if (_compoundProperties != null && _compoundProperties.length > 0)
+ return false;
+ if (_includedStyles != null && _includedStyles.length > 0)
+ return false;
+ if (_includedProperties != null && _includedProperties.length > 0)
+ return false;
+ return true;
+ }
/**
* Implementation of StyleNode.getProperties().
Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocument.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocument.java?view=diff&rev=486881&r1=486880&r2=486881
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocument.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocument.java Wed Dec 13 14:49:17 2006
@@ -19,7 +19,7 @@
import java.awt.Color;
import java.util.Map;
-import java.util.Hashtable;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.NoSuchElementException;
@@ -194,14 +194,10 @@
// We also need to provide a Map for storing selector-based
// styles and another for storing name-based styles, used by
// _resolveStyle() to store results
- // -= Simon Lessard =-
- // TODO: Check if synchronization is truly required
- Hashtable<String, StyleNode> resolvedStyles =
- new Hashtable<String, StyleNode>();
- // -= Simon Lessard =-
- // TODO: Check if synchronization is truly required
- Hashtable<String, StyleNode> resolvedNamedStyles =
- new Hashtable<String, StyleNode>();
+ HashMap<String, StyleNode> resolvedStyles =
+ new HashMap<String, StyleNode>();
+ HashMap<String, StyleNode> resolvedNamedStyles =
+ new HashMap<String, StyleNode>();
// Now, loop through all StyleNodes in all StyleSheetNodes
// Note: The algorithm used here is actually much more inefficient
@@ -375,12 +371,10 @@
if (styleSheets == null)
return null;
- // -= Simon Lessard =-
- // TODO: Check if synchronization is truly required
return _resolveStyle(context,
styleSheets,
- new Hashtable<String, StyleNode>(19), // Resolved styles
- new Hashtable<String, StyleNode>(19), // Resolved named styles
+ new HashMap<String, StyleNode>(19), // Resolved styles
+ new HashMap<String, StyleNode>(19), // Resolved named styles
null, // Include stack
null, // Named include stack
id,