package de.thedevstack.conversationsplus.entities; import de.thedevstack.conversationsplus.enums.FileStatus; import de.thedevstack.conversationsplus.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; } }