From 901b316c06b2a455461f43befbd937415b5cf3a6 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sun, 6 May 2018 18:47:44 +0200 Subject: [PATCH] Add and register BodyElementProvider --- .../jivesoftware/smack/CoreInitializer.java | 27 +++++++++++++ .../smack/provider/BodyElementProvider.java | 38 +++++++++++++++++++ .../org.jivesoftware.smack/core.providers | 9 +++++ .../org.jivesoftware.smack/smack-config.xml | 1 + 4 files changed, 75 insertions(+) create mode 100644 smack-core/src/main/java/org/jivesoftware/smack/CoreInitializer.java create mode 100644 smack-core/src/main/java/org/jivesoftware/smack/provider/BodyElementProvider.java create mode 100644 smack-core/src/main/resources/org.jivesoftware.smack/core.providers diff --git a/smack-core/src/main/java/org/jivesoftware/smack/CoreInitializer.java b/smack-core/src/main/java/org/jivesoftware/smack/CoreInitializer.java new file mode 100644 index 000000000..155a4fbaa --- /dev/null +++ b/smack-core/src/main/java/org/jivesoftware/smack/CoreInitializer.java @@ -0,0 +1,27 @@ +/** + * + * Copyright 2018 Paul Schaub. + * + * 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.smack; + +import org.jivesoftware.smack.initializer.UrlInitializer; + +public class CoreInitializer extends UrlInitializer { + + @Override + protected String getProvidersUri() { + return "classpath:org.jivesoftware.smack/core.providers"; + } +} diff --git a/smack-core/src/main/java/org/jivesoftware/smack/provider/BodyElementProvider.java b/smack-core/src/main/java/org/jivesoftware/smack/provider/BodyElementProvider.java new file mode 100644 index 000000000..53fd25c20 --- /dev/null +++ b/smack-core/src/main/java/org/jivesoftware/smack/provider/BodyElementProvider.java @@ -0,0 +1,38 @@ +/** + * + * Copyright 2018 Paul Schaub. + * + * 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.smack.provider; + +import static org.jivesoftware.smack.util.PacketParserUtils.parseElementText; + +import org.jivesoftware.smack.packet.Message; +import org.jivesoftware.smack.util.ParserUtils; + +import org.xmlpull.v1.XmlPullParser; + +public class BodyElementProvider extends ExtensionElementProvider { + + @Override + public Message.Body parse(XmlPullParser parser, int initialDepth) throws Exception { + String xmlLang = ParserUtils.getXmlLang(parser); + if (xmlLang == null) { + xmlLang = "en"; + } + + String body = parseElementText(parser); + return new Message.Body(xmlLang, body); + } +} diff --git a/smack-core/src/main/resources/org.jivesoftware.smack/core.providers b/smack-core/src/main/resources/org.jivesoftware.smack/core.providers new file mode 100644 index 000000000..4e13951f5 --- /dev/null +++ b/smack-core/src/main/resources/org.jivesoftware.smack/core.providers @@ -0,0 +1,9 @@ + + + + + body + jabber:client + org.jivesoftware.smack.provider.BodyElementProvider + + diff --git a/smack-core/src/main/resources/org.jivesoftware.smack/smack-config.xml b/smack-core/src/main/resources/org.jivesoftware.smack/smack-config.xml index fd4468b90..6f68760f1 100644 --- a/smack-core/src/main/resources/org.jivesoftware.smack/smack-config.xml +++ b/smack-core/src/main/resources/org.jivesoftware.smack/smack-config.xml @@ -5,6 +5,7 @@ org.jivesoftware.smack.initializer.VmArgInitializer org.jivesoftware.smack.ReconnectionManager + org.jivesoftware.smack.CoreInitializer