Permalink
Browse files

Merge branch 'TFJ-671'

Conflicts:
	readme.txt
  • Loading branch information...
2 parents c6c4ed3 + 4fd0aac commit 4bf42e9be646032a5142ee071eb9b45ea3ba42af @yusuke committed Nov 17, 2012
Showing with 325 additions and 222 deletions.
  1. +1 −0 readme.txt
  2. +1 −1 twitter4j-core/src/main/java/twitter4j/StatusDeletionNoticeImpl.java
  3. +2 −2 twitter4j-core/src/main/java/twitter4j/TwitterException.java
  4. +1 −1 twitter4j-core/src/main/java/twitter4j/internal/json/AccountSettingsJSONImpl.java
  5. +1 −1 twitter4j-core/src/main/java/twitter4j/internal/json/AccountTotalsJSONImpl.java
  6. +0 −1 twitter4j-core/src/main/java/twitter4j/internal/json/CategoryJSONImpl.java
  7. +1 −1 twitter4j-core/src/main/java/twitter4j/internal/json/DirectMessageJSONImpl.java
  8. +52 −0 twitter4j-core/src/main/java/twitter4j/internal/json/EntityIndex.java
  9. +1 −1 twitter4j-core/src/main/java/twitter4j/internal/json/FriendshipJSONImpl.java
  10. +56 −9 twitter4j-core/src/main/java/twitter4j/internal/{http → json}/HTMLEntity.java
  11. +10 −20 twitter4j-core/src/main/java/twitter4j/internal/json/HashtagEntityJSONImpl.java
  12. +0 −1 twitter4j-core/src/main/java/twitter4j/internal/json/IDsJSONImpl.java
  13. +1 −1 twitter4j-core/src/main/java/twitter4j/internal/json/LocationJSONImpl.java
  14. +6 −10 twitter4j-core/src/main/java/twitter4j/internal/json/MediaEntityJSONImpl.java
  15. +0 −1 twitter4j-core/src/main/java/twitter4j/internal/json/PagableResponseListImpl.java
  16. +2 −2 twitter4j-core/src/main/java/twitter4j/internal/json/PlaceJSONImpl.java
  17. +1 −1 twitter4j-core/src/main/java/twitter4j/internal/json/QueryResultJSONImpl.java
  18. +2 −2 twitter4j-core/src/main/java/twitter4j/internal/json/RateLimitStatusJSONImpl.java
  19. +1 −1 twitter4j-core/src/main/java/twitter4j/internal/json/RelationshipJSONImpl.java
  20. +0 −1 twitter4j-core/src/main/java/twitter4j/internal/json/ResponseListImpl.java
  21. +1 −1 twitter4j-core/src/main/java/twitter4j/internal/json/SavedSearchJSONImpl.java
  22. +13 −3 twitter4j-core/src/main/java/twitter4j/internal/json/StatusJSONImpl.java
  23. +1 −1 twitter4j-core/src/main/java/twitter4j/internal/json/TimeZoneJSONImpl.java
  24. +1 −1 twitter4j-core/src/main/java/twitter4j/internal/json/TrendJSONImpl.java
  25. +1 −2 twitter4j-core/src/main/java/twitter4j/internal/json/TrendsJSONImpl.java
  26. +1 −1 twitter4j-core/src/main/java/twitter4j/internal/json/TwitterAPIConfigurationJSONImpl.java
  27. +0 −1 twitter4j-core/src/main/java/twitter4j/internal/json/TwitterResponseImpl.java
  28. +15 −27 twitter4j-core/src/main/java/twitter4j/internal/json/URLEntityJSONImpl.java
  29. +1 −1 twitter4j-core/src/main/java/twitter4j/internal/json/UserJSONImpl.java
  30. +1 −1 twitter4j-core/src/main/java/twitter4j/internal/json/UserListJSONImpl.java
  31. +11 −22 twitter4j-core/src/main/java/twitter4j/internal/json/UserMentionEntityJSONImpl.java
  32. +3 −4 twitter4j-core/src/main/java/twitter4j/internal/{util → json}/z_T4JInternalParseUtil.java
  33. +11 −17 twitter4j-core/src/test/java/twitter4j/TweetsResourcesTest.java
  34. +2 −1 twitter4j-core/src/test/java/twitter4j/Twitter4JTestSuite.java
  35. +0 −1 twitter4j-core/src/test/java/twitter4j/UsersResourcesTest.java
  36. +0 −73 twitter4j-core/src/test/java/twitter4j/http/HTMLEntityTest.java
  37. +113 −0 twitter4j-core/src/test/java/twitter4j/internal/json/HTMLEntityTest.java
  38. +1 −0 twitter4j-core/src/test/java/twitter4j/internal/util/ParseUtilTest.java
  39. +2 −0 twitter4j-core/src/test/resources/twitter4j.properties
  40. +2 −2 twitter4j-stream/src/main/java/twitter4j/ControlStreamInfo.java
  41. +1 −1 twitter4j-stream/src/main/java/twitter4j/SiteStreamsImpl.java
  42. +2 −2 twitter4j-stream/src/main/java/twitter4j/StallWarning.java
  43. +1 −1 twitter4j-stream/src/main/java/twitter4j/StatusStreamImpl.java
  44. +2 −2 twitter4j-stream/src/main/java/twitter4j/StreamController.java
View
@@ -21,6 +21,7 @@ Alan Gutierrez <alan at blogometer.com>
Alessandro Bahgat <ale.bahgat at gmail.com> @abahgat
Alex Kira <alex.kira at gmail.com> @alexkira
Anton Novopashin <antonevane at gmail.com> @anton_evane
+Andy Boothe <andy.boothe at gmail.com> @sigpwned
Blake Barnes <blake.barnes at gmail.com>
Bruno Torres Goyanna <bgoyanna at gmail.com> @bgoyanna
Ciaran Jessup <ciaranj at gmail.com> @ciaran_j
@@ -17,7 +17,7 @@
package twitter4j;
import twitter4j.internal.org.json.JSONObject;
-import twitter4j.internal.util.z_T4JInternalParseUtil;
+import twitter4j.internal.json.z_T4JInternalParseUtil;
/**
* StatusDeletionNotice implementation. This class is NOT intended to be extended but left non-final for the ease of mock testing.
@@ -21,11 +21,11 @@
import twitter4j.internal.json.z_T4JInternalJSONImplFactory;
import twitter4j.internal.org.json.JSONException;
import twitter4j.internal.org.json.JSONObject;
-import twitter4j.internal.util.z_T4JInternalParseUtil;
+import twitter4j.internal.json.z_T4JInternalParseUtil;
import java.util.List;
-import static twitter4j.internal.util.z_T4JInternalParseUtil.getInt;
+import static twitter4j.internal.json.z_T4JInternalParseUtil.getInt;
/**
* An exception class that will be thrown when TwitterAPI calls are failed.<br>
@@ -26,7 +26,7 @@
import twitter4j.internal.org.json.JSONException;
import twitter4j.internal.org.json.JSONObject;
-import static twitter4j.internal.util.z_T4JInternalParseUtil.getBoolean;
+import static twitter4j.internal.json.z_T4JInternalParseUtil.getBoolean;
/**
* @author Yusuke Yamamoto - yusuke at mac.com
@@ -22,7 +22,7 @@
import twitter4j.internal.http.HttpResponse;
import twitter4j.internal.org.json.JSONObject;
-import static twitter4j.internal.util.z_T4JInternalParseUtil.getInt;
+import static twitter4j.internal.json.z_T4JInternalParseUtil.getInt;
/**
* @author Yusuke Yamamoto - yusuke at mac.com
@@ -24,7 +24,6 @@
import twitter4j.internal.org.json.JSONArray;
import twitter4j.internal.org.json.JSONException;
import twitter4j.internal.org.json.JSONObject;
-import twitter4j.internal.util.z_T4JInternalParseUtil;
/**
* @author Yusuke Yamamoto - yusuke at mac.com
@@ -28,7 +28,7 @@
import java.util.Date;
-import static twitter4j.internal.util.z_T4JInternalParseUtil.*;
+import static twitter4j.internal.json.z_T4JInternalParseUtil.*;
/**
* A data class representing sent/received direct message.
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2007 Yusuke Yamamoto
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package twitter4j.internal.json;
+
+/**
+ * @author Yusuke Yamamoto - yusuke at mac.com
+ */
+abstract class EntityIndex implements Comparable<EntityIndex> {
+ private int start = -1;
+ private int end = -1;
+
+ @Override
+ public int compareTo(EntityIndex that) {
+ long delta = this.start - that.start;
+ if (delta < Integer.MIN_VALUE) {
+ return Integer.MIN_VALUE;
+ } else if (delta > Integer.MAX_VALUE) {
+ return Integer.MAX_VALUE;
+ }
+ return (int) delta;
+ }
+
+ void setStart(int start) {
+ this.start = start;
+ }
+
+ void setEnd(int end) {
+ this.end = end;
+ }
+
+ int getStart() {
+ return start;
+ }
+
+ int getEnd() {
+ return end;
+ }
+}
@@ -25,7 +25,7 @@
import twitter4j.internal.org.json.JSONException;
import twitter4j.internal.org.json.JSONObject;
-import static twitter4j.internal.util.z_T4JInternalParseUtil.getLong;
+import static twitter4j.internal.json.z_T4JInternalParseUtil.getLong;
/**
* @author Yusuke Yamamoto - yusuke at mac.com
@@ -14,19 +14,21 @@
* limitations under the License.
*/
-package twitter4j.internal.http;
+package twitter4j.internal.json;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
-public final class HTMLEntity {
- public static String escape(String original) {
+final class HTMLEntity {
+
+ static String escape(String original) {
StringBuilder buf = new StringBuilder(original);
escape(buf);
return buf.toString();
}
- public static void escape(StringBuilder original) {
+ static void escape(StringBuilder original) {
int index = 0;
String escaped;
while (index < original.length()) {
@@ -40,7 +42,7 @@ public static void escape(StringBuilder original) {
}
}
- public static String unescape(String original) {
+ static String unescape(String original) {
String returnValue = null;
if (original != null) {
StringBuilder buf = new StringBuilder(original);
@@ -50,7 +52,7 @@ public static String unescape(String original) {
return returnValue;
}
- public static void unescape(StringBuilder original) {
+ static void unescape(StringBuilder original) {
int index = 0;
int semicolonIndex;
String escaped;
@@ -74,8 +76,54 @@ public static void unescape(StringBuilder original) {
}
}
- private static Map<String, String> entityEscapeMap = new HashMap<String, String>();
- private static Map<String, String> escapeEntityMap = new HashMap<String, String>();
+ static String unescapeAndSlideEntityIncdices(String text, EntityIndex[] entities) {
+ Arrays.sort(entities);
+ boolean handlingStart = true;
+ int entityIndex = 0;
+
+ int delta = 0;
+ int semicolonIndex;
+ String escaped;
+ String entity;
+ StringBuilder unescaped = new StringBuilder(text.length());
+
+ for (int i = 0; i < text.length(); i++) {
+ char c = text.charAt(i);
+ if (c == '&') {
+ semicolonIndex = text.indexOf(";", i);
+ if (-1 != semicolonIndex) {
+ escaped = text.substring(i, semicolonIndex + 1);
+ entity = escapeEntityMap.get(escaped);
+ if (entity != null) {
+ unescaped.append(entity);
+ i = semicolonIndex;
+ }else{
+ unescaped.append(c);
+ }
+ }else{
+ unescaped.append(c);
+ }
+ } else {
+ unescaped.append(c);
+ }
+ if (entityIndex < entities.length) {
+ if (handlingStart) {
+ if (entities[entityIndex].getStart() == (delta + i)) {
+ entities[entityIndex].setStart(unescaped.length() - 1);
+ handlingStart = false;
+ }
+ } else if (entities[entityIndex].getEnd() == (delta + i)) {
+ entities[entityIndex].setEnd(unescaped.length() - 1);
+ entityIndex++;
+ handlingStart = true;
+ }
+ }
+ }
+ return unescaped.toString();
+ }
+
+ private static final Map<String, String> entityEscapeMap = new HashMap<String, String>();
+ private static final Map<String, String> escapeEntityMap = new HashMap<String, String>();
static {
String[][] entities =
@@ -364,5 +412,4 @@ public static void unescape(StringBuilder original) {
escapeEntityMap.put(entity[1], entity[2]);
}
}
-
}
@@ -28,10 +28,8 @@
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.1.9
*/
-/*package*/ class HashtagEntityJSONImpl implements HashtagEntity {
+/*package*/ class HashtagEntityJSONImpl extends EntityIndex implements HashtagEntity {
private static final long serialVersionUID = 4068992372784813200L;
- private int start = -1;
- private int end = -1;
private String text;
@@ -42,8 +40,8 @@
/* package */ HashtagEntityJSONImpl(int start, int end, String text) {
super();
- this.start = start;
- this.end = end;
+ setStart(start);
+ setEnd(end);
this.text = text;
}
@@ -55,8 +53,8 @@
private void init(JSONObject json) throws TwitterException {
try {
JSONArray indicesArray = json.getJSONArray("indices");
- this.start = indicesArray.getInt(0);
- this.end = indicesArray.getInt(1);
+ setStart(indicesArray.getInt(0));
+ setEnd(indicesArray.getInt(1));
if (!json.isNull("text")) {
this.text = json.getString("text");
@@ -79,15 +77,15 @@ public String getText() {
*/
@Override
public int getStart() {
- return start;
+ return super.getStart();
}
/**
* {@inheritDoc}
*/
@Override
public int getEnd() {
- return end;
+ return super.getEnd();
}
@Override
@@ -97,28 +95,20 @@ public boolean equals(Object o) {
HashtagEntityJSONImpl that = (HashtagEntityJSONImpl) o;
- if (end != that.end) return false;
- if (start != that.start) return false;
- if (text != null ? !text.equals(that.text) : that.text != null)
- return false;
+ if (text != null ? !text.equals(that.text) : that.text != null) return false;
return true;
}
@Override
public int hashCode() {
- int result = start;
- result = 31 * result + end;
- result = 31 * result + (text != null ? text.hashCode() : 0);
- return result;
+ return text != null ? text.hashCode() : 0;
}
@Override
public String toString() {
return "HashtagEntityJSONImpl{" +
- "start=" + start +
- ", end=" + end +
- ", text='" + text + '\'' +
+ "text='" + text + '\'' +
'}';
}
}
@@ -23,7 +23,6 @@
import twitter4j.internal.org.json.JSONArray;
import twitter4j.internal.org.json.JSONException;
import twitter4j.internal.org.json.JSONObject;
-import twitter4j.internal.util.z_T4JInternalParseUtil;
import java.util.Arrays;
@@ -25,7 +25,7 @@
import twitter4j.internal.org.json.JSONException;
import twitter4j.internal.org.json.JSONObject;
-import static twitter4j.internal.util.z_T4JInternalParseUtil.*;
+import static twitter4j.internal.json.z_T4JInternalParseUtil.*;
/**
* @author Yusuke Yamamoto - yusuke at mac.com
@@ -24,17 +24,15 @@
import java.util.HashMap;
import java.util.Map;
-import static twitter4j.internal.util.z_T4JInternalParseUtil.getLong;
+import static twitter4j.internal.json.z_T4JInternalParseUtil.getLong;
/**
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.2.3
*/
-public class MediaEntityJSONImpl implements MediaEntity {
+public class MediaEntityJSONImpl extends EntityIndex implements MediaEntity {
private static final long serialVersionUID = 224487082931268487L;
private long id;
- private int start = -1;
- private int end = -1;
private String url;
private String mediaURL;
private String mediaURLHttps;
@@ -46,8 +44,8 @@
MediaEntityJSONImpl(JSONObject json) throws TwitterException {
try {
JSONArray indicesArray = json.getJSONArray("indices");
- this.start = indicesArray.getInt(0);
- this.end = indicesArray.getInt(1);
+ setStart(indicesArray.getInt(0));
+ setEnd(indicesArray.getInt(1));
this.id = getLong("id", json);
this.url = json.getString("url");
@@ -149,15 +147,15 @@ public String getType() {
*/
@Override
public int getStart() {
- return start;
+ return super.getStart();
}
/**
* {@inheritDoc}
*/
@Override
public int getEnd() {
- return end;
+ return super.getEnd();
}
static class Size implements MediaEntity.Size {
@@ -240,8 +238,6 @@ public int hashCode() {
public String toString() {
return "MediaEntityJSONImpl{" +
"id=" + id +
- ", start=" + start +
- ", end=" + end +
", url=" + url +
", mediaURL=" + mediaURL +
", mediaURLHttps=" + mediaURLHttps +
Oops, something went wrong.

0 comments on commit 4bf42e9

Please sign in to comment.