2017-01-29 22:07:29 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright © 2017 Grigory Fedorov
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smackx.httpfileupload.element;
|
|
|
|
|
|
|
|
import java.net.URL;
|
2017-03-09 21:35:29 +01:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Map;
|
2017-01-29 22:07:29 +01:00
|
|
|
|
2017-06-14 17:12:43 +02:00
|
|
|
import org.jivesoftware.smack.packet.IQ;
|
|
|
|
|
2017-01-29 22:07:29 +01:00
|
|
|
/**
|
|
|
|
* Slot responded by upload service.
|
|
|
|
*
|
|
|
|
* @author Grigory Fedorov
|
|
|
|
* @see <a href="http://xmpp.org/extensions/xep-0363.html">XEP-0363: HTTP File Upload</a>
|
|
|
|
*/
|
|
|
|
public class Slot extends IQ {
|
|
|
|
|
|
|
|
public static final String ELEMENT = "slot";
|
|
|
|
public static final String NAMESPACE = SlotRequest.NAMESPACE;
|
|
|
|
|
2017-12-09 14:35:35 +01:00
|
|
|
protected final URL putUrl;
|
|
|
|
protected final URL getUrl;
|
|
|
|
|
2017-03-09 21:35:29 +01:00
|
|
|
private final Map<String, String> headers;
|
2017-01-29 22:07:29 +01:00
|
|
|
|
|
|
|
public Slot(URL putUrl, URL getUrl) {
|
2017-03-09 21:35:29 +01:00
|
|
|
this(putUrl, getUrl, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Slot(URL putUrl, URL getUrl, Map<String, String> headers) {
|
|
|
|
this(putUrl, getUrl, headers, NAMESPACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Slot(URL putUrl, URL getUrl, Map<String, String> headers, String namespace) {
|
|
|
|
super(ELEMENT, namespace);
|
2017-01-29 22:07:29 +01:00
|
|
|
setType(Type.result);
|
|
|
|
this.putUrl = putUrl;
|
|
|
|
this.getUrl = getUrl;
|
2017-03-09 21:35:29 +01:00
|
|
|
if (headers == null) {
|
|
|
|
this.headers = Collections.emptyMap();
|
|
|
|
} else {
|
|
|
|
this.headers = Collections.unmodifiableMap(headers);
|
|
|
|
}
|
2017-01-29 22:07:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public URL getPutUrl() {
|
|
|
|
return putUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
public URL getGetUrl() {
|
|
|
|
return getUrl;
|
|
|
|
}
|
|
|
|
|
2017-03-09 21:35:29 +01:00
|
|
|
public Map<String, String> getHeaders() {
|
|
|
|
return headers;
|
|
|
|
}
|
2017-01-29 22:07:29 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
|
|
|
xml.rightAngleBracket();
|
|
|
|
|
2017-12-09 14:35:35 +01:00
|
|
|
xml.halfOpenElement("put").attribute("url", putUrl.toString());
|
|
|
|
if (headers.isEmpty()) {
|
|
|
|
xml.closeEmptyElement();
|
|
|
|
} else {
|
|
|
|
xml.rightAngleBracket();
|
|
|
|
for (Map.Entry<String, String> entry : getHeaders().entrySet()) {
|
|
|
|
xml.halfOpenElement("header").attribute("name", entry.getKey()).rightAngleBracket();
|
|
|
|
xml.escape(entry.getValue());
|
|
|
|
xml.closeElement("header");
|
|
|
|
}
|
|
|
|
xml.closeElement("put");
|
2017-03-09 21:35:29 +01:00
|
|
|
}
|
2017-01-29 22:07:29 +01:00
|
|
|
|
2017-12-09 14:35:35 +01:00
|
|
|
xml.halfOpenElement("get").attribute("url", getUrl.toString()).closeEmptyElement();
|
|
|
|
|
2017-01-29 22:07:29 +01:00
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
}
|