Home | History | Annotate | Download | only in pubsub
      1 /**
      2  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
      3  * you may not use this file except in compliance with the License.
      4  * You may obtain a copy of the License at
      5  *
      6  *     http://www.apache.org/licenses/LICENSE-2.0
      7  *
      8  * Unless required by applicable law or agreed to in writing, software
      9  * distributed under the License is distributed on an "AS IS" BASIS,
     10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     11  * See the License for the specific language governing permissions and
     12  * limitations under the License.
     13  */
     14 package org.jivesoftware.smackx.pubsub;
     15 
     16 import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
     17 
     18 /**
     19  * Defines all the possible element types as defined for all the pubsub
     20  * schemas in all 3 namespaces.
     21  *
     22  * @author Robin Collier
     23  */
     24 public enum PubSubElementType
     25 {
     26 	CREATE("create", PubSubNamespace.BASIC),
     27 	DELETE("delete", PubSubNamespace.OWNER),
     28 	DELETE_EVENT("delete", PubSubNamespace.EVENT),
     29 	CONFIGURE("configure", PubSubNamespace.BASIC),
     30 	CONFIGURE_OWNER("configure", PubSubNamespace.OWNER),
     31 	CONFIGURATION("configuration", PubSubNamespace.EVENT),
     32 	OPTIONS("options", PubSubNamespace.BASIC),
     33 	DEFAULT("default", PubSubNamespace.OWNER),
     34 	ITEMS("items", PubSubNamespace.BASIC),
     35 	ITEMS_EVENT("items", PubSubNamespace.EVENT),
     36 	ITEM("item", PubSubNamespace.BASIC),
     37 	ITEM_EVENT("item", PubSubNamespace.EVENT),
     38 	PUBLISH("publish", PubSubNamespace.BASIC),
     39 	PUBLISH_OPTIONS("publish-options", PubSubNamespace.BASIC),
     40 	PURGE_OWNER("purge", PubSubNamespace.OWNER),
     41 	PURGE_EVENT("purge", PubSubNamespace.EVENT),
     42 	RETRACT("retract", PubSubNamespace.BASIC),
     43 	AFFILIATIONS("affiliations", PubSubNamespace.BASIC),
     44 	SUBSCRIBE("subscribe", PubSubNamespace.BASIC),
     45 	SUBSCRIPTION("subscription", PubSubNamespace.BASIC),
     46 	SUBSCRIPTIONS("subscriptions", PubSubNamespace.BASIC),
     47 	UNSUBSCRIBE("unsubscribe", PubSubNamespace.BASIC);
     48 
     49 	private String eName;
     50 	private PubSubNamespace nSpace;
     51 
     52 	private PubSubElementType(String elemName, PubSubNamespace ns)
     53 	{
     54 		eName = elemName;
     55 		nSpace = ns;
     56 	}
     57 
     58 	public PubSubNamespace getNamespace()
     59 	{
     60 		return nSpace;
     61 	}
     62 
     63 	public String getElementName()
     64 	{
     65 		return eName;
     66 	}
     67 
     68 	public static PubSubElementType valueOfFromElemName(String elemName, String namespace)
     69 	{
     70 		int index = namespace.lastIndexOf('#');
     71 		String fragment = (index == -1 ? null : namespace.substring(index+1));
     72 
     73 		if (fragment != null)
     74 		{
     75 			return valueOf((elemName + '_' + fragment).toUpperCase());
     76 		}
     77 		return valueOf(elemName.toUpperCase().replace('-', '_'));
     78 	}
     79 
     80 }
     81