001/** 002 * 003 * Copyright © 2017 Grigory Fedorov 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.httpfileupload.element; 018 019import org.jivesoftware.smack.packet.IQ; 020 021import java.net.URL; 022import java.util.Collections; 023import java.util.Map; 024 025/** 026 * Slot responded by upload service. 027 * 028 * @author Grigory Fedorov 029 * @see <a href="http://xmpp.org/extensions/xep-0363.html">XEP-0363: HTTP File Upload</a> 030 */ 031public class Slot extends IQ { 032 033 public static final String ELEMENT = "slot"; 034 public static final String NAMESPACE = SlotRequest.NAMESPACE; 035 036 private final URL putUrl; 037 private final URL getUrl; 038 private final Map<String, String> headers; 039 040 public Slot(URL putUrl, URL getUrl) { 041 this(putUrl, getUrl, null); 042 } 043 044 public Slot(URL putUrl, URL getUrl, Map<String, String> headers) { 045 this(putUrl, getUrl, headers, NAMESPACE); 046 } 047 048 protected Slot(URL putUrl, URL getUrl, Map<String, String> headers, String namespace) { 049 super(ELEMENT, namespace); 050 setType(Type.result); 051 this.putUrl = putUrl; 052 this.getUrl = getUrl; 053 if (headers == null) { 054 this.headers = Collections.emptyMap(); 055 } else { 056 this.headers = Collections.unmodifiableMap(headers); 057 } 058 } 059 060 public URL getPutUrl() { 061 return putUrl; 062 } 063 064 public URL getGetUrl() { 065 return getUrl; 066 } 067 068 public Map<String, String> getHeaders() { 069 return headers; 070 } 071 072 @Override 073 protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { 074 xml.rightAngleBracket(); 075 076 xml.element("put", putUrl.toString()); 077 xml.element("get", getUrl.toString()); 078 for (Map.Entry<String, String> entry : getHeaders().entrySet()) { 079 xml.openElement("header").attribute(entry.getKey(), entry.getValue()); 080 } 081 082 return xml; 083 } 084}