2 Copyright (c) 2007-2009, Yusuke Yamamoto
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the Yusuke Yamamoto nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY
17 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 package weibo4android
;
29 import org
.w3c
.dom
.Element
;
30 import org
.w3c
.dom
.Document
;
31 import org
.w3c
.dom
.NodeList
;
33 import weibo4android
.http
.Response
;
34 import weibo4android
.org
.json
.JSONArray
;
35 import weibo4android
.org
.json
.JSONException
;
36 import weibo4android
.org
.json
.JSONObject
;
38 import java
.util
.Date
;
39 import java
.util
.List
;
40 import java
.util
.ArrayList
;
43 * A data class representing one single retweet details.
45 * @author Yusuke Yamamoto - yusuke at mac.com
46 * @since Weibo4J 2.0.10
48 public class RetweetDetails
extends WeiboResponse
implements
49 java
.io
.Serializable
{
50 private long retweetId
;
51 private Date retweetedAt
;
52 private User retweetingUser
;
53 static final long serialVersionUID
= 1957982268696560598L;
55 /*package*/RetweetDetails(Response res
, Weibo weibo
) throws WeiboException
{
57 Element elem
= res
.asDocument().getDocumentElement();
58 init(res
, elem
, weibo
);
61 RetweetDetails(JSONObject json
) throws WeiboException
{
68 private void init(JSONObject json
) throws WeiboException
{
70 retweetId
= json
.getInt("retweetId");
71 retweetedAt
= parseDate(json
.getString("retweetedAt"), "EEE MMM dd HH:mm:ss z yyyy");
72 retweetingUser
=new User(json
.getJSONObject("retweetingUser"));
74 } catch (JSONException jsone
) {
75 throw new WeiboException(jsone
.getMessage() + ":" + json
.toString(), jsone
);
79 /*package*/RetweetDetails(Response res
, Element elem
, Weibo weibo
) throws
82 init(res
, elem
, weibo
);
85 private void init(Response res
, Element elem
, Weibo weibo
) throws
87 ensureRootNodeNameIs("retweet_details", elem
);
88 retweetId
= getChildLong("retweet_id", elem
);
89 retweetedAt
= getChildDate("retweeted_at", elem
);
90 retweetingUser
= new User(res
, (Element
) elem
.getElementsByTagName("retweeting_user").item(0)
94 public long getRetweetId() {
98 public Date
getRetweetedAt() {
102 public User
getRetweetingUser() {
103 return retweetingUser
;
105 /*modify by sycheng add json*/
107 static List
<RetweetDetails
> createRetweetDetails(Response res
) throws WeiboException
{
109 JSONArray list
= res
.asJSONArray();
110 int size
= list
.length();
111 List
<RetweetDetails
> retweets
= new ArrayList
<RetweetDetails
>(size
);
112 for (int i
= 0; i
< size
; i
++) {
113 retweets
.add(new RetweetDetails(list
.getJSONObject(i
)));
116 } catch (JSONException jsone
) {
117 throw new WeiboException(jsone
);
118 } catch (WeiboException te
) {
124 static List
<RetweetDetails
> createRetweetDetails(Response res
,
125 Weibo weibo
) throws WeiboException
{
126 Document doc
= res
.asDocument();
127 if (isRootNodeNilClasses(doc
)) {
128 return new ArrayList
<RetweetDetails
>(0);
131 ensureRootNodeNameIs("retweets", doc
);
132 NodeList list
= doc
.getDocumentElement().getElementsByTagName(
134 int size
= list
.getLength();
135 List
<RetweetDetails
> statuses
= new ArrayList
<RetweetDetails
>(size
);
136 for (int i
= 0; i
< size
; i
++) {
137 Element status
= (Element
) list
.item(i
);
138 statuses
.add(new RetweetDetails(res
, status
, weibo
));
141 } catch (WeiboException te
) {
142 ensureRootNodeNameIs("nil-classes", doc
);
143 return new ArrayList
<RetweetDetails
>(0);
150 public boolean equals(Object o
) {
151 if (this == o
) return true;
152 if (!(o
instanceof RetweetDetails
)) return false;
154 RetweetDetails that
= (RetweetDetails
) o
;
156 return retweetId
== that
.retweetId
;
160 public int hashCode() {
161 int result
= (int) (retweetId ^
(retweetId
>>> 32));
162 result
= 31 * result
+ retweetedAt
.hashCode();
163 result
= 31 * result
+ retweetingUser
.hashCode();
168 public String
toString() {
169 return "RetweetDetails{" +
170 "retweetId=" + retweetId
+
171 ", retweetedAt=" + retweetedAt
+
172 ", retweetingUser=" + retweetingUser
+