001/** 002 * 003 * Copyright 2014-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.iqprivate.packet; 018 019import org.jivesoftware.smack.packet.IQ; 020 021public class PrivateDataIQ extends IQ { 022 023 public static final String ELEMENT = QUERY_ELEMENT; 024 public static final String NAMESPACE = "jabber:iq:private"; 025 026 private final PrivateData privateData; 027 private final String getElement; 028 private final String getNamespace; 029 030 @SuppressWarnings("this-escape") 031 public PrivateDataIQ(PrivateData privateData) { 032 this(privateData, null, null); 033 setType(Type.set); 034 } 035 036 @SuppressWarnings("this-escape") 037 public PrivateDataIQ(String element, String namespace) { 038 this(null, element, namespace); 039 setType(Type.get); 040 } 041 042 private PrivateDataIQ(PrivateData privateData, String getElement, String getNamespace) { 043 super(ELEMENT, NAMESPACE); 044 this.privateData = privateData; 045 this.getElement = getElement; 046 this.getNamespace = getNamespace; 047 } 048 049 public PrivateData getPrivateData() { 050 return privateData; 051 } 052 053 @Override 054 protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { 055 xml.rightAngleBracket(); 056 if (privateData != null) { 057 xml.append(privateData.toXML()); 058 } else { 059 xml.halfOpenElement(getElement).xmlnsAttribute(getNamespace).closeEmptyElement(); 060 } 061 return xml; 062 } 063}