diff options
author | Kevin Smith <git@kismith.co.uk> | 2012-01-12 16:48:02 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-01-16 15:54:31 (GMT) |
commit | 839db071f46d083b86996f514f5fe0f2d6aee80a (patch) | |
tree | 9f14beb42dcd82fa4deba10f516a0ba0368e57b5 /src/com/isode/stroke/parser/payloadparsers/DiscoInfoParser.java | |
parent | 3adee817bfcbd54fd13c4d946bedadeca661e9b1 (diff) | |
download | stroke-839db071f46d083b86996f514f5fe0f2d6aee80a.zip stroke-839db071f46d083b86996f514f5fe0f2d6aee80a.tar.bz2 |
Add support for DiscoItems and DiscoInfo.
Updates requisite classes in line with Swiften.
Also fixes bugs in the EventLoops not using handleEvent.
Diffstat (limited to 'src/com/isode/stroke/parser/payloadparsers/DiscoInfoParser.java')
-rw-r--r-- | src/com/isode/stroke/parser/payloadparsers/DiscoInfoParser.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/com/isode/stroke/parser/payloadparsers/DiscoInfoParser.java b/src/com/isode/stroke/parser/payloadparsers/DiscoInfoParser.java new file mode 100644 index 0000000..445a6de --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/DiscoInfoParser.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2012, Isode Limited, London, England. + * All rights reserved. + */ +/* + * Copyright (c) 2010, Remko Tronçon. + * All rights reserved. + */ +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.elements.DiscoInfo; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; + + +class DiscoInfoParser extends GenericPayloadParser<DiscoInfo> { + public DiscoInfoParser() { + super(new DiscoInfo()); + } + + public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == PayloadLevel) { + if (element .equals("identity")) { + getPayloadInternal().addIdentity(new DiscoInfo.Identity(attributes.getAttribute("name"), attributes.getAttribute("category"), attributes.getAttribute("type"), attributes.getAttribute("lang", "http://www.w3.org/XML/1998/namespace"))); + } + else if (element.equals("feature")) { + getPayloadInternal().addFeature(attributes.getAttribute("var")); + } + else if (element.equals("x") && ns.equals("jabber:x:data")) { + assert(formParser_ == null); + formParser_ = new FormParser(); + } + } + if (formParser_ != null) { + formParser_.handleStartElement(element, ns, attributes); + } + ++level_; + } + + public void handleEndElement(String element, String ns) { + --level_; + if (formParser_ != null) { + formParser_.handleEndElement(element, ns); + } + if (level_ == PayloadLevel && formParser_ != null) { + getPayloadInternal().addExtension(formParser_.getPayloadInternal()); + formParser_ = null; + } + } + + public void handleCharacterData(String data) { + if (formParser_ != null) { + formParser_.handleCharacterData(data); + } + } + + private static final int TopLevel = 0; + private static final int PayloadLevel = 1; + private int level_ = 0; + private FormParser formParser_ = null; +} |