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/05/02 03:58:46 UTC
svn commit: r770843 [1/2] - in /myfaces/trinidad/branches/1.2.11.3-branch:
./ trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/
trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/
trinidad-examples/trinidad-demo/src/main/webapp/...
Author: jwaldman
Date: Fri May 1 22:26:23 2009
New Revision: 770843
URL: http://svn.apache.org/viewvc?rev=770843&view=rev
Log:
TRINIDAD-1453 need a public API to get the CSS style properties on the server in our renderers.
merging in jwaldman_StylesMap branch
Added:
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/
- copied from r770778, myfaces/trinidad/branches/jwaldman_StyleMap/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/CoreStyle.java
Removed:
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/Style.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleMap.java
Modified:
myfaces/trinidad/branches/1.2.11.3-branch/ (props changed)
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/RenderingContext.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Selector.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Style.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Styles.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/image/laf/browser/BlafImageUtils.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/image/painter/AdjustableBorderPainter.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/skin/XhtmlSkin.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/expl/Coercions.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/BaseImageIcon.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/ContextImageIcon.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/TextIcon.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/URIImageIcon.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/BaseStyle.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/CSSStyle.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleProvider.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSUtils.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/BaseLafRenderer.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/BaseLafUtils.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/Icon.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/ButtonRenderer.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/GeneratedImageRenderer.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/GlobalHeaderRenderer.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/TabBarRenderer.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/pda/GlobalHeaderRenderer.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/pda/TabBarRenderer.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/AccentedLafIconProvider.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/XhtmlLafRenderer.java
myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/XhtmlLafUtils.java
Propchange: myfaces/trinidad/branches/1.2.11.3-branch/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri May 1 22:26:23 2009
@@ -1,3 +1,4 @@
/myfaces/trinidad/branches/1.2.9.1-branch:697924,699406,699496
/myfaces/trinidad/branches/TRINIDAD-1402:745675
+/myfaces/trinidad/branches/jwaldman_StyleMap:754977-770778
/myfaces/trinidad/trunk:745151,755794,758112,758415-758416,765711,765745,766910,767634
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/RenderingContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/RenderingContext.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/RenderingContext.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/RenderingContext.java Fri May 1 22:26:23 2009
@@ -25,6 +25,7 @@
import org.apache.myfaces.trinidad.skin.Skin;
import org.apache.myfaces.trinidad.skin.Icon;
+import org.apache.myfaces.trinidad.style.Styles;
import org.apache.myfaces.trinidad.util.ThreadLocalUtils;
/**
@@ -88,6 +89,13 @@
abstract public String getStyleClass(String styleClass);
+ /**
+ * Return the Styles object that is attached to this RenderingContext.
+ * Styles is a useful object if you need to know the css properties for a given
+ * selector.
+ * @return Styles
+ */
+ abstract public Styles getStyles();
abstract public void setSkinResourceKeyMap(Map<String, String> mapping);
abstract public Map<String, String> getSkinResourceKeyMap();
abstract public boolean isRightToLeft();
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Selector.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Selector.java?rev=770843&r1=770778&r2=770843&view=diff
==============================================================================
(empty)
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Style.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Style.java?rev=770843&r1=770778&r2=770843&view=diff
==============================================================================
(empty)
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Styles.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/style/Styles.java?rev=770843&r1=770778&r2=770843&view=diff
==============================================================================
(empty)
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css Fri May 1 22:26:23 2009
@@ -26,6 +26,9 @@
in other component's style selectors or other component's icons. It is
meant to be a fast way to change styles. The alternative is to style each
component. **/
+
+af|foo af|bar {color: purple; background-color: green; border-color: pink}
+
.AFInstructionText
{
font-size: medium;
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java Fri May 1 22:26:23 2009
@@ -205,10 +205,18 @@
//
// Values for CAP_STYLE_ATTRIBUTES
//
+ // no styling is supported
static public Object STYLES_NONE =
CapabilityValue.getCapabilityValue (CAP_STYLE_ATTRIBUTES, "none");
+ // only the 'style' attribute is supported. The 'class' attribute is not
+ // supported.
+ static public Object STYLES_STYLE_ONLY =
+ CapabilityValue.getCapabilityValue (CAP_STYLE_ATTRIBUTES, "style_only");
+ // internal styles only; this includes the style attribute, or the class attribute
+ // as long as the style selectors are in the page with the <style> tag.
static public Object STYLES_INTERNAL =
CapabilityValue.getCapabilityValue (CAP_STYLE_ATTRIBUTES, "internal");
+ // external css files are supported.
static public Object STYLES_EXTERNAL =
CapabilityValue.getCapabilityValue (CAP_STYLE_ATTRIBUTES, "external");
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/image/laf/browser/BlafImageUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/image/laf/browser/BlafImageUtils.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/image/laf/browser/BlafImageUtils.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/image/laf/browser/BlafImageUtils.java Fri May 1 22:26:23 2009
@@ -40,13 +40,12 @@
import org.apache.myfaces.trinidadinternal.image.painter.ImmInsets;
import org.apache.myfaces.trinidadinternal.style.ParsedPropertyKey;
-import org.apache.myfaces.trinidadinternal.style.PropertyParseException;
-import org.apache.myfaces.trinidadinternal.style.Style;
-import org.apache.myfaces.trinidadinternal.style.StyleMap;
+import org.apache.myfaces.trinidadinternal.style.CoreStyle;
/**
* Utilities for Browser Look And Feel support.
+ * This class and everything in the image package needs to be deleted.
*
* @version $Name: $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/image/laf/browser/BlafImageUtils.java#0 $) $Date: 10-nov-2005.19:05:04 $
*/
@@ -158,7 +157,7 @@
String styleClass
)
{
- return _getColor(context, styleClass, Style.FOREGROUND_KEY, false);
+ return _getColor(context, styleClass, CoreStyle.FOREGROUND_KEY, false);
}
// Returns the foreground Color from the specified style
@@ -167,7 +166,7 @@
String styleClass
)
{
- return _getColor(context, styleClass, Style.BACKGROUND_KEY, false);
+ return _getColor(context, styleClass, CoreStyle.BACKGROUND_KEY, false);
}
// Returns the foreground Color from the specified style
@@ -176,7 +175,7 @@
String styleName
)
{
- return _getColor(context, styleName, Style.FOREGROUND_KEY, true);
+ return _getColor(context, styleName, CoreStyle.FOREGROUND_KEY, true);
}
// Returns the foreground Color from the specified style
@@ -185,7 +184,7 @@
String styleName
)
{
- return _getColor(context, styleName, Style.BACKGROUND_KEY, true);
+ return _getColor(context, styleName, CoreStyle.BACKGROUND_KEY, true);
}
// Get a mnemonic index given a String and access char.
@@ -360,40 +359,6 @@
boolean isNamed
)
{
- StyleMap map = context.getStyleContext().getStyleMap();
-
- if (map == null)
- {
-// =-=ags Don't log this condition for now. The ImageGenerator doesn't
-// set up the StyleMap yet, so let's blow this off for now
-// _LOG.fine(_MAP_ERROR);
- return null;
- }
-
- Style style = null;
-
- if (isNamed)
- style = map.getStyleByName(context.getStyleContext(), styleID);
- else
- style = map.getStyleByClass(context.getStyleContext(), styleID);
-
- if (style == null)
- {
- if (_LOG.isFine())
- _LOG.fine(_STYLE_ERROR + styleID);
-
- return null;
- }
-
- try
- {
- return (Color)style.getParsedProperty(key);
- }
- catch (PropertyParseException e)
- {
- _LOG.warning(e);
- }
-
return null;
}
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/image/painter/AdjustableBorderPainter.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/image/painter/AdjustableBorderPainter.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/image/painter/AdjustableBorderPainter.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/image/painter/AdjustableBorderPainter.java Fri May 1 22:26:23 2009
@@ -18,18 +18,13 @@
*/
package org.apache.myfaces.trinidadinternal.image.painter;
-import java.awt.Font;
import org.apache.myfaces.trinidadinternal.util.nls.LocaleUtils;
import org.apache.myfaces.trinidadinternal.style.PropertyParseException;
-import org.apache.myfaces.trinidadinternal.style.StyleContext;
-import org.apache.myfaces.trinidadinternal.style.Style;
-import org.apache.myfaces.trinidadinternal.style.StyleMap;
-import org.apache.myfaces.trinidadinternal.style.StyleProvider;
+import org.apache.myfaces.trinidadinternal.style.CoreStyle;
import org.apache.myfaces.trinidadinternal.style.util.CSSUtils;
-import org.apache.myfaces.trinidadinternal.image.ImageContext;
/**
* A border that insets painting of the wrapped painter by an amount
@@ -41,6 +36,7 @@
* for the "Dialog" font. Padding values for each inset are defined using
* the CSS style properties "padding-top", "padding-bottom", "padding-left"
* and "padding-right".
+ * This class and everything in its package needs to be deleted.
*
* @version $Name: $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/image/painter/AdjustableBorderPainter.java#0 $) $Date: 10-nov-2005.19:04:53 $
*/
@@ -96,7 +92,7 @@
int bottom = _defaultInsets.bottom;
int right = _defaultInsets.right;
- Style style = _getPaddingStyle(context);
+ CoreStyle style = _getPaddingStyle(context);
if (style != null)
{
top = _getPadding(style, _TOP_PADDING, top);
@@ -114,27 +110,8 @@
// Get the Style object which contains padding information
// for this specific paint.
- private Style _getPaddingStyle(PaintContext context)
+ private CoreStyle _getPaddingStyle(PaintContext context)
{
- // First, get the StyleProvider from the context
- ImageContext imageContext = context.getImageContext();
- StyleContext styleContext = imageContext.getStyleContext();
- StyleProvider provider = styleContext.getStyleProvider();
- if (provider != null)
- {
- // Get the StyleMap
- StyleMap map = provider.getStyleMap(styleContext);
-
- if (map != null)
- {
- // Derive the style name to use from the font name.
- Font font = context.getPaintFont();
- String name = _styleNamePrefix + font.getName();
-
- return map.getStyleByName(styleContext, name);
- }
- }
-
return null;
}
@@ -144,14 +121,14 @@
// value can not be converted to an int, the
// defaultValue is used.
private static int _getPadding(
- Style style,
+ CoreStyle style,
String propertyName,
int defaultValue
)
{
if (style != null)
{
- String value = style.getProperty(propertyName);
+ String value = style.getProperties().get(propertyName);
if (value != null)
{
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java Fri May 1 22:26:23 2009
@@ -42,6 +42,7 @@
import org.apache.myfaces.trinidad.skin.Icon;
import org.apache.myfaces.trinidad.skin.Skin;
import org.apache.myfaces.trinidad.skin.SkinFactory;
+import org.apache.myfaces.trinidad.style.Styles;
import org.apache.myfaces.trinidadinternal.agent.AgentUtil;
import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
import org.apache.myfaces.trinidadinternal.agent.TrinidadAgentImpl;
@@ -256,6 +257,20 @@
}
return _skin;
}
+
+ /**
+ * Return the Styles object that is attached to this RenderingContext. You can use the Styles
+ * object to retrieve a map of the skin selectors and their css properties, already resolved
+ * for this specific request. A skin has selectors for all agents, locales, etc., and there
+ * might be blocks for ie-only or gecko-only or rtl, etc., and the resolved styles are styles
+ * for the specific request (agent, locale, aliases are merged, etc).
+ * @return
+ */
+ @Override
+ public Styles getStyles()
+ {
+ return getStyleContext().getStyles();
+ }
/**
* Get an interface that can be used for style lookups and generation.
@@ -808,6 +823,11 @@
TrinidadAgent.SCRIPTING_SPEED_CAP_NONE);
_EMAIL_CAPABILITIES.put(TrinidadAgent.CAP_EDITING,
Boolean.FALSE);
+ // email clients cannot handle external css files, but they can
+ // handle the 'class' attribute, as long as the css definitions are
+ // in the html documents
+ _EMAIL_CAPABILITIES.put(TrinidadAgent.CAP_STYLE_ATTRIBUTES,
+ TrinidadAgent.STYLES_INTERNAL);
_EMAIL_CAPABILITIES.put(TrinidadAgent.CAP_PARTIAL_RENDERING,
Boolean.FALSE);
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/StyleContextImpl.java Fri May 1 22:26:23 2009
@@ -30,13 +30,13 @@
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.Styles;
import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.HtmlRenderer;
import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.StyleSheetRenderer;
import org.apache.myfaces.trinidadinternal.share.config.Configuration;
import org.apache.myfaces.trinidadinternal.skin.SkinStyleProvider;
import org.apache.myfaces.trinidadinternal.style.StyleContext;
-import org.apache.myfaces.trinidadinternal.style.StyleMap;
import org.apache.myfaces.trinidadinternal.style.StyleProvider;
@@ -54,7 +54,7 @@
assert(_arc.getAccessibilityProfile() != null);
}
-
+ @Override
public StyleProvider getStyleProvider()
{
if (_styleProvider == null)
@@ -67,6 +67,7 @@
/* added this in case we switch the skin after the styleProvider was cached above. */
/* we want to recompute, not get it from the cache. */
+ @Override
public StyleProvider getStyleProvider(boolean recompute)
{
if (recompute)
@@ -79,24 +80,28 @@
return getStyleProvider();
}
-
- public StyleMap getStyleMap()
+
+ /**
+ *
+ */
+ @Override
+ public Styles getStyles()
{
- if (_styleMap == null)
- _styleMap = getStyleProvider().getStyleMap(this);
- return _styleMap;
+ if (_styles == null)
+ _styles = getStyleProvider().getStyles(this);
+ return _styles;
}
-
/**
* Returns the end user's locale.
*/
+ @Override
public LocaleContext getLocaleContext()
{
return _arc.getLocaleContext();
}
-
+ @Override
public String getGeneratedFilesPath()
{
return _generatedFilesPath;
@@ -105,11 +110,12 @@
/**
* Returns the end user's Agent.
*/
+ @Override
public TrinidadAgent getAgent()
{
return ((CoreRenderingContext) _arc).getTrinidadAgent();
}
-
+ @Override
public boolean checkStylesModified()
{
FacesContext context = FacesContext.getCurrentInstance();
@@ -117,13 +123,15 @@
context.getExternalContext().getInitParameter(Configuration.CHECK_TIMESTAMP_PARAM);
return "true".equals(checkTimestamp);
}
-
+
+ @Override
public boolean disableStandardsMode()
{
FacesContext fContext = FacesContext.getCurrentInstance();
return HtmlRenderer.isStandardsModeDisabled(fContext);
}
-
+
+ @Override
public AccessibilityProfile getAccessibilityProfile()
{
return _arc.getAccessibilityProfile();
@@ -238,11 +246,11 @@
return null;
}
- public StyleMap getStyleMap(StyleContext context)
+ public Styles getStyles(StyleContext context)
{
return null;
}
-
+
public ConcurrentMap<String, Icon> getIcons(StyleContext context)
{
return null;
@@ -260,7 +268,7 @@
private RenderingContext _arc;
private String _generatedFilesPath;
private StyleProvider _styleProvider;
- private StyleMap _styleMap;
+ private Styles _styles;
private Boolean _isDisableStyleCompression;
private static final TrinidadLogger _LOG =
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/skin/XhtmlSkin.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/skin/XhtmlSkin.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/skin/XhtmlSkin.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/skin/XhtmlSkin.java Fri May 1 22:26:23 2009
@@ -18,6 +18,9 @@
*/
package org.apache.myfaces.trinidadinternal.renderkit.core.skin;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SkinProperties;
import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SkinSelectors;
import org.apache.myfaces.trinidadinternal.skin.icon.ContextImageIcon;
@@ -102,17 +105,26 @@
null,
SkinSelectors.QUICK_SELECT_DISABLED_ICON_STYLE_CLASS,
null);
-
- private static final CSSStyle spinboxTopStyle = new CSSStyle();
- private static final CSSStyle spinboxBottomStyle = new CSSStyle();
-
+
+ private static final Map<String, String> _spinboxTopStyleMap;
+ private static final Map<String, String> _spinboxBottomStyleMap;
+
static
{
+ // does this matter if it's not an ArrayMap?
+ _spinboxTopStyleMap = new HashMap<String, String>();
+ _spinboxTopStyleMap.put("display", "block");
// this is needed for the image
- spinboxTopStyle.setProperty("display", "block");
- spinboxBottomStyle.setProperty("display", "block");
- spinboxBottomStyle.setProperty("padding-top", "2px");
+ _spinboxBottomStyleMap = new HashMap<String, String>();
+ _spinboxBottomStyleMap.put("display", "block");
+ _spinboxBottomStyleMap.put("padding-top", "2px");
+
}
+
+ private static final CSSStyle spinboxTopStyle = new CSSStyle(_spinboxTopStyleMap);
+ private static final CSSStyle spinboxBottomStyle = new CSSStyle(_spinboxBottomStyleMap);
+
+
// Icons array
private static final Object[] _CUSTOMIZABLE_ICONS = new Object[]
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/StyleSheetRenderer.java Fri May 1 22:26:23 2009
@@ -23,6 +23,8 @@
import java.util.List;
import java.util.Map;
+import java.util.Set;
+
import javax.faces.component.UIComponent;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
@@ -31,6 +33,10 @@
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.agent.TrinidadAgent;
import org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderingContext;
import org.apache.myfaces.trinidadinternal.style.StyleContext;
import org.apache.myfaces.trinidadinternal.style.StyleProvider;
@@ -85,13 +91,15 @@
StyleContext sContext = ((CoreRenderingContext) arc).getStyleContext();
StyleProvider provider = sContext.getStyleProvider();
+
if (provider != null)
{
List<String> uris = provider.getStyleSheetURIs(sContext);
- // Check if we want to write out the css into the page or not. In portlet mode the
+ // Check if we want to write out the css into the page or not. In portlet mode the
// producer tries to share the consumer's stylesheet if it matches exactly.
boolean suppressStylesheet = _isSuppressStylesheet(context, arc);
+
if (!suppressStylesheet)
{
if (uris != null && !uris.isEmpty())
@@ -161,17 +169,23 @@
}
}
-
// In the portlet environment, the consumer might like the producers to share its stylesheet
- // for performance reasons. To indicate this the producer sends a
+ // for performance reasons. To indicate this the producer sends a
// suppress stylesheet parameter on the request map.
+ // Also, if the Agent Capability cannot handle external css files, this will
+ // return true.
// returns true if the stylesheet should be suppressed and not written out in the page.
private boolean _isSuppressStylesheet(FacesContext context, RenderingContext arc)
{
+ // first see if the agent's capability does not support external css files.
+ if (!_supportsExternalStylesheet(arc))
+ return true;
+ // next check if in portlet mode, and if the suppress stylesheet parameter
+ // is set, and it's valid to suppress the stylesheet.
String outputMode = arc.getOutputMode();
if (XhtmlConstants.OUTPUT_MODE_PORTLET.equals(outputMode))
- {
+ {
Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
boolean suppressStylesheet = "true".equals(requestMap.get(_SUPPRESS_STYLESHEET_ID_PARAM));
if (suppressStylesheet)
@@ -185,6 +199,18 @@
return false;
}
+ // Get the Capability from the agent and return true if the
+ // TrinidadAgent.CAP_STYLE_ATTRIBUTES == STYLES_EXTERNAL.
+ // Defaults to true in case no capability is set.
+ static private boolean _supportsExternalStylesheet(RenderingContext arc)
+ {
+ Object styleCapability = arc.getAgent().getCapabilities().get(
+ TrinidadAgent.CAP_STYLE_ATTRIBUTES);
+
+ return (styleCapability == null ||
+ TrinidadAgent.STYLES_EXTERNAL == styleCapability);
+ }
+
static private final String _SUPPRESS_STYLESHEET_ID_PARAM =
"org.apache.myfaces.trinidad.skin.suppressStylesheet";
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/expl/Coercions.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/expl/Coercions.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/expl/Coercions.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/expl/Coercions.java Fri May 1 22:26:23 2009
@@ -33,7 +33,7 @@
import org.apache.myfaces.trinidadinternal.share.text.RGBColorFormat;
import org.apache.myfaces.trinidadinternal.share.xml.NamespaceURI;
import org.apache.myfaces.trinidadinternal.share.xml.XMLUtils;
-import org.apache.myfaces.trinidadinternal.style.Style;
+import org.apache.myfaces.trinidadinternal.style.CoreStyle;
import org.apache.myfaces.trinidadinternal.style.util.CSSUtils;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
@@ -166,7 +166,7 @@
{
return NamespaceURI.create(context, text, "");
}
- else if (type == Style.class)
+ else if (type == CoreStyle.class)
{
return CSSUtils.parseStyle(text);
}
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java Fri May 1 22:26:23 2009
@@ -724,7 +724,7 @@
if (includeStyle.endsWith(":alias"))
{
// strip off :alias first and the . at the beginning
-
+
int endIndex = includeStyle.indexOf(":alias");
int startIndex = 0;
if (includeStyle.charAt(0) == '.')
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/BaseImageIcon.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/BaseImageIcon.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/BaseImageIcon.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/BaseImageIcon.java Fri May 1 22:26:23 2009
@@ -28,9 +28,9 @@
import org.apache.myfaces.trinidad.skin.Icon;
import org.apache.myfaces.trinidad.context.RenderingContext;
+import org.apache.myfaces.trinidad.style.Style;
import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.OutputUtils;
-import org.apache.myfaces.trinidadinternal.style.Style;
import org.apache.myfaces.trinidadinternal.style.util.StyleUtils;
/**
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/ContextImageIcon.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/ContextImageIcon.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/ContextImageIcon.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/ContextImageIcon.java Fri May 1 22:26:23 2009
@@ -24,8 +24,7 @@
import javax.faces.context.FacesContext;
import org.apache.myfaces.trinidad.context.RenderingContext;
-
-import org.apache.myfaces.trinidadinternal.style.Style;
+import org.apache.myfaces.trinidad.style.Style;
/**
* An Icon implementation for icons which are under the
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/TextIcon.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/TextIcon.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/TextIcon.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/TextIcon.java Fri May 1 22:26:23 2009
@@ -24,11 +24,11 @@
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import org.apache.myfaces.trinidad.context.RenderingContext;
import org.apache.myfaces.trinidad.skin.Icon;
+import org.apache.myfaces.trinidad.style.Style;
-import org.apache.myfaces.trinidad.context.RenderingContext;
-import org.apache.myfaces.trinidadinternal.style.Style;
import org.apache.myfaces.trinidadinternal.style.util.StyleUtils;
/**
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/URIImageIcon.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/URIImageIcon.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/URIImageIcon.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/icon/URIImageIcon.java Fri May 1 22:26:23 2009
@@ -21,7 +21,7 @@
import javax.faces.context.FacesContext;
import org.apache.myfaces.trinidad.context.RenderingContext;
-import org.apache.myfaces.trinidadinternal.style.Style;
+import org.apache.myfaces.trinidad.style.Style;
/**
* ImageIcon implementation which takes a full URI.
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/BaseStyle.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/BaseStyle.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/BaseStyle.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/BaseStyle.java Fri May 1 22:26:23 2009
@@ -19,113 +19,56 @@
package org.apache.myfaces.trinidadinternal.style;
import java.io.Serializable;
-import java.util.Map;
-import java.util.Iterator;
+import java.util.Collections;
+import java.util.Map;
-import org.apache.myfaces.trinidad.util.ArrayMap;
+import java.util.concurrent.ConcurrentHashMap;
/**
* Base class for Style implementations
+ * TODO Remove the ParsedProperty code from Trinidad. It is only used for
+ * the un-used image generation code.
+ * 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 Style, Serializable
+abstract public class BaseStyle extends CoreStyle implements Serializable
{
/**
- * Creates an empty BaseStyle.
+ * Creates an empty BaseStyle. For better performance,
+ * use the Base(Map<String, String>) constructor.
*/
public BaseStyle()
{
+ _propertiesMap = Collections.emptyMap();
}
/**
* Creates a BaseStyle with the specified properties
*
- * @param properties The properties of this style. The
- * values must be Strings.
+ * @param propertiesMap The properties of this style. The
+ * name and values must be Strings.
*/
- public BaseStyle(Map<String, String> properties)
+ public BaseStyle(Map<String, String> propertiesMap)
{
- if ((properties != null) && (properties.size() > 0))
+ if ((propertiesMap != null) && (!propertiesMap.isEmpty()))
{
- // Initialize the properties array
- int length = properties.size() * 2;
- _properties = new String[length];
-
- int i = 0;
- for(Map.Entry<String, String> entry : properties.entrySet())
- {
- String key = entry.getKey();
- String value = entry.getValue();
-
- // -= Simon Lessard =-
- // FIXME: If key is ever null, NullPointerException will occurs
- _properties[i*2] = key.toLowerCase();
- _properties[i*2+1] = value;
- i++;
- }
- }
- }
-
- /**
- * Creates a BaseStyle from an arbitrary Style object.
- */
- public BaseStyle(Style style)
- {
- if ( style != null)
- {
-
- // First, loop through to get the property count
- int propertyCount = 0;
- Iterator<Object> e = style.getPropertyNames();
- while (e.hasNext())
- {
- e.next();
- propertyCount++;
- }
-
- if (propertyCount == 0)
- return;
-
- // Initialize the properties array
- Object properties[] = new Object[propertyCount * 2];
-
- // Now, loop through to initialize the properties
- int i = 0;
- Iterator<Object> names = style.getPropertyNames();
- while (names.hasNext())
- {
- String name = (String)names.next();
- String value = style.getProperty(name);
-
- properties[i*2] = name.toLowerCase();
- properties[i*2+1] = value;
-
- i++;
- }
-
- _properties = properties;
+ // Initialize the propertiesMap with a ConcurrentHashMap.
+ // This uses more memory than ArrayMap, but is faster and safer.
+ _propertiesMap = new ConcurrentHashMap<String, String>(propertiesMap.size());
+
+ _propertiesMap.putAll(propertiesMap);
}
+ else
+ _propertiesMap = Collections.emptyMap();
}
/**
- * Returns the names of the properties defined by this style.
- * <p>
- * The property names can be any valid property name.
- */
- public Iterator<Object> getPropertyNames()
- {
- return ArrayMap.getKeys(_properties);
- }
-
- /**
- * Returns the value of the property with the specified name.
- *
- * @param name The property name for the property to return
+ * Returns an UnmodifiableMap
*/
- public String getProperty(String name)
+ public Map<String, String> getProperties()
{
- return (String)ArrayMap.get(_properties, name.toLowerCase());
+ return Collections.unmodifiableMap(_propertiesMap);
}
@@ -190,16 +133,13 @@
*/
public void setProperty(String name, String value)
{
- // We store all names/values as lowercase string
- name = name.toLowerCase();
synchronized (this)
{
- _properties = ArrayMap.remove(_properties, name);
-
- if (value != null)
- _properties = ArrayMap.put(_properties, name, value);
-
+ if (_propertiesMap.isEmpty())
+ _propertiesMap = new ConcurrentHashMap<String, String>();
+ _propertiesMap.put(name, value);
+
// We need to reset to parsed properties if our properties change
// Really, we could just null out the corresponding parsed property
// value, but what the heck.
@@ -221,7 +161,7 @@
abstract protected Object parseProperty(Object key)
throws PropertyParseException;
- private Object[] _properties;
+ volatile private Map<String, String> _propertiesMap;
transient private Object[] _parsedProperties;
// Count of parsed properties defined by Style
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/CSSStyle.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/CSSStyle.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/CSSStyle.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/CSSStyle.java Fri May 1 22:26:23 2009
@@ -23,6 +23,8 @@
import java.util.Collections;
import java.util.Iterator;
+import org.apache.myfaces.trinidad.style.Style;
+
import org.apache.myfaces.trinidadinternal.style.util.CSSUtils;
@@ -56,10 +58,13 @@
* All of the properties from the specified Style object are
* copied into this CSSStyle.
*/
+ /********
public CSSStyle(Style style)
{
super(style);
}
+***/
+
/**
* Converts the style to a String suitable for use as an inline style
@@ -72,27 +77,23 @@
if (inline != null)
return inline;
-
- Iterator<Object> e = getPropertyNames();
+
+ Map<String, String> properties = getProperties();
StringBuffer buffer = new StringBuffer(_DEFAULT_BUFFER_SIZE);
- boolean first = true;
-
- if ( e != null )
+ boolean first = true;
+
+ for (Map.Entry<String, String> entrySet : properties.entrySet())
{
- while (e.hasNext())
- {
- if (first)
- first = false;
- else
- buffer.append(";");
-
- String name = (String)e.next();
- String value = getProperty(name);
-
- buffer.append(name);
- buffer.append(":");
- buffer.append(value);
- }
+
+ if (first)
+ first = false;
+ else
+ buffer.append(";");
+ String name = entrySet.getKey();
+ String value = entrySet.getValue();
+ buffer.append(name);
+ buffer.append(":");
+ buffer.append(value);
}
inline = buffer.toString();
@@ -106,7 +107,9 @@
}
/**
- * Sets the specified property value.
+ * Sets the specified property value. If the properties are all known up front,
+ * it is better for performance to use the CSSStyle(Map<String, String> properties) constructor
+ * than to create an empty CSSStyle and call setProperty for each property.
*/
@Override
public void setProperty(String name, String value)
@@ -128,38 +131,41 @@
throws PropertyParseException
{
Object value = null;
+
+ Map<String, String> properties = getProperties();
+
- if (key == Style.BACKGROUND_KEY)
+ if (key == CoreStyle.BACKGROUND_KEY)
{
- value = CSSUtils.parseColor(getProperty(_BACKGROUND_NAME));
+ value = CSSUtils.parseColor(properties.get(_BACKGROUND_NAME));
}
- else if (key == Style.FOREGROUND_KEY)
+ else if (key == CoreStyle.FOREGROUND_KEY)
{
- value = CSSUtils.parseColor(getProperty(_FOREGROUND_NAME));
+ value = CSSUtils.parseColor(properties.get(_FOREGROUND_NAME));
}
- else if (key == Style.FONT_SIZE_KEY)
+ else if (key == CoreStyle.FONT_SIZE_KEY)
{
- value = CSSUtils.parseFontSize(getProperty(_FONT_SIZE_NAME));
+ value = CSSUtils.parseFontSize(properties.get(_FONT_SIZE_NAME));
}
- else if (key == Style.FONT_STYLE_KEY)
+ else if (key == CoreStyle.FONT_STYLE_KEY)
{
- value = CSSUtils.parseFontStyle(getProperty(_FONT_STYLE_NAME));
+ value = CSSUtils.parseFontStyle(properties.get(_FONT_STYLE_NAME));
}
- else if (key == Style.FONT_WEIGHT_KEY)
+ else if (key == CoreStyle.FONT_WEIGHT_KEY)
{
- value = CSSUtils.parseFontWeight(getProperty(_FONT_WEIGHT_NAME));
+ value = CSSUtils.parseFontWeight(properties.get(_FONT_WEIGHT_NAME));
}
- else if (key == Style.FONT_FAMILIES_KEY)
+ else if (key == CoreStyle.FONT_FAMILIES_KEY)
{
- String[] families = CSSUtils.parseFontFamilies(getProperty(
+ String[] families = CSSUtils.parseFontFamilies(properties.get(
_FONT_FAMILY_NAME));
if (families != null)
value = Collections.unmodifiableList(Arrays.asList(families));
}
- else if (key == Style.TEXT_ANTIALIAS_KEY)
+ else if (key == CoreStyle.TEXT_ANTIALIAS_KEY)
{
- String antialiased = getProperty(_TEXT_ANTIALIAS_NAME);
+ String antialiased = properties.get(_TEXT_ANTIALIAS_NAME);
if ((antialiased != null) && "true".equalsIgnoreCase(antialiased))
{
value = Boolean.TRUE;
Added: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/CoreStyle.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/CoreStyle.java?rev=770843&view=auto
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/CoreStyle.java (added)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/CoreStyle.java Fri May 1 22:26:23 2009
@@ -0,0 +1,136 @@
+/*
+ * 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;
+
+import org.apache.myfaces.trinidad.style.Style;
+
+/**
+ * A CoreStyle object defines a set of visual (or aural) style properties.
+ * The CoreStyle interface exposes one method for retrieving properties:
+ * getParsedProperty().
+ * getParsedProperty() takes a key object (eg. FONT_WEIGHT_KEY) and
+ * returns the parsed, typed, Java object which represents the
+ * property value. The type of the returned object is key-specific,
+ * eg. for FONT_WEIGHT_KEY, an java.lang.Integer is returned.
+ * For BACKGROUND_KEY, a java.awt.Color is returned.
+ * @deprecated Use the Style interface instead. The parsedProperties should
+ * not be used in new code. It's only used now in the image generation code
+ * 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 abstract class CoreStyle extends Style
+{
+ /**
+ * Key for obtaining the Color object which corresponds to the
+ * style's "background-color" property.
+ */
+ public static final ParsedPropertyKey BACKGROUND_KEY =
+ new ParsedPropertyKey("background", 0);
+
+ /**
+ * Key for obtaining the Color object which corresponds to the
+ * style's "color" property.
+ */
+ public static final ParsedPropertyKey FOREGROUND_KEY =
+ new ParsedPropertyKey("foreground", 1);
+
+ /**
+ * Key for obtaining the list of font family names for this style.
+ * The list is implemented as an oracle.bali.share.collection.ImmutableArray
+ * of String objects, sorted from most preferable to least preferable.
+ */
+ public static final ParsedPropertyKey FONT_FAMILIES_KEY =
+ new ParsedPropertyKey("families", 2);
+
+ /**
+ * This key is passed to Style.parseProperty() to obtain the font
+ * size for a Style. The font size value returned from
+ * parseProperty() is an Integer object which indicates the font size
+ * in point units.
+ */
+ public static final ParsedPropertyKey FONT_SIZE_KEY =
+ new ParsedPropertyKey("size", 3);
+
+ /**
+ * This key is passed to Style.parseProperty() to obtain the font
+ * style for a Style. The font style value returned from
+ * parseProperty() is one of the FONT_STYLE constants defined by
+ * the Style interface.
+ */
+ public static final ParsedPropertyKey FONT_STYLE_KEY =
+ new ParsedPropertyKey("style", 4);
+
+ /**
+ * This key is passed to Style.parseProperty() to obtain the font
+ * weight for a Style. The font weight value returned from
+ * parseProperty() is one of the FONT_WEIGHT constants defined by
+ * the Style interface.
+ */
+ public static final ParsedPropertyKey FONT_WEIGHT_KEY =
+ new ParsedPropertyKey("weight", 5);
+
+ /**
+ * This key is passed to Style.parseProperty() to obtain the text antialias
+ * style for a Style object. The text antialias value returned from
+ * parseProperty() is a Boolean object. A returned value of Boolean.TRUE
+ * indicates that text rendered using the Style should be antialiased.
+ */
+ public static final ParsedPropertyKey TEXT_ANTIALIAS_KEY =
+ new ParsedPropertyKey("antialias", 6);
+
+ /**
+ * Constant for plain font style.
+ */
+ public static final Object PLAIN_FONT_STYLE = 0;
+
+ /**
+ * Constant for italic font style.
+ */
+ public static final Object ITALIC_FONT_STYLE = 1;
+
+ /**
+ * Constant for plain font weight.
+ */
+ public static final Object PLAIN_FONT_WEIGHT = 0;
+
+ /**
+ * Constant for bold font weight.
+ */
+ public static final Object BOLD_FONT_WEIGHT = 1;
+
+ /**
+ * Returns a parsed Java object corresponding to the specified
+ * property key.
+ * <p>
+ * The type of object returned is dependent on the type of
+ * property requested. For example, when the FONT_SIZE_KEY is
+ * requested, an java.lang.Integer object is
+ * returned. When BACKGROUND_KEY or FOREGROUND_KEY is requested
+ * a java.awt.Color is returned. Null is returned if no value
+ * is defined for the specified property.
+ *
+ * @param One of the KEY constants (eg. FONT_SIZE_KEY, BACKGROUND_KEY,
+ * etc...) defined by the Style interface.
+ * @param throws PropertyParseException Thrown if the property value
+ * can not be parsed.
+ */
+ abstract public Object getParsedProperty(ParsedPropertyKey key)
+ throws PropertyParseException;
+
+}
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleContext.java Fri May 1 22:26:23 2009
@@ -21,6 +21,7 @@
import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
import org.apache.myfaces.trinidad.context.AccessibilityProfile;
import org.apache.myfaces.trinidad.context.LocaleContext;
+import org.apache.myfaces.trinidad.style.Styles;
/**
* The StyleContext interface is used to provide information
@@ -48,7 +49,7 @@
public StyleProvider getStyleProvider();
public StyleProvider getStyleProvider(boolean recompute);
- public StyleMap getStyleMap();
+ public Styles getStyles();
public AccessibilityProfile getAccessibilityProfile();
public boolean isPortletMode();
public boolean isDisableStyleCompression();
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleProvider.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleProvider.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleProvider.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/StyleProvider.java Fri May 1 22:26:23 2009
@@ -23,13 +23,14 @@
import java.util.concurrent.ConcurrentMap;
import org.apache.myfaces.trinidad.skin.Icon;
+import org.apache.myfaces.trinidad.style.Styles;
/**
* The StyleProvider API is used to access context-dependent style
* information. Style information is exposed in two ways - as
* CSS style sheet URIs (via getStyleSheetURI()), or as Style objects
- * (via getStyleMap()). Both methods take a StyleContext object,
+ * (via getStyles()). Both methods take a StyleContext object,
* which describes the target end user environment.
*
* In addition to providing access to style-related information, the
@@ -37,8 +38,8 @@
* style sheets via the getIcons() API.
*
* @see StyleContext
- * @see StyleMap
- * @see Style
+ * @see Styles
+ * @see org.apache.myfaces.trinidad.Style
*
* @version $Name: $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/style/StyleProvider.java#0 $) $Date: 10-nov-2005.18:57:58 $
*/
@@ -70,15 +71,14 @@
public List<String> getStyleSheetURIs(StyleContext context);
/**
- * Returns a StyleMap object, which can be used to
- * retreive Style objects for the specified context.
- *
- * @param context The context which describes the target end user
- * environment
- * @return A StyleMap object which exposes the Styles for the
- * specified context.
- */
- public StyleMap getStyleMap(StyleContext context);
+ * Return the Styles object that is attached to this StyleProvider. You can use the Styles
+ * object to retrieve a map of the skin selectors and their css properties, already resolved
+ * for this specific request. A skin has selectors for all agents, locales, etc., and there
+ * might be blocks for ie-only or gecko-only or rtl, etc., and the resolved styles are styles
+ * for the specific request (agent, locale, aliases are merged, etc).
+ * @return
+ */
+ public Styles getStyles(StyleContext context);
/**
* Returns a map of icon names to Icon instances.
Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java?rev=770843&r1=770842&r2=770843&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java Fri May 1 22:26:23 2009
@@ -49,6 +49,9 @@
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;
import org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderingContext;
import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SkinSelectors;
@@ -59,9 +62,7 @@
import org.apache.myfaces.trinidadinternal.share.xml.JaxpXMLProvider;
import org.apache.myfaces.trinidadinternal.share.xml.XMLProvider;
import org.apache.myfaces.trinidadinternal.style.CSSStyle;
-import org.apache.myfaces.trinidadinternal.style.Style;
import org.apache.myfaces.trinidadinternal.style.StyleContext;
-import org.apache.myfaces.trinidadinternal.style.StyleMap;
import org.apache.myfaces.trinidadinternal.style.StyleProvider;
import org.apache.myfaces.trinidadinternal.style.util.CSSGenerationUtils;
import org.apache.myfaces.trinidadinternal.style.util.NameUtils;
@@ -83,7 +84,7 @@
* caches generated CSS style sheets on the file system.
*
* Note that StyleProviders are responsible for providing access
- * both to style information (eg. getStyleSheetURI(), getStyleMap()) as
+ * both to style information (eg. getStyleSheetURI(), getStyles()) as
* well as to icons registered via style sheets (see getIcons()).
*
* @see org.apache.myfaces.trinidadinternal.style.StyleProvider
@@ -95,6 +96,10 @@
// TODO: Synchronization does not seem to be needed since there's
// synchronized blocks in the code, using HashMap hence
// looks like a better choice than Hashtable.
+// -= Blake Sullivan =-
+// rebuttal - _createEntry() which assigns values to _cache and _entryCache is called
+// without a lock and these Maps are read without a lock.
+// _cache and _entryCache should probably be ConcurrentHashMaps.
public class FileSystemStyleCache implements StyleProvider
{
/**
@@ -143,7 +148,7 @@
// If the target directory does not exist, create it now.
// Note: If we can't create the target directory, we just
// plug along anyway instead of throwing an IllegalArgumentException.
- // That way, we can still use the StyleMap for this style sheet
+ // That way, we can still use the Styles for this style sheet
// even if the style sheet isn't generated.
File targetDirectory = new File(target);
if (!targetDirectory.exists())
@@ -161,16 +166,17 @@
if (entry == null)
{
- return null;
+ return Collections.emptyList();
}
return entry.uris;
}
/**
- * Implementation of StyleProvider.getStyleMap().
+ * Implementation of StyleProvider.getStyles().
*/
- public StyleMap getStyleMap(StyleContext context)
+ @Override
+ public Styles getStyles(StyleContext context)
{
Entry entry = _getEntry(context);
@@ -178,7 +184,7 @@
if (entry == null)
return null;
- return entry.map;
+ return entry.styles;
}
/**
@@ -521,15 +527,22 @@
// Next, get the fully resolved styles for this context. This will be
// those StyleNodes that match the locale, direction, browser, portlet mode
// etc -- the info that is in the StyleContext.
- StyleNode[] styles = _getStyleContextResolvedStyles(context, document);
- if (styles == null)
+ // These styles contain all the StyleNodes, that is, where selector or
+ // name (aka alias) are non-null.
+ StyleNode[] styleNodes = _getStyleContextResolvedStyles(context, document);
+ if (styleNodes == null)
return null;
+
// Generate the style sheet file, if it isn't already generated,
// and return the uri.
+ // Only the StyleNodes with non-null selectors get written to the
+ // generated css file.
+ // Named styles (StyleNode where name != null) do not get
+ // written to the generated css file.
List<String> uris = _createStyleSheetFiles(context,
document,
- styles,
+ styleNodes,
shortStyleClassMap,
namespacePrefixes,
checkModified);
@@ -548,7 +561,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 StyleMapImpl(), 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
@@ -966,31 +981,28 @@
}
/**
- * Initiializes the NameResolver
+ * Initiializes the NameResolver. Does not need to be synchronized only because it is
+ * synchronized in the calling code.
*/
private void _initResolver()
{
- // Synchronize just in case two different threads hit this
- // at the same time
- synchronized (this)
+
+ if (_resolver == null)
{
- if (_resolver == null)
- {
- NameResolver resolver = new DefaultNameResolver(_sourceFile, null);
+ NameResolver resolver = new DefaultNameResolver(_sourceFile, null);
- // We explicitly wrap the NameResolver in a CachingNameResolver
- // since that conveniently handles checking for modifications to
- // dependent (imported) files.
- // The default storage for cached files is a bit large,
- // so we use a smaller hash table. Also, always enable
- // modification checking.
- // FIXME: Should probably be a ConcurrentHashMap
- resolver = new CachingNameResolver(resolver,
- new Hashtable<Object, InputStreamProvider>(17),
- true);
+ // We explicitly wrap the NameResolver in a CachingNameResolver
+ // since that conveniently handles checking for modifications to
+ // dependent (imported) files.
+ // The default storage for cached files is a bit large,
+ // so we use a smaller hash table. Also, always enable
+ // modification checking.
+ // FIXME: Should probably be a ConcurrentHashMap
+ resolver = new CachingNameResolver(resolver,
+ new Hashtable<Object, InputStreamProvider>(17),
+ true);
- _resolver = resolver;
- }
+ _resolver = resolver;
}
}
@@ -1199,7 +1211,7 @@
agent.getAgentApplication(),
agent.getAgentVersion(),
agent.getAgentOS(),
- true,
+ !context.isDisableStyleCompression(),
accProfile,
context.isPortletMode());
}
@@ -1296,18 +1308,18 @@
private static class Entry
{
public final List<String> uris;
- public final StyleMap map;
+ public final Styles styles;
public final ConcurrentMap<String, Icon> icons;
public final ConcurrentMap<Object, Object> skinProperties;
public Entry(
List<String> uris,
- StyleMap map,
+ Styles styles,
ConcurrentMap<String, Icon> icons,
ConcurrentMap<Object, Object> skinProperties)
{
this.uris = uris;
- this.map = map;
+ this.styles = styles;
this.icons = icons;
this.skinProperties = skinProperties;
}
@@ -1382,122 +1394,179 @@
private boolean _short; // Do we use short style classes?
}
- /**
- * A StyleMap implemenation which creates Style objects as needed
- */
- private class StyleMapImpl implements StyleMap
- {
- // Implementation of StyleMap.getStyleBySelector()
- public Style getStyleBySelector(
- StyleContext context,
- String selector
- )
- {
- if (_selectorMap == null)
- _selectorMap = _createMap();
-
- return _getStyle(context, _selectorMap, selector, "", false);
- }
-
- // Implementation of StyleMap.getStyleByClass()
- public Style getStyleByClass(
- StyleContext context,
- String styleClass
- )
- {
- if (_classMap == null)
- _classMap = _createMap();
- String prefix = (styleClass.indexOf('|') > -1) ? "" : ".";
- return _getStyle(context, _classMap, styleClass, prefix , false);
- }
-
- // Implementation of StyleMap.getStyleByClass()
- public Style getStyleByName(
- StyleContext context,
- String name
- )
- {
- if (_nameMap == null)
- _nameMap = _createMap();
-
- return _getStyle(context, _nameMap, name, "", true);
- }
- // Do all of the real work
- private Style _getStyle(
- StyleContext context,
- Map<String, Style> map,
- String id,
- String prefix,
- boolean isName
- )
- {
- CSSStyle style = (CSSStyle)map.get(id);
- if (style == _MISS)
- return null;
- if (style != null)
- return style;
- // Next, try getting the Style from the StyleSheetDocument
- StyleSheetDocument document = __getStyleSheetDocument();
- if (document == null)
- return null;
+ /**
+ * A Styles implementation that adds the resolved (merged together based on the StyleContext)
+ * StyleNodes to a Map. Only the style selectors and not the aliased (aka named) styles
+ * are added to this map.
+ */
+ private static final class StylesImpl extends Styles
+ {
+ /**
+ * This constructor takes an array of StyleNode Objects where each StyleNode has
+ * already been resolved based on the StyleContext. Therefore there is no
+ * more merging that needs to be done, and the 'included' properties on
+ * StyleNode are all null. This way we do not have to resolve the
+ * 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> 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;
- StyleNode styleNode = null;
- if (isName)
+ // Loop through each StyleNode and use it to add to the StyleMap.
+ for (int i=0; i < resolvedStyles.length; i++)
{
- styleNode = document.getStyleByName(context, id);
+ String selector = resolvedStyles[i].getSelector();
+ if (selector != null)
+ {
+ Style style = _convertStyleNodeToStyle(resolvedStyles[i]);
+ if (resolvedSelectorStyleMap == null)
+ resolvedSelectorStyleMap = new ConcurrentHashMap<Selector, Style>();
+ resolvedSelectorStyleMap.put(Selector.createSelector(selector), style);
+ }
+ /*
+ else
+ {
+ // For now, do not add the named styles to the map. If we do add the named styles
+ // to the map then we should in SkinStyleSheetParserUtils put the full name in
+ // the StyleNode, not strip out the '.' or the ':alias'. However, in the XSS
+ // the named styles do not have the '.' or the ':alias' which is why we string them out.
+ // if we put them back, then things won't merge correctly. How do I workaround this?
+ // Do I change all the named styles in the XSS file?
+ // I think the best thing to do is to change the XSS file, since that is proprietary,
+ // and no one should be relying on it. If we instead kept stripping out the . and the alias
+ // and required the person to ask for the alias without this,
+ // that is much more confusing to the user.
+ String name = _resolvedStyles[i].getName();
+ if (name != null)
+ {
+ // create a Style Object from the StyleNode object
+ Style style = _convertStyleNode(resolvedStyles[i]);
+ resolvedSelectorStyleMap.put(name, style);
+ }
+ }
+ */
}
+ if (resolvedSelectorStyleMap != null)
+ _unmodifiableResolvedSelectorStyleMap =
+ Collections.unmodifiableMap(resolvedSelectorStyleMap);
else
- {
- styleNode = document.getStyleBySelector(context, prefix + id);
- }
-
- if (styleNode == null)
- {
- map.put(id, _MISS);
- return null;
- }
-
- // Convert the styleNode into a Style
- style = new CSSStyle();
-
+ _unmodifiableResolvedSelectorStyleMap = Collections.emptyMap();
+
+ }
+
+ /**
+ * Returns a Map containing the selector String as the key and the Style Object
+ * (contains all the css property names/values) as the value. This Map can then be used
+ * 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.
+ * This map does not contain 'alias' (aka named) selectors. It only contains selectors
+ * that would be in the generated css file.
+ *
+ * @return unmodifiableMap of the resolved Selector -> Style map.
+ */
+ @Override
+ public Map<Selector, Style> getSelectorStyleMap()
+ {
+ return _unmodifiableResolvedSelectorStyleMap;
+ }
+
+ /**
+ * Returns the Selector in String form, converted to a format that
+ * is suitable to be written to the browse. This is the css-2 format which doesn't have
+ * namespaces and our psuedo-elements.
+ * @param selector Selector
+ * @return String the Selector in a String form that is suitable to be
+ * written to the client.
+ */
+ @Override
+ public String getNativeSelectorString(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.
+ 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);
+ }
+
+
+ /**
+ * Given a StyleNode object, which is an internal API that denotes a Style object
+ * with additional information like includedSelectors, create a simple public
+ * Style object which will be used in the SelectorStyleMap. The StyleNode object
+ * should already be resolved (included selectors have been merged in)
+ * so that all the css properties are there.
+ * @param styleNode
+ * @return A Style object created from the information in the styleNode.
+ */
+ public Style _convertStyleNodeToStyle(StyleNode styleNode)
+ {
+ Map<String, String> styleProperties = new ConcurrentHashMap<String, String>();
// Add in the properties for the style
Iterable<PropertyNode> propertyNodeList = styleNode.getProperties();
for (PropertyNode property : propertyNodeList)
{
String name = property.getName();
String value = property.getValue();
-
- style.setProperty(name, value);
- }
-
- map.put(id, style);
- return style;
- }
-
- // Creates a map of the specified size
- private Hashtable<String, Style> _createMap()
- {
- return new Hashtable<String, Style>(19);
- }
-
-
- // Our local Style maps
- // -= Simon Lessard =-
- // TODO: Check if synchronization is truly needed
- private Hashtable<String, Style> _selectorMap;
- private Hashtable<String, Style> _classMap;
- private Hashtable<String, Style> _nameMap;
+ // We get a NPE in CSSStyle(styleProperties) -> putAll if we add a value that is null.
+ // See the BaseStyle(Map<String, String> propertiesMap) constructor.
+ if (name != null && value != null)
+ styleProperties.put(name, value);
+ }
+
+ return new CSSStyle(styleProperties);
+
+ }
+
+ private final Map<Selector, Style> _unmodifiableResolvedSelectorStyleMap;
+ private final Map<String, String> _afSelectorMap;
+ private final String[] _namespacePrefixArray;
+ private final Map<String, String> _shortStyleClassMap;
+ private final boolean _compress;
}
-
+
private class StyleWriterFactoryImpl
implements StyleWriterFactory
{
- private String _outputDirectory;
- private String _baseFilename;
+ private final String _outputDirectory;
+ private final String _baseFilename;
private PrintWriter _out;
private List<File> _files = new LinkedList<File>();
@@ -1540,7 +1609,7 @@
}
private File _sourceFile; // The source XSS file
- private String _targetPath; // The location of the cache
+ private final String _targetPath; // The location of the cache
private String _baseName; // The base file name for generated CSS files
/**
@@ -1548,7 +1617,7 @@
* resolve/load all files. We also use the InputStreamProvider
* to check for modifications to any dependent files.
*/
- private NameResolver _resolver;
+ private volatile NameResolver _resolver;
/** The parsed StyleSheetDocument */
private StyleSheetDocument _document;
@@ -1577,18 +1646,12 @@
private static final String _CSS_EXTENSION = ".css";
/** Java name for UTF8 encoding */
- private static String _UTF8_ENCODING = "UTF8";
+ private static final String _UTF8_ENCODING = "UTF8";
/** Stub StyleSheetDocument instance */
private static final StyleSheetDocument _EMPTY_DOCUMENT =
new StyleSheetDocument(null, null, StyleSheetDocument.UNKNOWN_TIMESTAMP);
- /**
- * Style used to represent misses in the StyleMap.
- * Package private to allow access from nested StyleMapImpl class
- */
- static final Style _MISS = new CSSStyle();
-
/** Prefix to use for short style classes */
private static final String _SHORT_CLASS_PREFIX = "x";