1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-18 08:51:08 +01:00

Refactor PEP to use PubSub API.

Fixes SMACK-416.
This commit is contained in:
Florian Schmaus 2015-08-17 08:16:49 +02:00
parent 0d6f00873f
commit 33e5c37af8
17 changed files with 479 additions and 453 deletions

View file

@ -20,6 +20,8 @@ import java.util.Arrays;
import java.util.List;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
/**
@ -32,6 +34,16 @@ import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
*/
public class EventElement implements EmbeddedPacketExtension
{
/**
* The constant String "event".
*/
public static final String ELEMENT = "event";
/**
* The constant String "http://jabber.org/protocol/pubsub#event".
*/
public static final String NAMESPACE = PubSubNamespace.EVENT.getXmlns();
private EventElementType type;
private NodeExtension ext;
@ -66,12 +78,16 @@ public class EventElement implements EmbeddedPacketExtension
return PubSubNamespace.EVENT.getXmlns();
}
public String toXML()
{
StringBuilder builder = new StringBuilder("<event xmlns='" + PubSubNamespace.EVENT.getXmlns() + "'>");
@Override
public XmlStringBuilder toXML() {
XmlStringBuilder xml = new XmlStringBuilder(this);
xml.rightAngleBracket();
xml.append(ext.toXML());
xml.closeElement(this);
return xml;
}
builder.append(ext.toXML());
builder.append("</event>");
return builder.toString();
}
public static EventElement from(Stanza stanza) {
return stanza.getExtension(ELEMENT, NAMESPACE);
}
}

View file

@ -0,0 +1,115 @@
/**
*
* Copyright 2015 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.pubsub;
import org.jivesoftware.smackx.disco.Feature;
import org.jivesoftware.smackx.disco.Feature.Support;
import org.jivesoftware.smackx.pubsub.packet.PubSub;
/**
* The features a PubSub service may provides. Some are optional or recommended, while others are required.
*
* @author Florian Schmaus
* @see <a href="http://www.xmpp.org/extensions/xep-0060.html#features">XEP-60 § 10</a>
*
*/
public enum PubSubFeature implements CharSequence {
access_authorize(Support.optional),
access_open(Support.optional),
access_presence(Support.optional),
access_roster(Support.optional),
acccess_whitelist(Support.optional),
auto_create(Support.optional),
auto_subscribe(Support.recommended),
collections(Support.optional),
config_node(Support.recommended),
create_and_configure(Support.recommended),
create_nodes(Support.recommended),
delete_items(Support.recommended),
delete_nodes(Support.recommended),
get_pending(Support.optional),
item_ids(Support.recommended),
last_published(Support.recommended),
leased_subscription(Support.optional),
manage_subscriptions(Support.optional),
member_affiliation(Support.recommended),
meta_data(Support.recommended),
modify_affiliations(Support.optional),
multi_collection(Support.optional),
multi_subscribe(Support.optional),
outcast_affiliation(Support.recommended),
persistent_items(Support.recommended),
presence_notifications(Support.optional),
presence_subscribe(Support.recommended),
publish(Support.required),
publish_options(Support.optional),
publish_only_affiliation(Support.optional),
publisher_affiliation(Support.recommended),
purge_nodes(Support.optional),
retract_items(Support.optional),
retrieve_affiliations(Support.recommended),
retrieve_default(Support.recommended),
retrieve_default_sub(Support.optional),
retrieve_items(Support.recommended),
retrieve_subscriptions(Support.recommended),
subscribe(Support.required),
subscription_options(Support.optional),
subscriptions_notifications(Support.optional),
instant_nodes(Support.recommended),
filtered_notifications(Support.recommended),
;
private final String feature;
private final String qualifiedFeature;
private final Feature.Support support;
private PubSubFeature(Feature.Support support) {
this.feature = name().replace('_', '-');
this.qualifiedFeature = PubSub.NAMESPACE + '#' + this.feature;
this.support = support;
}
public String getFeatureName() {
return feature;
}
@Override
public String toString() {
return qualifiedFeature;
}
public Feature.Support support() {
return support;
}
@Override
public int length() {
return qualifiedFeature.length();
}
@Override
public char charAt(int index) {
return qualifiedFeature.charAt(index);
}
@Override
public CharSequence subSequence(int start, int end) {
return qualifiedFeature.subSequence(start, end);
}
}

View file

@ -44,6 +44,7 @@ import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
import org.jivesoftware.smackx.pubsub.util.NodeUtils;
import org.jivesoftware.smackx.xdata.Form;
import org.jivesoftware.smackx.xdata.FormField;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
@ -61,12 +62,12 @@ import org.jxmpp.stringprep.XmppStringprepException;
public final class PubSubManager extends Manager {
private static final Logger LOGGER = Logger.getLogger(PubSubManager.class.getName());
private static final Map<XMPPConnection, Map<DomainBareJid, PubSubManager>> INSTANCES = new WeakHashMap<>();
private static final Map<XMPPConnection, Map<BareJid, PubSubManager>> INSTANCES = new WeakHashMap<>();
/**
* The JID of the PubSub service this manager manages.
*/
private final DomainBareJid pubSubService;
private final BareJid pubSubService;
/**
* A map of node IDs to Nodes, used to cache those Nodes. This does only cache the type of Node,
@ -112,8 +113,8 @@ public final class PubSubManager extends Manager {
* @param pubSubService the PubSub service.
* @return a PubSub manager for the connection and service.
*/
public static synchronized PubSubManager getInstance(XMPPConnection connection, DomainBareJid pubSubService) {
Map<DomainBareJid, PubSubManager> managers = INSTANCES.get(connection);
public static synchronized PubSubManager getInstance(XMPPConnection connection, BareJid pubSubService) {
Map<BareJid, PubSubManager> managers = INSTANCES.get(connection);
if (managers == null) {
managers = new HashMap<>();
INSTANCES.put(connection, managers);
@ -133,7 +134,7 @@ public final class PubSubManager extends Manager {
* @param connection The XMPP connection
* @param toAddress The pubsub specific to address (required for some servers)
*/
PubSubManager(XMPPConnection connection, DomainBareJid toAddress)
PubSubManager(XMPPConnection connection, BareJid toAddress)
{
super(connection);
pubSubService = toAddress;
@ -356,7 +357,7 @@ public final class PubSubManager extends Manager {
*
* @return the JID of the PubSub service.
*/
public DomainBareJid getServiceJid() {
public BareJid getServiceJid() {
return pubSubService;
}

View file

@ -0,0 +1,36 @@
/**
*
* Copyright 2015 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.pubsub.filter;
import org.jivesoftware.smack.filter.StanzaExtensionFilter;
import org.jivesoftware.smackx.pubsub.EventElement;
/**
* Filter for stanzas with the PubSub 'event' extension.
*
* @author Florian Schmaus
*
*/
public final class EventExtensionFilter extends StanzaExtensionFilter {
public static final EventExtensionFilter INSTANCE = new EventExtensionFilter();
private EventExtensionFilter() {
super(EventElement.ELEMENT, EventElement.NAMESPACE);
}
}

View file

@ -0,0 +1,21 @@
/**
*
* Copyright 2015 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.
*/
/**
* Filters for Publish-Subscribe (XEP-60).
*/
package org.jivesoftware.smackx.pubsub.filter;