001/** 002 * 003 * Copyright 2016 Fernando Ramirez, 2020 Florian Schmaus 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.bob.element; 018 019import org.jivesoftware.smack.packet.IQ; 020 021import org.jivesoftware.smackx.bob.BoBData; 022import org.jivesoftware.smackx.bob.BoBManager; 023import org.jivesoftware.smackx.bob.ContentId; 024 025/** 026 * Bits of Binary IQ class. 027 * 028 * @author Fernando Ramirez 029 * @see <a href="http://xmpp.org/extensions/xep-0231.html">XEP-0231: Bits of 030 * Binary</a> 031 */ 032public class BoBIQ extends IQ { 033 034 /** 035 * data element. 036 */ 037 public static final String ELEMENT = "data"; 038 039 /** 040 * the IQ NAMESPACE. 041 */ 042 public static final String NAMESPACE = BoBManager.NAMESPACE; 043 044 private final ContentId cid; 045 private final BoBData bobData; 046 047 /** 048 * Bits of Binary IQ constructor. 049 * 050 * @param cid TODO javadoc me please 051 * @param bobData TODO javadoc me please 052 */ 053 public BoBIQ(ContentId cid, BoBData bobData) { 054 super(ELEMENT, NAMESPACE); 055 this.cid = cid; 056 this.bobData = bobData; 057 } 058 059 /** 060 * Bits of Binary IQ constructor. 061 * 062 * @param cid TODO javadoc me please 063 */ 064 public BoBIQ(ContentId cid) { 065 this(cid, null); 066 } 067 068 /** 069 * Get the BoB hash. 070 * 071 * @return the BoB hash 072 * @deprecated use {@link #getContentId()} instead. 073 */ 074 // TODO: Remove in Smack 4.5. 075 @Deprecated 076 public ContentId getBoBHash() { 077 return cid; 078 } 079 080 /** 081 * Get the BoB hash. 082 * 083 * @return the BoB hash 084 */ 085 public ContentId getContentId() { 086 return cid; 087 } 088 089 /** 090 * Get the BoB data. 091 * 092 * @return the BoB data 093 */ 094 public BoBData getBoBData() { 095 return bobData; 096 } 097 098 @Override 099 protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { 100 xml.attribute("cid", cid.getCid()); 101 102 if (bobData != null) { 103 xml.optIntAttribute("max_age", bobData.getMaxAge()); 104 xml.attribute("type", bobData.getType()); 105 xml.rightAngleBracket(); 106 xml.escape(bobData.getContentBase64Encoded()); 107 } else { 108 xml.setEmptyElement(); 109 } 110 111 return xml; 112 } 113 114}