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 2010/01/05 22:32:47 UTC
svn commit: r896231 [1/2] - in /myfaces/trinidad/trunk:
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-impl/src/main/java/org/apache/myfaces/...
Author: jwaldman
Date: Tue Jan 5 21:32:45 2010
New Revision: 896231
URL: http://svn.apache.org/viewvc?rev=896231&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
Also fix bug where the css file was missing most of the selectors from the .xss skinning files.
The reason was that the AgentAtRuleMatcher was being checked, even for StyleSheetNode's that did not have browsers specified.
Therefore only the StyleSheetNodes with browsers specified and that matched the user's browser were being included in the css.
Modified:
myfaces/trinidad/trunk/src/site/xdoc/devguide/skinning.xml
myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/Version.java
myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/CollectionUtils.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentNameUtil.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentUtil.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgentImpl.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/HiddenLabelUtils.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/MediaRenderer.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java
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/cache/FileSystemStyleCache.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/NameUtils.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/data/bind/IsAgentApplicationBoundValue.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/expl/UIFunctions.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/NameAndAgentScorer.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/ApplicationSwitcherRenderer.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/BaseDesktopUtils.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/ButtonRenderer.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/HeaderRenderer.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/HtmlLafRenderer.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/PageLayoutRenderer.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/FormElementRenderer.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/GlobalButtonBarRenderer.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/HiddenLabelUtils.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/NavigationBarRenderer.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/XhtmlLafUtils.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/partial/PartialPageRendererUtils.java
myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeEqualsTest.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=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/src/site/xdoc/devguide/skinning.xml (original)
+++ myfaces/trinidad/trunk/src/site/xdoc/devguide/skinning.xml Tue Jan 5 21:32:45 2010
@@ -829,15 +829,27 @@
</li>
<li>
<strong>@agent</strong> {/skin definitions go here/} - >
- Possible values are: netscape, ie, mozilla, gecko, opera, webkit (maps to safari), ice, email.
+ Possible values are: netscape, ie, mozilla, gecko, webkit (maps to safari), ice, email.
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 +859,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/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/Version.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/Version.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/Version.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/Version.java Tue Jan 5 21:32:45 2010
@@ -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/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/CollectionUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/CollectionUtils.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/CollectionUtils.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/CollectionUtils.java Tue Jan 5 21:32:45 2010
@@ -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/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentNameUtil.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentNameUtil.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentNameUtil.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentNameUtil.java Tue Jan 5 21:32:45 2010
@@ -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/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentUtil.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentUtil.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentUtil.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentUtil.java Tue Jan 5 21:32:45 2010
@@ -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/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java Tue Jan 5 21:32:45 2010
@@ -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/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgentImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgentImpl.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgentImpl.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgentImpl.java Tue Jan 5 21:32:45 2010
@@ -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/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/HiddenLabelUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/HiddenLabelUtils.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/HiddenLabelUtils.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/HiddenLabelUtils.java Tue Jan 5 21:32:45 2010
@@ -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/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/MediaRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/MediaRenderer.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/MediaRenderer.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/MediaRenderer.java Tue Jan 5 21:32:45 2010
@@ -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));
}
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinCSSDocumentHandler.java Tue Jan 5 21:32:45 2010
@@ -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/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetNode.java Tue Jan 5 21:32:45 2010
@@ -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/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=896231&r1=896230&r2=896231&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 Tue Jan 5 21:32:45 2010
@@ -268,7 +268,7 @@
trSkinPropertyNodeList,
null,/*locales, not yet supported*/
skinSSNode.getDirection(),
- skinSSNode.getAgentVersions(),
+ skinSSNode.getAgentMatcher(),
skinSSNode.getPlatforms(),
0,
skinSSNode.getAcessibilityProperties());
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java Tue Jan 5 21:32:45 2010
@@ -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/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java Tue Jan 5 21:32:45 2010
@@ -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 + " */");
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/NameUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/NameUtils.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/NameUtils.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/NameUtils.java Tue Jan 5 21:32:45 2010
@@ -23,8 +23,8 @@
import java.util.Set;
import java.util.Vector;
-import org.apache.myfaces.trinidad.context.Version;
import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
+import org.apache.myfaces.trinidadinternal.skin.AgentAtRuleMatcher;
import org.apache.myfaces.trinidadinternal.style.StyleContext;
import org.apache.myfaces.trinidadinternal.style.xml.XMLConstants;
import org.apache.myfaces.trinidadinternal.style.xml.parse.StyleSheetDocument;
@@ -43,91 +43,22 @@
/**
* Returns the id of the browser with the specified name
*/
- public static int getBrowser(String browserName)
+ public static TrinidadAgent.Application getAgentApplication(String agentName)
{
- if (browserName == null)
- return TrinidadAgent.APPLICATION_UNKNOWN;
-
- int browser = TrinidadAgent.APPLICATION_UNKNOWN;
-
- if (_BROWSER_NETSCAPE.equals(browserName))
- browser = TrinidadAgent.APPLICATION_NETSCAPE;
- else if (_BROWSER_IE.equals(browserName))
- browser = TrinidadAgent.APPLICATION_IEXPLORER;
- else if (_BROWSER_GECKO.equals(browserName) ||
- _BROWSER_MOZILLA.equals(browserName))
- browser = TrinidadAgent.APPLICATION_GECKO;
- else if (_BROWSER_ICE.equals(browserName))
- browser = TrinidadAgent.APPLICATION_ICE;
- else if (_BROWSER_WEBKIT.equals(browserName))
- browser = TrinidadAgent.APPLICATION_SAFARI;
- else if (_BROWSER_OPERA.equals(browserName))
- browser = TrinidadAgent.APPLICATION_OPERA;
- else if (_BROWSER_BLACKBERRY.equals(browserName))
- browser = TrinidadAgent.APPLICATION_BLACKBERRY;
- else if (_BROWSER_NOKIA_S60.equals(browserName))
- browser = TrinidadAgent.APPLICATION_NOKIA_S60;
- else if (_BROWSER_GENERICPDA.equals(browserName))
- browser = TrinidadAgent.APPLICATION_GENERICPDA;
- else if (_BROWSER_EMAIL.equals(browserName))
- browser = TrinidadAgent.APPLICATION_EMAIL;
- else
+ if (agentName == null)
+ return TrinidadAgent.Application.UNKNOWN;
+
+ TrinidadAgent.Application application = TrinidadAgent.Application.fromAgentName(agentName);
+
+ if (application == null)
{
// Either a new or an invalid browser
- assert false:"Invalid browser name: " + browserName;
+ assert false:"Invalid browser name: " + agentName;
+
+ application = TrinidadAgent.Application.UNKNOWN;
}
-
- return browser;
- }
-
- /**
- * Returns the name of the specified browser id
- */
- public static String getBrowserName(int browser)
- {
- String name = null;
-
- switch (browser)
- {
- case TrinidadAgent.APPLICATION_NETSCAPE:
- name = _BROWSER_NETSCAPE;
- break;
- case TrinidadAgent.APPLICATION_IEXPLORER:
- name = _BROWSER_IE;
- break;
- case TrinidadAgent.APPLICATION_GECKO:
- name = _BROWSER_GECKO;
- break;
- case TrinidadAgent.APPLICATION_ICE:
- name = _BROWSER_ICE;
- break;
- case TrinidadAgent.APPLICATION_SAFARI:
- name = _BROWSER_WEBKIT;
- break;
- case TrinidadAgent.APPLICATION_OPERA:
- name = _BROWSER_OPERA;
- break;
- case TrinidadAgent.APPLICATION_BLACKBERRY:
- name = _BROWSER_BLACKBERRY;
- break;
- case TrinidadAgent.APPLICATION_NOKIA_S60:
- name = _BROWSER_NOKIA_S60;
- break;
- case TrinidadAgent.APPLICATION_GENERICPDA:
- name = _BROWSER_GENERICPDA;
- break;
- case TrinidadAgent.APPLICATION_EMAIL:
- name = _BROWSER_EMAIL;
- break;
- case TrinidadAgent.APPLICATION_UNKNOWN:
- // This case is only here to avoid the default assertion
- break;
- default:
- // New or invalid browser id
- assert false:"Invalid browser id: " +browser;
- }
-
- return name;
+
+ return application;
}
/**
@@ -500,13 +431,9 @@
// Get the browser as a String
private static String _getBrowserString(StyleContext context)
{
- int browser = context.getAgent().getAgentApplication();
- String name = getBrowserName(browser);
-
- if (name == null)
- return _UNKNOWN_NAME;
-
- return name;
+ TrinidadAgent.Application application = context.getAgent().getAgentApplication();
+
+ return application.getApplicationName();
}
// get the StyleSheetDocument's id.
@@ -644,36 +571,40 @@
private static boolean[] _isBrowserAndVersionMatch(StyleContext context,
StyleSheetNode[] styleSheets)
{
- int browser = context.getAgent().getAgentApplication();
- Version version = new Version(context.getAgent().getAgentVersion());
- if (browser == TrinidadAgent.APPLICATION_UNKNOWN)
+ TrinidadAgent agent = context.getAgent();
+ TrinidadAgent.Application browser = agent.getAgentApplication();
+ if (browser == TrinidadAgent.Application.UNKNOWN)
{
return new boolean[] { false, false };
}
boolean browserMatched = false;
- Integer browserNum = Integer.valueOf(browser);
// If any style sheet has a non-null browser variant, we must
// have a browser match.
for (int i = 0; i < styleSheets.length; i++)
{
- if (!styleSheets[i].getAgentVersions().isEmpty())
+ AgentAtRuleMatcher agentMatcher = styleSheets[i].getAgentMatcher();
+
+ if (agentMatcher != null)
{
- Set<Version> versions = styleSheets[i].getAgentVersions().get(browserNum);
+ Set<AgentAtRuleMatcher.Match> matches = agentMatcher.match(agent);
- if (versions != null)
+ if (matches.contains(AgentAtRuleMatcher.Match.APPLICATION))
{
+ // latch the browser matched
browserMatched = true;
- for (Version av : versions)
- {
- if (av.compareTo(version) == 0)
- {
- return new boolean[] { true, true };
- }
- }
+
+ // we can't match better than application and version, so return immediately
+ if (matches.contains(AgentAtRuleMatcher.Match.VERSION))
+ return new boolean[] { true, true };
}
}
+ else
+ {
+ // no agent matcher, so all agents match
+ browserMatched = true;
+ }
}
return new boolean[] { browserMatched, false };
@@ -745,29 +676,6 @@
private static final String _DIRECTION_RTL = "rtl";
private static final String _DIRECTION_LTR = "ltr";
-
- // Browser constants
- private static final String _BROWSER_NETSCAPE = "netscape";
-
- private static final String _BROWSER_IE = "ie";
-
- private static final String _BROWSER_MOZILLA = "mozilla";
-
- private static final String _BROWSER_GECKO = "gecko";
-
- private static final String _BROWSER_WEBKIT = "webkit";
-
- private static final String _BROWSER_ICE = "ice";
-
- private static final String _BROWSER_BLACKBERRY = "blackberry";
-
- private static final String _BROWSER_NOKIA_S60 = "nokia_s60";
-
- private static final String _BROWSER_GENERICPDA = "genericpda";
-
- private static final String _BROWSER_EMAIL = "email";
-
- private static final String _BROWSER_OPERA = "opera";
// Platform constants
private static final String _PLATFORM_WINDOWS = "windows";
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNode.java Tue Jan 5 21:32:45 2010
@@ -32,6 +32,7 @@
import org.apache.myfaces.trinidad.context.AccessibilityProfile;
import org.apache.myfaces.trinidad.context.Version;
import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
+import org.apache.myfaces.trinidadinternal.skin.AgentAtRuleMatcher;
import org.apache.myfaces.trinidadinternal.style.util.ModeUtils;
import org.apache.myfaces.trinidadinternal.style.util.NameUtils;
import org.apache.myfaces.trinidadinternal.style.xml.XMLConstants;
@@ -58,7 +59,7 @@
Collection<SkinPropertyNode> skinProperties,
Locale[] locales,
int direction,
- Map<Integer, Set<Version>> agentVersions,
+ AgentAtRuleMatcher agentMatcher,
int[] platforms,
int mode,
Set<String> accessibilityProperties
@@ -91,12 +92,7 @@
else
_locales = Collections.emptySet();
- if (agentVersions != null)
- {
- _agentVersions = Collections.unmodifiableMap(agentVersions);
- }
- else
- _agentVersions = Collections.emptyMap();
+ _agentMatcher = agentMatcher;
if (platforms != null)
{
@@ -169,12 +165,11 @@
}
/**
- * Implementation of StyleSheetNode.getAgentVersions().
- * @return a map containing each browser type mapped to its versions set
+ * @return AgentAtRuleMatcher for matching @Agent selectors
*/
- public Map<Integer, Set<Version>> getAgentVersions()
+ public AgentAtRuleMatcher getAgentMatcher()
{
- return _agentVersions;
+ return _agentMatcher;
}
/**
@@ -216,10 +211,8 @@
int directionMatch = _compareDirection(direction);
if (directionMatch == 0)
return 0;
-
- int browser = agent.getAgentApplication();
- int browserAndVersionMatch = _compareBrowserAndVersion(browser, agent);
+ int browserAndVersionMatch = _compareBrowserAndVersion(agent);
if (browserAndVersionMatch == 0)
return 0;
int modeMatch = _compareMode(mode);
@@ -278,8 +271,7 @@
return getClass().getName() + "[" +
"locales=" + (_locales != null ? _locales.toString() : "") + ", " +
"direction=" + _getDirectionString() + ", " +
- "agentVersions=" + (_agentVersions != null ? _agentVersions.toString() : "") + ", " +
-// "versions=" + _versions.toString() + ", " +
+ "agentVersions=" + (_agentMatcher != null ? _agentMatcher.toString() : "") + ", " +
"platforms=" + (_platforms != null ? _platforms.toString() : "") + ", " +
"styles=" + (_styles != null ? _styles.toString() : "") + ", " +
"icons=" + (_icons != null ? _icons.toString() :"") + ", " +
@@ -317,7 +309,7 @@
hash = 37*hash + _mode;
hash = 37*hash + _direction;
hash = 37*hash + _locales.hashCode();
- hash = 37*hash + _agentVersions.hashCode();
+ hash = 37*hash + ((_agentMatcher != null) ? _agentMatcher.hashCode() : 0);
hash = 37*hash + _platforms.hashCode();
hash = 37*hash + _styles.hashCode();
hash = 37*hash + _accProps.hashCode();
@@ -385,39 +377,36 @@
}
//Compares the browser and its version against the supported variants
- private int _compareBrowserAndVersion(int browser, TrinidadAgent agent)
+ private int _compareBrowserAndVersion(TrinidadAgent agent)
{
// If we don't have a browser specified, we match anything
- if (_agentVersions.isEmpty())
+ if (_agentMatcher == null)
return _BROWSER_UNKNOWN_MATCH;
+ TrinidadAgent.Application application = agent.getAgentApplication();
+
// On the other hand, if we do have a browser specified, but
// the client browser is not known, we don't have a match
- if (browser == TrinidadAgent.APPLICATION_UNKNOWN)
+ if (application == TrinidadAgent.Application.UNKNOWN)
return 0;
- //If we have browser exact match, compare versions
- Integer browserNum = Integer.valueOf(browser);
- if (_agentVersions.containsKey(browserNum))
+ Set<AgentAtRuleMatcher.Match> matches = _agentMatcher.match(agent);
+
+ int matchResult = _NO_MATCH;
+
+ // first check that we have a match against the browser
+ if (matches.contains(AgentAtRuleMatcher.Match.APPLICATION))
{
- Set<Version> versions = _agentVersions.get(browserNum);
- if (versions.isEmpty())
- return _BROWSER_EXACT_MATCH | _VERSION_UNKNOWN_MATCH;
-
- Version version = new Version(agent.getAgentVersion());
-
- for (Version av : versions)
- {
- if (av.compareTo(version) == 0)
- {
- return _BROWSER_EXACT_MATCH | _VERSION_EXACT_MATCH;
- }
- }
+ matchResult |= _BROWSER_EXACT_MATCH;
- return 0;
+ // check if the browser also specified a version match that we matched
+ int versionMatch = (matches.contains(AgentAtRuleMatcher.Match.VERSION))
+ ? _VERSION_EXACT_MATCH
+ : _VERSION_UNKNOWN_MATCH;
+ matchResult |= versionMatch;
}
- return 0;
+ return matchResult;
}
@@ -582,18 +571,17 @@
// Order does not matter for locales, browsers, versions, platforms
private final Set<Locale> _locales; // The locale variants
private final int _direction; // The reading direction
- // The browsers mapped to their versions (multiple versions for browser supported)
- // The Integer value is the APPLICATION value in TrinidadAgent, like if
- // Integer is 3, it is APPLICATION_GECKO.
- // TODO It would be clearer to make the Integer an Enum, and to make the
- // Application constants an enum.
- private final Map<Integer, Set<Version>> _agentVersions;
+
+ // matches Agent at-rules
+ private final AgentAtRuleMatcher _agentMatcher;
private final Set<Integer> _platforms; // The platform variants
private final int _mode; // The mode
private final Set<String> _accProps; // Accessibility profile properties
private final int _id; // The cached style sheet id
// Constants for accessibility matches - 0x0f000000 bits
+ private static final int _NO_MATCH = 0;
+
private static final int _ACC_EXACT_MATCH = 0x02000000;
private static final int _ACC_UNKNOWN_MATCH = 0x01000000;
@@ -616,7 +604,7 @@
// Constants for version matches - 0x000000f0 bits
private static final int _VERSION_EXACT_MATCH = 0x00000020;
- private static final int _VERSION_UNKNOWN_MATCH = 0x00000020;
+ private static final int _VERSION_UNKNOWN_MATCH = 0x00000010;
// Constants for os matches - 0x0000000f bits
private static final int _OS_EXACT_MATCH = 0x00000004;
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetNodeParser.java Tue Jan 5 21:32:45 2010
@@ -18,10 +18,13 @@
*/
package org.apache.myfaces.trinidadinternal.style.xml.parse;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -34,6 +37,7 @@
import org.apache.myfaces.trinidadinternal.share.xml.NodeParser;
import org.apache.myfaces.trinidadinternal.share.xml.ParseContext;
import org.apache.myfaces.trinidadinternal.share.xml.XMLUtils;
+import org.apache.myfaces.trinidadinternal.skin.AgentAtRuleMatcher;
import org.apache.myfaces.trinidadinternal.style.StyleConstants;
import org.apache.myfaces.trinidadinternal.style.util.NameUtils;
import org.apache.myfaces.trinidadinternal.style.xml.XMLConstants;
@@ -61,7 +65,7 @@
_initLocales(attrs.getValue(LOCALES_ATTR));
_direction = NameUtils.getDirection(attrs.getValue(DIRECTION_ATTR));
_mode = NameUtils.getMode(attrs.getValue(MODE_ATTR));
- _initBrowsers(attrs.getValue(BROWSERS_ATTR));
+ _browsers = _initBrowsers(attrs.getValue(BROWSERS_ATTR));
_initVersions(attrs.getValue(VERSIONS_ATTR));
_initPlatforms(attrs.getValue(PLATFORMS_ATTR));
_initAccessibilityProperties(attrs.getValue(ACC_PROFILE_ATTR));
@@ -83,33 +87,18 @@
styles = new StyleNode[_styles.size()];
_styles.copyInto(styles);
}
-
- int versionCount = (_versions != null) ? _versions.length : 0;
-
- Set<Version> versions = new HashSet<Version>(versionCount);
- for (int i = 0; i < versionCount ; i++)
- {
- versions.add(_versions[i]);
- }
-
- int browserCount = (_browsers != null) ? _browsers.length : 0;
- Map<Integer, Set<Version>> browsers
- = new HashMap<Integer, Set<Version>>(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++)
- {
- browsers.put(_browsers[i], new HashSet<Version>(versions));
- }
-
+ // Do not create an agentMatcher if there are no browsers or versions to compare against.
+ // This way a styleSheetNode will match any browser if it hasn't specified a specific browser.
+ AgentAtRuleMatcher agentMatcher =
+ (_browsers.isEmpty()) ? null : new AgentAtRuleMatcher(_browsers, _versions);
+
return new StyleSheetNode(
styles,
null, // icons only supported in skin CSS - not XSS
null, // properties only supported in skin CSS - not XSS
_locales,
_direction,
- browsers,
+ agentMatcher,
_platforms,
_mode,
_accProperties
@@ -196,24 +185,23 @@
}
// Initialize browsers
- private void _initBrowsers(String browserAttr)
+ private List<TrinidadAgent.Application> _initBrowsers(String browserAttr)
{
Iterator<String> browsers = _getTokens(browserAttr);
if (browsers == null)
- return;
+ return Collections.emptyList();
- // -= Simon Lessard =-
- // TODO: Check if synchronization is really needed.
- Vector<Integer> v = new Vector<Integer>();
+ List<TrinidadAgent.Application> applications = new ArrayList<TrinidadAgent.Application>();
+
while (browsers.hasNext())
{
- int browser = NameUtils.getBrowser(browsers.next());
+ TrinidadAgent.Application browser = NameUtils.getAgentApplication(browsers.next());
- if (browser != TrinidadAgent.APPLICATION_UNKNOWN)
- v.addElement(browser);
+ if (browser != TrinidadAgent.Application.UNKNOWN)
+ applications.add(browser);
}
-
- _browsers = _getIntegers(v);
+
+ return applications;
}
// Initialize version
@@ -324,7 +312,7 @@
private Locale[] _locales;
private int _direction;
private int _mode;
- private int[] _browsers;
+ private List<TrinidadAgent.Application> _browsers;
private Version[] _versions;
private int[] _platforms;
private Set<String> _accProperties;
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/data/bind/IsAgentApplicationBoundValue.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/data/bind/IsAgentApplicationBoundValue.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/data/bind/IsAgentApplicationBoundValue.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/data/bind/IsAgentApplicationBoundValue.java Tue Jan 5 21:32:45 2010
@@ -50,7 +50,7 @@
UIXRenderingContext context
)
{
- return Boolean.valueOf(_app == context.getAgent().getAgentApplication());
+ return Boolean.valueOf(_app == context.getAgent().getAgentApplication().ordinal());
}
private int _app;
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/expl/UIFunctions.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/expl/UIFunctions.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/expl/UIFunctions.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/expl/UIFunctions.java Tue Jan 5 21:32:45 2010
@@ -96,7 +96,7 @@
String text, String breakChars)
{
UIXRenderingContext rc = uix.getRenderingContext();
- int agentApp = rc.getAgent().getAgentApplication();
+ TrinidadAgent.Application agentApp = rc.getAgent().getAgentApplication();
// bug 3364275
@@ -114,9 +114,9 @@
final char breakHint;
- if ((agentApp == TrinidadAgent.APPLICATION_IEXPLORER) ||
- (agentApp == TrinidadAgent.APPLICATION_GECKO) ||
- (agentApp == TrinidadAgent.APPLICATION_NETSCAPE))
+ if ((agentApp == TrinidadAgent.Application.IEXPLORER) ||
+ (agentApp == TrinidadAgent.Application.GECKO) ||
+ (agentApp == TrinidadAgent.Application.NETSCAPE))
{
// insert the special unicode character that tells the output method to
// use the <wbr> tag. This character is recognized by HTMLEscapes:
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/NameAndAgentScorer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/NameAndAgentScorer.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/NameAndAgentScorer.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/NameAndAgentScorer.java Tue Jan 5 21:32:45 2010
@@ -77,7 +77,7 @@
TrinidadAgent agent = context. getAgent();
int typeScore = _score(_agentType, agent.getAgentType());
- int appScore = _score(_agentApplication, agent.getAgentApplication());
+ int appScore = _score(_agentApplication, agent.getAgentApplication().ordinal());
int versScore = _score(_agentMajorVersion, agent.getAgentMajorVersion());
int osScore = _score(_agentOS, agent.getAgentOS());
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/ApplicationSwitcherRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/ApplicationSwitcherRenderer.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/ApplicationSwitcherRenderer.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/ApplicationSwitcherRenderer.java Tue Jan 5 21:32:45 2010
@@ -226,7 +226,7 @@
writer.startElement(TABLE_DATA_ELEMENT, null);
if ( context.getAgent().getAgentApplication()
- != TrinidadAgent.APPLICATION_NETSCAPE)
+ != TrinidadAgent.Application.NETSCAPE)
writer.writeAttribute("valign", "bottom", null);
}
@@ -284,7 +284,7 @@
writer.startElement(TABLE_DATA_ELEMENT, null);
if ( context.getAgent().getAgentApplication()
- != TrinidadAgent.APPLICATION_NETSCAPE)
+ != TrinidadAgent.Application.NETSCAPE)
writer.writeAttribute("valign", "bottom", null);
// render goto button
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/BaseDesktopUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/BaseDesktopUtils.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/BaseDesktopUtils.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/BaseDesktopUtils.java Tue Jan 5 21:32:45 2010
@@ -96,7 +96,7 @@
Score score = super.scoreLookAndFeel(context, lafName);
// We don't support Netscape 4.x
- if (TrinidadAgent.APPLICATION_NETSCAPE ==
+ if (TrinidadAgent.Application.NETSCAPE ==
context.getAgent().getAgentApplication())
{
score = new ScoreProxy(score)
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/ButtonRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/ButtonRenderer.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/ButtonRenderer.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/ButtonRenderer.java Tue Jan 5 21:32:45 2010
@@ -334,11 +334,11 @@
// In screen reader mode, "middle" instead of "absmiddle" for vAlign to
// comply with 4.01 HTML Spec.
- int application = context.getAgent().getAgentApplication();
+ TrinidadAgent.Application application = context.getAgent().getAgentApplication();
Object align;
- if ((application == TrinidadAgent.APPLICATION_NETSCAPE)
- || (application == TrinidadAgent.APPLICATION_GECKO)
+ if ((application == TrinidadAgent.Application.NETSCAPE)
+ || (application == TrinidadAgent.Application.GECKO)
|| (isScreenReaderMode(context)))
{
align = UIConstants.V_ALIGN_MIDDLE;
@@ -709,3 +709,4 @@
}
+
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/HeaderRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/HeaderRenderer.java?rev=896231&r1=896230&r2=896231&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/HeaderRenderer.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/HeaderRenderer.java Tue Jan 5 21:32:45 2010
@@ -154,7 +154,7 @@
// of the changes, I'll only tweak it here.
if ((context.getAgent().getAgentOS() == TrinidadAgent.OS_MACOS) &&
(context.getAgent().getAgentApplication() ==
- TrinidadAgent.APPLICATION_IEXPLORER))
+ TrinidadAgent.Application.IEXPLORER))
renderAttribute(context, NAME_ATTRIBUTE, label);
else