SubscribeOptionFields.java

  1. /**
  2.  *
  3.  * Copyright the original author or authors
  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 java.util.Calendar;

  19. /**
  20.  * Defines the possible field options for a subscribe options form as defined
  21.  * by <a href="http://xmpp.org/extensions/xep-0060.html#registrar-formtypes-subscribe">Section 16.4.2</a>.
  22.  *
  23.  * @author Robin Collier
  24.  */
  25. public enum SubscribeOptionFields
  26. {
  27.     /**
  28.      * Whether an entity wants to receive or disable notifications
  29.      *
  30.      * <p><b>Value: boolean</b></p>
  31.      */
  32.     deliver,

  33.     /**
  34.      * Whether an entity wants to receive digests (aggregations) of
  35.      * notifications or all notifications individually.
  36.      *
  37.      * <p><b>Value: boolean</b></p>
  38.      */
  39.     digest,
  40.    
  41.     /**
  42.      * The minimum number of seconds between sending any two notifications digests
  43.      *
  44.      * <p><b>Value: int</b></p>
  45.      */
  46.     digest_frequency,

  47.     /**
  48.      *
  49.      * <p><b>Value: {@link Calendar}</b></p>
  50.      */
  51.     expire,

  52.     /**
  53.      * Whether an entity wants to receive an XMPP message body in addition to
  54.      * the payload format.
  55.      *
  56.      * <p><b>Value: boolean</b></p>
  57.      */
  58.     include_body,
  59.    
  60.     /**
  61.      * The presence states for which an entity wants to receive notifications.
  62.      *
  63.      * <p><b>Value: {@link PresenceState}</b></p>
  64.      */
  65.     show_values,
  66.    
  67.     /**
  68.      *
  69.      *
  70.      * <p><b>Value: </b></p>
  71.      */
  72.     subscription_type,
  73.    
  74.     /**
  75.      *
  76.      * <p><b>Value: </b></p>
  77.      */
  78.     subscription_depth;
  79.    
  80.     public String getFieldName()
  81.     {
  82.         if (this == show_values)
  83.             return "pubsub#" + toString().replace('_', '-');
  84.         return "pubsub#" + toString();
  85.     }
  86.    
  87.     static public SubscribeOptionFields valueOfFromElement(String elementName)
  88.     {
  89.         String portion = elementName.substring(elementName.lastIndexOf('#' + 1));
  90.        
  91.         if ("show-values".equals(portion))
  92.             return show_values;
  93.         else
  94.             return valueOf(portion);
  95.     }
  96. }