diff options
author | steckbrief <steckbrief@chefmail.de> | 2016-10-20 19:45:26 +0200 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2016-10-20 19:45:26 +0200 |
commit | 59e861ee6904296cbe8dd43c4a29513c2e928981 (patch) | |
tree | a3bf768814ece1c377caefca35bc535c758a47c5 /src/main/java/de/thedevstack/conversationsplus/entities | |
parent | 2860088f0ea1cd5753756861c71cc7c118094f32 (diff) | |
parent | 9ec29bb1dcf664fea606105b7e700641a4b44ae4 (diff) |
Merge remote-tracking branch 'remotes/origin/trz/rename' into trz/rebase
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/entities')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/entities/FileParams.java | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/FileParams.java b/src/main/java/de/thedevstack/conversationsplus/entities/FileParams.java new file mode 100644 index 00000000..1eef078f --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/entities/FileParams.java @@ -0,0 +1,130 @@ +package de.thedevstack.conversationsplus.entities; + +import de.thedevstack.conversationsplus.enums.FileStatus; + +import eu.siacs.conversations.utils.MimeUtils; + +/** + * + */ +public class FileParams { + private String name; + private String path; + private String url; + private String mimeType; + private long size = 0; + private int width = 0; + private int height = 0; + private FileStatus fileStatus; + + public FileParams() { + fileStatus = FileStatus.UNDEFINED; + } + + public FileParams(String url) { + this(); + this.url = url; + } + + public FileParams(String url, long size) { + this(url); + this.size = size; + } + + public FileParams(String url, long size, int width, int height) { + this(url, size); + this.width = width; + this.height = height; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public long getSize() { + return size; + } + + public void setSize(long size) { + this.size = size; + } + + public int getWidth() { + return width; + } + + public void setWidth(int width) { + this.width = width; + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } + + public String getMimeType() { + return mimeType; + } + + public void setMimeType(String mimeType) { + this.mimeType = mimeType; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPath() { + return path; + } + + /** + * Sets the path to the file. + * If no file name is stored yet here - this method tries to extract the file name from the path. + * If the file name is stored here and the path does not end with the name - the name is appended to the path. + * @param path the path to be stored + */ + public void setPath(String path) { + if (null != path) { + if (null != this.name) { + path = (!path.endsWith(this.name)) ? path + "/" + this.name : path; + } else { + if (!path.endsWith("/")) { + this.setName(path.substring(path.lastIndexOf('/') + 1)); + } + } + if (null == this.mimeType) { + int start = path.lastIndexOf('.') + 1; + if (start < path.length()) { + String extension = path.substring(start); + this.mimeType = MimeUtils.guessMimeTypeFromExtension(extension); + } + } + } + + this.path = path; + } + + public boolean isRemoteAvailable() { + return null != this.url || FileStatus.UPLOADED == this.fileStatus || FileStatus.DELETE_FAILED == this.fileStatus; + } + + public void setFileStatus(FileStatus fileStatus) { + this.fileStatus = fileStatus; + } + + public FileStatus getFileStatus() { + return this.fileStatus; + } +} |