001/** 002 * 003 * Copyright 2016 Fernando Ramirez, 2020-2024 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 */ 073 public ContentId getContentId() { 074 return cid; 075 } 076 077 /** 078 * Get the BoB data. 079 * 080 * @return the BoB data 081 */ 082 public BoBData getBoBData() { 083 return bobData; 084 } 085 086 @Override 087 protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { 088 xml.attribute("cid", cid.getCid()); 089 090 if (bobData != null) { 091 xml.optIntAttribute("max_age", bobData.getMaxAge()); 092 xml.attribute("type", bobData.getType()); 093 xml.rightAngleBracket(); 094 xml.escape(bobData.getContentBase64Encoded()); 095 } else { 096 xml.setEmptyElement(); 097 } 098 099 return xml; 100 } 101 102}