EventElement.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.Arrays;
  19. import java.util.List;

  20. import org.jivesoftware.smack.packet.ExtensionElement;
  21. import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;

  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.     public List<ExtensionElement> getExtensions()
  46.     {
  47.         return Arrays.asList(new ExtensionElement[]{getEvent()});
  48.     }

  49.     public NodeExtension getEvent()
  50.     {
  51.         return ext;
  52.     }

  53.     public String getElementName()
  54.     {
  55.         return "event";
  56.     }

  57.     public String getNamespace()
  58.     {
  59.         return PubSubNamespace.EVENT.getXmlns();
  60.     }

  61.     public String toXML()
  62.     {
  63.         StringBuilder builder = new StringBuilder("<event xmlns='" + PubSubNamespace.EVENT.getXmlns() + "'>");

  64.         builder.append(ext.toXML());
  65.         builder.append("</event>");
  66.         return builder.toString();
  67.     }
  68. }