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 */
14package org.jivesoftware.smackx.pubsub.packet;
15
16/**
17 * Defines all the valid namespaces that are used with the {@link PubSub} packet
18 * as defined by the specification.
19 *
20 * @author Robin Collier
21 */
22public enum PubSubNamespace
23{
24	BASIC(null),
25	ERROR("errors"),
26	EVENT("event"),
27	OWNER("owner");
28
29	private String fragment;
30
31	private PubSubNamespace(String fragment)
32	{
33		this.fragment = fragment;
34	}
35
36	public String getXmlns()
37	{
38		String ns = "http://jabber.org/protocol/pubsub";
39
40		if (fragment != null)
41			ns += '#' + fragment;
42
43		return ns;
44	}
45
46	public String getFragment()
47	{
48		return fragment;
49	}
50
51	public static PubSubNamespace valueOfFromXmlns(String ns)
52	{
53		int index = ns.lastIndexOf('#');
54
55		if (index != -1)
56		{
57			String suffix = ns.substring(ns.lastIndexOf('#')+1);
58			return valueOf(suffix.toUpperCase());
59		}
60		else
61			return BASIC;
62	}
63}
64