Browse files

aiueo initial commit

  • Loading branch information...
1 parent 72eb6c0 commit c81418c52e70cd23a0062a2b8677972675a8aa02 @yusuke committed Sep 13, 2012
View
2 .gitignore
@@ -4,6 +4,8 @@ countyusuke/target/*
countyusuke/src/test/resources/twitter4j.properties
countyusuke/src/main/resources/twitter4j.properties
countyusuke/store/*
+aiueo/src/test/resources/twitter4j.properties
+aiueo/src/main/resources/twitter4j.properties
.DS_Store
.idea
sync.sh
View
91 aiueo/pom.xml
@@ -0,0 +1,91 @@
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>ch.deathmar</groupId>
+ <artifactId>aiueo</artifactId>
+ <version>1.0</version>
+ <packaging>war</packaging>
+ <name>aiueo</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.twitter4j</groupId>
+ <artifactId>twitter4j-core</artifactId>
+ <version>2.2.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.twitter4j</groupId>
+ <artifactId>twitter4j-async</artifactId>
+ <version>2.2.6</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-core</artifactId>
+ <version>5.1.3.FINAL</version>
+ </dependency>
+
+ </dependencies>
+ <build>
+ <defaultGoal>jetty:run</defaultGoal>
+ <sourceDirectory>src/main/java</sourceDirectory>
+ <testSourceDirectory>src/test/java</testSourceDirectory>
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ </testResource>
+ </testResources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ <version>8.1.4.v20120524</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-ajp</artifactId>
+ <version>8.1.4.v20120524</version>
+ </dependency>
+ </dependencies>
+ <configuration>
+ <connectors>
+ <connector implementation="org.eclipse.jetty.ajp.Ajp13SocketConnector">
+ <port>9998</port>
+ </connector>
+ <!--<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">-->
+ <!--<port>8080</port>-->
+ <!--</connector>-->
+ </connectors>
+ <webApp>
+ <contextPath>/countyusuke</contextPath>
+ </webApp>
+ <stopKey>1</stopKey>
+ <stopPort>10000</stopPort>
+ <scanIntervalSeconds>0</scanIntervalSeconds>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
View
182 aiueo/src/main/java/ch/deathmar/CountYusuke.java
@@ -0,0 +1,182 @@
+/*
+Copyright (c) 2012, Yusuke Yamamoto
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the Yusuke Yamamoto nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package ch.deathmar;
+
+import twitter4j.*;
+import twitter4j.internal.async.DispatcherFactory;
+
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class CountYusuke implements Progress {
+ public void count(final Twitter twitter) {
+ try {
+ User me = twitter.verifyCredentials();
+ screenName = twitter.getScreenName();
+ final Set<Long> connected = new HashSet<Long>(me.getFollowersCount() + me.getFriendsCount());
+ long cursor = -1L;
+ IDs friends;
+ do {
+ friends = twitter.getFriendsIDs(cursor);
+ for (long id : friends.getIDs()) {
+ connected.add(id);
+ }
+ cursor = friends.getNextCursor();
+ } while (friends.hasNext());
+
+ cursor = -1L;
+ do {
+ friends = twitter.getFollowersIDs(cursor);
+ for (long id : friends.getIDs()) {
+ connected.add(id);
+ }
+ cursor = friends.getNextCursor();
+ } while (friends.hasNext());
+ total = connected.size();
+ final Iterator<Long> ite = connected.iterator();
+ new DispatcherFactory().getInstance().invokeLater(
+ new Runnable() {
+ @Override
+ public void run() {
+ ResponseList<User> users;
+ try {
+ long[] lookupTarget = null;
+ for (int i = 0; i < connected.size(); i++) {
+ if (i % 100 == 0) {
+ if (i != 0) {
+ users = twitter.lookupUsers(lookupTarget);
+ count(users);
+ evaluated += users.size();
+ if (users.getRateLimitStatus().getRemainingHits() == 0) {
+ failed = true;
+ break;
+ }
+ }
+ lookupTarget = new long[Math.min(100, connected.size() - i)];
+ }
+ lookupTarget[i % 100] = ite.next();
+ }
+ if (lookupTarget.length != 100) {
+ users = twitter.lookupUsers(lookupTarget);
+ count(users);
+ evaluated += users.size();
+ }
+ Store.put(String.valueOf(twitter.getScreenName()), yusukes);
+ } catch (TwitterException te) {
+ failed = true;
+ }
+ }
+ });
+
+ } catch (TwitterException te) {
+ failed = true;
+ }
+ }
+
+ int total;
+
+ public String getScreenName() {
+ return screenName;
+ }
+
+ String screenName;
+
+ public List<String> getYusukes() {
+ return yusukes;
+ }
+
+ List<String> yusukes = new ArrayList<String>();
+ boolean failed = false;
+ int evaluated = 0;
+
+ private void count(List<User> users) {
+ for (User user : users) {
+ if (isYusuke(user.getScreenName() + user.getName())) {
+ yusukes.add(user.getScreenName());
+ }
+ }
+ }
+
+ private static final Pattern p = Pattern.compile(".*(ゆうすけ|ゆーすけ|ユウスケ|ユースケ|ユウスケ|ユースケ|yusuke|佑亮|佑介|佑助|佑輔|優介|優佑|優助|優祐|優輔|勇介|勇佑|勇典|勇助|勇祐|勇輔|友介|友佑|友助|友祐|友輔|右介|右典|夕介|悠介|悠佑|悠助|悠祐|悠輔|攸介|有介|有佑|有資|祐介|祐助|祐輔|裕介|裕典|裕助|裕将|裕祐|裕輔|遊助|雄亮|雄介|雄佑|雄助|雄右|雄祐|雄輔).*", Pattern.CASE_INSENSITIVE);
+
+ public static boolean isYusuke(String name) {
+ Matcher m = p.matcher(name);
+ return m.matches();
+ }
+
+ @Override
+ public int getProgress() {
+ return (int) ((double) evaluated / (double) total * 90 + 10);
+ }
+
+ @Override
+ public boolean isFailed() {
+ return failed;
+ }
+ public int getCount(){
+ return yusukes.size();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ CountYusuke that = (CountYusuke) o;
+
+ if (evaluated != that.evaluated) return false;
+ if (failed != that.failed) return false;
+ if (total != that.total) return false;
+ if (screenName != null ? !screenName.equals(that.screenName) : that.screenName != null) return false;
+ if (yusukes != null ? !yusukes.equals(that.yusukes) : that.yusukes != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = total;
+ result = 31 * result + (screenName != null ? screenName.hashCode() : 0);
+ result = 31 * result + (yusukes != null ? yusukes.hashCode() : 0);
+ result = 31 * result + (failed ? 1 : 0);
+ result = 31 * result + evaluated;
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "CountYusuke{" +
+ "total=" + total +
+ ", screenName='" + screenName + '\'' +
+ ", yusukes=" + yusukes +
+ ", failed=" + failed +
+ ", evaluated=" + evaluated +
+ '}';
+ }
+}
View
32 aiueo/src/main/java/ch/deathmar/Progress.java
@@ -0,0 +1,32 @@
+/*
+Copyright (c) 2012, Yusuke Yamamoto
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the Yusuke Yamamoto nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+package ch.deathmar;
+
+public interface Progress {
+ int getProgress();
+ boolean isFailed();
+}
View
81 aiueo/src/main/java/ch/deathmar/ProgressServlet.java
@@ -0,0 +1,81 @@
+/*
+Copyright (c) 2012, Yusuke Yamamoto
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the Yusuke Yamamoto nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package ch.deathmar;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.List;
+
+public class ProgressServlet extends HttpServlet {
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ HttpSession session = request.getSession(true);
+ String callback = request.getParameter("callback");
+ CountYusuke countYusuke = (CountYusuke) session.getAttribute("progress");
+ PrintWriter writer = response.getWriter();
+ if (null != callback) {
+ writer.print(callback);
+ writer.print("(");
+ }
+ writer.print("{\"failed\":" + countYusuke.isFailed() + ",\"progress\":" + countYusuke.getProgress());
+
+ writer.print(",\"total\":"+countYusuke.total);
+ writer.print(",\"screenName\":\""+countYusuke.screenName+"\"");
+ writer.print(",\"yusukeCount\":"+countYusuke.yusukes.size());
+ writer.print(",\"yusuke\":");
+
+ writer.print(join(countYusuke.yusukes));
+ writer.print("}");
+ if (null != callback) {
+ writer.print(");");
+ }
+ }
+
+ public static String join(List<String> yusukes) {
+ StringBuilder buf = new StringBuilder(11 * yusukes.size());
+ buf.append("[");
+ if(yusukes.size() != 0){
+ buf.append("\"");
+ }
+ for (String str : yusukes) {
+ if (0 != buf.length()) {
+ buf.append("\",\"");
+ }
+ buf.append(str);
+ }
+ if(yusukes.size() != 0){
+ buf.append("\"");
+ }
+ buf.append("]");
+ return buf.toString();
+ }
+}
View
45 aiueo/src/main/java/ch/deathmar/Result.java
@@ -0,0 +1,45 @@
+/*
+Copyright (c) 2012, Yusuke Yamamoto
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the Yusuke Yamamoto nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+package ch.deathmar;
+
+import java.io.Serializable;
+
+public class Result implements Serializable {
+ int count;
+ int total;
+ String screenName;
+
+ public Result(String twitter, int count, int total) {
+ this.screenName = twitter;
+ this.count = count;
+ this.total = total;
+ }
+
+ public String toString() {
+ return ".@" + screenName + "のフォロー・フォロワー" + total + "アカウントのうち" + count + "はユースケです " + (count / total * 100) + "%";
+ }
+}
View
32 aiueo/src/main/java/ch/deathmar/Store.java
@@ -0,0 +1,32 @@
+package ch.deathmar;
+
+import org.infinispan.Cache;
+import org.infinispan.manager.DefaultCacheManager;
+
+import java.io.IOException;
+
+public class Store {
+ static Cache<String , Object> cache;
+ static Cache<String , Object> tempCache;
+ static{
+ try {
+ cache = new DefaultCacheManager(Store.class.getResourceAsStream("/infinispan.xml")).getCache("xml-configured-cache");
+ tempCache = new DefaultCacheManager(Store.class.getResourceAsStream("/infinispan.xml")).getCache("temporary-cache");
+ } catch (IOException e) {
+ throw new ExceptionInInitializerError(e);
+ }
+ }
+ public static void put(String str, Object obj){
+ cache.put(str,obj);
+ }
+ public static Object get(String str){
+ return cache.get(str);
+ }
+
+ public static void putTemporal(String key, Object obj){
+ tempCache.put(key,obj);
+ }
+ public static Object getTemporal(String key){
+ return tempCache.get(key);
+ }
+}
View
48 aiueo/src/main/java/ch/deathmar/YusukeServlet.java
@@ -0,0 +1,48 @@
+/*
+Copyright (c) 2012, Yusuke Yamamoto
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the Yusuke Yamamoto nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+package ch.deathmar;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+
+public class YusukeServlet extends HttpServlet {
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ String screenName = request.getPathInfo().substring(1);
+ List<String> yusukes = (List<String>)Store.get(screenName);
+ if(yusukes == null){
+ response.sendRedirect(request.getContextPath() + "/");
+ } else {
+ request.setAttribute("yusukes", yusukes);
+ request.setAttribute("screenName", screenName);
+ }
+ request.getRequestDispatcher("/yusuke.jsp").forward(request, response);
+ }
+}
View
61 aiueo/src/main/java/twitter4j/examples/signin/CallbackServlet.java
@@ -0,0 +1,61 @@
+/*
+Copyright (c) 2007-2009, Yusuke Yamamoto
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the Yusuke Yamamoto nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+package twitter4j.examples.signin;
+
+import ch.deathmar.CountYusuke;
+import ch.deathmar.Store;
+import twitter4j.Twitter;
+import twitter4j.TwitterException;
+import twitter4j.TwitterFactory;
+import twitter4j.auth.RequestToken;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+public class CallbackServlet extends HttpServlet {
+ private static final long serialVersionUID = 1657390011452788111L;
+
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ RequestToken requestToken = (RequestToken) Store.getTemporal(request.getParameter("oauth_token"));
+ String verifier = request.getParameter("oauth_verifier");
+ try {
+ Twitter twitter = new TwitterFactory().getInstance();
+ twitter.getOAuthAccessToken(requestToken, verifier);
+ CountYusuke countYusuke = new CountYusuke();
+ countYusuke.count(twitter);
+ request.getSession().setAttribute("twitter", twitter);
+ request.getSession().setAttribute("progress", countYusuke);
+ request.getSession().removeAttribute("requestToken");
+ } catch (TwitterException e) {
+ throw new ServletException(e);
+ }
+ response.sendRedirect(request.getContextPath() + "/");
+ }
+}
View
42 aiueo/src/main/java/twitter4j/examples/signin/LogoutServlet.java
@@ -0,0 +1,42 @@
+/*
+Copyright (c) 2007-2009, Yusuke Yamamoto
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the Yusuke Yamamoto nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+package twitter4j.examples.signin;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import java.io.IOException;
+
+public class LogoutServlet extends HttpServlet {
+ private static final long serialVersionUID = -4433102460849019660L;
+
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ request.getSession().invalidate();
+ response.sendRedirect(request.getContextPath()+ "/");
+ }
+}
View
52 aiueo/src/main/java/twitter4j/examples/signin/PostServlet.java
@@ -0,0 +1,52 @@
+/*
+Copyright (c) 2007-2009, Yusuke Yamamoto
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the Yusuke Yamamoto nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+package twitter4j.examples.signin;
+
+import twitter4j.Twitter;
+import twitter4j.TwitterException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+public class PostServlet extends HttpServlet {
+ private static final long serialVersionUID = 2132731135996613711L;
+
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ request.setCharacterEncoding("UTF-8");
+ String text = request.getParameter("text");
+ Twitter twitter = (Twitter)request.getSession().getAttribute("twitter");
+ try {
+ twitter.updateStatus(text);
+ } catch (TwitterException e) {
+ throw new ServletException(e);
+ }
+ response.sendRedirect(request.getContextPath()+ "/");
+ }
+}
View
62 aiueo/src/main/java/twitter4j/examples/signin/SigninServlet.java
@@ -0,0 +1,62 @@
+/*
+Copyright (c) 2007-2009, Yusuke Yamamoto
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the Yusuke Yamamoto nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+package twitter4j.examples.signin;
+
+import ch.deathmar.Store;
+import twitter4j.Twitter;
+import twitter4j.TwitterException;
+import twitter4j.TwitterFactory;
+import twitter4j.auth.RequestToken;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.io.IOException;
+
+public class SigninServlet extends HttpServlet {
+ private static final long serialVersionUID = -6205814293093350242L;
+
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ Twitter twitter = new TwitterFactory().getInstance();
+ try {
+ StringBuffer callbackURL = request.getRequestURL();
+ int index = callbackURL.lastIndexOf("/");
+ callbackURL.replace(index, callbackURL.length(), "").append("/callback");
+
+ RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL.toString());
+ request.getSession().setAttribute("requestToken", requestToken);
+ response.sendRedirect(requestToken.getAuthorizationURL());
+ Store.putTemporal(requestToken.getToken(),requestToken);
+
+ } catch (TwitterException e) {
+ throw new ServletException(e);
+ }
+
+ }
+}
View
BIN aiueo/src/main/resources/icon.acorn
Binary file not shown.
View
BIN aiueo/src/main/resources/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
29 aiueo/src/main/resources/infinispan.xml
@@ -0,0 +1,29 @@
+<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:infinispan:config:5.1 http://www.infinispan.org/schemas/infinispan-config-5.1.xsd"
+ xmlns="urn:infinispan:config:5.1">
+ <global/>
+ <namedCache name="xml-configured-cache">
+ <loaders passivation="false" shared="true" preload="true">
+ <loader class="org.infinispan.loaders.file.FileCacheStore"
+ fetchPersistentState="true" ignoreModifications="false"
+ purgeOnStartup="false">
+ <properties>
+ <property name="location" value="/Users/yusuke/store/"/>
+ </properties>
+ </loader>
+ </loaders>
+ </namedCache>
+ <namedCache name="temporary-cache">
+ <loaders passivation="false" shared="true" preload="true">
+ <loader class="org.infinispan.loaders.file.FileCacheStore"
+ fetchPersistentState="true" ignoreModifications="false"
+ purgeOnStartup="false">
+ <properties>
+ <property name="location" value="/Users/yusuke/store/"/>
+ </properties>
+ </loader>
+ </loaders>
+ <expiration wakeUpInterval="500"/>
+ <eviction maxEntries="2000" strategy="LRU"/>
+ </namedCache>
+</infinispan>
View
65 aiueo/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,65 @@
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
+ version="2.4">
+ <welcome-file-list>
+ <welcome-file>index.jsp</welcome-file>
+ </welcome-file-list>
+ <servlet>
+ <servlet-name>yusuke</servlet-name>
+ <servlet-class>ch.deathmar.YusukeServlet</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>yusuke</servlet-name>
+ <url-pattern>/yusuke/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
+ <servlet-name>signin</servlet-name>
+ <servlet-class>twitter4j.examples.signin.SigninServlet
+ </servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>signin</servlet-name>
+ <url-pattern>/signin</url-pattern>
+ </servlet-mapping>
+ <servlet>
+ <servlet-name>callback</servlet-name>
+ <servlet-class>twitter4j.examples.signin.CallbackServlet
+ </servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>callback</servlet-name>
+ <url-pattern>/callback</url-pattern>
+ </servlet-mapping>
+ <servlet>
+ <servlet-name>logout</servlet-name>
+ <servlet-class>twitter4j.examples.signin.LogoutServlet
+ </servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>logout</servlet-name>
+ <url-pattern>/logout</url-pattern>
+ </servlet-mapping>
+ <servlet>
+ <servlet-name>post</servlet-name>
+ <servlet-class>twitter4j.examples.signin.PostServlet
+ </servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>post</servlet-name>
+ <url-pattern>/post</url-pattern>
+ </servlet-mapping>
+ <servlet>
+ <servlet-name>progress</servlet-name>
+ <servlet-class>ch.deathmar.ProgressServlet</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>progress</servlet-name>
+ <url-pattern>/progress.json</url-pattern>
+ </servlet-mapping>
+ <error-page>
+ <exception-type>twitter4j.TwitterException</exception-type>
+ <location>/error.jsp</location>
+ </error-page>
+</web-app>

0 comments on commit c81418c

Please sign in to comment.