Shuyi Chen | d7955ce | 2013-05-22 14:51:55 -0700 | [diff] [blame] | 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 java.util.Arrays;
|
| 17 | import java.util.List;
|
| 18 |
|
| 19 | import org.jivesoftware.smack.packet.PacketExtension;
|
| 20 | import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
|
| 21 |
|
| 22 | /**
|
| 23 | * Represents the top level element of a pubsub event extension. All types of pubsub events are
|
| 24 | * represented by this class. The specific type can be found by {@link #getEventType()}. The
|
| 25 | * embedded event information, which is specific to the event type, can be retrieved by the {@link #getEvent()}
|
| 26 | * method.
|
| 27 | *
|
| 28 | * @author Robin Collier
|
| 29 | */
|
| 30 | public class EventElement implements EmbeddedPacketExtension
|
| 31 | {
|
| 32 | private EventElementType type;
|
| 33 | private NodeExtension ext;
|
| 34 |
|
| 35 | public EventElement(EventElementType eventType, NodeExtension eventExt)
|
| 36 | {
|
| 37 | type = eventType;
|
| 38 | ext = eventExt;
|
| 39 | }
|
| 40 |
|
| 41 | public EventElementType getEventType()
|
| 42 | {
|
| 43 | return type;
|
| 44 | }
|
| 45 |
|
| 46 | public List<PacketExtension> getExtensions()
|
| 47 | {
|
| 48 | return Arrays.asList(new PacketExtension[]{getEvent()});
|
| 49 | }
|
| 50 |
|
| 51 | public NodeExtension getEvent()
|
| 52 | {
|
| 53 | return ext;
|
| 54 | }
|
| 55 |
|
| 56 | public String getElementName()
|
| 57 | {
|
| 58 | return "event";
|
| 59 | }
|
| 60 |
|
| 61 | public String getNamespace()
|
| 62 | {
|
| 63 | return PubSubNamespace.EVENT.getXmlns();
|
| 64 | }
|
| 65 |
|
| 66 | public String toXML()
|
| 67 | {
|
| 68 | StringBuilder builder = new StringBuilder("<event xmlns='" + PubSubNamespace.EVENT.getXmlns() + "'>");
|
| 69 |
|
| 70 | builder.append(ext.toXML());
|
| 71 | builder.append("</event>");
|
| 72 | return builder.toString();
|
| 73 | }
|
| 74 | }
|