From bad2718b1b85d806221fce52c76fa1d388993396 Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Wed, 7 Dec 2016 18:53:37 +0700 Subject: singleton java 8 date formatters --- .../com/juick/xmpp/extensions/JuickMessage.java | 132 ++++++++++----------- 1 file changed, 61 insertions(+), 71 deletions(-) (limited to 'juick-xmpp/src') diff --git a/juick-xmpp/src/main/java/com/juick/xmpp/extensions/JuickMessage.java b/juick-xmpp/src/main/java/com/juick/xmpp/extensions/JuickMessage.java index 18477b2a..b8a329db 100644 --- a/juick-xmpp/src/main/java/com/juick/xmpp/extensions/JuickMessage.java +++ b/juick-xmpp/src/main/java/com/juick/xmpp/extensions/JuickMessage.java @@ -18,35 +18,27 @@ package com.juick.xmpp.extensions; import com.juick.Tag; +import com.juick.util.DateFormattersHolder; +import com.juick.xmpp.StanzaChild; import com.juick.xmpp.utils.XmlUtils; -import com.juick.xmpp.*; -import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.TimeZone; - import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; +import java.io.IOException; +import java.text.ParseException; + /** - * * @author Ugnich Anton */ public class JuickMessage extends com.juick.Message implements StanzaChild { - public final static String XMLNS = "http://juick.com/message"; public final static String TagName = "juick"; - private SimpleDateFormat df; public JuickMessage() { - df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - df.setTimeZone(TimeZone.getTimeZone("UTC")); } public JuickMessage(com.juick.Message msg) { super(msg); - df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - df.setTimeZone(TimeZone.getTimeZone("UTC")); } @Override @@ -84,7 +76,7 @@ public class JuickMessage extends com.juick.Message implements StanzaChild { } String ts = parser.getAttributeValue(null, "ts"); if (ts != null) { - jmsg.setDate(df.parse(ts)); + jmsg.setDate(DateFormattersHolder.getMessageFormatterInstance().parse(ts)); } jmsg.setAttachmentType(parser.getAttributeValue(null, "attach")); @@ -106,78 +98,76 @@ public class JuickMessage extends com.juick.Message implements StanzaChild { @Override public String toString() { - String ret = ""; + StringBuilder builder = new StringBuilder(); - ret = "<" + TagName + " xmlns=\"" + XMLNS + "\""; - if (getMid() > 0) { - ret += " mid=\"" + getMid() + "\""; - } - if (getRid() > 0) { - ret += " rid=\"" + getRid() + "\""; - } - if (getReplyto() > 0) { - ret += " replyto=\"" + getReplyto() + "\""; - } - ret += " privacy=\"" + getPrivacy() + "\""; - if (FriendsOnly) { - ret += " friendsonly=\"1\""; - } - if (ReadOnly) { - ret += " readonly=\"1\""; - } - if (getDate() != null) { - ret += " ts=\"" + df.format(getDate()) + "\""; - } - if (getAttachmentType() != null) { - ret += " attach=\"" + getAttachmentType() + "\""; - } - ret += ">"; - if (getUser() != null) { - ret += JuickUser.toString(getUser()); - } - if (getText() != null) { - ret += "
" + XmlUtils.escape(getText()) + ""; - } - for (com.juick.Tag Tag : getTags()) { - ret += "