001/** 002 * 003 * Copyright © 2014 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 public PrivateDataIQ(PrivateData privateData) { 031 this(privateData, null, null); 032 setType(Type.set); 033 } 034 035 public PrivateDataIQ(String element, String namespace) { 036 this(null, element, namespace); 037 setType(Type.get); 038 } 039 040 private PrivateDataIQ(PrivateData privateData, String getElement, String getNamespace) { 041 super(ELEMENT, NAMESPACE); 042 this.privateData = privateData; 043 this.getElement = getElement; 044 this.getNamespace = getNamespace; 045 } 046 047 public PrivateData getPrivateData() { 048 return privateData; 049 } 050 051 @Override 052 protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { 053 xml.rightAngleBracket(); 054 if (privateData != null) { 055 xml.append(privateData.toXML()); 056 } else { 057 xml.halfOpenElement(getElement).xmlnsAttribute(getNamespace).closeEmptyElement(); 058 } 059 return xml; 060 } 061}