aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/SlotRequestPacket.java
blob: d08665088092904359e6785c11f96b2b5c1641a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload;

import de.thedevstack.conversationsplus.xml.Element;
import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;

/**
 *
 */
public class SlotRequestPacket extends IqPacket {
    public static final String ELEMENT_NAME = "request";
    public static final String FILENAME_ELEMENT_NAME = "filename";
    public static final String FILESIZE_ELEMENT_NAME = "size";
    public static final String MIME_ELEMENT_NAME = "content-type";
    private Element requestElement;
    private String filename;
    private long filesize;
    private String mime;

    private SlotRequestPacket() {
        super(TYPE.GET);
        this.requestElement = super.addChild(SlotRequestPacket.ELEMENT_NAME, HttpUpload.NAMESPACE);
    }

    public SlotRequestPacket(String filename, long filesize) {
        this();
        this.setFilename(filename);
        this.setFilesize(filesize);
    }

    public void setFilename(String filename) {
        if (null == filename || filename.isEmpty()) {
            throw new IllegalArgumentException("filename must not be null or empty.");
        }
        this.filename = filename;
        this.requestElement.addChild(FILENAME_ELEMENT_NAME).setContent(filename);
    }

    public void setFilesize(long filesize) {
        if (0 >= filesize) {
            throw new IllegalArgumentException("filesize must not be null or empty.");
        }
        this.filesize = filesize;
        this.requestElement.addChild(FILESIZE_ELEMENT_NAME).setContent(String.valueOf(filesize));
    }

    public void setMime(String mime) {
        if (null == mime || mime.isEmpty()) {
            throw new IllegalArgumentException("mime type must not be null or empty.");
        }
        this.mime = mime;
        this.requestElement.addChild(MIME_ELEMENT_NAME).setContent(mime);
    }
}