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. {
  28.     CREATE("create", PubSubNamespace.BASIC),
  29.     DELETE("delete", PubSubNamespace.OWNER),
  30.     DELETE_EVENT("delete", PubSubNamespace.EVENT),
  31.     CONFIGURE("configure", PubSubNamespace.BASIC),
  32.     CONFIGURE_OWNER("configure", PubSubNamespace.OWNER),
  33.     CONFIGURATION("configuration", PubSubNamespace.EVENT),
  34.     OPTIONS("options", PubSubNamespace.BASIC),
  35.     DEFAULT("default", PubSubNamespace.OWNER),  
  36.     ITEMS("items", PubSubNamespace.BASIC),
  37.     ITEMS_EVENT("items", PubSubNamespace.EVENT),
  38.     ITEM("item", PubSubNamespace.BASIC),
  39.     ITEM_EVENT("item", PubSubNamespace.EVENT),
  40.     PUBLISH("publish", PubSubNamespace.BASIC),
  41.     PUBLISH_OPTIONS("publish-options", PubSubNamespace.BASIC),
  42.     PURGE_OWNER("purge", PubSubNamespace.OWNER),
  43.     PURGE_EVENT("purge", PubSubNamespace.EVENT),
  44.     RETRACT("retract", PubSubNamespace.BASIC),
  45.     AFFILIATIONS("affiliations", PubSubNamespace.BASIC),
  46.     SUBSCRIBE("subscribe", PubSubNamespace.BASIC),
  47.     SUBSCRIPTION("subscription", PubSubNamespace.BASIC),
  48.     SUBSCRIPTIONS("subscriptions", PubSubNamespace.BASIC),
  49.     UNSUBSCRIBE("unsubscribe", PubSubNamespace.BASIC);

  50.     private String eName;
  51.     private PubSubNamespace nSpace;
  52.    
  53.     private PubSubElementType(String elemName, PubSubNamespace ns)
  54.     {
  55.         eName = elemName;
  56.         nSpace = ns;
  57.     }
  58.    
  59.     public PubSubNamespace getNamespace()
  60.     {
  61.         return nSpace;
  62.     }
  63.    
  64.     public String getElementName()
  65.     {
  66.         return eName;
  67.     }
  68.    
  69.     public static PubSubElementType valueOfFromElemName(String elemName, String namespace)
  70.     {
  71.         int index = namespace.lastIndexOf('#');
  72.         String fragment = (index == -1 ? null : namespace.substring(index+1));
  73.        
  74.         if (fragment != null)
  75.         {
  76.             return valueOf((elemName + '_' + fragment).toUpperCase(Locale.US));
  77.         }
  78.         return valueOf(elemName.toUpperCase(Locale.US).replace('-', '_'));
  79.     }

  80. }