Shuyi Chen | d7955ce | 2013-05-22 14:51:55 -0700 | [diff] [blame] | 1 | /**
|
| 2 | * $RCSfile$
|
| 3 | * $Revision: 2407 $
|
| 4 | * $Date: 2004-11-02 15:37:00 -0800 (Tue, 02 Nov 2004) $
|
| 5 | *
|
| 6 | * Copyright 2003-2007 Jive Software.
|
| 7 | *
|
| 8 | * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
|
| 9 | * you may not use this file except in compliance with the License.
|
| 10 | * You may obtain a copy of the License at
|
| 11 | *
|
| 12 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 13 | *
|
| 14 | * Unless required by applicable law or agreed to in writing, software
|
| 15 | * distributed under the License is distributed on an "AS IS" BASIS,
|
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 17 | * See the License for the specific language governing permissions and
|
| 18 | * limitations under the License.
|
| 19 | */
|
| 20 |
|
| 21 | package org.jivesoftware.smackx.packet;
|
| 22 |
|
| 23 | import org.jivesoftware.smackx.ChatState;
|
| 24 | import org.jivesoftware.smack.packet.PacketExtension;
|
| 25 | import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
| 26 | import org.xmlpull.v1.XmlPullParser;
|
| 27 |
|
| 28 | /**
|
| 29 | * Represents a chat state which is an extension to message packets which is used to indicate
|
| 30 | * the current status of a chat participant.
|
| 31 | *
|
| 32 | * @author Alexander Wenckus
|
| 33 | * @see org.jivesoftware.smackx.ChatState
|
| 34 | */
|
| 35 | public class ChatStateExtension implements PacketExtension {
|
| 36 |
|
| 37 | private ChatState state;
|
| 38 |
|
| 39 | /**
|
| 40 | * Default constructor. The argument provided is the state that the extension will represent.
|
| 41 | *
|
| 42 | * @param state the state that the extension represents.
|
| 43 | */
|
| 44 | public ChatStateExtension(ChatState state) {
|
| 45 | this.state = state;
|
| 46 | }
|
| 47 |
|
| 48 | public String getElementName() {
|
| 49 | return state.name();
|
| 50 | }
|
| 51 |
|
| 52 | public String getNamespace() {
|
| 53 | return "http://jabber.org/protocol/chatstates";
|
| 54 | }
|
| 55 |
|
| 56 | public String toXML() {
|
| 57 | return "<" + getElementName() + " xmlns=\"" + getNamespace() + "\" />";
|
| 58 | }
|
| 59 |
|
| 60 | public static class Provider implements PacketExtensionProvider {
|
| 61 |
|
| 62 | public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
|
| 63 | ChatState state;
|
| 64 | try {
|
| 65 | state = ChatState.valueOf(parser.getName());
|
| 66 | }
|
| 67 | catch (Exception ex) {
|
| 68 | state = ChatState.active;
|
| 69 | }
|
| 70 | return new ChatStateExtension(state);
|
| 71 | }
|
| 72 | }
|
| 73 | }
|