diff options
Diffstat (limited to 'src/com/isode/stroke/parser/payloadparsers')
3 files changed, 104 insertions, 2 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; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/DiscoItemsParser.java b/src/com/isode/stroke/parser/payloadparsers/DiscoItemsParser.java new file mode 100644 index 0000000..caf75cf --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/DiscoItemsParser.java @@ -0,0 +1,41 @@ +/* + * 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.DiscoItems; +import com.isode.stroke.elements.DiscoItems.Item; +import com.isode.stroke.jid.JID; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; + +class DiscoItemsParser extends GenericPayloadParser<DiscoItems> { + public DiscoItemsParser() { + super(new DiscoItems()); + } + + public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == PayloadLevel) { + if (element.equals("item")) { + Item item = new Item(attributes.getAttribute("name"), new JID(attributes.getAttribute("jid")), attributes.getAttribute("node")); + getPayloadInternal().addItem(item); + } + } + ++level_; + } + + public void handleEndElement(String element, String ns) { + --level_; + } + + public void handleCharacterData(String data) { + } + private static final int TopLevel = 0; + private static final int PayloadLevel = 1; + private int level_ = TopLevel; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java index 6114626..7273cf2 100644 --- a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java +++ b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java @@ -27,8 +27,8 @@ public class FullPayloadParserFactoryCollection extends PayloadParserFactoryColl addFactory(new SoftwareVersionParserFactory()); //addFactory(new StorageParserFactory()); addFactory(new RosterParserFactory()); - //addFactory(new DiscoInfoParserFactory()); - //addFactory(new DiscoItemsParserFactory()); + addFactory(new GenericPayloadParserFactory<DiscoInfoParser>("query", "http://jabber.org/protocol/disco#info", DiscoInfoParser.class)); + addFactory(new GenericPayloadParserFactory<DiscoItemsParser>("query", "http://jabber.org/protocol/disco#items", DiscoItemsParser.class)); //addFactory(new CapsInfoParserFactory()); addFactory(new ResourceBindParserFactory()); addFactory(new StartSessionParserFactory()); |