commit | author | age
|
5bfd34
|
1 |
/* |
U |
2 |
Dateiverwaltung - File management in your browser |
|
3 |
Copyright (C) 2017 Ulrich Hilger, http://uhilger.de |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
|
|
19 |
package de.uhilger.filecms.data; |
|
20 |
|
|
21 |
import java.io.Serializable; |
|
22 |
|
|
23 |
/** |
|
24 |
* A reference to a file consisting of the file's absolute path and additional |
|
25 |
* information about whether or not the referenced file is a directory, is hidden, etc. |
|
26 |
* Note that FileRef only references a file, the file itself and its contents are not |
|
27 |
* modelled by this class. |
|
28 |
* |
|
29 |
* @author Ulrich Hilger, http://uhilger.de |
|
30 |
* @author Bereitgestellt unter den Bedingungen der |
|
31 |
* <a href="http://www.gnu.org/licenses/agpl-3.0" target="_blank">GNU Affero |
|
32 |
* General Public License</a> |
|
33 |
* |
|
34 |
* @version 2, 12.01.2008 |
|
35 |
*/ |
|
36 |
public class FileRef implements Serializable { |
|
37 |
|
|
38 |
public static final long serialVersionUID = 42L; |
|
39 |
private String absolutePath; |
|
40 |
private Boolean isDirectory; |
|
41 |
private Boolean isHidden; |
|
42 |
private Long lastModified; |
|
43 |
private Long length; |
f7d8bf
|
44 |
private String mimetype; |
5bfd34
|
45 |
|
U |
46 |
/** |
|
47 |
* create a new instance of <code>FileRef</code>. Note that the created FileRef is |
|
48 |
* only a reference to a file, the file itself will not be created. |
|
49 |
* |
|
50 |
* @param absolutePath the absolute path that denotes this instance of <code>FileRef</code> |
|
51 |
* @param isDirectory whether or not this file is a directory |
|
52 |
* @param isHidden whether or not this file is a hidden file |
|
53 |
* @param lastModified the date/time this file was last modified measured in milliseconds |
|
54 |
* since the epoch (00:00:00 GMT, January 1, 1970) |
|
55 |
* @param length the length of this file in bytes |
|
56 |
*/ |
|
57 |
public FileRef(String absolutePath, boolean isDirectory, boolean isHidden, |
|
58 |
long lastModified, long length) |
|
59 |
{ |
|
60 |
super(); |
|
61 |
this.absolutePath = absolutePath; |
|
62 |
this.isDirectory = isDirectory; |
|
63 |
this.isHidden = isHidden; |
|
64 |
this.lastModified = lastModified; |
|
65 |
this.length = length; |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Create a new instance of class <code>FileRef</code> with a given absolute path. |
|
70 |
* Other characteristics of the file are created with default settings |
|
71 |
* (i.e. not a directory, not hidden, unknown modification date |
|
72 |
* and length). Note that the created FileRef is only a reference to a file, the file |
|
73 |
* itself will not be created. |
|
74 |
* |
|
75 |
* @param absolutePath the absolute path that denotes this instance |
|
76 |
* of <code>FileRef</code> |
|
77 |
*/ |
|
78 |
public FileRef(String absolutePath) { |
|
79 |
this(absolutePath, false, false, 0, 0); |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* Create a new instance of class <code>FileRef</code> with a given absolute path |
|
84 |
* and an indicator whether or not the new FileRef denotes a directory. |
|
85 |
* Other characteristics of the file are created with default settings |
|
86 |
* (i.e. not hidden, unknown modification date and length). Note that the created |
|
87 |
* FileRef is only a reference to a file, the file itself will not be created. |
|
88 |
* |
|
89 |
* @param absolutePath the absolute path that denotes this instance |
|
90 |
* of <code>FileRef</code> |
|
91 |
* @param isDirectory true, if the file to create should denote a directory |
|
92 |
*/ |
|
93 |
public FileRef(String absolutePath, boolean isDirectory) { |
|
94 |
this(absolutePath, isDirectory, false, 0, 0); |
|
95 |
} |
|
96 |
|
f7d8bf
|
97 |
public String getMimetype() { |
U |
98 |
return mimetype; |
|
99 |
} |
|
100 |
|
|
101 |
public void setMimetype(String mimetype) { |
|
102 |
this.mimetype = mimetype; |
|
103 |
} |
|
104 |
|
5bfd34
|
105 |
/** |
U |
106 |
* get the absolute path that denotes this file |
|
107 |
* @return the path |
|
108 |
*/ |
|
109 |
public String getAbsolutePath() { |
|
110 |
return absolutePath; |
|
111 |
} |
|
112 |
|
|
113 |
/** |
|
114 |
* Tests whether the file denoted by this abstract pathname is a |
|
115 |
* directory. |
|
116 |
* |
|
117 |
* @return <code>true</code> if this file is a directory, |
|
118 |
* <code>false</code> otherwise |
|
119 |
*/ |
|
120 |
public boolean isDirectory() { |
|
121 |
return isDirectory; |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* Tests whether the file denoted by this abstract pathname is a |
|
126 |
* file. |
|
127 |
* |
|
128 |
* @return <code>true</code> if this file is a file, |
|
129 |
* <code>false</code> otherwise |
|
130 |
*/ |
|
131 |
public boolean isFile() { |
|
132 |
return !isDirectory; |
|
133 |
} |
|
134 |
|
|
135 |
/** |
|
136 |
* Tests whether the file denoted by this abstract pathname is a |
|
137 |
* hidden file. |
|
138 |
* |
|
139 |
* @return <code>true</code> if this file is a hidden file, |
|
140 |
* <code>false</code> otherwise |
|
141 |
*/ |
|
142 |
public boolean isHidden() { |
|
143 |
return isHidden; |
|
144 |
} |
|
145 |
|
|
146 |
/** |
|
147 |
* Returns the time that this file was |
|
148 |
* last modified. |
|
149 |
* |
|
150 |
* @return A <code>long</code> value representing the time the file was |
|
151 |
* last modified, measured in milliseconds since the epoch |
|
152 |
* (00:00:00 GMT, January 1, 1970) |
|
153 |
*/ |
|
154 |
public long getLastModified() { |
|
155 |
return lastModified; |
|
156 |
} |
|
157 |
|
|
158 |
/** |
|
159 |
* Returns the length of this file. |
|
160 |
* The return value is unspecified if this file denotes a directory. |
|
161 |
* |
|
162 |
* @return The length, in bytes, of this file |
|
163 |
*/ |
|
164 |
public long getLength() { |
|
165 |
return length; |
|
166 |
} |
|
167 |
|
|
168 |
/** |
|
169 |
* get the name of this file without path |
|
170 |
* @param separatorChar the string that is used to separate directories and file names in |
|
171 |
* path expressions |
|
172 |
* @return the name of this file without path |
|
173 |
*/ |
|
174 |
public String getName(String separatorChar) { |
|
175 |
String path = getAbsolutePath(); |
|
176 |
String name = path.substring(path.lastIndexOf(separatorChar) + 1); |
|
177 |
if(name == null || name.length() < 1) { |
|
178 |
name = path; |
|
179 |
} |
|
180 |
return name; |
|
181 |
} |
|
182 |
|
|
183 |
/** |
|
184 |
* get a string representation of this instance of FileRef |
|
185 |
* @return the string representation of this FileRef object |
|
186 |
*/ |
|
187 |
public String toString() { |
|
188 |
return getAbsolutePath(); |
|
189 |
} |
|
190 |
|
|
191 |
/** |
|
192 |
* Indicates whether some object is equal to this instance of class FileRef. Two |
|
193 |
* GenericFiles are regarded as equal when their absolute paths are equal case independently. |
|
194 |
* |
|
195 |
* @param obj the object to compare with this instance of FileRef |
|
196 |
* @return true, if obj is equal to this instance of FileRef, false if not |
|
197 |
*/ |
|
198 |
public boolean equals(Object obj) { |
|
199 |
boolean isEqual = false; |
|
200 |
if(obj != null && obj instanceof FileRef) { |
|
201 |
isEqual = ((FileRef) obj).getAbsolutePath().toLowerCase().equals( |
|
202 |
this.getAbsolutePath().toLowerCase()); |
|
203 |
} |
|
204 |
return isEqual; |
|
205 |
} |
|
206 |
} |