aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/entities/FileParams.java
blob: bce8e57198e486e79a65be9353efd545d50fe133 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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;
    }
}