PubSubFeature.java

  1. /**
  2.  *
  3.  * Copyright 2015 Florian Schmaus
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.pubsub;

  18. import org.jivesoftware.smackx.disco.Feature;
  19. import org.jivesoftware.smackx.disco.Feature.Support;
  20. import org.jivesoftware.smackx.pubsub.packet.PubSub;

  21. /**
  22.  * The features a PubSub service may provides. Some are optional or recommended, while others are required.
  23.  *
  24.  * @author Florian Schmaus
  25.  * @see <a href="http://www.xmpp.org/extensions/xep-0060.html#features">XEP-60 ยง 10</a>
  26.  *
  27.  */
  28. public enum PubSubFeature implements CharSequence {

  29.     access_authorize(Support.optional),
  30.     access_open(Support.optional),
  31.     access_presence(Support.optional),
  32.     access_roster(Support.optional),
  33.     access_whitelist(Support.optional),
  34.     auto_create(Support.optional),
  35.     auto_subscribe(Support.recommended),
  36.     collections(Support.optional),
  37.     config_node(Support.recommended),
  38.     create_and_configure(Support.recommended),
  39.     create_nodes(Support.recommended),
  40.     delete_items(Support.recommended),
  41.     delete_nodes(Support.recommended),
  42.     get_pending(Support.optional),
  43.     item_ids(Support.recommended),
  44.     last_published(Support.recommended),
  45.     leased_subscription(Support.optional),
  46.     manage_subscriptions(Support.optional),
  47.     member_affiliation(Support.recommended),
  48.     meta_data(Support.recommended),
  49.     modify_affiliations(Support.optional),
  50.     multi_collection(Support.optional),
  51.     multi_subscribe(Support.optional),
  52.     outcast_affiliation(Support.recommended),
  53.     persistent_items(Support.recommended),
  54.     presence_notifications(Support.optional),
  55.     presence_subscribe(Support.recommended),
  56.     publish(Support.required),
  57.     publish_options(Support.optional),
  58.     publish_only_affiliation(Support.optional),
  59.     publisher_affiliation(Support.recommended),
  60.     purge_nodes(Support.optional),
  61.     retract_items(Support.optional),
  62.     retrieve_affiliations(Support.recommended),
  63.     retrieve_default(Support.recommended),
  64.     retrieve_default_sub(Support.optional),
  65.     retrieve_items(Support.recommended),
  66.     retrieve_subscriptions(Support.recommended),
  67.     subscribe(Support.required),
  68.     subscription_options(Support.optional),
  69.     subscriptions_notifications(Support.optional),
  70.     instant_nodes(Support.recommended),
  71.     filtered_notifications(Support.recommended),
  72.     ;

  73.     private final String feature;
  74.     private final String qualifiedFeature;
  75.     private final Feature.Support support;

  76.     PubSubFeature(Feature.Support support) {
  77.         this.feature = name().replace('_', '-');
  78.         this.qualifiedFeature = PubSub.NAMESPACE + '#' + this.feature;
  79.         this.support = support;
  80.     }

  81.     public String getFeatureName() {
  82.         return feature;
  83.     }

  84.     @Override
  85.     public String toString() {
  86.         return qualifiedFeature;
  87.     }

  88.     public Feature.Support support() {
  89.         return support;
  90.     }

  91.     @Override
  92.     public int length() {
  93.         return qualifiedFeature.length();
  94.     }

  95.     @Override
  96.     public char charAt(int index) {
  97.         return qualifiedFeature.charAt(index);
  98.     }

  99.     @Override
  100.     public CharSequence subSequence(int start, int end) {
  101.         return qualifiedFeature.subSequence(start, end);
  102.     }

  103. }