BoBIQ.java

  1. /**
  2.  *
  3.  * Copyright 2016 Fernando Ramirez, 2020-2024 Florian Schmaus
  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.bob.element;

  18. import org.jivesoftware.smack.packet.IQ;

  19. import org.jivesoftware.smackx.bob.BoBData;
  20. import org.jivesoftware.smackx.bob.BoBManager;
  21. import org.jivesoftware.smackx.bob.ContentId;

  22. /**
  23.  * Bits of Binary IQ class.
  24.  *
  25.  * @author Fernando Ramirez
  26.  * @see <a href="http://xmpp.org/extensions/xep-0231.html">XEP-0231: Bits of
  27.  *      Binary</a>
  28.  */
  29. public class BoBIQ extends IQ {

  30.     /**
  31.      * data element.
  32.      */
  33.     public static final String ELEMENT = "data";

  34.     /**
  35.      * the IQ NAMESPACE.
  36.      */
  37.     public static final String NAMESPACE = BoBManager.NAMESPACE;

  38.     private final ContentId cid;
  39.     private final BoBData bobData;

  40.     /**
  41.      * Bits of Binary IQ constructor.
  42.      *
  43.      * @param cid TODO javadoc me please
  44.      * @param bobData TODO javadoc me please
  45.      */
  46.     public BoBIQ(ContentId cid, BoBData bobData) {
  47.         super(ELEMENT, NAMESPACE);
  48.         this.cid = cid;
  49.         this.bobData = bobData;
  50.     }

  51.     /**
  52.      * Bits of Binary IQ constructor.
  53.      *
  54.      * @param cid TODO javadoc me please
  55.      */
  56.     public BoBIQ(ContentId cid) {
  57.         this(cid, null);
  58.     }

  59.     /**
  60.      * Get the BoB hash.
  61.      *
  62.      * @return the BoB hash
  63.      */
  64.     public ContentId getContentId() {
  65.         return cid;
  66.     }

  67.     /**
  68.      * Get the BoB data.
  69.      *
  70.      * @return the BoB data
  71.      */
  72.     public BoBData getBoBData() {
  73.         return bobData;
  74.     }

  75.     @Override
  76.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
  77.         xml.attribute("cid", cid.getCid());

  78.         if (bobData != null) {
  79.             xml.optIntAttribute("max_age", bobData.getMaxAge());
  80.             xml.attribute("type", bobData.getType());
  81.             xml.rightAngleBracket();
  82.             xml.escape(bobData.getContentBase64Encoded());
  83.         } else {
  84.             xml.setEmptyElement();
  85.         }

  86.         return xml;
  87.     }

  88. }