PubSubElementType.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.Locale;

  19. import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;

  20. /**
  21.  * Defines all the possible element types as defined for all the pubsub
  22.  * schemas in all 3 namespaces.
  23.  *
  24.  * @author Robin Collier
  25.  */
  26. public enum PubSubElementType {
  27.     CREATE("create", PubSubNamespace.basic),
  28.     DELETE("delete", PubSubNamespace.owner),
  29.     DELETE_EVENT("delete", PubSubNamespace.event),
  30.     CONFIGURE("configure", PubSubNamespace.basic),
  31.     CONFIGURE_OWNER("configure", PubSubNamespace.owner),
  32.     CONFIGURATION("configuration", PubSubNamespace.event),
  33.     OPTIONS("options", PubSubNamespace.basic),
  34.     DEFAULT("default", PubSubNamespace.owner),
  35.     ITEMS("items", PubSubNamespace.basic),
  36.     ITEMS_EVENT("items", PubSubNamespace.event),
  37.     ITEM("item", PubSubNamespace.basic),
  38.     ITEM_EVENT("item", PubSubNamespace.event),
  39.     PUBLISH("publish", PubSubNamespace.basic),
  40.     PUBLISH_OPTIONS("publish-options", PubSubNamespace.basic),
  41.     PURGE_OWNER("purge", PubSubNamespace.owner),
  42.     PURGE_EVENT("purge", PubSubNamespace.event),
  43.     RETRACT("retract", PubSubNamespace.basic),
  44.     AFFILIATIONS("affiliations", PubSubNamespace.basic),
  45.     AFFILIATIONS_OWNER("affiliations", PubSubNamespace.owner),
  46.     SUBSCRIBE("subscribe", PubSubNamespace.basic),
  47.     SUBSCRIPTION("subscription", PubSubNamespace.basic),
  48.     SUBSCRIPTIONS("subscriptions", PubSubNamespace.basic),
  49.     SUBSCRIPTIONS_OWNER("subscriptions", PubSubNamespace.owner),
  50.     UNSUBSCRIBE("unsubscribe", PubSubNamespace.basic);

  51.     private final String eName;
  52.     private final PubSubNamespace nSpace;

  53.     PubSubElementType(String elemName, PubSubNamespace ns) {
  54.         eName = elemName;
  55.         nSpace = ns;
  56.     }

  57.     public PubSubNamespace getNamespace() {
  58.         return nSpace;
  59.     }

  60.     public String getElementName() {
  61.         return eName;
  62.     }

  63.     public static PubSubElementType valueOfFromElemName(String elemName, String namespace) {
  64.         int index = namespace.lastIndexOf('#');
  65.         String fragment = index == -1 ? null : namespace.substring(index + 1);

  66.         if (fragment != null) {
  67.             return valueOf((elemName + '_' + fragment).toUpperCase(Locale.US));
  68.         }
  69.         return valueOf(elemName.toUpperCase(Locale.US).replace('-', '_'));
  70.     }

  71. }