From 33371cffaf4979d197bea6d7d0c1be969675e717 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 23 Jan 2017 22:59:53 +0100 Subject: [PATCH] Move ChatStateExtension Provider in its own class --- .../chatstates/packet/ChatStateExtension.java | 16 --------- .../provider/ChatStateExtensionProvider.java | 34 +++++++++++++++++++ .../chatstates/provider/package-info.java | 21 ++++++++++++ .../extensions.providers | 12 +++---- 4 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/provider/ChatStateExtensionProvider.java create mode 100644 smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/provider/package-info.java diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/packet/ChatStateExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/packet/ChatStateExtension.java index 8aac8339c..ab0f0c772 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/packet/ChatStateExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/packet/ChatStateExtension.java @@ -19,9 +19,7 @@ package org.jivesoftware.smackx.chatstates.packet; import org.jivesoftware.smackx.chatstates.ChatState; import org.jivesoftware.smack.packet.ExtensionElement; -import org.jivesoftware.smack.provider.ExtensionElementProvider; import org.jivesoftware.smack.util.XmlStringBuilder; -import org.xmlpull.v1.XmlPullParser; /** * Represents a chat state which is an extension to message packets which is used to indicate @@ -66,18 +64,4 @@ public class ChatStateExtension implements ExtensionElement { return xml; } - public static class Provider extends ExtensionElementProvider { - - @Override - public ChatStateExtension parse(XmlPullParser parser, int initialDepth) { - ChatState state; - try { - state = ChatState.valueOf(parser.getName()); - } - catch (Exception ex) { - state = ChatState.active; - } - return new ChatStateExtension(state); - } - } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/provider/ChatStateExtensionProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/provider/ChatStateExtensionProvider.java new file mode 100644 index 000000000..03506dbaa --- /dev/null +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/provider/ChatStateExtensionProvider.java @@ -0,0 +1,34 @@ +/** + * + * Copyright 2017 Florian Schmaus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smackx.chatstates.provider; + +import org.jivesoftware.smack.provider.ExtensionElementProvider; +import org.jivesoftware.smackx.chatstates.ChatState; +import org.jivesoftware.smackx.chatstates.packet.ChatStateExtension; +import org.xmlpull.v1.XmlPullParser; + +public class ChatStateExtensionProvider extends ExtensionElementProvider { + + @Override + public ChatStateExtension parse(XmlPullParser parser, int initialDepth) throws Exception { + String chatStateString = parser.getName(); + ChatState state = ChatState.valueOf(chatStateString); + + return new ChatStateExtension(state); + } + +} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/provider/package-info.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/provider/package-info.java new file mode 100644 index 000000000..81c818453 --- /dev/null +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/provider/package-info.java @@ -0,0 +1,21 @@ +/** + * + * Copyright 2017 Florian Schmaus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Provider classes for Chat State Notifications (XEP-0085). + */ +package org.jivesoftware.smackx.chatstates.provider; diff --git a/smack-extensions/src/main/resources/org.jivesoftware.smack.extensions/extensions.providers b/smack-extensions/src/main/resources/org.jivesoftware.smack.extensions/extensions.providers index 15247d647..41705f0ca 100644 --- a/smack-extensions/src/main/resources/org.jivesoftware.smack.extensions/extensions.providers +++ b/smack-extensions/src/main/resources/org.jivesoftware.smack.extensions/extensions.providers @@ -16,35 +16,35 @@ org.jivesoftware.smackx.time.provider.TimeProvider - + active http://jabber.org/protocol/chatstates - org.jivesoftware.smackx.chatstates.packet.ChatStateExtension$Provider + org.jivesoftware.smackx.chatstates.provider.ChatStateExtensionProvider composing http://jabber.org/protocol/chatstates - org.jivesoftware.smackx.chatstates.packet.ChatStateExtension$Provider + org.jivesoftware.smackx.chatstates.provider.ChatStateExtensionProvider paused http://jabber.org/protocol/chatstates - org.jivesoftware.smackx.chatstates.packet.ChatStateExtension$Provider + org.jivesoftware.smackx.chatstates.provider.ChatStateExtensionProvider inactive http://jabber.org/protocol/chatstates - org.jivesoftware.smackx.chatstates.packet.ChatStateExtension$Provider + org.jivesoftware.smackx.chatstates.provider.ChatStateExtensionProvider gone http://jabber.org/protocol/chatstates - org.jivesoftware.smackx.chatstates.packet.ChatStateExtension$Provider + org.jivesoftware.smackx.chatstates.provider.ChatStateExtensionProvider