summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGurmeen Bindra <gurmeen.bindra@isode.com>2012-04-17 09:29:05 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-04-19 10:45:53 (GMT)
commitd9d9451156ee8a4315de30571131d114af205fa1 (patch)
tree24d0dfb36be867651c39ff6898c944ed035e7f5b /src/com/isode/stroke/parser/payloadparsers/MUCUserPayloadParser.java
parentb54bc5406f95902ce2438ac64a19390ae0f2f409 (diff)
downloadstroke-d9d9451156ee8a4315de30571131d114af205fa1.zip
stroke-d9d9451156ee8a4315de30571131d114af205fa1.tar.bz2
Port MUC Payload Parsers from Swiften to Stroke
This patch ports the MUC Payload parsers from swiften to stroke. Test-information: ported junits work fine
Diffstat (limited to 'src/com/isode/stroke/parser/payloadparsers/MUCUserPayloadParser.java')
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/MUCUserPayloadParser.java71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/com/isode/stroke/parser/payloadparsers/MUCUserPayloadParser.java b/src/com/isode/stroke/parser/payloadparsers/MUCUserPayloadParser.java
new file mode 100644
index 0000000..170e935
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/MUCUserPayloadParser.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2012, Isode Limited, London, England.
+ * All rights reserved.
+ */
+/*
+ * Copyright (c) 2010, Kevin Smith
+ * All rights reserved.
+ */
+package com.isode.stroke.parser.payloadparsers;
+
+import com.isode.stroke.elements.MUCItem;
+import com.isode.stroke.elements.MUCUserPayload;
+import com.isode.stroke.jid.JID;
+import com.isode.stroke.parser.GenericPayloadTreeParser;
+import com.isode.stroke.parser.PayloadParserFactoryCollection;
+import com.isode.stroke.parser.tree.ParserElement;
+import com.isode.stroke.parser.tree.TreeReparser;
+
+/**
+ * Class representing a parser for MUC User payload
+ *
+ */
+public class MUCUserPayloadParser extends GenericPayloadTreeParser<MUCUserPayload> {
+
+ private PayloadParserFactoryCollection factories;
+
+ /**
+ * Create the parser
+ * @param collection reference to payload parser factory collection, not null
+ */
+ public MUCUserPayloadParser(PayloadParserFactoryCollection collection){
+ super(new MUCUserPayload());
+ this.factories = collection;
+ }
+
+ @Override
+ public void handleTree(ParserElement root) {
+ for (ParserElement child : root.getAllChildren()) {
+ if ("item".equals(child.getName()) && child.getNamespace().equals(root.getNamespace())) {
+ MUCItem item = MUCItemParser.itemFromTree(child);
+ getPayloadInternal().addItem(item);
+ } else if ("password".equals(child.getName()) && child.getNamespace().equals(root.getNamespace())) {
+ getPayloadInternal().setPassword(child.getText());
+ } else if ("invite".equals(child.getName()) && child.getNamespace().equals(root.getNamespace())) {
+ MUCUserPayload.Invite invite = new MUCUserPayload.Invite();
+ String to = child.getAttributes().getAttribute("to");
+ if (to != null && !to.isEmpty()) {
+ invite.to = JID.fromString(to);
+ }
+ String from = child.getAttributes().getAttribute("from");
+ if (from != null && !from.isEmpty()) {
+ invite.from = JID.fromString(from);
+ }
+ ParserElement reason = child.getChild("reason", root.getNamespace());
+ if (reason != null) {
+ invite.reason = reason.getText();
+ }
+ getPayloadInternal().setInvite(invite);
+ } else if ("status".equals(child.getName()) && child.getNamespace().equals(root.getNamespace())) {
+ MUCUserPayload.StatusCode status = new MUCUserPayload.StatusCode();
+ try {
+ status.code = Integer.parseInt(child.getAttributes().getAttribute("code"));
+ getPayloadInternal().addStatusCode(status);
+ }catch (NumberFormatException e) {
+ }
+ } else {
+ getPayloadInternal().setPayload(TreeReparser.parseTree(child, factories));
+ }
+ }
+ }
+}