aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2018-05-10 20:03:46 +0200
committersteckbrief <steckbrief@chefmail.de>2018-05-10 20:03:46 +0200
commitae30167461b89e7362d1ec5e77c14ec7640c537e (patch)
treedf7f90c591c92214bb2ee99bc06233e962344cb5 /src
parent9d5197223924ca3b51afe016d1f68119d244a1b4 (diff)
moves delay element references to xmpp package
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/generator/MessageGenerator.java5
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/parser/AbstractParser.java3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xml/Element.java12
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/delay/Delay.java27
4 files changed, 38 insertions, 9 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/generator/MessageGenerator.java b/src/main/java/de/thedevstack/conversationsplus/generator/MessageGenerator.java
index 13494baf..d402fa45 100644
--- a/src/main/java/de/thedevstack/conversationsplus/generator/MessageGenerator.java
+++ b/src/main/java/de/thedevstack/conversationsplus/generator/MessageGenerator.java
@@ -17,6 +17,7 @@ import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.xml.Element;
import de.thedevstack.conversationsplus.xmpp.carbons.Carbons;
import de.thedevstack.conversationsplus.xmpp.chatstate.ChatState;
+import de.thedevstack.conversationsplus.xmpp.delay.Delay;
import de.thedevstack.conversationsplus.xmpp.httpuploadim.HttpUploadHint;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
import de.thedevstack.conversationsplus.xmpp.openpgp.OpenPgpXep;
@@ -28,7 +29,7 @@ public class MessageGenerator extends AbstractGenerator {
/**
* Moved to messaging.MessageGenerator
*/
- private MessagePacket preparePacket(Message message) {
+ protected MessagePacket preparePacket(Message message) {
Conversation conversation = message.getConversation();
Account account = conversation.getAccount();
MessagePacket packet = new MessagePacket();
@@ -59,7 +60,7 @@ public class MessageGenerator extends AbstractGenerator {
final SimpleDateFormat mDateFormat = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
mDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
- Element delay = packet.addChild("delay", "urn:xmpp:delay");
+ Element delay = packet.addChild(Delay.DELAY.getXmlElement());
Date date = new Date(timestamp);
delay.setAttribute("stamp", mDateFormat.format(date));
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/parser/AbstractParser.java b/src/main/java/de/thedevstack/conversationsplus/parser/AbstractParser.java
index cb5c9d83..0358bddd 100644
--- a/src/main/java/de/thedevstack/conversationsplus/parser/AbstractParser.java
+++ b/src/main/java/de/thedevstack/conversationsplus/parser/AbstractParser.java
@@ -9,6 +9,7 @@ import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Contact;
import de.thedevstack.conversationsplus.services.XmppConnectionService;
import de.thedevstack.conversationsplus.xml.Element;
+import de.thedevstack.conversationsplus.xmpp.delay.Delay;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
import de.thedevstack.conversationsplus.xmpp.stanzas.AbstractStanza;
@@ -30,7 +31,7 @@ public abstract class AbstractParser {
* attribute the current time is returned.
*/
public static Long getTimestamp(Element element, Long defaultValue) {
- Element delay = element.findChild("delay","urn:xmpp:delay");
+ Element delay = element.findChild(Delay.DELAY);
if (delay != null) {
String stamp = delay.getAttribute("stamp");
if (stamp != null) {
diff --git a/src/main/java/de/thedevstack/conversationsplus/xml/Element.java b/src/main/java/de/thedevstack/conversationsplus/xml/Element.java
index 0b8c2035..95ed4c4e 100644
--- a/src/main/java/de/thedevstack/conversationsplus/xml/Element.java
+++ b/src/main/java/de/thedevstack/conversationsplus/xml/Element.java
@@ -31,18 +31,18 @@ public class Element {
}
public Element addChild(String name) {
- this.content = null;
- Element child = new Element(name);
- children.add(child);
- return child;
+ return this.addChild(new Element(name));
}
public Element addChild(String name, String xmlns) {
- this.content = null;
Element child = new Element(name);
child.setAttribute("xmlns", xmlns);
children.add(child);
- return child;
+ return this.addChild(child);
+ }
+
+ public Element addChild(XmlElementContainer container) {
+ return this.addChild(container.getXmlElement());
}
public Element setContent(String content) {
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/delay/Delay.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/delay/Delay.java
new file mode 100644
index 00000000..3f1dd50e
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/delay/Delay.java
@@ -0,0 +1,27 @@
+package de.thedevstack.conversationsplus.xmpp.delay;
+
+import de.thedevstack.conversationsplus.xml.Element;
+import de.thedevstack.conversationsplus.xml.XmlElementContainer;
+
+/**
+ */
+public enum Delay implements XmlElementContainer {
+ DELAY("delay");
+
+ private Element xmlElement;
+
+ Delay(String elementName) {
+ this.xmlElement = new Element(elementName, NAMESPACE);
+ }
+
+ @Override
+ public Element getXmlElement() {
+ return xmlElement;
+ }
+
+ /**
+ * The namespace of the delay timestamp as defined in XEP-0203.
+ * @see <a href="https://xmpp.org/extensions/xep-0203.html">https://xmpp.org/extensions/xep-0203.html</a>
+ */
+ public static final String NAMESPACE = "urn:xmpp:delay";
+}