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/12/31 18:39:17 UTC
svn commit: r894905 [1/2] - in /myfaces/trinidad/branches/1.2.12.2-branch:
src/site/xdoc/devguide/
trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/
trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/
trinidad-examples/trinidad-d...
Author: jwaldman
Date: Thu Dec 31 17:39:14 2009
New Revision: 894905
URL: http://svn.apache.org/viewvc?rev=894905&view=rev
Log:
TRINIDAD-1547 @agent in skinning should allow for a range of agent versions
also, TrinidadAgent.getApplication() changed from an int to an enum, and non-TrinidadImpl users of this api (ADF Faces) will need to change to using the enum
commit for Blake Sullivan
Added:
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/AgentAtRuleMatcher.java
Modified:
myfaces/trinidad/branches/1.2.12.2-branch/src/site/xdoc/devguide/skinning.xml
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/Version.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/CollectionUtils.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentNameUtil.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentUtil.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgentImpl.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/HiddenLabelUtils.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/MediaRenderer.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/NameUtils.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/data/bind/IsAgentApplicationBoundValue.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/expl/UIFunctions.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/NameAndAgentScorer.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/ApplicationSwitcherRenderer.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/BaseDesktopUtils.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/ButtonRenderer.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/HeaderRenderer.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/HtmlLafRenderer.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/PageLayoutRenderer.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/FormElementRenderer.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/GlobalButtonBarRenderer.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/HiddenLabelUtils.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/NavigationBarRenderer.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/XhtmlLafUtils.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/partial/PartialPageRendererUtils.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.java
Modified: myfaces/trinidad/branches/1.2.12.2-branch/src/site/xdoc/devguide/skinning.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/src/site/xdoc/devguide/skinning.xml?rev=894905&r1=894904&r2=894905&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/src/site/xdoc/devguide/skinning.xml (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/src/site/xdoc/devguide/skinning.xml Thu Dec 31 17:39:14 2009
@@ -829,15 +829,41 @@
</li>
<li>
<strong>@agent</strong> {/skin definitions go here/} - >
- Possible values are: netscape, ie, mozilla, gecko, webkit (maps to safari), ice, email.
+ Possible values are:
+ <ul>
+ <li>netscape</li>
+ <li>ie</li>
+ <li>mozilla</li>
+ <li>gecko</li>
+ <li>webkit (maps to safari)</li>
+ <li>ice</li>
+ <li>email</li>
+ <li>blackberry</li>
+ <li>nokia_s60</li>
+ <li>genericpda</li>
+ <li>konqueror</li>
+ <li>opera</li>
+ </ul>
This is to define styles only for a particular agent.
- Agent type can be followed by a space separated list of version numbers.
- Several agents can be specified separated by commas.
+ <source>
+ @agent ie
+ </source>
+ Matches any version of Internet Explorer
<P>
- You can specify agent versions as well. For example:
+ Agent type may be optionally followed by "and" separated version rules:
<source>
- @agent ie and (version: 6) and (version: 7), gecko and (version: 1.9)
+ @agent ie and (version: 6)
</source>
+ Matches any 6.x version of Internet Explorer
+ </P>
+ <P>
+ Rules may be OR'ed together using comma-separated rules:
+ <source>
+ @agent ie and (version: 6), ie and (version: 7), gecko and (version: 1.9)
+ </source>
+ Matches either Internet Explorer version 6.x or Internet Explorer version 7.x or Gecko
+ engine version 1.9 (in FireFox for example).
+
These are the same:
<source>
@agent ie and (version: 6.*)
@@ -847,7 +873,14 @@
<source>
@agent ie and (version: 6.0)
</source>
- There is currently no syntax to specify a range of versions.
+ Similarly, you can use max-version and min-version to specify ranges of versions. The rule:
+ <source>
+ @agent ie and (version: 6), ie and (version: 7), gecko and (version: 1.9)
+ </source>
+ can be written as:
+ <source>
+ @agent ie and (min-version: 6) and (max-version: 7), gecko and (version: 1.9)
+ </source>
</P>
</li>
<li>
Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/Version.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/Version.java?rev=894905&r1=894904&r2=894905&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/Version.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/Version.java Thu Dec 31 17:39:14 2009
@@ -31,7 +31,7 @@
* subsection is compared from left to right. If one Version doesn't have
* a version subsection at the current index, the value of versionPadding
* is used for this comparison. Version subsections with the wild-card value "*"
- * care considered equal. The value returned by compareTo() is the value of the
+ * are considered equal. The value returned by compareTo() is the value of the
* first non-equal version subsection or zero if all subsections match.
*
* Due to the support for wild-cards, this class has a natural ordering
Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/CollectionUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/CollectionUtils.java?rev=894905&r1=894904&r2=894905&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/CollectionUtils.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/CollectionUtils.java Thu Dec 31 17:39:14 2009
@@ -27,9 +27,11 @@
import java.util.AbstractQueue;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.ConcurrentModificationException;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -40,6 +42,7 @@
import java.util.RandomAccess;
import java.util.Set;
+import org.apache.myfaces.trinidad.context.Version;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
/**
@@ -116,6 +119,71 @@
{
return (ListIterator<T>)_EMPTY_LIST_ITERATOR;
}
+
+ /**
+ * Returns a minimal Set containing the elements passed in. There is no guarantee that the
+ * returned set is mutable or immutable.
+ * @param <T>
+ * @param a The elements to add to the Set
+ * @return A set containing the elements passed in.
+ * @see #asUnmodifiableSet
+ */
+ public static <T> Set<T> asSet(T... a)
+ {
+ return _asSet(a, false);
+ }
+
+ /**
+ * Returns an unmodifiable Set containing the elements passed in.
+ * @param <T>
+ * @param a The elements to add to the Set
+ * @return A set containing the elements passed in.
+ * @see #asSet
+ */
+ public static <T> Set<T> asUnmodifiableSet(T... a)
+ {
+ return _asSet(a, true);
+ }
+
+ private static <T> Set<T> _asSet(T[] a, boolean makeImmutable)
+ {
+ int count = (a != null) ? a.length : 0;
+
+ Set<T> outSet;
+
+ if (count == 0)
+ {
+ outSet = Collections.emptySet();
+ }
+ else
+ {
+ if (count == 1)
+ {
+ outSet = Collections.singleton(a[0]);
+ }
+ else
+ {
+ // make the initial size big enough that we don't have to rehash to fit the array, for
+ // the .75 load factor we pass in
+ int initialSize = (int)Math.ceil(count / .75d);
+
+ outSet = new HashSet<T>(initialSize, .75f);
+
+ for (int i = 0; i < count ; i++)
+ {
+ outSet.add(a[i]);
+ }
+
+ if (makeImmutable)
+ {
+ outSet = Collections.unmodifiableSet(outSet);
+ }
+ }
+ }
+
+ return outSet;
+ }
+
/**
* Returns a Collection based on the passed in Collection <code>c</code>,
Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css?rev=894905&r1=894904&r2=894905&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-examples/trinidad-demo/src/main/webapp/skins/purple/purpleSkin.css Thu Dec 31 17:39:14 2009
@@ -914,3 +914,13 @@
{
af|selectBooleanCheckbox::label {color: red}
}
+
+@agent ie and (version:7)
+{
+ af|selectBooleanCheckbox::label {color: aqua}
+}
+
+@agent gecko and (min-version:0.8.1.*) and (max-version:0.9.1.*), gecko and (version:5), ie and (min-version:5.*) and (max-version:8), gecko and (version: 2.9.1.*){
+ af|selectBooleanCheckbox::label {color: fuschia}
+}
+
Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentNameUtil.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentNameUtil.java?rev=894905&r1=894904&r2=894905&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentNameUtil.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentNameUtil.java Thu Dec 31 17:39:14 2009
@@ -29,88 +29,6 @@
public class AgentNameUtil
{
/**
- * utility method to get AdfFacesAgent application constant (int) from agent name strings
- *
- * @param agentName
- * @return
- */
- public static int getAgent(String agentName)
- {
- if (TrinidadAgent.AGENT_NETSCAPE.equals(agentName))
- {
- return TrinidadAgent.APPLICATION_NETSCAPE;
- }
-
- if (TrinidadAgent.AGENT_IE.equals(agentName))
- {
- return TrinidadAgent.APPLICATION_IEXPLORER;
- }
-
- if (TrinidadAgent.AGENT_GECKO.equals(agentName))
- {
- return TrinidadAgent.APPLICATION_GECKO;
- }
-
- if (TrinidadAgent.AGENT_EMAIL.equals(agentName))
- {
- return TrinidadAgent.APPLICATION_EMAIL;
- }
-
- if (TrinidadAgent.AGENT_ELAINE.equals(agentName))
- {
- return TrinidadAgent.APPLICATION_WEB_CLIPPING;
- }
-
- if (TrinidadAgent.AGENT_ICE_BROWSER.equals(agentName))
- {
- return TrinidadAgent.APPLICATION_ICE;
- }
-
- if (TrinidadAgent.AGENT_PIXO.equals(agentName))
- {
- return TrinidadAgent.APPLICATION_PIXO;
- }
-
- if ((TrinidadAgent.AGENT_NETFRONT.equals(agentName)) ||
- (TrinidadAgent.AGENT_WEBPRO.equals(agentName)))
- {
- return TrinidadAgent.APPLICATION_NET_FRONT;
- }
-
- if (TrinidadAgent.AGENT_WEBKIT.equals(agentName))
- {
- return TrinidadAgent.APPLICATION_SAFARI;
- }
-
- if (TrinidadAgent.AGENT_OPERA.equals(agentName))
- {
- return TrinidadAgent.APPLICATION_OPERA;
- }
-
- if(TrinidadAgent.AGENT_BLACKBERRY.equals(agentName))
- {
- return TrinidadAgent.APPLICATION_BLACKBERRY;
- }
-
- if (TrinidadAgent.AGENT_NOKIA_S60.equals(agentName))
- {
- return TrinidadAgent.APPLICATION_NOKIA_S60;
- }
-
- if(TrinidadAgent.AGENT_GENERICPDA.equals(agentName))
- {
- return TrinidadAgent.APPLICATION_GENERICPDA;
- }
-
- if(TrinidadAgent.AGENT_KONQUEROR.equals(agentName))
- {
- return TrinidadAgent.APPLICATION_KONQUEROR;
- }
-
- return TrinidadAgent.APPLICATION_UNKNOWN;
- }
-
- /**
* utility method to get AdfFacesAgent application constant (int) from platform/os name strings
*
* @param platformName
@@ -194,48 +112,6 @@
}
/**
- * utility method to get agent name string from AdfFacesAgent application constant (int)
- *
- * @param agentId
- * @return
- */
- public static String getAgentName(int agentId)
- {
- switch (agentId) {
- case TrinidadAgent.APPLICATION_NETSCAPE:
- return TrinidadAgent.AGENT_NETSCAPE;
- case TrinidadAgent.APPLICATION_IEXPLORER:
- return TrinidadAgent.AGENT_IE;
- case TrinidadAgent.APPLICATION_GECKO:
- return TrinidadAgent.AGENT_GECKO;
- case TrinidadAgent.APPLICATION_WEB_CLIPPING:
- return TrinidadAgent.AGENT_ELAINE;
- case TrinidadAgent.APPLICATION_ICE:
- return TrinidadAgent.AGENT_ICE_BROWSER;
- case TrinidadAgent.APPLICATION_PIXO:
- return TrinidadAgent.AGENT_PIXO;
- case TrinidadAgent.APPLICATION_NET_FRONT:
- return TrinidadAgent.AGENT_NETFRONT;
- case TrinidadAgent.APPLICATION_SAFARI:
- return TrinidadAgent.AGENT_WEBKIT;
- case TrinidadAgent.APPLICATION_OPERA:
- return TrinidadAgent.AGENT_OPERA;
- case TrinidadAgent.APPLICATION_BLACKBERRY:
- return TrinidadAgent.AGENT_BLACKBERRY;
- case TrinidadAgent.APPLICATION_NOKIA_S60:
- return TrinidadAgent.AGENT_NOKIA_S60;
- case TrinidadAgent.APPLICATION_GENERICPDA:
- return TrinidadAgent.AGENT_GENERICPDA;
- case TrinidadAgent.APPLICATION_KONQUEROR:
- return TrinidadAgent.AGENT_KONQUEROR;
- case TrinidadAgent.APPLICATION_EMAIL:
- return TrinidadAgent.AGENT_EMAIL;
- default:
- return TrinidadAgent.AGENT_UNKNOWN;
- }
- }
-
- /**
* utility method to get platform name string from AdfFacesAgent application constant (int)
*
* @param platformId
Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentUtil.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentUtil.java?rev=894905&r1=894904&r2=894905&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentUtil.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentUtil.java Thu Dec 31 17:39:14 2009
@@ -32,59 +32,6 @@
public class AgentUtil
{
/**
- * Construct an AdfFacesAgent from agentType, agent application constant, agent version
- * and plaform application constant
- *
- * //TODO: Check: if this is really needed
- *
- * @param type
- * @param browser
- * @param agentVersion
- * @param platform
- * @return
- */
- public static TrinidadAgent getAgent(
- int type,
- int browser,
- String agentVersion,
- int platform)
- {
- final int fType = type;
- final int fBrowser = browser;
- final String fAgentVersion = agentVersion;
- final int fPlatform = platform;
-
- Agent agent =
- new DefaultAgent ()
- {
- @Override
- public Object getType()
- {
- return AgentNameUtil.getAgentName(fType);
- }
-
- @Override
- public String getAgentName()
- {
- return AgentNameUtil.getAgentName(fBrowser);
- }
-
- @Override
- public String getAgentVersion()
- {
- return fAgentVersion;
- }
-
- @Override
- public String getPlatformName()
- {
- return AgentNameUtil.getPlatformName(fPlatform);
- }
- };
- return new TrinidadAgentImpl(agent);
- }
-
- /**
* Get a default agent, that defines no characteristics.
*
* @return
Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java?rev=894905&r1=894904&r2=894905&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java Thu Dec 31 17:39:14 2009
@@ -18,7 +18,11 @@
*/
package org.apache.myfaces.trinidadinternal.agent;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.myfaces.trinidad.context.Agent;
+import org.apache.myfaces.trinidad.context.Version;
/**
* Extension of public Agent interface. Defines constants/method for AdInternal use.
@@ -26,7 +30,7 @@
* the current (internal) code base uses this heavily.
*
*/
-public interface TrinidadAgent extends Agent
+public abstract class TrinidadAgent implements Agent, Cloneable
{
static public final CapabilityKey CAP_DOM =
CapabilityKey.getCapabilityKey("dom", true);
@@ -179,59 +183,59 @@
//
// Values for CAP_DOM
//
- static public Object DOM_CAP_NONE =
+ static public final Object DOM_CAP_NONE =
CapabilityValue.getCapabilityValue (CAP_DOM, "none");
- static public Object DOM_CAP_FORM =
+ static public final Object DOM_CAP_FORM =
CapabilityValue.getCapabilityValue (CAP_DOM, "form");
- static public Object DOM_CAP_LEVEL_1 =
+ static public final Object DOM_CAP_LEVEL_1 =
CapabilityValue.getCapabilityValue (CAP_DOM, "level1");
- static public Object DOM_CAP_LEVEL_2 =
+ static public final Object DOM_CAP_LEVEL_2 =
CapabilityValue.getCapabilityValue (CAP_DOM, "level2");
//
// Values for CAP_SCRIPTING_SPEED
//
- static public Object SCRIPTING_SPEED_CAP_NONE =
+ static public final Object SCRIPTING_SPEED_CAP_NONE =
CapabilityValue.getCapabilityValue (CAP_SCRIPTING_SPEED, "none");
- static public Object SCRIPTING_SPEED_CAP_SLOW =
+ static public final Object SCRIPTING_SPEED_CAP_SLOW =
CapabilityValue.getCapabilityValue (CAP_SCRIPTING_SPEED, "slow");
- static public Object SCRIPTING_SPEED_CAP_FAST =
+ static public final Object SCRIPTING_SPEED_CAP_FAST =
CapabilityValue.getCapabilityValue (CAP_SCRIPTING_SPEED,"fast");
//
// Values for CAP_TABLES
//
- static public Object TABLES_CAP_BASIC =
+ static public final Object TABLES_CAP_BASIC =
CapabilityValue.getCapabilityValue (CAP_TABLES, "basic");
- static public Object TABLES_CAP_ADVANCED_ATTRS =
+ static public final Object TABLES_CAP_ADVANCED_ATTRS =
CapabilityValue.getCapabilityValue (CAP_TABLES, "advanced_attrs");
- static public Object TABLES_CAP_ADVANCED =
+ static public final Object TABLES_CAP_ADVANCED =
CapabilityValue.getCapabilityValue (CAP_TABLES, "advanced");
//
// Values for CAP_STYLE_ATTRIBUTES
//
// no styling is supported
- static public Object STYLES_NONE =
+ static public final 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 =
+ static public final 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 =
+ static public final Object STYLES_INTERNAL =
CapabilityValue.getCapabilityValue (CAP_STYLE_ATTRIBUTES, "internal");
// external css files are supported.
- static public Object STYLES_EXTERNAL =
+ static public final Object STYLES_EXTERNAL =
CapabilityValue.getCapabilityValue (CAP_STYLE_ATTRIBUTES, "external");
// Values for CAP_CSS_SELECTORS
- static public Object SELECTORS_NONE =
+ static public final Object SELECTORS_NONE =
CapabilityValue.getCapabilityValue (CAP_CSS_SELECTORS, "none");
- static public Object SELECTORS_SINGLE =
+ static public final Object SELECTORS_SINGLE =
CapabilityValue.getCapabilityValue (CAP_CSS_SELECTORS, "single");
- static public Object SELECTORS_MULTIPLE =
+ static public final Object SELECTORS_MULTIPLE =
CapabilityValue.getCapabilityValue (CAP_CSS_SELECTORS, "multiple");
/**
@@ -255,31 +259,192 @@
*/
static public final int TYPE_VOICE = 3;
-
-
+ /**
+ * Enumeration representing an Application
+ */
+ public static enum Application
+ {
+ /**
+ * Application enum when the user agent isn't known.
+ */
+ UNKNOWN("0", AGENT_UNKNOWN),
+ /**
+ * Application enum for the Netscape Navigator browser.
+ */
+ NETSCAPE("netscape", AGENT_NETSCAPE),
+ /**
+ * Application enum for the Microsoft Internet Explorer browser.
+ */
+ IEXPLORER("ie", AGENT_IE),
+ /**
+ * Application enum for browsers based on the Gecko Layout Engine,
+ * eg: Mozilla, Netscape 7.0+
+ */
+ GECKO("gecko", AGENT_GECKO, "mozilla"),
+ /**
+ * Application enum for Palm Web Clippings
+ */
+ WEB_CLIPPING("web-clipping", AGENT_ELAINE),
+ /**
+ * Application enum for the ICE Browser
+ */
+ ICE("ice", AGENT_ICE_BROWSER, "ice"),
+ /**
+ * Application enum for the Pixo Microbrowser
+ */
+ PIXO("pixo", AGENT_PIXO),
+ /**
+ * Application enum for the WML Microbrowser
+ */
+ WML("wml", "wml"),
+ /**
+ * Application enum for SimpleResult intermediate Form
+ */
+ SIMPLE_RESULT("simple-result", "simple-result"),
+ /**
+ * Application enum for iAS wireless (PTG) client
+ */
+ PTG("ptg", AGENT_PTG),
+ /**
+ * Application enum for the NetFront browser.
+ */
+ NET_FRONT("netfront", AGENT_NETFRONT),
+ /**
+ * Application enum for the Safari browser.
+ */
+ SAFARI("safari", AGENT_WEBKIT),
+ /**
+ * Application enum for the BlackBerry browser.
+ */
+ BLACKBERRY("blackberry", AGENT_BLACKBERRY),
+ /**
+ * Application enum for the Nokia S60 browser.
+ */
+ NOKIA_S60("nokia_s60", AGENT_NOKIA_S60),
+ /**
+ * Application enum for the basic HTMLbrowser.
+ */
+ GENERICPDA("genericpda", AGENT_GENERICPDA),
+ /**
+ * Application enum for Konqueror.
+ */
+ KONQUEROR("konqueror", AGENT_KONQUEROR),
+ /**
+ * Application enum for email.
+ */
+ EMAIL("email", AGENT_EMAIL),
+ /**
+ * Application enum for opera.
+ */
+ OPERA("opera", AGENT_OPERA);
+
+ /**
+ * Return the appropriate Application instance given the name of an Application
+ * @param applicationName Name of application to return the instance of
+ * @return Then Application instance for this name, if any
+ */
+ public static Application fromApplicationName(String applicationName)
+ {
+ return StateHolder.NAME_TO_APPLICATION.get(applicationName);
+ }
+
+ /**
+ * Return the appropriate Application instance given the name of an Agent. For
+ * backwards compatibility reasons, alias names for some Agents are also supported.
+ * @param agentName Name of Agent to return the instance of
+ * @return Then Application instance for this name, if any
+ */
+ public static Application fromAgentName(String agentName)
+ {
+ return StateHolder.AGENT_TO_APPLICATION.get(agentName);
+ }
+
+ /**
+ * @param applicationName application name for this Application
+ * @param agentName agent name for this Application
+ */
+ private Application(String applicationName, String agentName)
+ {
+ this(applicationName, agentName, null);
+ }
+
+ /**
+ * @param applicationName application name for this Application
+ * @param agentName agent name for this Application
+ * @param agentAlias additional agent name, if any, to support for look ups
+ */
+ private Application(String applicationName, String agentName, String agentAlias)
+ {
+ _applicationName = applicationName;
+ _agentName = agentName;
+
+ StateHolder.NAME_TO_APPLICATION.put(applicationName, this);
+
+ Map<String, Application> agentToApplication = StateHolder.AGENT_TO_APPLICATION;
+ agentToApplication.put(agentName, this);
+
+ // if we have an alias for this agent name, register that as well
+ if (agentAlias != null)
+ agentToApplication.put(agentAlias, this);
+ }
+
+ /**
+ * Returns the application name that this Application is registered under
+ * @return application name that this Application is registered under
+ */
+ public String getApplicationName()
+ {
+ return _applicationName;
+ }
+
+ /**
+ * Returns the agent name that this Application is registered under
+ * @return agent name that this Application is registered under
+ */
+ public String getAgentName()
+ {
+ return _agentName;
+ }
+
+ private final String _applicationName;
+ private final String _agentName;
+
+ /**
+ * Holds the maps of agent name and application name to Application object. By
+ * using a separate class, we avoid restrictions on Enums refrerencing static
+ * variables from their constructors.
+ */
+ private static class StateHolder
+ {
+ static public final Map<String, Application> NAME_TO_APPLICATION = new HashMap<String, Application>();
+ static public final Map<String, Application> AGENT_TO_APPLICATION = new HashMap<String, Application>();
+ }
+ }
+
+
/**
* Application constant for an entirely unknown application.
*/
- static public final int APPLICATION_UNKNOWN = 0;
+ static public final int APPLICATION_UNKNOWN = Application.UNKNOWN.ordinal();
/**
* Application constant for the Netscape Navigator browser.
* Note that Netscape 6 is considered as Mozilla, since
* its rendering engine is that of the Mozilla project.
*/
- static public final int APPLICATION_NETSCAPE = 1;
+ static public final int APPLICATION_NETSCAPE = Application.NETSCAPE.ordinal();
/**
* Application constant for the Microsoft Internet Explorer
* browser.
*/
- static public final int APPLICATION_IEXPLORER = 2;
+ static public final int APPLICATION_IEXPLORER = Application.IEXPLORER.ordinal();
/**
* Application constant for browsers based on the Gecko Layout Engine,
* eg: Mozilla, Netscape 7.0+
*/
- static public final int APPLICATION_GECKO = 3;
+ static public final int APPLICATION_GECKO = Application.GECKO.ordinal();
/**
* Application constant for the Mozilla browser, or browsers
@@ -292,72 +457,72 @@
/**
* Application constant for Palm Web Clippings
*/
- static public final int APPLICATION_WEB_CLIPPING = 4;
+ static public final int APPLICATION_WEB_CLIPPING = Application.WEB_CLIPPING.ordinal();
/**
* Application constant for the ICE Browser
*/
- static public final int APPLICATION_ICE = 5;
+ static public final int APPLICATION_ICE = Application.ICE.ordinal();
/**
* Application constant for the Pixo Microbrowser
*/
- static public final int APPLICATION_PIXO = 6;
+ static public final int APPLICATION_PIXO = Application.PIXO.ordinal();
/**
* Application constant for a WML Microbrowser
*/
- static public final int APPLICATION_WML = 7;
+ static public final int APPLICATION_WML = Application.WML.ordinal();
/**
* Application constant for SimpleResult intermediate Form
*/
- static public final int APPLICATION_SIMPLE_RESULT = 8;
+ static public final int APPLICATION_SIMPLE_RESULT = Application.SIMPLE_RESULT.ordinal();
/**
* Application constant for iAS wireless (PTG) client
*/
- static public final int APPLICATION_PTG = 9;
+ static public final int APPLICATION_PTG = Application.PTG.ordinal();
/**
* Application constant for the NetFront browser.
*/
- static public final int APPLICATION_NET_FRONT = 10;
+ static public final int APPLICATION_NET_FRONT = Application.NET_FRONT.ordinal();
/**
* Application constant for the Safari browser.
*/
- static public final int APPLICATION_SAFARI = 11;
+ static public final int APPLICATION_SAFARI = Application.SAFARI.ordinal();
/**
* Application constant for the BlackBerry browser.
*/
- static public final int APPLICATION_BLACKBERRY = 12;
+ static public final int APPLICATION_BLACKBERRY = Application.BLACKBERRY.ordinal();
/**
* Application constant for the Nokia S60 browser.
*/
- static public final int APPLICATION_NOKIA_S60 = 13;
+ static public final int APPLICATION_NOKIA_S60 = Application.NOKIA_S60.ordinal();
/**
* Application constant for the basic HTMLbrowser.
*/
- static public final int APPLICATION_GENERICPDA = 14;
+ static public final int APPLICATION_GENERICPDA = Application.GENERICPDA.ordinal();
/**
* Application constant for Konqueror.
*/
- static public final int APPLICATION_KONQUEROR = 15;
+ static public final int APPLICATION_KONQUEROR = Application.KONQUEROR.ordinal();
/**
* Application constant for email.
*/
- static public final int APPLICATION_EMAIL = 16;
+ static public final int APPLICATION_EMAIL = Application.EMAIL.ordinal();
/**
* Application constant for opera.
*/
- static public final int APPLICATION_OPERA = 17;
+ static public final int APPLICATION_OPERA = Application.OPERA.ordinal();
/**
* OS constant for an unknown operating system.
@@ -518,43 +683,41 @@
* Returns the type of agent to which we're rendering. Currently,
* only web browsers are understood.
*/
- public int getAgentType();
+ public abstract int getAgentType();
/**
* Returns the specific application to which we're rendering.
- * Returns APPLICATION_UNKNOWN is the application couldn't
+ * Returns Application.UNKNOWN is the application couldn't
* be identified.
*/
- public int getAgentApplication();
+ public abstract Application getAgentApplication();
/**
* Returns the major version number of the application, or 0
* if a version number couldn't be identified.
*/
- public int getAgentMajorVersion();
-
-
+ public abstract int getAgentMajorVersion();
+
/**
- * Returns the full, unparsed version string. Returns null
- * if no version string could be identified.
+ * Returns the Version identifier to use for comparing the Version of this Agent to other
+ * Versions.
*/
- public String getAgentVersion();
-
+ public abstract Version getVersion();
/**
* Returns the client operating system. Returns OS_UNKNOWN if the
* operating system can't be identified.
*/
- public int getAgentOS();
+ public abstract int getAgentOS();
/**
* Returns a capability of a TrinidadAgent
*/
- public Object getCapability(CapabilityKey key);
+ public abstract Object getCapability(CapabilityKey key);
- public Object clone();
+ public abstract Object clone();
/*
* @return <code>String</code> object that represents an agent's
@@ -562,5 +725,21 @@
* Agents with the same name can have different skin families
* if agents' versions or platforms are different.
*/
- public String getSkinFamilyType();
+ public abstract String getSkinFamilyType();
+
+ /**
+ * Convenienc method for cloning by subclases.
+ */
+ protected final TrinidadAgent cloneTrinidadAgent()
+ {
+ try
+ {
+ return (TrinidadAgent) super.clone();
+ }
+ catch (CloneNotSupportedException cnse)
+ {
+ assert false;
+ return null;
+ }
+ }
}
Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgentImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgentImpl.java?rev=894905&r1=894904&r2=894905&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgentImpl.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgentImpl.java Thu Dec 31 17:39:14 2009
@@ -28,28 +28,48 @@
import javax.faces.context.FacesContext;
+import org.apache.myfaces.trinidad.context.Version;
import org.apache.myfaces.trinidad.util.ClassLoaderUtils;
/**
* implementation that supports the AdfFacesAgent
- *
*/
-public class TrinidadAgentImpl implements TrinidadAgent, Cloneable
+public class TrinidadAgentImpl extends TrinidadAgent
{
public TrinidadAgentImpl(FacesContext context, Agent agent)
{
_delegate = agent;
- _initialize(context);
- }
+ _type = AgentNameUtil.getAgentType(getType());
+ _application = Application.fromAgentName(getAgentName());
+ _os = AgentNameUtil.getPlatform(getPlatformName());
+
+ String versionString = getAgentVersion();
+
+ if (Application.GECKO == _application)
+ _major = 1;
+ else
+ _major = _getMajorVersion(versionString);
+
+ _version = new Version(versionString);
+
+ _skinFamilyType = _getSkinFamilyType(_os, _application);
+ _capMap = _getCapabilityMap(context);
+
+ Map<Object, Object> requestCaps = _delegate.getCapabilities();
+
+ if (requestCaps != null)
+ {
+ _capMap = _capMap.merge(requestCaps);
+ }
+ }
public TrinidadAgentImpl(Agent agent)
{
this (null, agent);
}
-
/**
* @return return the Type of Agent.
* <br>E.g. desktop, pda, phone, voice
@@ -79,10 +99,10 @@
/**
* Returns the specific application to which we're rendering.
- * Returns APPLICATION_UNKNOWN is the application couldn't
+ * Returns Application.UNKNOWN is the application couldn't
* be identified.
*/
- public int getAgentApplication()
+ public Application getAgentApplication()
{
return _application;
}
@@ -96,6 +116,16 @@
}
/**
+ * Returns the Version identifier to use for comparing the Version of this Agent to other
+ * Versions.
+ * @return This Agent's Version
+ */
+ public Version getVersion()
+ {
+ return _version;
+ }
+
+ /**
* Returns the major version number of the application, or 0
* if a version number couldn't be identified.
*/
@@ -169,17 +199,9 @@
@Override
public Object clone()
{
- try
- {
- TrinidadAgentImpl that = (TrinidadAgentImpl) super.clone();
- that._capMap = (CapabilityMap) _capMap.clone();
- return that;
- }
- catch (CloneNotSupportedException cnse)
- {
- assert false;
- return null;
- }
+ TrinidadAgentImpl that = (TrinidadAgentImpl)cloneTrinidadAgent();
+ that._capMap = (CapabilityMap) _capMap.clone();
+ return that;
}
@@ -233,25 +255,6 @@
return new String(buffer);
}
- private void _initialize(FacesContext context)
- {
- _type = AgentNameUtil.getAgentType(getType());
- _application = AgentNameUtil.getAgent(getAgentName());
- _os = AgentNameUtil.getPlatform(getPlatformName());
-
- if (APPLICATION_GECKO == _application)
- _major = 1;
- else
- _major = _getMajorVersion(getAgentVersion());
- _setskinFamilyType();
- _capMap = _getCapabilityMap(context);
- Map<Object, Object> requestCaps = _delegate.getCapabilities();
- if (requestCaps != null)
- {
- _capMap = _capMap.merge(requestCaps);
- }
- }
-
/**
* intialization must have happened beforre calling this methodb
*/
@@ -389,44 +392,44 @@
* the agent's CSS-support. Agents with the same name can have different
* skin families if the agents' versions or platforms are different.
*/
- void _setskinFamilyType()
+ private String _getSkinFamilyType(int os, Application application)
{
- if (_os == TrinidadAgent.OS_PPC)
+ if (os == TrinidadAgent.OS_PPC)
{
- _skinFamilyType = TrinidadAgent.SKIN_WINDOWS_MOBILE;
+ return TrinidadAgent.SKIN_WINDOWS_MOBILE;
}
- else if (_application == TrinidadAgent.APPLICATION_NOKIA_S60)
+ else if (application == TrinidadAgent.Application.NOKIA_S60)
{
- _skinFamilyType = TrinidadAgent.SKIN_WEBKIT_NOKIA;
+ return TrinidadAgent.SKIN_WEBKIT_NOKIA;
}
- else if (_application == TrinidadAgent.APPLICATION_SAFARI)
+ else if (application == TrinidadAgent.Application.SAFARI)
{
- if (_os == TrinidadAgent.OS_IPHONE)
+ if (os == TrinidadAgent.OS_IPHONE)
{
- _skinFamilyType = TrinidadAgent.SKIN_WEBKIT_IPHONE;
+ return TrinidadAgent.SKIN_WEBKIT_IPHONE;
}
- else if (_os == TrinidadAgent.OS_LINUX)
+ else if (os == TrinidadAgent.OS_LINUX)
{
- _skinFamilyType = TrinidadAgent.SKIN_WEBKIT_LINUX;
+ return TrinidadAgent.SKIN_WEBKIT_LINUX;
}
- else if (_os == TrinidadAgent.OS_MACOS)
+ else if (os == TrinidadAgent.OS_MACOS)
{
- _skinFamilyType = TrinidadAgent.SKIN_WEBKIT_MAC;
+ return TrinidadAgent.SKIN_WEBKIT_MAC;
}
- else if (_os == TrinidadAgent.OS_WINDOWS)
+ else if (os == TrinidadAgent.OS_WINDOWS)
{
- _skinFamilyType = TrinidadAgent.SKIN_WEBKIT_WINDOWS;
+ return TrinidadAgent.SKIN_WEBKIT_WINDOWS;
}
else
{
- _skinFamilyType = TrinidadAgent.SKIN_WEBKIT_DEFAULT;
+ return TrinidadAgent.SKIN_WEBKIT_DEFAULT;
}
}
- else if (_application == TrinidadAgent.APPLICATION_GENERICPDA)
+ else if (application == TrinidadAgent.Application.GENERICPDA)
{
- _skinFamilyType = TrinidadAgent.SKIN_GENERIC_PDA;
+ return TrinidadAgent.SKIN_GENERIC_PDA;
}
- else if (_application == TrinidadAgent.APPLICATION_BLACKBERRY)
+ else if (application == TrinidadAgent.Application.BLACKBERRY)
{
// BlackBerry browsers' versions are in the format x.y.z.[...]
// (x,y and z are numerals). For determining the skin-family, truncate
@@ -438,13 +441,15 @@
if (Float.parseFloat(version) > 4.5)
{
- _skinFamilyType = TrinidadAgent.SKIN_BLACKBERRY;
+ return TrinidadAgent.SKIN_BLACKBERRY;
}
else
{
- _skinFamilyType = TrinidadAgent.SKIN_BLACKBERRY_MINIMAL;
+ return TrinidadAgent.SKIN_BLACKBERRY_MINIMAL;
}
}
+
+ return null;
}
void __mergeCapabilities(Map<Object, Object> capabilities)
@@ -467,13 +472,12 @@
private static boolean _deviceRepositoryLoaded;
private static DeviceRepository _deviceRepository;
- private Agent _delegate;
+ private final Agent _delegate;
private CapabilityMap _capMap;
- private int _type;
- private int _application;
- private int _os;
- private int _major;
- private String _skinFamilyType;
-
-
+ private final int _type;
+ private final Application _application;
+ private final int _os;
+ private final int _major;
+ private final String _skinFamilyType;
+ private final Version _version;
}
Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/HiddenLabelUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/HiddenLabelUtils.java?rev=894905&r1=894904&r2=894905&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/HiddenLabelUtils.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/HiddenLabelUtils.java Thu Dec 31 17:39:14 2009
@@ -44,7 +44,7 @@
TrinidadAgent agent = ((CoreRenderingContext) arc).getTrinidadAgent();
switch (agent.getAgentApplication())
{
- case TrinidadAgent.APPLICATION_IEXPLORER:
+ case IEXPLORER:
if (agent.getAgentOS() == TrinidadAgent.OS_WINDOWS)
{
// IE 4 doesn't support the label hack.
@@ -63,11 +63,11 @@
return false;
// Mozilla does support the label hack
- case TrinidadAgent.APPLICATION_GECKO:
+ case GECKO:
return true;
// Assume everyone else doesn't.
- case TrinidadAgent.APPLICATION_NETSCAPE:
+ case NETSCAPE:
default:
return false;
}
Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/MediaRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/MediaRenderer.java?rev=894905&r1=894904&r2=894905&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/MediaRenderer.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/MediaRenderer.java Thu Dec 31 17:39:14 2009
@@ -443,7 +443,7 @@
// =-= bts only desktop IE seems to support this
// Move this to capability
return !((agent.getAgentType() == TrinidadAgent.TYPE_DESKTOP) &&
- (agent.getAgentApplication() == TrinidadAgent.APPLICATION_IEXPLORER) &&
+ (agent.getAgentApplication() == TrinidadAgent.Application.IEXPLORER) &&
(agent.getAgentOS() == TrinidadAgent.OS_WINDOWS));
}
Added: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/AgentAtRuleMatcher.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/AgentAtRuleMatcher.java?rev=894905&view=auto
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/AgentAtRuleMatcher.java (added)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/AgentAtRuleMatcher.java Thu Dec 31 17:39:14 2009
@@ -0,0 +1,641 @@
+/*
+ * 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.skin;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+
+import java.util.regex.Pattern;
+
+import org.apache.myfaces.trinidad.context.Version;
+import org.apache.myfaces.trinidad.util.CollectionUtils;
+import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
+import org.apache.myfaces.trinidadinternal.style.util.NameUtils;
+
+/**
+ * Threadsafe immutable class that stores the @agent rule for a particular @agent query string
+ * from the skinning css file (e.g., @agent ie and (version:5), ie and (version:6), gecko {}).
+ * This class is used to match the current agent against the @agent rule.
+ * @see StyleSheetNode
+ * @see NameUtils
+ */
+public final class AgentAtRuleMatcher
+{
+ /**
+ * Enumeration representing the result of a call to <code>match</code>.
+ * @see #match
+ */
+ public enum Match
+ {
+ /** The Match matched the agent applications */
+ APPLICATION,
+ /** The Match matched the agent version */
+ VERSION
+ };
+
+ /**
+ * Constructor used by bogus XSS files to create a version matcher for a list of browsers and
+ * versions. Since XSS has no syntax to specify separate versions for each browser, all
+ * browsers share the same version and only Version equality comparison is supported, though
+ * since Version equality comparisons support wild-cards, this isn't as limiting as it might
+ * seem.
+ * @param browsers List of TrinidadAgent.Applications representing the browsers that this matcher
+ * matches
+ * @param versions Optional array of Version objects of the Versions to match
+ */
+ public AgentAtRuleMatcher(List<TrinidadAgent.Application> browsers, Version[] versions)
+ {
+ //
+ // create the Set of VersionMatchers shared by all of the browsers
+ //
+ int versionCount = (versions != null) ? versions.length : 0;
+
+ AgentMatcher[] versionMatchers;
+
+ if (versionCount == 0)
+ {
+ versionMatchers = null;
+ }
+ else
+ {
+ versionMatchers = new AgentMatcher[versionCount];
+
+ for (int i = 0; i < versionCount; i++)
+ {
+ // XSS only supports equals comparisons
+ versionMatchers[i] = new VersionMatcher(versions[i], Comparison.EQUALS);
+ }
+ }
+
+ Set<AgentMatcher> versionSet = CollectionUtils.asSet(versionMatchers);
+
+ //
+ // Create the Map from TrinidadAgent.Application to the Set of AgentMatchers we created
+ // above. Since the most common cases are to have 0 or 1 entry, we special case to reduce
+ // memory consumption.
+ // ==-= btsulliv Actually, we should really further optimize the 0 case and create a single
+ // constant empty matcher and check for that case and return it at the top
+ // of this function.
+ int browserCount = browsers.size();
+
+ Map<TrinidadAgent.Application, Set<AgentMatcher>> browserMap;
+
+ if (browserCount == 0)
+ browserMap = Collections.emptyMap();
+ else if (browserCount == 1)
+ browserMap = Collections.singletonMap(browsers.get(0), versionSet);
+ else
+ {
+ browserMap = new HashMap<TrinidadAgent.Application, Set<AgentMatcher>>(browserCount);
+
+ //in XSS there's now way of having multiple browsers and multiple versions
+ //if encountered, we map all versions to each browser (it works for 1 browser)
+ for (int i=0; i < browserCount ; i++)
+ {
+ browserMap.put(browsers.get(i), versionSet);
+ }
+ }
+
+ _selectorAgents = browserMap;
+ }
+
+ /**
+ * Creates an AgentAtRuleMatcher from an @agent query string. if the @agent rule were
+ * <code>@agent ie and (version:8), gecko and (version:1.9) { .foo {background-color:red}}</code>
+ * the query string would be <code>"ie and (version:8), gecko and (version:1.9)"</code>
+ * @param queryString String containing the query portion of the @agent at-rule
+ */
+ public AgentAtRuleMatcher(String queryString)
+ {
+ // split each of the comma-separated 'or' pieces into separate strings from processing
+ this(queryString.split(","));
+ }
+
+
+ /**
+ * Creates an AgentAtRuleMatcher from a decomposed array of @agent query selectors. With one
+ * array entry for each comma-separated selector.
+ * if the @agent rule were
+ * <code>@agent ie and (version:8), gecko and (version:1.9) { .foo {background-color:red}}</code>
+ * the decomposed selectors would be:
+ * <code>selector[0] = "ie and (version:8)"; selector[1] = "gecko and (version:1.9)";</code>
+ * @param selectors Array of query selectors with one selector for every or'ed rule
+ */
+ public AgentAtRuleMatcher(String[] selectors)
+ {
+ Map<TrinidadAgent.Application, Set<AgentMatcher>> selectorAgents = Collections.emptyMap();
+
+ // process each of the selectors to build the Map of the AgentMatchers to run for any
+ // particular agent in this array of rules.
+ for (int selectorIndex = 0; selectorIndex < selectors.length; selectorIndex++)
+ {
+ // parse the agent versions. Examples:
+ // @agent ie and (version:6)
+ // @agent ie and (version:6.*)
+ // @agent ie and (version:5.0.*)
+ // @agent ie and (min-version:5.*) and (max-version:6)
+ // @agent ie and (version:6), ie and (version:7), gecko and (version:1.1)
+
+ String currSelector = selectors[selectorIndex];
+
+ // split each of the sections between the "and"s. For example
+ // gecko and (min-version:1.5) and (max-version:1.9) would result in
+ // {"gecko", "(min-version:1.5)", "(max-version:1.9)"}
+ String[] sections = _AND_SPLITTER.split(currSelector);
+
+ // the agent is always the first section and is required.
+ // We trim because we are often passed strings with trailing whitespace
+ String agentName = sections[0].trim();
+
+ // convert the name of the agent to its TrinidadAgent.Application enum
+ TrinidadAgent.Application browser = NameUtils.getAgentApplication(agentName);
+
+ // turn the array of sections into the Set of AgentMatchers
+ //
+ if (browser != TrinidadAgent.Application.UNKNOWN)
+ {
+ int sectionCount = sections.length;
+
+ Set<AgentMatcher> agentMatchers;
+
+ if (sectionCount == 1)
+ {
+ // we only have the agent identifier, so no matchers
+ agentMatchers = Collections.emptySet();
+ }
+ else
+ {
+ AgentMatcher newVersionMatcher;
+
+ if (sectionCount > 2)
+ {
+ // we have multiple ands, so we need to build up the list of sections to pass to
+ // to the AndMatcher, which will AND the results of each of the matches together
+ List<AgentMatcher> andedMatchers = new ArrayList<AgentMatcher>(sectionCount - 1);
+
+ // create version matchers for each section
+ for (int sectionIndex = 1; sectionIndex < sectionCount; sectionIndex++)
+ {
+ andedMatchers.add(_getVersionMatcher(sections[sectionIndex]));
+ }
+
+ newVersionMatcher = new AndMatcher(andedMatchers);
+ }
+ else
+ {
+ // only a single and with a version match, so return that matcher directly
+ newVersionMatcher = _getVersionMatcher(sections[1]);
+ }
+
+ // if you have selectors that repeat the browser, then get the agentMatchers that
+ // you have so far for that browser so you can append to it.
+ // @agent ie and (version: 6), ie and (version: 7), gecko and (version: 1.9)
+ // Th comma ORs the rules together.
+ agentMatchers = selectorAgents.get(browser);
+
+ // create the Version Set if it doesn't already exist, or add the Version to the
+ // current Version Set if it isn't already in there. Since most Version entries are
+ // a single value, we optimize for that case
+ if ((agentMatchers == null) || agentMatchers.isEmpty())
+ agentMatchers = Collections.singleton(newVersionMatcher);
+ else if (!agentMatchers.contains(newVersionMatcher))
+ {
+ // we didn't already have an entry for this matcher. If the old size is 1, then
+ // the current set is going to be a Collections.singleton(), which is immutable,
+ // so we need to copy the the singleton Set into a HashSet, which IS mutable
+ if (agentMatchers.size() == 1)
+ agentMatchers = new HashSet<AgentMatcher>(agentMatchers);
+
+ agentMatchers.add(newVersionMatcher);
+ }
+ }
+
+ // optimize the size of the SelectorAgents Map when we add the new Versions
+ if (selectorAgents.isEmpty())
+ selectorAgents = Collections.singletonMap(browser, agentMatchers);
+ else if (!agentMatchers.equals(selectorAgents.get(browser)))
+ {
+ if (selectorAgents.size() == 1)
+ {
+ // similar issue as with the Set case above. If the Map currently has only one
+ // entry, then we have an immutable singleton Map and we need to copy the single item
+ // out into a new mutable Map. Chances are, this map isn't going to be very big, so
+ // a size of 3 seems a good start.
+ Map<TrinidadAgent.Application, Set<AgentMatcher>> newSelectorAgents =
+ new HashMap<TrinidadAgent.Application, Set<AgentMatcher>>(3);
+
+ // get the single entry out of here so we can add it into the new mutable map
+ Map.Entry<TrinidadAgent.Application, Set<AgentMatcher>> singleEntry =
+ selectorAgents.entrySet().iterator().next();
+
+ newSelectorAgents.put(singleEntry.getKey(), singleEntry.getValue());
+
+ selectorAgents = newSelectorAgents;
+ }
+
+ // add the new mapping
+ selectorAgents.put(browser, agentMatchers);
+ }
+ }
+ }
+
+ _selectorAgents = selectorAgents;
+ }
+
+ /**
+ * Given a property selector of the form
+ * (<opt whitespace><identifier><opt whitespace>:<opt whitespace><version><opt whitespace>)
+ * where "identifier" can be "min-version", "max-version" or "version" and "value" represents
+ * a browser or HTML layout engine version number, return a VersionMatcher that will
+ * perform the correct comparison against the current Agent.
+ * @param propertySelector String containing the type of version comparison and version value
+ * to match
+ * @return VersionMatcher for the property selector
+ */
+ private VersionMatcher _getVersionMatcher(String propertySelector)
+ {
+ // split out the separate <identifier> and <version> parts of the property selector. The
+ // <identifier> will be in the first group, the <version> in the second.
+ Matcher m = _PROPERTY_SPLITTER.matcher(propertySelector);
+
+ if (m.find())
+ {
+ String propName = m.group(1);
+ String version = m.group(2);
+
+ // turn the property name--either "min-version", "max-version" or "version" into the
+ // type of comparison to perform
+ Comparison comparison = _COMPARISON_PARSER.get(propName);
+
+ if (comparison == null)
+ {
+ throw new IllegalArgumentException("Invalid @agent property name: " + propName);
+ }
+
+ // create the new Version, padding the version number out with wildcards
+ Version newVersion = new Version(version, "*");
+
+ return new VersionMatcher(newVersion, comparison);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Invalid @agent property selector: " + propertySelector);
+ }
+ }
+
+ /**
+ * <p>
+ * Called to actually determine if this AgentAtRuleMatcher applies to the current agent. The
+ * result is a Set of Match constants indicating how precise the match is. While all anded
+ * rules must match for the match to succeed, some callers need information regarding whether
+ * the Version information was also necessary in order for the match to succeed. For example,
+ * when generating CSS files, the version information is only part of the CSS name if the
+ * generated CSS file for the agent contained version-dependent content.
+ * </p>
+ * <p>
+ * There are three possible return values
+ * <ol>
+ * <li>An empty Set, indicating no match</li>
+ * <li>A set containing <code>Match.APPLICATION</code>, indicating a match that only needed to
+ * match against the agent Application</li>
+ * <li>A set containing both <code>Match.APPLICATION</code> and <code>Match.VERSION</code>,
+ * indicating that both the agent Application and its version needed to be matched against</li>
+ * </ol>
+ * @param agent Agent to test for compatibility with
+ * @return the Set of successful matches, if any
+ */
+ public Set<Match> match(TrinidadAgent agent)
+ {
+ // If we have browser exact match, compare versions
+ TrinidadAgent.Application browser = agent.getAgentApplication();
+
+ if (_selectorAgents.containsKey(browser))
+ {
+ Set<AgentMatcher> agentMatchers = _selectorAgents.get(browser);
+ if (agentMatchers.isEmpty())
+ return _APPLICATION_ONLY_MATCH;
+
+ for (AgentMatcher currMatcher : agentMatchers)
+ {
+ if (currMatcher.match(agent))
+ {
+ return _APPLICATION_AND_VERSION_MATCH;
+ }
+ }
+ }
+
+ return _NO_MATCH;
+ }
+
+ @Override
+ public boolean equals(Object other)
+ {
+ if (this == other)
+ return true;
+ else
+ {
+ if (other instanceof AgentAtRuleMatcher)
+ {
+ return _selectorAgents.equals(((AgentAtRuleMatcher)other)._selectorAgents);
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return _selectorAgents.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return super.toString() + "agents=" + _selectorAgents.toString();
+ }
+
+ // the type of comparison to perform on the version
+ private static enum Comparison {
+ EQUALS, // Compared object must be equal
+ MIN, // Compared object must be less than or equal to
+ MAX}; // Compared object must be greater than or equal to
+
+ /**
+ * <p>
+ * Abstract class that all matchers against Agents must implement.
+ * </p>
+ * <p>
+ * <code>match(TrinidadAgent)</code> is called to determine if the match succeeds.
+ * </p>
+ * <p>
+ * Since the AgentMatchers
+ * are added to Maps (or sets that use Maps in the implementation), they are required to
+ * implement <code>equals</code> and <code>hashCode</code>
+ * </p>
+ * <p>
+ * While used to hide the differences between VersionMatchers and AndMatchers,
+ * this class should be abstract enough to support any new types of Agent matchers that we might
+ * want to add in the future.
+ * </p>
+ * @see #match
+ */
+ private static abstract class AgentMatcher
+ {
+ /**
+ * Returns <code>true</code> if the AgentMatcher matches the Agent
+ * @param agent Agent to check against
+ * @return <code>true</code> if the match succeeds
+ */
+ public abstract boolean match(TrinidadAgent agent);
+
+ @Override
+ public abstract int hashCode();
+
+ @Override
+ public abstract boolean equals(Object o);
+ }
+
+ /**
+ * Immutable and thread-safe AgentMatcher that matches the supplied Version against the
+ * version of a TrinidadAgent using the supplied, MAX, MIN, or EQUALS Comparison
+ */
+ private static class VersionMatcher extends AgentMatcher
+ {
+ /**
+ * Creates a VersionMatcher
+ * @param version Version to compare with
+ * @param comparison Comparison to perform
+ */
+ public VersionMatcher(Version version, Comparison comparison)
+ {
+ _version = version;
+ _comparison = comparison;
+ }
+
+ /**
+ * Matches the Version of this VersionMatcher against the Version of the supplied Agent,
+ * using the VersionMatcher's comparison
+ * @param agent Agent to check the Version of
+ * @return <code>true</code> if the comparison is successful
+ */
+ @Override
+ public boolean match(TrinidadAgent agent)
+ {
+ // use the Version's comparator
+ int result = _version.compareTo(agent.getVersion());
+
+ // since MIN means less than or equal to and MAX means greater than or equal to, a result
+ // of equality always means success
+ if (result == 0)
+ return true;
+ else
+ {
+ switch (_comparison)
+ {
+ case MIN:
+ return result < 0; // min version has to be less than current version
+
+ case MAX:
+ return result > 0; // max version has to be bigger than current version
+
+ case EQUALS:
+ return false; // if the result were equal, we wouldn't have gotten this far
+
+ default:
+ assert false : "Unknown comparison type " + _comparison;
+ return false; // this should never happen, but the compiler doesn't know that
+ }
+ }
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return _version.hashCode() * 37 + _comparison.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object other)
+ {
+ if (this == other)
+ return true;
+ else
+ {
+ if (other instanceof VersionMatcher)
+ {
+ VersionMatcher otherVersionMatcher = (VersionMatcher)other;
+
+ return _version.equals(otherVersionMatcher._version) &&
+ _comparison.equals(otherVersionMatcher._comparison);
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return super.toString() + ", version=" + _version + ", comparison=" + _comparison;
+ }
+
+ private final Version _version;
+ private final Comparison _comparison;
+ }
+
+ /**
+ * AgentMatcher that ANDs the results of all calling match() on its AgentMatchers together,
+ * short-circuiting on the first AgentMatcher.match() that returns false.
+ */
+ private static class AndMatcher extends AgentMatcher
+ {
+ /**
+ * Creates an AndMatcher
+ * @param matchers List of AgentMatchers to AND together
+ */
+ public AndMatcher(List<AgentMatcher> matchers)
+ {
+ // =-= btsulliv should we do anything if matchers contains fewer than two items? The code
+ // will still work, it just suggests a lack of optimization in the caller
+ _matchers = matchers;
+
+ // cache the hashcode so we don't traverse the list asking all of the other matchers for
+ // their hash codes each time our hash code is called
+ _hashCode = matchers.hashCode();
+ }
+
+ /**
+ * @param agent Agent to match againt
+ * @return <code>true</code> if all of the matchers matched the Agent
+ */
+ @Override
+ public boolean match(TrinidadAgent agent)
+ {
+ int matcherCount = _matchers.size();
+
+ for (int i = 0; i < matcherCount; i++)
+ {
+ // a matcher failed, so no sense in trying to match any more. Let's pick up our
+ // ball and go home
+ if (!_matchers.get(i).match(agent))
+ return false;
+ }
+
+ // all of the matchers matched. Yay!
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return _hashCode;
+ }
+
+ @Override
+ public boolean equals(Object other)
+ {
+ if (this == other)
+ return true;
+ else
+ {
+ if (other instanceof AndMatcher)
+ {
+ return _matchers.equals(((AndMatcher)other)._matchers);
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return super.toString() + ", matchers=" + _matchers;
+ }
+
+ private final List<AgentMatcher> _matchers;
+ private final int _hashCode;
+ }
+
+ // RegExp Pattern used to breaking apart the property selectors into a separate property name
+ // and value. The property selectors are in the form:
+ // (<opt whitespace><prop name><opt whitespace>:<opt whitespace><prop value><opt whitespace>)
+ // This isn't as complicated as it seems at first. Taking it from outside-in
+ // 1) The double backslashes are because Java Strings already use backslashes for escaping, so
+ // a double backslash is necessary in order to generate the single backslash needed for RegExp,
+ // so this is really the RegExp pattern
+ // \(\s*([A-Za-z0-9_-]+)\s*:\s*(\S+)\s*\)
+ // 2) We are using parentheses for both exact character matching (the parentheses at the ends of
+ // the RegExp), and for RegExp grouping (so that we can extract the property name and value.
+ // Notice that since we need to exactly match the parentheses at the ends, they are escaped.
+ // Removing these gives us:
+ // \s*([A-Za-z0-9_-]+)\s*:\s*(\S+)\s*
+ // 3) The \s* represent the option white space, removing these gives us the grouping expressions
+ // for the property name:([A-Za-z0-9_-]+) and property value (\S+)
+ // The property name is allowed to contain one or more word characters, plush the character '-'
+ // (needed for min-version and max-version), while the property value can contain any
+ // non-whitespace character
+ private static final Pattern _PROPERTY_SPLITTER =
+ Pattern.compile("\\(\\s*([A-Za-z0-9_-]+)\\s*:\\s*(\\S+)\\s*\\)");
+
+ // used for splitting up the agenet selectors between the "and"s. Just in case a "sand" operator
+ // is added later, we require the "and" to be surrounded with whitespace.
+ private static final Pattern _AND_SPLITTER = Pattern.compile("\\s+and\\s+");
+
+ // constants representing the three types of Match sets match returns
+ private static final Set<Match> _NO_MATCH = Collections.emptySet();
+ private static final Set<Match> _APPLICATION_ONLY_MATCH = Collections.singleton(Match.APPLICATION);
+
+ private static final Set<Match> _APPLICATION_AND_VERSION_MATCH =
+ Collections.unmodifiableSet(EnumSet.of(Match.APPLICATION, Match.VERSION));
+
+
+ // map of property names to the types of comparison to use for each name
+ private static final Map<String, Comparison> _COMPARISON_PARSER;
+
+ static
+ {
+ // initialize property-name to Comparison type Map. Thread-safe because the Map is not
+ // modified after initialization
+ _COMPARISON_PARSER = new HashMap<String, Comparison>(4);
+
+ _COMPARISON_PARSER.put("version", Comparison.EQUALS);
+ _COMPARISON_PARSER.put("max-version", Comparison.MAX);
+ _COMPARISON_PARSER.put("min-version", Comparison.MIN);
+ }
+
+ // As we need to be able to have multiple version matching rules for the same agent:
+ // @agent ie and (version:5), ie and (version:6), gecko.
+ // We store a map of agents and their version sets
+ private final Map<TrinidadAgent.Application, Set<AgentMatcher>> _selectorAgents;
+}
Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java?rev=894905&r1=894904&r2=894905&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java Thu Dec 31 17:39:14 2009
@@ -26,8 +26,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.apache.myfaces.trinidad.context.Version;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
@@ -112,7 +110,7 @@
CompleteSelectorNode node =
_createCompleteSelectorNode(selector,
_propertyNodeList,
- _selectorAgents,
+ _agentAtRuleMatcher,
_selectorPlatforms,
_getSelectorAccProperties());
_completeSelectorNodeList.add(node);
@@ -225,7 +223,7 @@
String type)
{
if (_AT_AGENT.equals(type))
- _selectorAgents = null;
+ _agentAtRuleMatcher = null;
else if (_AT_PLATFORM.equals(type))
_selectorPlatforms = null;
else if (_AT_ACC_PROFILE.equals(type))
@@ -242,7 +240,7 @@
private CompleteSelectorNode _createCompleteSelectorNode(
String selector,
List<PropertyNode> propertyNodeList,
- Map<Integer, Set<Version>> selectorAgentVersions,
+ AgentAtRuleMatcher agentMatcher,
int[] selectorPlatforms,
Set<String> selectorAccProperties)
{
@@ -269,7 +267,7 @@
selector,
propertyNodeList,
direction,
- selectorAgentVersions,
+ agentMatcher,
selectorPlatforms,
selectorAccProperties);
}
@@ -293,7 +291,7 @@
{
// we add to the ssNodeList in this method.
int direction = completeSelectorNode.getDirection();
- Map<Integer, Set<Version>> agentVersions = completeSelectorNode.getAgentVersions();
+ AgentAtRuleMatcher agentMatcher = completeSelectorNode.getAgentMatcher();
int[] platforms = completeSelectorNode.getPlatforms();
Set<String> accProperties = completeSelectorNode.getAccessibilityProperties();
@@ -306,16 +304,16 @@
for (int i = skinStyleSheetNodes.size() - 1; i >= 0 && !match; --i)
{
SkinStyleSheetNode ssNode = skinStyleSheetNodes.get(i);
- match = ssNode.matches(direction, agentVersions, platforms, accProperties);
+ match = ssNode.matches(direction, agentMatcher, platforms, accProperties);
if (match)
ssNode.add(completeSelectorNode.getSkinSelectorPropertiesNode());
}
if (!match)
{
- // no matching stylesheet node found, so create a new one
+ // no matching stylesheet node found, so create a new one
SkinStyleSheetNode ssNode =
- new SkinStyleSheetNode(namespaceMap, direction, agentVersions, platforms, accProperties);
+ new SkinStyleSheetNode(namespaceMap, direction, agentMatcher, platforms, accProperties);
ssNode.add(completeSelectorNode.getSkinSelectorPropertiesNode());
skinStyleSheetNodes.add(ssNode);
}
@@ -345,48 +343,7 @@
if (_AT_AGENT.equals(type))
{
- _selectorAgents = new HashMap<Integer, Set<Version>>();
-
- for (int i=0; i < typeArray.length; i++)
- {
- // TODO: support min-version and max-version
- // parse the agent versions. Examples:
- // @agent ie and (version:6)
- // @agent ie and (version:6.*)
- // @agent ie and (version:5.0.*)
- // @agent ie and (version:5.*) and (version:6)
-
- String[] sections = _WHITESPACE_PATTERN.split(typeArray[i].trim(), 2);
-
- // currently the type must be first
- if (sections.length == 0)
- {
- throw new IllegalArgumentException("Invalid @agent string: " + typeArray[i]);
- }
- int agentInt = NameUtils.getBrowser(sections[0]);
- if (agentInt != TrinidadAgent.APPLICATION_UNKNOWN)
- {
- Set<Version> versions = new HashSet<Version>();
- _selectorAgents.put(agentInt, versions);
-
- if (sections.length == 2)
- {
- Matcher m = _AND_MEDIA_PROPERTY_SPLITTER.matcher(sections[1]);
-
- while (m.find())
- {
- String propName = m.group(1);
- String version = m.group(2);
-
- if (!"version".equals(propName))
- {
- throw new IllegalArgumentException("Invalid @agent property name: " + propName);
- }
- versions.add(new Version(version, "*"));
- }
- }
- }
- }
+ _agentAtRuleMatcher = new AgentAtRuleMatcher(typeArray);
}
else if (_AT_PLATFORM.equals(type))
{
@@ -545,19 +502,17 @@
String selectorName,
List<PropertyNode> propertyNodes,
int direction,
- Map<Integer, Set<Version>> agentVersions,
+ AgentAtRuleMatcher agentMatcher,
int[] platforms,
Set<String> accProperties
)
{
_node = new SkinSelectorPropertiesNode(selectorName, propertyNodes);
_direction = direction;
+
// copy the agents and platforms because these get nulled out
// at the end of the @rule parsing.
- _agentVersions = agentVersions != null ?
- new HashMap<Integer, Set<Version>>(agentVersions) :
- new HashMap<Integer, Set<Version>>();
-
+ _agentMatcher = agentMatcher;
_platforms = _copyIntArray(platforms);
if (accProperties != null)
@@ -567,6 +522,10 @@
// the pattern used for the agents/platforms arrays.
_accProperties = new HashSet<String>(accProperties);
}
+ else
+ {
+ _accProperties = null;
+ }
}
public SkinSelectorPropertiesNode getSkinSelectorPropertiesNode()
@@ -580,11 +539,11 @@
}
/**
- * @return The versions of the agent to be supported
+ * @return The AgentMatcher if any for this rule
*/
- public Map<Integer, Set<Version>> getAgentVersions()
+ public AgentAtRuleMatcher getAgentMatcher()
{
- return _agentVersions;
+ return _agentMatcher;
}
public int[] getPlatforms()
@@ -609,11 +568,11 @@
return copy;
}
- private SkinSelectorPropertiesNode _node;
- private int _direction; // the reading direction
- private Map<Integer, Set<Version>> _agentVersions;
- private int[] _platforms;
- private Set<String> _accProperties;
+ private final SkinSelectorPropertiesNode _node;
+ private final int _direction; // the reading direction
+ private final AgentAtRuleMatcher _agentMatcher;
+ private final int[] _platforms;
+ private final Set<String> _accProperties;
}
private static String _AT_AGENT = "@agent";
@@ -632,9 +591,8 @@
// selectors we are currently parsing in this document.
private int[] _selectorPlatforms = null;
- // As we need to be able to have multiple versions to an agent
- // we store a map of agents and their version sets
- private Map<Integer, Set<Version>> _selectorAgents = null;
+ // matches the current Agent against the allowed agents
+ private AgentAtRuleMatcher _agentAtRuleMatcher = null;
// Stack of accessibility property sets. While java.util.Stack has the
// push/pop API that we want, we don't need the synchronization, so we
@@ -645,12 +603,6 @@
private Map<String, String> _namespaceMap = new HashMap<String, String>();
private static final TrinidadLogger _LOG =
TrinidadLogger.createTrinidadLogger(SkinCSSDocumentHandler.class);
-
- private static final Pattern _WHITESPACE_PATTERN =
- Pattern.compile("\\s+");
-
- private static final Pattern _AND_MEDIA_PROPERTY_SPLITTER =
- Pattern.compile("\\band\\s+\\((\\w+)\\s*:\\s*(\\S+)\\s*\\)");
}
Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java?rev=894905&r1=894904&r2=894905&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java Thu Dec 31 17:39:14 2009
@@ -24,8 +24,6 @@
import java.util.Map;
import java.util.Set;
-import org.apache.myfaces.trinidad.context.Version;
-
/** Stores information about the .css skin file.
* namespaceMap, a List of SkinSelectorPropertiesNodes, and direction.
* @todo honor the namespaces that are set in the css file. For now, we ignore
@@ -43,26 +41,27 @@
List<SkinSelectorPropertiesNode> skinSelectorNodeList,
Map<String, String> namespaceMap,
int direction,
- Map<Integer, Set<Version>> agentVersions,
+ AgentAtRuleMatcher agentMatcher,
Set<String> accProperties)
{
_skinSelectorNodeList = skinSelectorNodeList;
_namespaceMap = namespaceMap;
_direction = direction;
- _agentVersions = agentVersions;
+ _agentMatcher = agentMatcher;
+ _platforms = null;
_accProperties = accProperties;
}
SkinStyleSheetNode(
Map<String, String> namespaceMap,
int direction,
- Map<Integer, Set<Version>> agentVersions,
+ AgentAtRuleMatcher agentMatcher,
int[] platforms,
Set<String> accProperties)
{
_namespaceMap = namespaceMap;
_direction = direction;
- _agentVersions = agentVersions;
+ _agentMatcher = agentMatcher;
_platforms = platforms;
_accProperties = accProperties;
}
@@ -104,9 +103,9 @@
/**
* @return a set of the supported agent versions
*/
- public Map<Integer, Set<Version>> getAgentVersions()
+ public AgentAtRuleMatcher getAgentMatcher()
{
- return _agentVersions;
+ return _agentMatcher;
}
public int[] getPlatforms()
@@ -121,13 +120,13 @@
public boolean matches(
int direction,
- Map<Integer, Set<Version>> agentVersions,
+ AgentAtRuleMatcher agentMatcher,
int[] platforms,
Set<String> accProperties)
{
if (direction == _direction)
{
- boolean agentsMatch = _mapsEqual(agentVersions, _agentVersions);
+ boolean agentsMatch = _objectsEqual(agentMatcher, _agentMatcher);
if (agentsMatch)
{
@@ -155,18 +154,18 @@
private boolean _setsEqual(Set<?> s1, Set<?> s2)
{
- return (s1 == null)? (s2 == null): (s1.equals(s2));
+ return _objectsEqual(s1, s2);
}
- private boolean _mapsEqual(Map<?, ?> m1, Map<?, ?> m2)
+ private boolean _objectsEqual(Object o1, Object o2)
{
- return (m1 == null)? (m2 == null): (m1.equals(m2));
+ return (o1 == o2) || ((o1 != null) && o1.equals(o2));
}
- private Map<String, String> _namespaceMap;
+ private final Map<String, String> _namespaceMap;
private List<SkinSelectorPropertiesNode> _skinSelectorNodeList;
- private int _direction; // reading direction
- private Map<Integer, Set<Version>> _agentVersions;
- private int[] _platforms;
- private Set<String> _accProperties;
+ private final int _direction; // reading direction
+ private final AgentAtRuleMatcher _agentMatcher;
+ private final int[] _platforms;
+ private final Set<String> _accProperties;
}
Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java?rev=894905&r1=894904&r2=894905&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java Thu Dec 31 17:39:14 2009
@@ -268,7 +268,7 @@
trSkinPropertyNodeList,
null,/*locales, not yet supported*/
skinSSNode.getDirection(),
- skinSSNode.getAgentVersions(),
+ skinSSNode.getAgentMatcher(),
skinSSNode.getPlatforms(),
0,
skinSSNode.getAcessibilityProperties());
Modified: myfaces/trinidad/branches/1.2.12.2-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.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java?rev=894905&r1=894904&r2=894905&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java Thu Dec 31 17:39:14 2009
@@ -1065,7 +1065,7 @@
{
//don't worry about synchronizing this
_hashCode = (_direction) ^
- (_browser << 2) ^
+ (_browser.ordinal() << 2) ^
(_platform << 8) ^
(_short ? 1 : 0) ^
(_portlet ? 1:0);
@@ -1110,7 +1110,7 @@
private void _init(
Locale locale,
int direction,
- int browser,
+ TrinidadAgent.Application browser,
String version,
int platform,
boolean useShort,
@@ -1141,7 +1141,7 @@
private Locale _locale;
private int _direction;
- private int _browser;
+ private TrinidadAgent.Application _browser;
private String _version;
private int _platform;
private boolean _short; // Do we use short style classes?
Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java?rev=894905&r1=894904&r2=894905&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java Thu Dec 31 17:39:14 2009
@@ -222,7 +222,7 @@
}
if (numberSelectorsWritten + matchingStyles.length >= _MSIE_SELECTOR_LIMIT
- && TrinidadAgent.APPLICATION_IEXPLORER == context.getAgent().getAgentApplication())
+ && TrinidadAgent.Application.IEXPLORER == context.getAgent().getAgentApplication())
{
out.println("/* The number of CSS selectors in this file is " +
numberSelectorsWritten + " */");