myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mstar...@apache.org
Subject svn commit: r1068466 - in /myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main: java/org/apache/myfaces/trinidadinternal/agent/ java/org/apache/myfaces/trinidadinternal/ui/laf/ java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop...
Date Tue, 08 Feb 2011 16:24:27 GMT
Author: mstarets
Date: Tue Feb  8 16:24:27 2011
New Revision: 1068466

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

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

Modified: myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentFactoryImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentFactoryImpl.java?rev=1068466&r1=1068465&r2=1068466&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentFactoryImpl.java
(original)
+++ myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/AgentFactoryImpl.java
Tue Feb  8 16:24:27 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
@@ -951,6 +987,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);
+
+  }
 
 
   /**
@@ -972,7 +1031,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++)
     {
@@ -1013,5 +1072,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/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java?rev=1068466&r1=1068465&r2=1068466&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java
(original)
+++ myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/agent/TrinidadAgent.java
Tue Feb  8 16:24:27 2011
@@ -254,6 +254,11 @@ public interface TrinidadAgent extends A
    * Application constant for voice
    */
   static public final int TYPE_VOICE = 3;
+  
+  /**
+   * Application constant for web crawlers
+   */
+  static public final int TYPE_WEBCRAWLER = 4;
 
 
 
@@ -353,6 +358,22 @@ public interface TrinidadAgent extends A
    * Application constant for email.
    */
   static public final int APPLICATION_EMAIL = 16;
+  
+  /**
+   * Application constant Google web crawler.
+   */
+  static public final int APPLICATION_GOOGLEBOT = 17;
+
+  /**
+   * Application constant for Bing web crawler.
+   */
+  static public final int APPLICATION_MSNBOT = 18;
+  
+  /**
+   * Application constant for Oracle SES.
+   */
+  static public final int APPLICATION_ORACLE_SES = 19;
+  
   /**
    * OS constant for an unknown operating system.
    */

Modified: myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/NameAndAgentScorer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/NameAndAgentScorer.java?rev=1068466&r1=1068465&r2=1068466&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/NameAndAgentScorer.java
(original)
+++ myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/NameAndAgentScorer.java
Tue Feb  8 16:24:27 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());
     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/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/BaseDesktopUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/BaseDesktopUtils.java?rev=1068466&r1=1068465&r2=1068466&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/BaseDesktopUtils.java
(original)
+++ myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/BaseDesktopUtils.java
Tue Feb  8 16:24:27 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/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/pda/PdaHtmlLafUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/pda/PdaHtmlLafUtils.java?rev=1068466&r1=1068465&r2=1068466&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/pda/PdaHtmlLafUtils.java
(original)
+++ myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/pda/PdaHtmlLafUtils.java
Tue Feb  8 16:24:27 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/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/simple/pda/SimplePdaUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/simple/pda/SimplePdaUtils.java?rev=1068466&r1=1068465&r2=1068466&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/simple/pda/SimplePdaUtils.java
(original)
+++ myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/simple/pda/SimplePdaUtils.java
Tue Feb  8 16:24:27 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/1.2.12.3.3-branch/trinidad-impl/src/main/resources/META-INF/agent/capabilities.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/resources/META-INF/agent/capabilities.xml?rev=1068466&r1=1068465&r2=1068466&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/resources/META-INF/agent/capabilities.xml
(original)
+++ myfaces/trinidad/branches/1.2.12.3.3-branch/trinidad-impl/src/main/resources/META-INF/agent/capabilities.xml
Tue Feb  8 16:24:27 2011
@@ -73,6 +73,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