SubscribeExtension.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. /**
  19.  * Represents a request to subscribe to a node.
  20.  *
  21.  * @author Robin Collier
  22.  */
  23. public class SubscribeExtension extends NodeExtension
  24. {
  25.     protected String jid;
  26.    
  27.     public SubscribeExtension(String subscribeJid)
  28.     {
  29.         super(PubSubElementType.SUBSCRIBE);
  30.         jid = subscribeJid;
  31.     }
  32.    
  33.     public SubscribeExtension(String subscribeJid, String nodeId)
  34.     {
  35.         super(PubSubElementType.SUBSCRIBE, nodeId);
  36.         jid = subscribeJid;
  37.     }

  38.     public String getJid()
  39.     {
  40.         return jid;
  41.     }

  42.     @Override
  43.     public String toXML()
  44.     {
  45.         StringBuilder builder = new StringBuilder("<");
  46.         builder.append(getElementName());
  47.        
  48.         if (getNode() != null)
  49.         {
  50.             builder.append(" node='");
  51.             builder.append(getNode());
  52.             builder.append("'");
  53.         }
  54.         builder.append(" jid='");
  55.         builder.append(getJid());
  56.         builder.append("'/>");
  57.        
  58.         return builder.toString();
  59.     }
  60. }