diff options
Diffstat (limited to 'src/com/isode/stroke/parser/payloadparsers')
7 files changed, 388 insertions, 0 deletions
diff --git a/src/com/isode/stroke/parser/payloadparsers/CarbonsDisableParser.java b/src/com/isode/stroke/parser/payloadparsers/CarbonsDisableParser.java new file mode 100644 index 0000000..e61a0c6 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/CarbonsDisableParser.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.elements.CarbonsDisable; +import com.isode.stroke.base.NotNull; + +public class CarbonsDisableParser extends GenericPayloadParser<CarbonsDisable> { + + public CarbonsDisableParser() { + super(new CarbonsDisable()); + } + + /** + * @param element. + * @param ns. + * @param attributes. + */ + @Override + public void handleStartElement(String element, String ns, AttributeMap attributes) { + + } + + /** + * @param element. + * @param ns. + */ + @Override + public void handleEndElement(String element, String ns) { + + } + + /** + * @param data. + */ + @Override + public void handleCharacterData(String data) { + + } +}
\ No newline at end of file diff --git a/src/com/isode/stroke/parser/payloadparsers/CarbonsEnableParser.java b/src/com/isode/stroke/parser/payloadparsers/CarbonsEnableParser.java new file mode 100644 index 0000000..39240a7 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/CarbonsEnableParser.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.elements.CarbonsEnable; +import com.isode.stroke.base.NotNull; + +public class CarbonsEnableParser extends GenericPayloadParser<CarbonsEnable> { + + public CarbonsEnableParser() { + super(new CarbonsEnable()); + } + + /** + * @param element. + * @param ns. + * @param attributes. + */ + @Override + public void handleStartElement(String element, String ns, AttributeMap attributes) { + + } + + /** + * @param element. + * @param ns. + */ + @Override + public void handleEndElement(String element, String ns) { + + } + + /** + * @param data. + */ + @Override + public void handleCharacterData(String data) { + + } +}
\ No newline at end of file diff --git a/src/com/isode/stroke/parser/payloadparsers/CarbonsPrivateParser.java b/src/com/isode/stroke/parser/payloadparsers/CarbonsPrivateParser.java new file mode 100644 index 0000000..be8df74 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/CarbonsPrivateParser.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.elements.CarbonsPrivate; +import com.isode.stroke.base.NotNull; + +public class CarbonsPrivateParser extends GenericPayloadParser<CarbonsPrivate> { + + public CarbonsPrivateParser() { + super(new CarbonsPrivate()); + } + + /** + * @param element. + * @param ns. + * @param attributes. + */ + @Override + public void handleStartElement(String element, String ns, AttributeMap attributes) { + + } + + /** + * @param element. + * @param ns. + */ + @Override + public void handleEndElement(String element, String ns) { + + } + + /** + * @param data. + */ + @Override + public void handleCharacterData(String data) { + + } +}
\ No newline at end of file diff --git a/src/com/isode/stroke/parser/payloadparsers/CarbonsReceivedParser.java b/src/com/isode/stroke/parser/payloadparsers/CarbonsReceivedParser.java new file mode 100644 index 0000000..e5ba2b6 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/CarbonsReceivedParser.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.payloadparsers.ForwardedParser; +import com.isode.stroke.elements.CarbonsReceived; +import com.isode.stroke.base.NotNull; + +public class CarbonsReceivedParser extends GenericPayloadParser<CarbonsReceived> { + + private final int TopLevel = 0; + private final int PayloadLevel = 1; + private int level_ = TopLevel; + private PayloadParserFactoryCollection factories_; + private ForwardedParser forwardedParser_; + + public CarbonsReceivedParser(PayloadParserFactoryCollection factories) { + super(new CarbonsReceived()); + this.factories_ = factories; + this.level_ = TopLevel; + } + + /** + * @param element. + * @param ns. + * @param attributes. + */ + @Override + public void handleStartElement(String element, String ns, AttributeMap attributes) { + NotNull.exceptIfNull(element, "element"); + if (level_ == PayloadLevel) { + if (element.equals("forwarded")) { + forwardedParser_ = (ForwardedParser)(new ForwardedParser(factories_)); + } + } + if (forwardedParser_ != null) { + forwardedParser_.handleStartElement(element, ns, attributes); + } + ++level_; + } + + /** + * @param element. + * @param ns. + */ + @Override + public void handleEndElement(String element, String ns) { + --level_; + if (forwardedParser_ != null && level_ >= PayloadLevel) { + forwardedParser_.handleEndElement(element, ns); + } + if (forwardedParser_ != null && level_ == PayloadLevel) { + /* done parsing nested stanza */ + getPayloadInternal().setForwarded(forwardedParser_.getPayloadInternal()); + forwardedParser_ = null; + } + } + + /** + * @param data. + */ + @Override + public void handleCharacterData(String data) { + if (forwardedParser_ != null) { + forwardedParser_.handleCharacterData(data); + } + } +}
\ No newline at end of file diff --git a/src/com/isode/stroke/parser/payloadparsers/CarbonsSentParser.java b/src/com/isode/stroke/parser/payloadparsers/CarbonsSentParser.java new file mode 100644 index 0000000..879e580 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/CarbonsSentParser.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.payloadparsers.ForwardedParser; +import com.isode.stroke.elements.CarbonsSent; +import com.isode.stroke.base.NotNull; + +public class CarbonsSentParser extends GenericPayloadParser<CarbonsSent> { + + private final int TopLevel = 0; + private final int PayloadLevel = 1; + private int level_ = TopLevel; + private PayloadParserFactoryCollection factories_; + private ForwardedParser forwardedParser_; + + public CarbonsSentParser(PayloadParserFactoryCollection factories) { + super(new CarbonsSent()); + this.factories_ = factories; + this.level_ = TopLevel; + } + + /** + * @param element, NotNull. + * @param ns. + * @param attributes. + */ + @Override + public void handleStartElement(String element, String ns, AttributeMap attributes) { + NotNull.exceptIfNull(element, "element"); + if (level_ == PayloadLevel) { + if (element.equals("forwarded")) { + forwardedParser_ = (ForwardedParser)(new ForwardedParser(factories_)); + } + } + if (forwardedParser_ != null) { + forwardedParser_.handleStartElement(element, ns, attributes); + } + ++level_; + } + + /** + * @param element. + * @param ns. + */ + @Override + public void handleEndElement(String element, String ns) { + --level_; + if (forwardedParser_ != null && level_ >= PayloadLevel) { + forwardedParser_.handleEndElement(element, ns); + } + if (forwardedParser_ != null && level_ == PayloadLevel) { + /* done parsing nested stanza */ + getPayloadInternal().setForwarded(forwardedParser_.getPayloadInternal()); + forwardedParser_ = null; + } + } + + /** + * @param data. + */ + @Override + public void handleCharacterData(String data) { + if (forwardedParser_ != null) { + forwardedParser_.handleCharacterData(data); + } + } +}
\ No newline at end of file diff --git a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java index f5ae485..d6d6483 100644 --- a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java +++ b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java @@ -14,6 +14,11 @@ public class FullPayloadParserFactoryCollection extends PayloadParserFactoryColl public FullPayloadParserFactoryCollection() { /* TODO: Port more */ //addFactory(new GenericPayloadParserFactory<IBBParser>("", "http://jabber.org/protocol/ibb")); + addFactory(new GenericPayloadParserFactory<CarbonsDisableParser>("disable", "urn:xmpp:carbons:2", CarbonsDisableParser.class)); + addFactory(new GenericPayloadParserFactory<CarbonsEnableParser>("enable", "urn:xmpp:carbons:2", CarbonsEnableParser.class)); + addFactory(new GenericPayloadParserFactory<CarbonsPrivateParser>("private", "urn:xmpp:carbons:2", CarbonsPrivateParser.class)); + addFactory(new GenericPayloadParserFactory2<CarbonsReceivedParser>("received", "urn:xmpp:carbons:2", this, CarbonsReceivedParser.class)); + addFactory(new GenericPayloadParserFactory2<CarbonsSentParser>("sent", "urn:xmpp:carbons:2", this, CarbonsSentParser.class)); addFactory(new GenericPayloadParserFactory<StatusShowParser>("show", StatusShowParser.class)); addFactory(new GenericPayloadParserFactory<StatusParser>("status", StatusParser.class)); addFactory(new GenericPayloadParserFactory<ReplaceParser>("replace", "http://swift.im/protocol/replace", ReplaceParser.class)); @@ -50,6 +55,7 @@ public class FullPayloadParserFactoryCollection extends PayloadParserFactoryColl addFactory(new GenericPayloadParserFactory<InBandRegistrationPayloadParser>("query", "jabber:iq:register", InBandRegistrationPayloadParser.class)); addFactory(new SearchPayloadParserFactory()); //addFactory(new StreamInitiationParserFactory()); + addFactory(new GenericPayloadParserFactory<ThreadParser>("thread", ThreadParser.class)); addFactory(new GenericPayloadParserFactory<BytestreamsParser>("query", "http://jabber.org/protocol/bytestreams", BytestreamsParser.class)); addFactory(new GenericPayloadParserFactory<VCardUpdateParser>("x", "vcard-temp:x:update", VCardUpdateParser.class)); addFactory(new GenericPayloadParserFactory<VCardParser>("vCard", "vcard-temp", VCardParser.class)); diff --git a/src/com/isode/stroke/parser/payloadparsers/ThreadParser.java b/src/com/isode/stroke/parser/payloadparsers/ThreadParser.java new file mode 100644 index 0000000..094e1e5 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/ThreadParser.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.elements.Thread; +import com.isode.stroke.base.NotNull; + +public class ThreadParser extends GenericPayloadParser<Thread> { + + private int level_ = 0; + private String text_ = ""; + + public ThreadParser() { + super(new Thread()); + } + + /** + * @param element, NotNull. + * @param ns. + * @param attributes, NotNull. + */ + @Override + public void handleStartElement(String element, String ns, AttributeMap attributes) { + NotNull.exceptIfNull(element, "element"); + NotNull.exceptIfNull(attributes, "attributes"); + ++level_; + if (element.equals("thread")) { + if(attributes.getAttributeValue("parent") != null) { + getPayloadInternal().setParent(attributes.getAttributeValue("parent")); + } else { + getPayloadInternal().setParent(""); + } + } + } + + /** + * @param element, NotNull. + * @param ns. + */ + @Override + public void handleEndElement(String element, String ns) { + --level_; + if (level_ == 0) { + getPayloadInternal().setText(text_); + } + } + + /** + * @param data, NotNull. + */ + @Override + public void handleCharacterData(String data) { + NotNull.exceptIfNull(data, "data"); + if (level_ == 1) { + text_ += data; + } + } +}
\ No newline at end of file |