diff options
author | Christian Schneppe <christian@pix-art.de> | 2016-11-19 23:07:54 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-11-19 23:07:54 +0100 |
commit | d783cec97084a12873ca62b5fcd64620056ec01b (patch) | |
tree | 65e63d03dd4ab7a834c343ba593c8cd8917620cb /src/main/java/de/pixart/messenger/parser/AbstractParser.java | |
parent | 969ba45c56adaaa056f04464cd98aec115c9611b (diff) |
reformat code
Diffstat (limited to 'src/main/java/de/pixart/messenger/parser/AbstractParser.java')
-rw-r--r-- | src/main/java/de/pixart/messenger/parser/AbstractParser.java | 130 |
1 files changed, 65 insertions, 65 deletions
diff --git a/src/main/java/de/pixart/messenger/parser/AbstractParser.java b/src/main/java/de/pixart/messenger/parser/AbstractParser.java index 3ad20783b..21da7fe67 100644 --- a/src/main/java/de/pixart/messenger/parser/AbstractParser.java +++ b/src/main/java/de/pixart/messenger/parser/AbstractParser.java @@ -15,88 +15,88 @@ import de.pixart.messenger.xmpp.jid.Jid; public abstract class AbstractParser { - protected XmppConnectionService mXmppConnectionService; + protected XmppConnectionService mXmppConnectionService; - protected AbstractParser(XmppConnectionService service) { - this.mXmppConnectionService = service; - } + protected AbstractParser(XmppConnectionService service) { + this.mXmppConnectionService = service; + } - public static Long parseTimestamp(Element element, Long d) { - Element delay = element.findChild("delay","urn:xmpp:delay"); - if (delay != null) { - String stamp = delay.getAttribute("stamp"); - if (stamp != null) { - try { - return AbstractParser.parseTimestamp(delay.getAttribute("stamp")); - } catch (ParseException e) { - return d; - } - } - } - return d; - } + public static Long parseTimestamp(Element element, Long d) { + Element delay = element.findChild("delay", "urn:xmpp:delay"); + if (delay != null) { + String stamp = delay.getAttribute("stamp"); + if (stamp != null) { + try { + return AbstractParser.parseTimestamp(delay.getAttribute("stamp")); + } catch (ParseException e) { + return d; + } + } + } + return d; + } - public static long parseTimestamp(Element element) { - return parseTimestamp(element, System.currentTimeMillis()); - } + public static long parseTimestamp(Element element) { + return parseTimestamp(element, System.currentTimeMillis()); + } - public static long parseTimestamp(String timestamp) throws ParseException { - timestamp = timestamp.replace("Z", "+0000"); - SimpleDateFormat dateFormat; - long ms; - if (timestamp.charAt(19) == '.' && timestamp.length() >= 25) { - String millis = timestamp.substring(19,timestamp.length() - 5); - try { - double fractions = Double.parseDouble("0" + millis); - ms = Math.round(1000 * fractions); - } catch (NumberFormatException e) { - ms = 0; - } - } else { - ms = 0; - } - timestamp = timestamp.substring(0,19)+timestamp.substring(timestamp.length() -5,timestamp.length()); - dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ",Locale.US); - return Math.min(dateFormat.parse(timestamp).getTime()+ms, System.currentTimeMillis()); - } + public static long parseTimestamp(String timestamp) throws ParseException { + timestamp = timestamp.replace("Z", "+0000"); + SimpleDateFormat dateFormat; + long ms; + if (timestamp.charAt(19) == '.' && timestamp.length() >= 25) { + String millis = timestamp.substring(19, timestamp.length() - 5); + try { + double fractions = Double.parseDouble("0" + millis); + ms = Math.round(1000 * fractions); + } catch (NumberFormatException e) { + ms = 0; + } + } else { + ms = 0; + } + timestamp = timestamp.substring(0, 19) + timestamp.substring(timestamp.length() - 5, timestamp.length()); + dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US); + return Math.min(dateFormat.parse(timestamp).getTime() + ms, System.currentTimeMillis()); + } - protected void updateLastseen(final Account account, final Jid from) { - final Contact contact = account.getRoster().getContact(from); - contact.setLastResource(from.isBareJid() ? "" : from.getResourcepart()); - } + protected void updateLastseen(final Account account, final Jid from) { + final Contact contact = account.getRoster().getContact(from); + contact.setLastResource(from.isBareJid() ? "" : from.getResourcepart()); + } - protected String avatarData(Element items) { - Element item = items.findChild("item"); - if (item == null) { - return null; - } - return item.findChildContent("data", "urn:xmpp:avatar:data"); - } + protected String avatarData(Element items) { + Element item = items.findChild("item"); + if (item == null) { + return null; + } + return item.findChildContent("data", "urn:xmpp:avatar:data"); + } - public static MucOptions.User parseItem(Conversation conference, Element item) { + public static MucOptions.User parseItem(Conversation conference, Element item) { return parseItem(conference, item, null); } public static MucOptions.User parseItem(Conversation conference, Element item, Jid fullJid) { - final String local = conference.getJid().getLocalpart(); - final String domain = conference.getJid().getDomainpart(); - String affiliation = item.getAttribute("affiliation"); - String role = item.getAttribute("role"); - String nick = item.getAttribute("nick"); + final String local = conference.getJid().getLocalpart(); + final String domain = conference.getJid().getDomainpart(); + String affiliation = item.getAttribute("affiliation"); + String role = item.getAttribute("role"); + String nick = item.getAttribute("nick"); if (nick != null && fullJid == null) { try { fullJid = Jid.fromParts(local, domain, nick); } catch (InvalidJidException e) { fullJid = null; } - } - Jid realJid = item.getAttributeAsJid("jid"); + } + Jid realJid = item.getAttributeAsJid("jid"); MucOptions.User user = new MucOptions.User(conference.getMucOptions(), fullJid); - user.setRealJid(realJid); - user.setAffiliation(affiliation); - user.setRole(role); - return user; - } + user.setRealJid(realJid); + user.setAffiliation(affiliation); + user.setRole(role); + return user; + } public static String extractErrorMessage(Element packet) { final Element error = packet.findChild("error"); @@ -105,7 +105,7 @@ public abstract class AbstractParser { if (text != null && !text.trim().isEmpty()) { return text; } else { - return error.getChildren().get(0).getName().replace("-"," "); + return error.getChildren().get(0).getName().replace("-", " "); } } else { return null; |