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/21 00:38:36 UTC
svn commit: r766900 - in
/myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style:
cache/FileSystemStyleCache.java util/CSSGenerationUtils.java
Author: jwaldman
Date: Mon Apr 20 22:38:36 2009
New Revision: 766900
URL: http://svn.apache.org/viewvc?rev=766900&view=rev
Log:
getNativeSelector will return the 'compressed' native selector if style class compression is on.
NOTE: StyleSheetRenderer contains some code we need, and some test code. Remember to delete the test code before checking this into trunk.
Modified:
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
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=766900&r1=766899&r2=766900&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 Mon Apr 20 22:38:36 2009
@@ -525,8 +525,8 @@
// etc -- the info that is in the StyleContext.
// These styles contain all the StyleNodes, that is, where selector or
// name (aka alias) are non-null.
- StyleNode[] styles = _getStyleContextResolvedStyles(context, document);
- if (styles == null)
+ StyleNode[] styleNodes = _getStyleContextResolvedStyles(context, document);
+ if (styleNodes == null)
return null;
@@ -538,7 +538,7 @@
// written to the generated css file.
List<String> uris = _createStyleSheetFiles(context,
document,
- styles,
+ styleNodes,
shortStyleClassMap,
namespacePrefixes,
checkModified);
@@ -557,7 +557,9 @@
// 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, namespacePrefixes, _STYLE_KEY_MAP), icons, skinProperties);
+ Styles styles = new StylesImpl(styleNodes, namespacePrefixes, _STYLE_KEY_MAP,
+ shortStyleClassMap, _isCompressStyles(context));
+ Entry entry = new Entry(uris, styles, icons, skinProperties);
cache.put(key, entry);
// Also, cache the new entry in the entry cache
@@ -1208,7 +1210,7 @@
agent.getAgentApplication(),
agent.getAgentVersion(),
agent.getAgentOS(),
- true,
+ !context.isDisableStyleCompression(),
accProfile,
context.isPortletMode());
}
@@ -1409,16 +1411,26 @@
* styles based on the StyleContext when someone calls getStyles,
* etc.
* @param resolvedStyles
+ * @param namespacePrefixArray an array of namespace prefixes that are used in the custom css
+ * skinning selectors, like "af" in af|inputText.
+ * @param afSelectoMap a map from one selector to another (like af|panelHeader::link maps to
+ * af|panelHeader A
+ * @param shortStyleClassMap a map from the non-compressed styleclass
+ * to a compressed styleclass.
*/
public StylesImpl(
StyleNode[] resolvedStyles,
String[] namespacePrefixArray,
- Map<String, String> afSelectorMap
+ Map<String, String> afSelectorMap,
+ Map<String, String> shortStyleClassMap,
+ boolean compress
)
{
// store these local variables to be used in getNativeSelectorString
_namespacePrefixArray = namespacePrefixArray;
_afSelectorMap = afSelectorMap;
+ _shortStyleClassMap = shortStyleClassMap;
+ _compress = compress;
// create a Selector->Style map right here (aggressively versus lazily)
ConcurrentMap<Selector, Style> resolvedSelectorStyleMap = null;
@@ -1502,6 +1514,13 @@
// do this when we write the css inline. We have the information now.
String mappedSelector = CSSGenerationUtils.getMappedSelector(
_afSelectorMap, _namespacePrefixArray, selector.toString());
+ // run through the compressed map if it is compressed.
+ if (_compress)
+ mappedSelector =
+ CSSGenerationUtils.getShortSelector(_shortStyleClassMap,
+ _namespacePrefixArray,
+ mappedSelector);
+
return CSSGenerationUtils.getValidFullNameSelector(
mappedSelector, _namespacePrefixArray);
}
@@ -1538,12 +1557,11 @@
}
- //private ConcurrentMap<Selector, Style> _resolvedSelectorStyleMap;
- private Map<Selector, Style> _unmodifiableResolvedSelectorStyleMap;
-
- private StyleNode[] _resolvedStyles;
- private Map<String, String> _afSelectorMap;
- private String[] _namespacePrefixArray;
+ private Map<Selector, Style> _unmodifiableResolvedSelectorStyleMap;
+ private Map<String, String> _afSelectorMap;
+ private String[] _namespacePrefixArray;
+ private Map<String, String> _shortStyleClassMap;
+ boolean _compress;
}
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=766900&r1=766899&r2=766900&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 Mon Apr 20 22:38:36 2009
@@ -195,7 +195,7 @@
// one will be needed.
// TODO: figure out why we write both the uncompressed & compressed styles for styles
// without a '|' character, shouldn't the uncompressed be enough on its own? This results
- // in some ugly code here
+ // in some ugly code here.
int stylesToBeWritten = 0;
String[] selectors = new String[matchingStyles.length];
String[] mappedSelectors = new String[matchingStyles.length];
@@ -256,38 +256,11 @@
}
- // shorten all the css-2 style class selectors (those that start with
- // '.' and don't have a namespace prefix in it)
- // and return the shortened string.
- // e.g., selector of '.OraBulletedList A' is shortened to '.xj A'
- // e.g., selector of af|inputText::content is not shortened since
- // it has no css-2 style class selector piece that starts with '.'.
- // e.g., selector of af|foo.Bar will shorten the '.Bar' piece
- // af|foo.xz
- // e.g., .Foo:hover -> .x0:hover
+
if (compressStyles)
{
- String shortSelector = _getShortSelector(mappedSelectors[j],
- shortStyleClassMap);
-
- if (shortSelector == null)
- shortSelector = mappedSelectors[j];
-
- // run it through a shortener one more time to shorten any
- // of the af component selectors.
- // e.g., 'af|menuPath' is shortened to '.x11'
-
- if (_hasNamespacePrefix(shortSelector, namespacePrefixArray))
- {
- String[] shortSelectorArray = _splitStringByWhitespace(shortSelector);
-
- shortSelector =
- _getMappedNSSelector(shortStyleClassMap,
- namespacePrefixArray,
- shortSelector,
- shortSelectorArray,
- true);
- }
+ String shortSelector =
+ getShortSelector(shortStyleClassMap, namespacePrefixArray, mappedSelectors[j]);
// if the transformed full name is different than the shortSelector
// then write out the shortSelector, too.
@@ -367,6 +340,51 @@
}
/**
+ * Shorten (compress) the selector.
+ * @param shortStyleClassMap
+ * @param namespacePrefixArray
+ * @param selector
+ * @return the shortened selector, or selector if nothing could be shortened.
+ */
+ public static String getShortSelector(
+ Map<String, String> shortStyleClassMap,
+ String[] namespacePrefixArray,
+ String selector)
+ {
+ // shorten all the css-2 style class selectors (those that start with
+ // '.' and don't have a namespace prefix in it)
+ // and return the shortened string.
+ // e.g., selector of '.OraBulletedList A' is shortened to '.xj A'
+ // e.g., selector of af|inputText::content is not shortened since
+ // it has no css-2 style class selector piece that starts with '.'.
+ // e.g., selector of af|foo.Bar will shorten the '.Bar' piece
+ // af|foo.xz
+ // e.g., .Foo:hover -> .x0:hover
+ String shortSelector = _getShortNonNamespacedSelector(selector,
+ shortStyleClassMap);
+
+ if (shortSelector == null)
+ shortSelector = selector;
+
+ // run it through a shortener one more time to shorten any
+ // of the af component selectors.
+ // e.g., 'af|menuPath' is shortened to '.x11'
+
+ if (_hasNamespacePrefix(shortSelector, namespacePrefixArray))
+ {
+ String[] shortSelectorArray = _splitStringByWhitespace(shortSelector);
+
+ shortSelector =
+ _getMappedNSSelector(shortStyleClassMap,
+ namespacePrefixArray,
+ shortSelector,
+ shortSelectorArray,
+ true);
+ }
+ return shortSelector;
+ }
+
+ /**
* Tests whether the specified selector is a single style class
* selector. A single style class selector is something like
* ".AFInstructionText". Examples that are not single style class
@@ -649,7 +667,7 @@
// there is a short version. does not shorten styles that start with the
// namespace
// returns null if it can't shorten the selector
- private static String _getShortSelector(
+ private static String _getShortNonNamespacedSelector(
String selector,
Map<String, String> shortStyleClassMap)
{