myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mstar...@apache.org
Subject svn commit: r1068481 - in /myfaces/trinidad/branches/trinidad-1.2.x: trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/ trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/ trinidad-impl/src/main/java/org/apache/myfaces/t...
Date Tue, 08 Feb 2011 17:06:41 GMT
Author: mstarets
Date: Tue Feb  8 17:06:40 2011
New Revision: 1068481

URL: http://svn.apache.org/viewvc?rev=1068481&view=rev
Log:
TRINIDAD-1948 - Trinidad's Agent API Should Support Detection of Web Crawlers

Modified:
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/Agent.java
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentFactoryImpl.java
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentNameUtil.java
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/NameAndAgentScorer.java
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/BaseDesktopUtils.java
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/pda/PdaHtmlLafUtils.java
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/simple/pda/SimplePdaUtils.java
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/resources/META-INF/agent/capabilities.xml

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/Agent.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/Agent.java?rev=1068481&r1=1068480&r2=1068481&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/Agent.java
(original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/Agent.java
Tue Feb  8 17:06:40 2011
@@ -60,6 +60,11 @@ public interface Agent
    * Constant for Phone sized devices
    */
   public static final Object TYPE_PHONE = "phone";
+  
+  /**
+  * Constant for Web Crawlers
+  */
+  public static final Object TYPE_WEBCRAWLER = "webcrawler";
 
  /**
    * Constant for Unknown platform
@@ -123,6 +128,21 @@ public interface Agent
    * Constant for generic PDA device browser
    */
   public static final String PLATFORM_GENERICPDA = "genericpda";
+  
+  /**
+   * Constant for MSN web crawler (currently used by Bing and Yahoo)
+   */
+  public static final String AGENT_MSNBOT = "msnbot";
+  
+  /**
+   * Constant for Google web crawler
+   */
+  public static final String AGENT_GOOGLEBOT = "googlebot";
+  
+  /**
+   * Constant for Oracle SES web crawler
+   */
+  public static final String AGENT_ORACLE_SES = "oracle_ses";
 
   /**
    * Constant for Unknown platform version

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentFactoryImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentFactoryImpl.java?rev=1068481&r1=1068480&r2=1068481&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentFactoryImpl.java
(original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentFactoryImpl.java
Tue Feb  8 17:06:40 2011
@@ -109,6 +109,42 @@ public class AgentFactoryImpl implements
       _populateUnknownAgentImpl(null, agent);
       return;
     }
+    
+    // Uncomment if you need to simulate googlebot crawler
+    /*if (facesContext != null && facesContext.getExternalContext().getRequestParameterMap().
+                        get("googlebot") != null)
+    {
+      _populateCrawlerAgentImpl("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
agent, Agent.AGENT_GOOGLEBOT, _GOOGLEBOT_ID, 25);
+      return;
+    }*/
+    
+    int googlebotIndex = userAgent.indexOf(_GOOGLEBOT_ID);
+    if (googlebotIndex >= 0)
+    {
+      _populateCrawlerAgentImpl(userAgent, agent, Agent.AGENT_GOOGLEBOT, _GOOGLEBOT_ID, googlebotIndex);
+      return;
+    }
+    
+    int bingIndex = userAgent.indexOf(_BINGBOT_ID);
+    if (bingIndex >= 0)
+    {
+      _populateCrawlerAgentImpl(userAgent, agent, Agent.AGENT_MSNBOT, _BINGBOT_ID, bingIndex);
+      return;
+    }
+    
+    bingIndex = userAgent.indexOf(_MSNBOT_ID);
+    if (bingIndex >= 0)
+    {
+      _populateCrawlerAgentImpl(userAgent, agent, Agent.AGENT_MSNBOT, _MSNBOT_ID, bingIndex);
+      return;
+    }
+    
+    int oracleSesIndex = userAgent.indexOf(_ORACLE_SES_ID);
+    if (oracleSesIndex >= 0)
+    {
+      _populateCrawlerAgentImpl(userAgent, agent, Agent.AGENT_ORACLE_SES, _ORACLE_SES_ID,
oracleSesIndex);
+      return;
+    }
 
     //the useragent string for telnet and PDA design time will start with
     //OracleJDevMobile because in each of these cases we know we have an
@@ -926,6 +962,29 @@ public class AgentFactoryImpl implements
     agentObj.setMakeModel(Agent.MAKE_MODEL_UNKNOWN);
 
   }
+  
+  /**
+   * Returns an AgentEntry for a web crawler
+   */
+  private void _populateCrawlerAgentImpl(String userAgent, 
+                                         AgentImpl agentObj,
+                                         String agent,
+                                         String agentId,
+                                         int idIndex)
+  {
+    agentObj.setType(Agent.TYPE_WEBCRAWLER);
+
+    agentObj.setAgent(agent);
+    String version = _getVersion(userAgent, idIndex + agentId.length());
+    if (version != null && version.length() > 0)
+    {
+      agentObj.setAgentVersion(version);
+    }
+    agentObj.setPlatform(Agent.PLATFORM_UNKNOWN);
+    agentObj.setPlatformVersion(Agent.PLATFORM_VERSION_UNKNOWN);
+    agentObj.setMakeModel(Agent.MAKE_MODEL_UNKNOWN);
+
+  }
 
 
   /**
@@ -947,7 +1006,7 @@ public class AgentFactoryImpl implements
     }
 
     int end = base.length();
-    start = start + 1;
+    start = (start >= end) ? end : start + 1;
 
     for (int i = start; i < end; i++)
     {
@@ -988,5 +1047,10 @@ public class AgentFactoryImpl implements
     "org.apache.myfaces.trinidad.agent.email";
   static final private String _IASW_DEVICE_HINT_PARAM = "X-Oracle-Device.Class";
   static final private TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(AgentFactoryImpl.class);
+  
+  static final private String _GOOGLEBOT_ID = "Googlebot";
+  static final private String _MSNBOT_ID = "msnbot";
+  static final private String _BINGBOT_ID = "bingbot";
+  static final private String _ORACLE_SES_ID = "Oracle Secure Enterprise Search";
 
 }

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentNameUtil.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentNameUtil.java?rev=1068481&r1=1068480&r2=1068481&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentNameUtil.java
(original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentNameUtil.java
Tue Feb  8 17:06:40 2011
@@ -106,6 +106,11 @@ public class AgentNameUtil
     {
       return TrinidadAgent.TYPE_PHONE;
     }
+    
+    if (otype == Agent.TYPE_WEBCRAWLER)
+    {
+      return TrinidadAgent.TYPE_WEBCRAWLER;
+    }
 
     //Default to desktop (This is UIX 2.2 logic)
     return TrinidadAgent.TYPE_DESKTOP;

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java?rev=1068481&r1=1068480&r2=1068481&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java
(original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java
Tue Feb  8 17:06:40 2011
@@ -258,6 +258,12 @@ public abstract class TrinidadAgent impl
    * Application constant for voice
    */
   static public final int TYPE_VOICE = 3;
+  
+  
+  /**
+   * Application constant for web crawlers
+   */
+  static public final int TYPE_WEBCRAWLER = 4;
 
   /**
    * Enumeration representing an Application
@@ -336,7 +342,20 @@ public abstract class TrinidadAgent impl
     /**
      * Application enum for opera.
      */
-    OPERA("opera", AGENT_OPERA);
+    OPERA("opera", AGENT_OPERA),
+    
+    /**
+     * Application enum for Google web crawler.
+     */
+    GOOGLEBOT("googlebot", AGENT_GOOGLEBOT),
+    /**
+     * Application enum for Bing web crawler.
+     */
+    MSNBOT("msnbot", AGENT_MSNBOT),
+    /**
+     * Application enum for Oracle SES.
+     */
+    ORACLE_SES("oracle_ses", AGENT_ORACLE_SES);
 
     /**
      * Return the appropriate Application instance given the name of an Application

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/NameAndAgentScorer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/NameAndAgentScorer.java?rev=1068481&r1=1068480&r2=1068481&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/NameAndAgentScorer.java
(original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/NameAndAgentScorer.java
Tue Feb  8 17:06:40 2011
@@ -40,14 +40,14 @@ public class NameAndAgentScorer extends 
    */
   public NameAndAgentScorer(
     String  requiredLafName,
-    Integer requiredAgentType,
     Integer requiredAgentApplication,
     Integer requiredAgentMajorVersion,
-    Integer requiredAgentOS
+    Integer requiredAgentOS,
+    Integer... requiredAgentTypes
     )
   {
     _lafName           = requiredLafName;
-    _agentType         = requiredAgentType;
+    _agentTypes        = requiredAgentTypes;
     _agentApplication  = requiredAgentApplication;
     _agentMajorVersion = requiredAgentMajorVersion;
     _agentOS           = requiredAgentOS;
@@ -76,7 +76,14 @@ public class NameAndAgentScorer extends 
     int nameScore = _scoreName(lafName);
 
     TrinidadAgent agent = context. getAgent();
-    int typeScore = _score(_agentType, agent.getAgentType());
+    
+    int typeScore = NO_MATCH;
+    int agentType = agent.getAgentType();
+    for (int type: _agentTypes)
+    {
+      typeScore = Math.max(typeScore, _score(type, agentType));
+    }
+    
     int appScore = _score(_agentApplication, agent.getAgentApplication().ordinal());
     int versScore = _score(_agentMajorVersion, agent.getAgentMajorVersion());
     int osScore = _score(_agentOS, agent.getAgentOS());
@@ -124,7 +131,7 @@ public class NameAndAgentScorer extends 
   }
   
   private String  _lafName;
-  private Integer _agentType;
+  private Integer _agentTypes[];
   private Integer _agentApplication;
   private Integer _agentMajorVersion;
   private Integer _agentOS;

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/BaseDesktopUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/BaseDesktopUtils.java?rev=1068481&r1=1068480&r2=1068481&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/BaseDesktopUtils.java
(original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/BaseDesktopUtils.java
Tue Feb  8 17:06:40 2011
@@ -69,7 +69,7 @@ public class BaseDesktopUtils extends Xh
 
   // We use a scorer which matches base/desktop - but not Netscape
   private static final NameAndAgentScorer _SCORER =
-    new NoNetscapeScorer("base");
+    new NoNetscapeScorer("base", TrinidadAgent.TYPE_DESKTOP, TrinidadAgent.TYPE_WEBCRAWLER);
 
   /**
    * @deprecated This class comes from the old Java 1.2 UIX codebase and should not be used
anymore.
@@ -77,14 +77,15 @@ public class BaseDesktopUtils extends Xh
   @Deprecated
   private static class NoNetscapeScorer extends NameAndAgentScorer
   {
-    public NoNetscapeScorer(String lafName)
+    public NoNetscapeScorer(String lafName, int type1, int type2)
     {
       // Initialize the NameAndAgentScorer for base/desktop
       super(lafName,
-            TrinidadAgent.TYPE_DESKTOP,
             null,
             null,
-            null);
+            null,
+            type1,
+            type2);
     }
 
     @Override

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/pda/PdaHtmlLafUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/pda/PdaHtmlLafUtils.java?rev=1068481&r1=1068480&r2=1068481&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/pda/PdaHtmlLafUtils.java
(original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/pda/PdaHtmlLafUtils.java
Tue Feb  8 17:06:40 2011
@@ -82,8 +82,8 @@ public class PdaHtmlLafUtils extends Xht
 
   private static final NameAndAgentScorer _SCORER =
     new NameAndAgentScorer(null,
-                           TrinidadAgent.TYPE_PDA,
                            null,
                            null,
-                           null);
+                           null,
+                           TrinidadAgent.TYPE_PDA);
 }

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/simple/pda/SimplePdaUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/simple/pda/SimplePdaUtils.java?rev=1068481&r1=1068480&r2=1068481&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/simple/pda/SimplePdaUtils.java
(original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/simple/pda/SimplePdaUtils.java
Tue Feb  8 17:06:40 2011
@@ -49,10 +49,10 @@ public class SimplePdaUtils extends PdaH
 
   private static final NameAndAgentScorer _PDA_SCORER =
     new NameAndAgentScorer("simple",
-                           TrinidadAgent.TYPE_PDA,
                            null,
                            null,
-                           null);
+                           null,
+                           TrinidadAgent.TYPE_PDA);
 
 
 }

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/resources/META-INF/agent/capabilities.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/resources/META-INF/agent/capabilities.xml?rev=1068481&r1=1068480&r2=1068481&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/resources/META-INF/agent/capabilities.xml
(original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/resources/META-INF/agent/capabilities.xml
Tue Feb  8 17:06:40 2011
@@ -74,6 +74,21 @@
       <include refid="html" />
       <include src="email.xml" />
     </capabilities>
+    
+    <capabilities id="googlebot" agents="googlebot">
+      <include refid="html" />
+      <include src="email.xml" />
+    </capabilities>
+    
+    <capabilities id="msnbot" agents="msnbot">
+      <include refid="html" />
+      <include src="email.xml" />
+    </capabilities>
+    
+    <capabilities id="oracle_ses" agents="oracle_ses">
+      <include refid="html" />
+      <include src="email.xml" />
+    </capabilities>
 
     <capabilities id="webkit" agents="webkit">
       <include refid="html" />



Mime
View raw message