001/**
002 *
003 * Copyright the original author or authors
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.pubsub;
018
019import java.util.Calendar;
020
021/**
022 * Defines the possible field options for a subscribe options form as defined
023 * by <a href="http://xmpp.org/extensions/xep-0060.html#registrar-formtypes-subscribe">Section 16.4.2</a>.
024 *
025 * @author Robin Collier
026 */
027public enum SubscribeOptionFields {
028    /**
029     * Whether an entity wants to receive or disable notifications.
030     *
031     * <p><b>Value: boolean</b></p>
032     */
033    deliver,
034
035    /**
036     * Whether an entity wants to receive digests (aggregations) of
037     * notifications or all notifications individually.
038     *
039     * <p><b>Value: boolean</b></p>
040     */
041    digest,
042
043    /**
044     * The minimum number of seconds between sending any two notifications digests.
045     *
046     * <p><b>Value: int</b></p>
047     */
048    digest_frequency,
049
050    /**
051     * Expire.
052     * <p><b>Value: {@link Calendar}</b></p>
053     */
054    expire,
055
056    /**
057     * Whether an entity wants to receive an XMPP message body in addition to
058     * the payload format.
059     *
060     * <p><b>Value: boolean</b></p>
061     */
062    include_body,
063
064    /**
065     * The presence states for which an entity wants to receive notifications.
066     *
067     * <p><b>Value: {@link PresenceState}</b></p>
068     */
069    show_values,
070
071    /**
072     * Subscription type.
073     *
074     * <p><b>Value: </b></p>
075     */
076    subscription_type,
077
078    /**
079     * Subscription depth.
080     *
081     * <p><b>Value: </b></p>
082     */
083    subscription_depth;
084
085    public String getFieldName() {
086        if (this == show_values)
087            return "pubsub#" + toString().replace('_', '-');
088        return "pubsub#" + toString();
089    }
090
091    public static SubscribeOptionFields valueOfFromElement(String elementName) {
092        String portion = elementName.substring(elementName.lastIndexOf('#' + 1));
093
094        if ("show-values".equals(portion))
095            return show_values;
096        else
097            return valueOf(portion);
098    }
099}