camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1436215 - in /camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter: TwitterConfiguration.java TwitterConstants.java consumer/search/SearchConsumer.java producer/SearchProducer.java
Date Mon, 21 Jan 2013 07:33:42 GMT
Author: ningjiang
Date: Mon Jan 21 07:33:42 2013
New Revision: 1436215

URL: http://svn.apache.org/viewvc?rev=1436215&view=rev
Log:
CAMEL-5984 Specification of the language for the search Consumer and Producer with thanks
to Luca

Modified:
    camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
    camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConstants.java
    camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java
    camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/producer/SearchProducer.java

Modified: camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java?rev=1436215&r1=1436214&r2=1436215&view=diff
==============================================================================
--- camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
(original)
+++ camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
Mon Jan 21 07:33:42 2013
@@ -81,6 +81,11 @@ public class TwitterConfiguration {
      * Used to set the sinceId from pulling
      */
     private long sinceId  = 1;
+
+    /**
+     * Used ot set the preferred language on which to search
+     */
+    private String lang;
     
     private Date parsedDate;
     private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
@@ -259,6 +264,13 @@ public class TwitterConfiguration {
         this.sinceId = sinceId;
     }
 
+    public String getLang() {
+        return lang;
+    }
+
+    public void setLang(String lang) {
+        this.lang = lang;
+    }
 }
 
 

Modified: camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConstants.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConstants.java?rev=1436215&r1=1436214&r2=1436215&view=diff
==============================================================================
--- camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConstants.java
(original)
+++ camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConstants.java
Mon Jan 21 07:33:42 2013
@@ -23,6 +23,8 @@ public final class TwitterConstants {
 
     public static final String TWITTER_KEYWORDS = "CamelTwitterKeywords";
 
+    public static final String TWITTER_SEARCH_LANGUAGE = "CamelTwitterSearchLanguage";
+
     private TwitterConstants() {
         // utility
     }

Modified: camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java?rev=1436215&r1=1436214&r2=1436215&view=diff
==============================================================================
--- camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java
(original)
+++ camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/search/SearchConsumer.java
Mon Jan 21 07:33:42 2013
@@ -21,6 +21,7 @@ import java.util.List;
 
 import org.apache.camel.component.twitter.TwitterEndpoint;
 import org.apache.camel.component.twitter.consumer.Twitter4JConsumer;
+import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import twitter4j.Query;
@@ -45,6 +46,9 @@ public class SearchConsumer extends Twit
         if (te.getProperties().isFilterOld()) {
             query.setSinceId(lastId);
         }
+        if (ObjectHelper.isNotEmpty(te.getProperties().getLang())) {
+            query.setLang(te.getProperties().getLang());
+        }
         LOG.debug("Searching twitter with keywords: {}", keywords);
         return search(query);
     }
@@ -54,8 +58,12 @@ public class SearchConsumer extends Twit
         if (keywords == null || keywords.trim().length() == 0) {
             return Collections.emptyList();
         }
+        Query query = new Query(keywords);
+        if (ObjectHelper.isNotEmpty(te.getProperties().getLang())) {
+            query.setLang(te.getProperties().getLang());
+        }
         LOG.debug("Searching twitter with keywords: {}", keywords);
-        return search(new Query(keywords));
+        return search(query);
     }
 
     private List<Status> search(Query query) throws TwitterException {

Modified: camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/producer/SearchProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/producer/SearchProducer.java?rev=1436215&r1=1436214&r2=1436215&view=diff
==============================================================================
--- camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/producer/SearchProducer.java
(original)
+++ camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/producer/SearchProducer.java
Mon Jan 21 07:33:42 2013
@@ -22,6 +22,7 @@ import org.apache.camel.CamelExchangeExc
 import org.apache.camel.Exchange;
 import org.apache.camel.component.twitter.TwitterConstants;
 import org.apache.camel.component.twitter.TwitterEndpoint;
+import org.apache.camel.util.ObjectHelper;
 import twitter4j.Query;
 import twitter4j.QueryResult;
 import twitter4j.Status;
@@ -47,11 +48,20 @@ public class SearchProducer extends Twit
         if (keywords == null) {
             throw new CamelExchangeException("No keywords to use for query", exchange);
         }
-
+        
         Query query = new Query(keywords);
         if (te.getProperties().isFilterOld() && myLastId != 0) {
             query.setSinceId(myLastId);
         }
+        
+        String lang = exchange.getIn().getHeader(TwitterConstants.TWITTER_SEARCH_LANGUAGE,
String.class);
+        if (lang == null) {
+            lang = te.getProperties().getLang();
+        }
+
+        if (ObjectHelper.isNotEmpty(lang)) {
+            query.setLang(lang);
+        }
 
         Twitter twitter = te.getProperties().getTwitter();
         log.debug("Searching twitter with keywords: {}", keywords);



Mime
View raw message