summaryrefslogtreecommitdiffstats
path: root/src/de/thedevstack/smackx/filetransferhttp/element
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/thedevstack/smackx/filetransferhttp/element')
-rw-r--r--src/de/thedevstack/smackx/filetransferhttp/element/FileList.java40
-rw-r--r--src/de/thedevstack/smackx/filetransferhttp/element/RemoteFile.java79
-rw-r--r--src/de/thedevstack/smackx/filetransferhttp/element/RemoteFileInfo.java54
-rw-r--r--src/de/thedevstack/smackx/filetransferhttp/element/Request.java19
4 files changed, 192 insertions, 0 deletions
diff --git a/src/de/thedevstack/smackx/filetransferhttp/element/FileList.java b/src/de/thedevstack/smackx/filetransferhttp/element/FileList.java
new file mode 100644
index 0000000..563ca15
--- /dev/null
+++ b/src/de/thedevstack/smackx/filetransferhttp/element/FileList.java
@@ -0,0 +1,40 @@
+package de.thedevstack.smackx.filetransferhttp.element;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jivesoftware.smack.packet.IQ;
+
+import de.thedevstack.smackx.filetransferhttp.FileTransferHttp;
+
+public class FileList extends IQ {
+ private List<RemoteFile> files = new ArrayList<>();
+
+ public FileList() {
+ super("list", FileTransferHttp.NAMESPACE);
+ }
+
+ public List<RemoteFile> getFiles() {
+ return files;
+ }
+
+ @Override
+ protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
+ xml.rightAngleBracket();
+
+ if (0 < this.files.size()) {
+ for (RemoteFile file : this.files) {
+ xml.append(file.toXML());
+ }
+ } else {
+ xml.emptyElement("empty");
+ }
+
+ return xml;
+ }
+
+ public void addRemoteFile(RemoteFile remoteFile) {
+ this.files.add(remoteFile);
+ }
+
+}
diff --git a/src/de/thedevstack/smackx/filetransferhttp/element/RemoteFile.java b/src/de/thedevstack/smackx/filetransferhttp/element/RemoteFile.java
new file mode 100644
index 0000000..483d8b3
--- /dev/null
+++ b/src/de/thedevstack/smackx/filetransferhttp/element/RemoteFile.java
@@ -0,0 +1,79 @@
+package de.thedevstack.smackx.filetransferhttp.element;
+
+import org.jivesoftware.smack.packet.NamedElement;
+import org.jivesoftware.smack.util.XmlStringBuilder;
+
+public class RemoteFile implements NamedElement {
+ private String url;
+ private long timestamp;
+ private RemoteFileInfo fileInfo;
+ private String from;
+ private String to;
+
+ public RemoteFile(String url, long timestamp) {
+ this.url = url;
+ this.timestamp = timestamp;
+ }
+
+ public String getFilename() {
+ return (null != fileInfo) ? fileInfo.getFilename() : null;
+ }
+
+ public long getSize() {
+ return (null != fileInfo) ? fileInfo.getSize() : -1;
+ }
+
+ public String getContentType() {
+ return (null != fileInfo) ? fileInfo.getContentType() : null;
+ }
+
+ public RemoteFileInfo getFileInfo() {
+ return fileInfo;
+ }
+
+ public void setFileInfo(RemoteFileInfo fileInfo) {
+ this.fileInfo = fileInfo;
+ }
+
+ public String getFrom() {
+ return from;
+ }
+
+ public void setFrom(String from) {
+ this.from = from;
+ }
+
+ public String getTo() {
+ return to;
+ }
+
+ public void setTo(String to) {
+ this.to = to;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ @Override
+ public String getElementName() {
+ return "file";
+ }
+
+ @Override
+ public CharSequence toXML() {
+ XmlStringBuilder xml = new XmlStringBuilder(this);
+ xml.attribute("timestamp", String.valueOf(this.timestamp));
+ xml.optAttribute("from", this.from);
+ xml.optAttribute("to", this.to);
+ xml.rightAngleBracket();
+ xml.element("url", this.url);
+ xml.append(fileInfo.toXML());
+ xml.closeElement(this);
+ return xml;
+ }
+}
diff --git a/src/de/thedevstack/smackx/filetransferhttp/element/RemoteFileInfo.java b/src/de/thedevstack/smackx/filetransferhttp/element/RemoteFileInfo.java
new file mode 100644
index 0000000..caeb2c8
--- /dev/null
+++ b/src/de/thedevstack/smackx/filetransferhttp/element/RemoteFileInfo.java
@@ -0,0 +1,54 @@
+package de.thedevstack.smackx.filetransferhttp.element;
+
+import org.jivesoftware.smack.packet.NamedElement;
+import org.jivesoftware.smack.util.XmlStringBuilder;
+
+public class RemoteFileInfo implements NamedElement {
+ private final String filename;
+ private final long size;
+ private String contentType;
+
+ public RemoteFileInfo(String filename, long size) {
+ this.filename = filename;
+ this.size = size;
+ }
+
+ public RemoteFileInfo(String filename, long size, String contentType) {
+ this(filename, size);
+ this.contentType = contentType;
+ }
+
+
+
+ public String getFilename() {
+ return filename;
+ }
+
+ public long getSize() {
+ return size;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
+ @Override
+ public String getElementName() {
+ return "file-info";
+ }
+
+ @Override
+ public CharSequence toXML() {
+ XmlStringBuilder xml = new XmlStringBuilder(this);
+ xml.rightAngleBracket();
+ xml.element("filename", this.filename);
+ xml.optElement("size", this.size);
+ xml.optElement("content-type", this.contentType);
+ xml.closeElement(this);
+ return xml;
+ }
+}
diff --git a/src/de/thedevstack/smackx/filetransferhttp/element/Request.java b/src/de/thedevstack/smackx/filetransferhttp/element/Request.java
new file mode 100644
index 0000000..ac974b9
--- /dev/null
+++ b/src/de/thedevstack/smackx/filetransferhttp/element/Request.java
@@ -0,0 +1,19 @@
+package de.thedevstack.smackx.filetransferhttp.element;
+
+import org.jivesoftware.smack.packet.IQ;
+
+import de.thedevstack.smackx.filetransferhttp.FileTransferHttp;
+
+public class Request extends IQ {
+ public Request() {
+ super("request", FileTransferHttp.NAMESPACE);
+ setType(Type.get);
+ }
+
+ @Override
+ protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
+ xml.attribute("type", "list");
+ xml.setEmptyElement();
+ return xml;
+ }
+}