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 2012/07/09 20:01:42 UTC
svn commit: r1359318 - in /myfaces/trinidad/trunk: src/site/xdoc/devguide/
trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/
trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/
Author: jwaldman
Date: Mon Jul 9 18:01:41 2012
New Revision: 1359318
URL: http://svn.apache.org/viewvc?rev=1359318&view=rev
Log:
TRINIDAD-2268 -tr-property-ref replacement needs to work with gradient settings
thanks to Prakash Udupa for the patch
Added:
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/EmbeddedIncludePropertyNode.java
Modified:
myfaces/trinidad/trunk/src/site/xdoc/devguide/skinning.xml
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocument.java
Modified: myfaces/trinidad/trunk/src/site/xdoc/devguide/skinning.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/src/site/xdoc/devguide/skinning.xml?rev=1359318&r1=1359317&r2=1359318&view=diff
==============================================================================
--- myfaces/trinidad/trunk/src/site/xdoc/devguide/skinning.xml (original)
+++ myfaces/trinidad/trunk/src/site/xdoc/devguide/skinning.xml Mon Jul 9 18:01:41 2012
@@ -955,13 +955,15 @@ public class SkinTranslationMapDemo
</source>
</li>
<li>
- <strong>-tr-property-ref</strong> - > This is used to include properties from other styles in your style.
- The syntax of -tr-include-property is: background-color: -tr-property-ref("af|foo","color"), where the first
+ <strong>-tr-property-ref</strong> - > This is used to include properties from one style into another.
+ The syntax of -tr-property-ref is: background-color: -tr-property-ref("af|foo","color"), where the first
parameter is the style from which the property is included and the second one is the name of the included property
- in that style. When the property included has the same name as in the including selector, the following syntax
+ in that style.
+ There can be more than one occurrence of -tr-property-ref in a property value, for example:
+ background: -webkit-linear-gradient(top, -tr-property-ref("af|foo","color") 0%, -tr-property-ref("af|bar","color") 100%);
+ When the property included has the same name as in the including selector, the following syntax
can also be used: background-color: -tr-property-ref("af|foo") instead of: background-color: -tr-property-ref("af|foo",
- "background-color"). You can also use this in compact property values, like border: 1px solid -tr-property-ref(".AFDefaultColor:alias","color");
- This is useful when only some properties from another style are needed to be included.
+ "background-color"). This is useful when only some properties from another style are needed to be included.
In this case, we won't need to include the entire style via a -tr-rule-ref rule, but only the needed property.
</li>
<li>
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java?rev=1359318&r1=1359317&r2=1359318&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java Mon Jul 9 18:01:41 2012
@@ -27,7 +27,9 @@ import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Pattern;
@@ -41,8 +43,8 @@ import org.apache.myfaces.trinidadintern
import org.apache.myfaces.trinidadinternal.share.xml.XMLUtils;
import org.apache.myfaces.trinidadinternal.style.util.CSSUtils;
import org.apache.myfaces.trinidadinternal.style.util.StyleUtils;
+import org.apache.myfaces.trinidadinternal.style.xml.parse.EmbeddedIncludePropertyNode;
import org.apache.myfaces.trinidadinternal.style.xml.parse.IconNode;
-import org.apache.myfaces.trinidadinternal.style.xml.parse.IncludeCompactPropertyNode;
import org.apache.myfaces.trinidadinternal.style.xml.parse.IncludePropertyNode;
import org.apache.myfaces.trinidadinternal.style.xml.parse.IncludeStyleNode;
import org.apache.myfaces.trinidadinternal.style.xml.parse.PropertyNode;
@@ -261,7 +263,7 @@ class SkinStyleSheetParserUtils
trSkinPropertyNodeList,
resolvedProperties.getTrRuleRefList(),
resolvedProperties.getIncludedPropertiesList(),
- resolvedProperties.getIncludedCompactPropertiesList(),
+ resolvedProperties.getEmbeddedIncludePropertiesList(),
resolvedProperties.getInhibitedProperties(),
resolvedProperties.isTrTextAntialias(),
styleNodeList);
@@ -275,7 +277,7 @@ class SkinStyleSheetParserUtils
trSkinPropertyNodeList,
resolvedProperties.getTrRuleRefList(),
resolvedProperties.getIncludedPropertiesList(),
- resolvedProperties.getIncludedCompactPropertiesList(),
+ resolvedProperties.getEmbeddedIncludePropertiesList(),
resolvedProperties.getInhibitedProperties(),
resolvedProperties.isTrTextAntialias(),
styleNodeList);
@@ -329,8 +331,8 @@ class SkinStyleSheetParserUtils
Set<String> inhibitedPropertySet = new TreeSet<String>();
List<IncludePropertyNode> includedPropertiesList =
new ArrayList<IncludePropertyNode>();
- List<IncludeCompactPropertyNode> includedCompactPropertiesList =
- new ArrayList<IncludeCompactPropertyNode>();
+ List<EmbeddedIncludePropertyNode> embeddedIncludedPropertiesList =
+ new ArrayList<EmbeddedIncludePropertyNode>();
List<PropertyNode> skinPropertyNodeList =
new ArrayList<PropertyNode>();
@@ -359,11 +361,14 @@ class SkinStyleSheetParserUtils
// Check for special propertyNames (-tr-rule-ref, -tr- skin properties)
// or propertyValue (-tr-property-ref)
- // Check for -tr-property-ref first, either regular or compact
+ // Check for -tr-property-ref first, either standalone or embedded
if(propertyValue.indexOf(_INCLUDE_PROPERTY) != -1)
{
- List<String> values = separateCompactValues(propertyValue);
- // border-color: -tr-property-ref(...) versus border: 1px solid -tr-property-ref();
+ List<String> values = _separateCompositeValues(propertyValue);
+
+ // border-color: -tr-property-ref(".AFRed:alias", "color") -> (size == 1)
+ // versus
+ // background: -ms-linear-gradient(top, -tr-property-ref(".AFRed:alias", "color") 1%, -tr-property-ref(".AFGreen:alias","color") 100%); -> (size > 1)
if (values.size() == 1)
{
// include property
@@ -373,27 +378,38 @@ class SkinStyleSheetParserUtils
}
else
{
- // include compact property
- List<IncludePropertyNode> compactIncludePropNodes = new ArrayList<IncludePropertyNode>();
- StringBuilder builder = new StringBuilder();
+ // We parse the value, and substitute each entire -tr-property-ref block with a unique
+ // token. The tokens are substituted later with the respective resolved value of the
+ // entire tr-property-ref block. This is a map with the key being token and value being
+ // the included property node that corresponds to the token.
+ Map<String, IncludePropertyNode> embeddedIncludePropNodes = new HashMap<String, IncludePropertyNode>();
+ // this list is all the non-whitespace segments in the entire value (includes placeholder
+ // that we substitute for each -tr-property-ref segment)
+ List<String> propertyValueChunks = new ArrayList<String>();
+ int count = 0;
for (String value : values)
{
if (value.startsWith(_INCLUDE_PROPERTY))
{
IncludePropertyNode node = _createIncludePropertyNode(
propertyName, value.substring(_INCLUDE_PROPERTY.length()));
- compactIncludePropNodes.add(node);
+ // the placeholder tokens will be of form -tr-0, -tr-1, -tr-2 etc.
+ String embedPlaceholder = _TR_PROPERTY_PREFIX + count++;
+ embeddedIncludePropNodes.put(embedPlaceholder, node);
+ propertyValueChunks.add(embedPlaceholder);
}
else
{
- builder.append(value);
- builder.append(" ");
+ propertyValueChunks.add(value);
}
}
- IncludeCompactPropertyNode iCPNode =
- new IncludeCompactPropertyNode(builder.toString(),
- compactIncludePropNodes, propertyName);
- includedCompactPropertiesList.add(iCPNode);
+
+ EmbeddedIncludePropertyNode eIPNode =
+ new EmbeddedIncludePropertyNode(propertyValueChunks,
+ embeddedIncludePropNodes,
+ propertyName);
+
+ embeddedIncludedPropertiesList.add(eIPNode);
}
}
@@ -442,47 +458,81 @@ class SkinStyleSheetParserUtils
noTrPropertyList,
trRuleRefList,
includedPropertiesList,
- includedCompactPropertiesList,
+ embeddedIncludedPropertiesList,
inhibitedPropertySet,
skinPropertyNodeList,
trTextAntialias);
}
-
- private static List<String> separateCompactValues(String propertyValue)
+
+ /**
+ * Separates a composite value into a list of strings. This will be recontructed later in
+ * StyleSheetDocument._createCompositeValue()
+ * @param propertyValue The full value of the property
+ * @return A list of deconstructed strings Each entry is either a contiguous block of
+ * non-whitespace characters, or a full segment of '-tr-property-ref("af|foo","color")'
+ */
+ private static List<String> _separateCompositeValues(String propertyValue)
{
- String[] test = _SPACE_PATTERN.split(propertyValue);
- List<String> propertyValueNoSpaces = new ArrayList<String>();
- boolean inTr = false;
- int inTrIndex = 0;
- for (int i=0; i < test.length; i++)
- {
- String string = test[i];
- if (string.startsWith(_INCLUDE_PROPERTY) && !string.endsWith(")"))
- {
- // keep looping through the pieces
- // until we get to a string that endsWith ")".
- inTr = true;
- inTrIndex = i;
- }
- else if (inTr)
+ // although unusual, skin authors may omit a space before -tr-property-ref, we split by space
+ // char and we do not want to miss processing -tr-property-ref. Handle this case by adding an
+ // extra space before all -tr-property-ref, regardless if it had one already.
+ propertyValue = propertyValue.replaceAll(_INCLUDE_PROPERTY, " " + _INCLUDE_PROPERTY);
+
+ // the delimiter is the whole set of consecutive white spaces
+ String[] test = _SPACE_PATTERN.split(propertyValue);
+ List<String> propertyValueNoSpaces = new ArrayList<String>();
+ boolean inTr = false;
+ int inTrIndex = 0;
+ for (int i=0; i < test.length; i++)
+ {
+ String string = test[i];
+ // see if we are dealing with a -tr-property-ref now
+ // if it does not end with a closing brace, this segment either contains much more than the
+ // entire -tr-property-ref block, or otherwise contains only partly the -tr-property-ref block
+ if (string.startsWith(_INCLUDE_PROPERTY) && !string.endsWith(")"))
+ {
+ // keep looping through the pieces
+ // until we get to a string that contains ")".
+ inTr = true;
+ inTrIndex = i;
+ }
+
+ if (inTr)
+ {
+ int closeBraceIndex = string.indexOf(')');
+ // the current string has the end segment of -tr-property-ref but this segment could be in
+ // middle (if it was not followed by a space character in the original property value)
+ if (closeBraceIndex != -1)
{
- if (string.endsWith(")"))
- {
- StringBuilder builder = new StringBuilder();
- for (int j=inTrIndex; j <= i; j++)
- {
- builder.append(test[j]);
- }
- inTr = false;
- propertyValueNoSpaces.add(builder.toString());
- }
+ StringBuilder builder = new StringBuilder();
+ // account for all previous chunks that belonged to -tr-property-ref that we skipped
+ // processing so far
+ for (int j=inTrIndex; j < i; j++)
+ {
+ builder.append(test[j]);
+ }
+ // add first part of the current processed string until the closing braces to the
+ // -tr-property-ref segment
+ builder.append(string.substring(0, closeBraceIndex+1));
+
+ inTr = false;
+ propertyValueNoSpaces.add(builder.toString());
+
+ // If there was a second part of the string after the closing braces, add it as another
+ // value chunk in the list of property values
+ if (closeBraceIndex != (string.length() - 1))
+ {
+ propertyValueNoSpaces.add(string.substring(closeBraceIndex + 1));
+ }
}
- else
- {
- propertyValueNoSpaces.add(string);
- }
- }
- return propertyValueNoSpaces;
+ }
+ // split() on a space pattern can leave the first entry as empty, exclude this empty value
+ else if (!test[i].isEmpty())
+ {
+ propertyValueNoSpaces.add(string);
+ }
+ }
+ return propertyValueNoSpaces;
}
/**
@@ -665,7 +715,7 @@ class SkinStyleSheetParserUtils
* @param skinPropertyNodeList
* @param trRuleRefList
* @param includePropertyNodes
- * @param includeCompactPropertyNodes
+ * @param embeddedIncludePropertyNodes
* @param inhibitedProperties
* @param trTextAntialias
* @param styleNodeList Once the StyleNode is created, it is added to the iconNodeList to be
@@ -678,7 +728,7 @@ class SkinStyleSheetParserUtils
List<PropertyNode> skinPropertyNodeList,
List<String> trRuleRefList,
List<IncludePropertyNode> includePropertyNodes,
- List<IncludeCompactPropertyNode> includeCompactPropertyNodes,
+ List<EmbeddedIncludePropertyNode> embeddedIncludePropertyNodes,
Set<String> inhibitedProperties,
boolean trTextAntialias,
List<StyleNode> styleNodeList)
@@ -687,7 +737,7 @@ class SkinStyleSheetParserUtils
StyleNode styleNode = _createStyleNode(selectorName, propertyNodeList, skinPropertyNodeList,
trRuleRefList,
includePropertyNodes,
- includeCompactPropertyNodes,
+ embeddedIncludePropertyNodes,
inhibitedProperties,
trTextAntialias);
@@ -701,7 +751,7 @@ class SkinStyleSheetParserUtils
List<PropertyNode> skinPropertyNodeList,
List<String> trRuleRefList,
List<IncludePropertyNode> includePropertyNodes,
- List<IncludeCompactPropertyNode> includeCompactPropertyNodes,
+ List<EmbeddedIncludePropertyNode> embeddedIncludePropertyNodes,
Set<String> inhibitedProperties,
boolean trTextAntialias)
{
@@ -761,8 +811,8 @@ class SkinStyleSheetParserUtils
includeStyleNodes.toArray(new IncludeStyleNode[0]),
includePropertyNodes.isEmpty() ?
null : includePropertyNodes.toArray(new IncludePropertyNode[0]),
- includeCompactPropertyNodes.isEmpty() ?
- null : includeCompactPropertyNodes.toArray(new IncludeCompactPropertyNode[0]),
+ embeddedIncludePropertyNodes.isEmpty() ?
+ null : embeddedIncludePropertyNodes.toArray(new EmbeddedIncludePropertyNode[0]),
inhibitedProperties,
false);
@@ -973,7 +1023,7 @@ class SkinStyleSheetParserUtils
List<PropertyNode> noTrPropertyList,
List<String> trRuleRefList,
List<IncludePropertyNode> includedPropertiesList,
- List<IncludeCompactPropertyNode> includedCompactPropertiesList,
+ List<EmbeddedIncludePropertyNode> embeddedIncludePropertiesList,
Set<String> inhibitedPropertySet,
List<PropertyNode> skinPropertyNodeList,
boolean trTextAntialias)
@@ -981,7 +1031,7 @@ class SkinStyleSheetParserUtils
_noTrPropertyList = noTrPropertyList;
_trRuleRefList = trRuleRefList;
_includedPropertiesList = includedPropertiesList;
- _includedCompactPropertiesList = includedCompactPropertiesList;
+ _embeddedIncludePropertiesList = embeddedIncludePropertiesList;
_inhibitedPropertySet = inhibitedPropertySet;
_skinPropertyNodeList = skinPropertyNodeList;
_trTextAntialias = trTextAntialias;
@@ -1002,9 +1052,9 @@ class SkinStyleSheetParserUtils
return _includedPropertiesList;
}
- public List<IncludeCompactPropertyNode> getIncludedCompactPropertiesList()
+ public List<EmbeddedIncludePropertyNode> getEmbeddedIncludePropertiesList()
{
- return _includedCompactPropertiesList;
+ return _embeddedIncludePropertiesList;
}
public List<PropertyNode> getSkinPropertyNodeList()
@@ -1026,7 +1076,7 @@ class SkinStyleSheetParserUtils
private List<PropertyNode> _noTrPropertyList;
private List<String> _trRuleRefList;
private List<IncludePropertyNode> _includedPropertiesList;
- private List<IncludeCompactPropertyNode> _includedCompactPropertiesList;
+ private List<EmbeddedIncludePropertyNode> _embeddedIncludePropertiesList;
private List<PropertyNode> _skinPropertyNodeList;
private boolean _trTextAntialias;
}
@@ -1042,7 +1092,7 @@ class SkinStyleSheetParserUtils
private static final String _INCLUDE_PROPERTY = "-tr-property-ref";
private static final String _PROPERTY_TEXT_ANTIALIAS = "text-antialias";
- private static final Pattern _SPACE_PATTERN = Pattern.compile("\\s");
+ private static final Pattern _SPACE_PATTERN = Pattern.compile("[\\s]+");
private static final Pattern _SELECTOR_PATTERN = Pattern.compile("selector\\(");
static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(
Added: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/EmbeddedIncludePropertyNode.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/EmbeddedIncludePropertyNode.java?rev=1359318&view=auto
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/EmbeddedIncludePropertyNode.java (added)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/EmbeddedIncludePropertyNode.java Mon Jul 9 18:01:41 2012
@@ -0,0 +1,145 @@
+/*
+ * 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.xml.parse;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+
+/**
+ * The EmbeddedIncludePropertyNode node is a data structure to store property values that can
+ * have multiple occurrences of -tr-property-ref at random locations in them, examples:
+ * border: 1px solid -tr-property-ref(".AFDarkColor:alias",color);
+ * background: -ms-linear-gradient(top, -tr-property-ref(".AFRed:alias", "color") 1%, -tr-property-ref(".AFGreen:alias","color") 100%);
+ *
+ * This is similar to includeProperty element, but it is used on composite css property values.
+ *
+ * Note that for cases of single occurrence of -tr-property-ref we should be using the simpler
+ * IncludePropertyNode.
+ * @version $Name: $ ($Revision: trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/EmbeddedIncludePropertyNode.java#0 $) $Date: 10-nov-2005.18:58:07 $
+ */
+public class EmbeddedIncludePropertyNode
+{
+
+ /**
+ * Creates an EmbeddedIncludePropertyNode.
+ * If we have border: 1px solid -tr-property-ref(".AFDarkColor:alias",color); in the css file,
+ * then localPropertyName == border, propertyValues == {"1px solid -tr-0"}, and
+ * includePropertyNodes will contain map of placeholder token '-tr-0' to
+ * -tr-property-ref(".AFDarkColor:alias",color);
+ * @param propertyValues the ordered list of property value chunks that when reconstructed will
+ * make up the entire property value
+ * @param includePropertyNodes the list of include properties that this embedded node holds
+ * @param localPropertyName the name of the property for which this embedded node represents the
+ * value.
+ */
+ public EmbeddedIncludePropertyNode(
+ List<String> propertyValues,
+ Map<String, IncludePropertyNode> includePropertyNodes,
+ String localPropertyName)
+ {
+ // The caller of this constructor must have all these values filled out.
+ if (propertyValues == null)
+ throw new IllegalArgumentException();
+ if (includePropertyNodes == null)
+ throw new IllegalArgumentException();
+ if (localPropertyName == null)
+ throw new IllegalArgumentException();
+
+ _propertyValues = propertyValues;
+ _includePropertyNodes = includePropertyNodes;
+ _localPropertyName = localPropertyName;
+
+ }
+
+ /**
+ * Returns the name of the style to include.
+ */
+ public String getLocalPropertyName()
+ {
+ return _localPropertyName;
+ }
+
+ /**
+ * Returns the property value segments that makes up the entire vlaue for the local property.
+ */
+ public Iterator<String> getPropertyValues()
+ {
+ return _propertyValues.iterator();
+ }
+
+ /**
+ * Returns the included property nodes in this embedded node, the key being the placeholder text
+ */
+ public Map<String, IncludePropertyNode> getIncludedProperties()
+ {
+ return _includePropertyNodes;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (!(obj instanceof EmbeddedIncludePropertyNode))
+ return false;
+
+ // obj at this point must be an EmbeddedIncludePropertyNode
+ EmbeddedIncludePropertyNode test = (EmbeddedIncludePropertyNode)obj;
+ return
+ (_localPropertyName == test._localPropertyName
+ || (_localPropertyName != null && _localPropertyName.equals(test._localPropertyName)))
+ && (_propertyValues == test._propertyValues
+ || (_propertyValues != null && _propertyValues.equals(test._propertyValues)))
+ && (_includePropertyNodes == test._includePropertyNodes
+ || (_includePropertyNodes != null
+ && _includePropertyNodes.equals(test._includePropertyNodes)));
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int hash = 17;
+ hash = 37*hash + ((null == _localPropertyName) ? 0 : _localPropertyName.hashCode());
+ hash = 37*hash + ((null == _propertyValues) ? 0 : _propertyValues.hashCode());
+ hash = 37*hash + ((null == _includePropertyNodes) ? 0 : _includePropertyNodes.hashCode());
+
+ return hash;
+ }
+
+
+ @Override
+ public String toString()
+ {
+ return
+ "[localPropertyName=" + _localPropertyName + ", " +
+ "propertyValues=" + _propertyValues + ", " +
+ "includePropertyNodeMap=" + _includePropertyNodes + "]";
+ }
+
+ private final List<String> _propertyValues;
+ private final Map<String, IncludePropertyNode> _includePropertyNodes;
+ private final String _localPropertyName;
+
+ private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(
+ EmbeddedIncludePropertyNode.class);
+}
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java?rev=1359318&r1=1359317&r2=1359318&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java Mon Jul 9 18:01:41 2012
@@ -45,7 +45,7 @@ public class StyleNode
PropertyNode[] skinProperties,
IncludeStyleNode[] includedStyles,
IncludePropertyNode[] includedProperties,
- IncludeCompactPropertyNode[] includedCompactProperties,
+ EmbeddedIncludePropertyNode[] embeddedIncludeProperties,
Set<String> inhibitedProperties
)
{
@@ -55,7 +55,7 @@ public class StyleNode
skinProperties,
includedStyles,
includedProperties,
- includedCompactProperties,
+ embeddedIncludeProperties,
inhibitedProperties,
false);
}
@@ -70,7 +70,7 @@ public class StyleNode
PropertyNode[] skinProperties,
IncludeStyleNode[] includedStyles,
IncludePropertyNode[] includedProperties,
- IncludeCompactPropertyNode[] includedCompactProperties,
+ EmbeddedIncludePropertyNode[] embeddedIncludeProperties,
Set<String> inhibitedProperties,
boolean resetProperties
)
@@ -116,15 +116,15 @@ public class StyleNode
else
_includedProperties = Collections.unmodifiableList(Arrays.asList(includedProperties));
- // Initialize _includedCompactProperties
+ // Initialize _embeddedIncludeProperties
// ------------------------------
- if ((includedCompactProperties == null) || (includedCompactProperties.length == 0))
- _includedCompactProperties = Collections.emptyList();
- else if (includedCompactProperties.length == 1)
- _includedCompactProperties = Collections.singletonList(includedCompactProperties[0]);
+ if ((embeddedIncludeProperties == null) || (embeddedIncludeProperties.length == 0))
+ _embeddedIncludeProperties = Collections.emptyList();
+ else if (embeddedIncludeProperties.length == 1)
+ _embeddedIncludeProperties = Collections.singletonList(embeddedIncludeProperties[0]);
else
- _includedCompactProperties =
- Collections.unmodifiableList(Arrays.asList(includedCompactProperties));
+ _embeddedIncludeProperties =
+ Collections.unmodifiableList(Arrays.asList(embeddedIncludeProperties));
// Initialize _skinProperties. These are server-side skin properties, like -tr-show-last-item,
// as opposed to client side, like background-color or color. client side properties get
@@ -234,11 +234,11 @@ public class StyleNode
/**
- * Implementation of StyleNode.getIncludedCompactProperties().
+ * Implementation of StyleNode.getEmbeddedIncludeProperties().
*/
- public Collection<IncludeCompactPropertyNode> getIncludedCompactProperties()
+ public Collection<EmbeddedIncludePropertyNode> getEmbeddedIncludeProperties()
{
- return _includedCompactProperties;
+ return _embeddedIncludeProperties;
}
/**
@@ -311,7 +311,7 @@ public class StyleNode
(_inhibitedProperties.equals(test._inhibitedProperties)) &&
(_includedStyles.equals(test._includedStyles)) &&
(_includedProperties.equals(test._includedProperties)) &&
- (_includedCompactProperties.equals(test._includedCompactProperties)) &&
+ (_embeddedIncludeProperties.equals(test._embeddedIncludeProperties)) &&
(_properties.equals(test._properties)) &&
(_skinProperties.equals(test._skinProperties));
}
@@ -327,7 +327,7 @@ public class StyleNode
hash = 37*hash + _inhibitedProperties.hashCode();
hash = 37*hash + _includedStyles.hashCode();
hash = 37*hash + _includedProperties.hashCode();
- hash = 37*hash + _includedCompactProperties.hashCode();
+ hash = 37*hash + _embeddedIncludeProperties.hashCode();
hash = 37*hash + _properties.hashCode();
hash = 37*hash + _skinProperties.hashCode();
@@ -344,7 +344,7 @@ public class StyleNode
"skinProperties=" + _skinProperties.toString() + ", " +
"includeStyles=" + _includedStyles.toString() + ", " +
"includeProperties=" + _includedProperties.toString() + ", " +
- "includeCompactProperties=" + _includedCompactProperties.toString() + ", " +
+ "embeddedIncludeProperties=" + _embeddedIncludeProperties.toString() + ", " +
"inhibitedProperties=" + _inhibitedProperties.toString() + ", " +
"resetProperties=" + _resetProperties + ", " +
"inhibitAll=" + _inhibitAll + "]";
@@ -365,7 +365,7 @@ public class StyleNode
private final List<PropertyNode> _skinProperties; // The skin property nodes
private final List<IncludeStyleNode> _includedStyles; // Included styles
private final List<IncludePropertyNode> _includedProperties; // Included properties
- private final List<IncludeCompactPropertyNode> _includedCompactProperties;
+ private final List<EmbeddedIncludePropertyNode> _embeddedIncludeProperties;
private final List<String> _inhibitedProperties; // Inhibited properties
// These flags checks whether the style should inherit properties
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocument.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocument.java?rev=1359318&r1=1359317&r2=1359318&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocument.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocument.java Mon Jul 9 18:01:41 2012
@@ -905,22 +905,34 @@ public class StyleSheetDocument
}
}
- // 2'. Resolve included properties in a compact selector.
+ // 2'. Resolve included properties in a composite property value.
// e.g., border: 1px solid -tr-property-ref(".AFDarkColor:alias",color);
- Iterable<IncludeCompactPropertyNode> includedCompactProperties =
- node.getIncludedCompactProperties();
- for (IncludeCompactPropertyNode includeCompact : includedCompactProperties)
+ // e.g., background: -ms-linear-gradient(top, -tr-property-ref(".AFRed:alias", "color") 0%, -tr-property-ref(".AFGreen:alias","color") 100%);
+ Iterable<EmbeddedIncludePropertyNode> embeddedIncludeProperties =
+ node.getEmbeddedIncludeProperties();
+ for (EmbeddedIncludePropertyNode embeddedInclude : embeddedIncludeProperties)
{
// get each IncludePropertyNode, and resolve it.
- Iterable<IncludePropertyNode> iPNodeIter = includeCompact.getIncludedProperties();
- List<String> resolvedValues = new ArrayList<String>();
- for (IncludePropertyNode includeProperty : iPNodeIter)
+ Map<String, IncludePropertyNode> ipNodes = embeddedInclude.getIncludedProperties();
+ Map<String, String> resolvedValues = new HashMap<String, String>();
+
+ Iterator<Map.Entry<String,IncludePropertyNode>> entryIter = ipNodes.entrySet().iterator();
+
+ while (entryIter.hasNext())
{
- StyleNode resolvedNode =
- _resolveIncludedProperties(context, forIconNode, styleSheets, resolvedStyles,
- resolvedNamedStyles, includesStack, namedIncludesStack,
- includeProperty);
-
+ Map.Entry<String,IncludePropertyNode> currEntry = entryIter.next();
+ String placeHolder = currEntry.getKey();
+ IncludePropertyNode includeProperty = currEntry.getValue();
+
+ StyleNode resolvedNode = _resolveIncludedProperties(context,
+ forIconNode,
+ styleSheets,
+ resolvedStyles,
+ resolvedNamedStyles,
+ includesStack,
+ namedIncludesStack,
+ includeProperty);
+
if (resolvedNode != null)
{
List<PropertyNode> pNodes = _getIncludedPropertyNodes(
@@ -928,23 +940,26 @@ public class StyleSheetDocument
includeProperty.getPropertyName(),
includeProperty.getLocalPropertyName());
// stores all the resolved 'values'. we will concat these values when we
- // create the PropertyNode because these are compact values, like "1px solid red"
+ // create the PropertyNode because these are composite values, like "1px solid red"
if (pNodes != null && !pNodes.isEmpty())
- resolvedValues.add(pNodes.get(0).getValue());
+ resolvedValues.put(placeHolder, pNodes.get(0).getValue());
}
}
- // here we are. We have processed one IncludeCompactPropertyNode's includePropertyNodes.
+ // here we are. We have processed one EmbeddedIncludePropertyNode's includePropertyNodes.
// now we need to add to the entry:
- String compactValue = _createCompactValue(includeCompact, resolvedValues);
- String localName = includeCompact.getLocalPropertyName();
- PropertyNode propertyNode = new PropertyNode(localName,
- compactValue);
-
- if (!(localName.startsWith(_TR_PROPERTY_PREFIX)))
- entry.addProperty(propertyNode);
- else
- entry.addSkinProperty(propertyNode);
+ if (!resolvedValues.isEmpty() || embeddedInclude.getPropertyValues().hasNext())
+ {
+ String compositeValue = _createCompositeValue(embeddedInclude, resolvedValues);
+ String localName = embeddedInclude.getLocalPropertyName();
+ PropertyNode propertyNode = new PropertyNode(localName,
+ compositeValue);
+
+ if (!(localName.startsWith(_TR_PROPERTY_PREFIX)))
+ entry.addProperty(propertyNode);
+ else
+ entry.addSkinProperty(propertyNode);
+ }
}
@@ -975,19 +990,47 @@ public class StyleSheetDocument
}
}
}
-
-
- private String _createCompactValue(
- IncludeCompactPropertyNode node,
- List<String> values)
+
+ /**
+ * Builds the composite value of the property that has one or more -tr-property-ref blocks
+ * used in it.
+ * @param node The EmbeddedIncludePropertyNode that has info about all the -tr-property-refs
+ * and other non-whitespace segments in the entire value
+ * @param values The map of placeholder token to resolved value of the respective -tr-property-ref
+ * segment. The placeholder is used to identify the position in the whole value where the
+ * different -tr-property refs existed.
+ */
+ private String _createCompositeValue(
+ EmbeddedIncludePropertyNode node,
+ Map<String, String> values)
{
StringBuilder builder = new StringBuilder();
- builder.append(node.getPropertyValues());
- for(String value : values)
+
+ Iterator<String> propertyValues = node.getPropertyValues();
+ while (propertyValues.hasNext())
{
- builder.append(value);
- builder.append(" ");
+ String valueFrag = propertyValues.next();
+ // the placeholder tokens will be of form -tr-0, -tr-1, -tr-2
+ if (valueFrag.startsWith(_TR_PROPERTY_PREFIX))
+ {
+ String resolvedValue = values.get(valueFrag);
+ // sometimes the alias referenced by -tr-property-ref may not be defined, so resolved value
+ // can be null
+ if (resolvedValue != null)
+ {
+ builder.append(resolvedValue);
+ if (propertyValues.hasNext())
+ builder.append(" ");
+ }
+ }
+ else
+ {
+ builder.append(valueFrag);
+ if (propertyValues.hasNext())
+ builder.append(" ");
+ }
}
+
return builder.toString();
}