diff options
author | Gurmeen Bindra <gurmeen.bindra@isode.com> | 2012-04-17 09:29:05 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-04-19 10:45:53 (GMT) |
commit | d9d9451156ee8a4315de30571131d114af205fa1 (patch) | |
tree | 24d0dfb36be867651c39ff6898c944ed035e7f5b /src/com/isode/stroke/parser/payloadparsers/MUCItemParser.java | |
parent | b54bc5406f95902ce2438ac64a19390ae0f2f409 (diff) | |
download | stroke-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/MUCItemParser.java')
-rw-r--r-- | src/com/isode/stroke/parser/payloadparsers/MUCItemParser.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/com/isode/stroke/parser/payloadparsers/MUCItemParser.java b/src/com/isode/stroke/parser/payloadparsers/MUCItemParser.java new file mode 100644 index 0000000..1a1bb74 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/MUCItemParser.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2012, Isode Limited, London, England. + * All rights reserved. + */ +/* + * Copyright (c) 2011, Kevin Smith + * All rights reserved. + */ +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.elements.MUCItem; +import com.isode.stroke.elements.MUCOccupant.Affiliation; +import com.isode.stroke.elements.MUCOccupant.Role; +import com.isode.stroke.jid.JID; +import com.isode.stroke.parser.tree.ParserElement; + +/** + * Class containing parser functions for MUC Item + * + */ +public class MUCItemParser { + + /** + * Get the MUC Item from the node + * @param root XML node element + * @return MUC Item, not null + */ + public static MUCItem itemFromTree(ParserElement root) { + MUCItem item = new MUCItem(); + String affiliation = root.getAttributes().getAttribute("affiliation"); + String role = root.getAttributes().getAttribute("role"); + String nick = root.getAttributes().getAttribute("nick"); + String jid = root.getAttributes().getAttribute("jid"); + item.affiliation = parseAffiliation(affiliation); + item.role = parseRole(role); + if (!jid.isEmpty()) { + item.realJID = new JID(jid); + } + if (!nick.isEmpty()) { + item.nick = nick; + } + String xmlns = root.getNamespace(); + String reason = root.getChild("reason", xmlns).getText(); + String actor = root.getChild("actor", xmlns).getAttributes().getAttribute("jid"); + if (!reason.isEmpty()) { + item.reason = reason; + } + if (!actor.isEmpty()) { + item.actor = new JID(actor); + } + + return item; + } + + private static Role parseRole(String val) { + for(Role role : Role.values()) { + if(role.nodeName.equals(val)) { + return role; + } + } + return null; + } + + private static Affiliation parseAffiliation(String val) { + for(Affiliation aff : Affiliation.values()) { + if(aff.nodeName.equals(val)) { + return aff; + } + } + return null; + } +} |