From 51d9de02265d6cc9d6045d79497d2a987ae2f7f7 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 15 Nov 2016 14:21:27 +0300 Subject: core classes are now serializeable with JAXB (to use as babbler extension) --- juick-core/src/main/java/com/juick/Message.java | 119 ++++++++++++++++-------- 1 file changed, 82 insertions(+), 37 deletions(-) (limited to 'juick-core/src/main/java/com/juick/Message.java') diff --git a/juick-core/src/main/java/com/juick/Message.java b/juick-core/src/main/java/com/juick/Message.java index 8afd1d7b..d60abc5e 100644 --- a/juick-core/src/main/java/com/juick/Message.java +++ b/juick-core/src/main/java/com/juick/Message.java @@ -20,7 +20,10 @@ package com.juick; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import com.juick.xml.adapters.SimpleDateAdapter; +import javax.xml.bind.annotation.*; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import java.util.*; import java.util.stream.Collectors; @@ -28,31 +31,37 @@ import java.util.stream.Collectors; * * @author Ugnich Anton */ +@XmlRootElement(name = "juick", namespace = "http://juick.com/message") +@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) public class Message implements Comparable { - private int MID = 0; - private int RID = 0; - - @JsonProperty("replyto") - public int ReplyTo = 0; - private String Text = null; - private User User = null; - @JsonProperty("tags") - public List Tags = new ArrayList<>(); + private int mid = 0; + private int rid = 0; + private int replyto = 0; + private String text = null; + private User user = null; + private List Tags = new ArrayList<>(); private Date date; + @XmlTransient public int TimeAgo = 0; @JsonIgnore - public int Privacy = 1; + private int privacy = 1; + @XmlTransient public boolean FriendsOnly = false; + @XmlTransient public boolean ReadOnly = false; + @XmlTransient public boolean Hidden = false; @JsonIgnore + @XmlTransient public boolean VisitorCanComment = true; + @XmlTransient public int Replies = 0; public String RepliesBy = null; public String AttachmentType = null; public String Photo = null; public String Video = null; public Place Place = null; + @XmlTransient public int Likes = 0; private boolean liked = false; public List childs = new ArrayList<>(); @@ -64,15 +73,15 @@ public class Message implements Comparable { } public Message(Message msg) { - setMID(msg.getMID()); - setRID(msg.getRID()); - ReplyTo = msg.ReplyTo; + setMid(msg.getMid()); + setRid(msg.getRid()); + replyto = msg.replyto; setText(msg.getText()); setUser(msg.getUser()); Tags = msg.Tags; setDate(msg.getDate()); TimeAgo = msg.TimeAgo; - Privacy = msg.Privacy; + privacy = msg.privacy; FriendsOnly = msg.FriendsOnly; ReadOnly = msg.ReadOnly; Hidden = msg.Hidden; @@ -101,7 +110,7 @@ public class Message implements Comparable { return false; } Message jmsg = (Message) obj; - return (this.getMID() == jmsg.getMID() && this.getRID() == jmsg.getRID()); + return (this.getMid() == jmsg.getMid() && this.getRid() == jmsg.getRid()); } @Override @@ -111,16 +120,16 @@ public class Message implements Comparable { } Message jmsg = (Message) obj; - if (this.getMID() != jmsg.getMID()) { - if (this.getMID() > jmsg.getMID()) { + if (this.getMid() != jmsg.getMid()) { + if (this.getMid() > jmsg.getMid()) { return -1; } else { return 1; } } - if (this.getRID() != jmsg.getRID()) { - if (this.getRID() < jmsg.getRID()) { + if (this.getRid() != jmsg.getRid()) { + if (this.getRid() < jmsg.getRid()) { return -1; } else { return 1; @@ -151,9 +160,9 @@ public class Message implements Comparable { if (AttachmentType != null) { String url = "http://i.juick.com/"; url += AttachmentType.equals("mp4") ? "video" : "photos-1024"; - url += "/" + getMID(); - if (getRID() > 0) { - url += "-" + getRID(); + url += "/" + getMid(); + if (getRid() > 0) { + url += "-" + getRid(); } url += "." + AttachmentType; return url; @@ -171,13 +180,13 @@ public class Message implements Comparable { if (FriendsOnly) { ret += " *friends"; } - if (Privacy == -2) { + if (privacy == -2) { ret += " *private"; } - if (Privacy == -1) { + if (privacy == -1) { ret += " *friends"; } - if (Privacy == 2) { + if (privacy == 2) { ret += " *public"; } if (ReadOnly) { @@ -188,42 +197,48 @@ public class Message implements Comparable { } @JsonProperty("mid") - public int getMID() { - return MID; + @XmlAttribute(name = "mid") + public int getMid() { + return mid; } - public void setMID(int MID) { - this.MID = MID; + public void setMid(int mid) { + this.mid = mid; } @JsonProperty("rid") - public int getRID() { - return RID; + @XmlAttribute(name = "rid") + public int getRid() { + return rid; } - public void setRID(int RID) { - this.RID = RID; + public void setRid(int rid) { + this.rid = rid; } + @XmlElement(name = "user", namespace = "http://juick.com/user") public com.juick.User getUser() { - return User; + return user; } public void setUser(com.juick.User user) { - User = user; + this.user = user; } @JsonProperty("body") + @XmlElement(name = "body") public String getText() { - return Text; + return text; } public void setText(String text) { - Text = text; + this.text = text; } @JsonProperty("timestamp") @JsonFormat(shape= JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss", timezone="UTC") + @XmlAttribute(name = "ts") + @XmlJavaTypeAdapter(SimpleDateAdapter.class) public Date getDate() { return date; } @@ -248,6 +263,7 @@ public class Message implements Comparable { this.Recommendation = recommendation; } + @XmlTransient public boolean isLiked() { return liked; } @@ -262,4 +278,33 @@ public class Message implements Comparable { public void setReplyQuote(String quote) { replyQuote = quote; } + + @JsonProperty("replyto") + @XmlAttribute(name = "replyto") + public int getReplyto() { + return replyto; + } + + public void setReplyto(int replyto) { + this.replyto = replyto; + } + + @JsonProperty("tags") + @XmlElement(name = "tag") + public List getTags() { + return Tags; + } + + public void setTags(List tags) { + Tags = tags; + } + + @XmlAttribute + public int getPrivacy() { + return privacy; + } + + public void setPrivacy(int privacy) { + this.privacy = privacy; + } } -- cgit v1.2.3