Dateiverwaltung für die WebBox
ulrich
2017-03-31 6e70be4f54f3482801d579407846810926cd9997
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
    WebBox - Dein Server.
    Copyright (C) 2017 Ulrich Hilger, http://uhilger.de
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.
 
    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
package de.uhilger.filecms.data;
 
import java.io.Serializable;
 
/**
 * A reference to a file consisting of the file's absolute path and additional
 * information about whether or not the referenced file is a directory, is hidden, etc.
 * Note that FileRef only references a file, the file itself and its contents are not
 * modelled by this class.
 *
 * @author Ulrich Hilger, http://uhilger.de
 * @author Bereitgestellt unter den Bedingungen der 
 *  <a href="http://www.gnu.org/licenses/agpl-3.0" target="_blank">GNU Affero
 *  General Public License</a>
 *
 * @version 2, 12.01.2008
 */
public class FileRef implements Serializable {
 
  public static final long serialVersionUID = 42L;
  private String absolutePath;
    private Boolean isDirectory;
    private Boolean isHidden;
    private Long lastModified;
    private Long length;
  private String mimetype;
 
    /**
     * create a new instance of <code>FileRef</code>. Note that the created FileRef is 
     * only a reference to a file, the file itself will not be created.
     * 
     * @param absolutePath  the absolute path that denotes this instance of <code>FileRef</code>
     * @param isDirectory  whether or not this file is a directory
     * @param isHidden  whether or not this file is a hidden file
     * @param lastModified  the date/time this file was last modified measured in milliseconds 
     *                         since the epoch (00:00:00 GMT, January 1, 1970)
     * @param length the length of this file in bytes
     */
    public FileRef(String absolutePath, boolean isDirectory, boolean isHidden, 
            long lastModified, long length)
    {
        super();
        this.absolutePath = absolutePath;
        this.isDirectory = isDirectory;
        this.isHidden = isHidden;
        this.lastModified = lastModified;
        this.length = length;
    }
    
    /**
     * Create a new instance of class <code>FileRef</code> with a given absolute path. 
     * Other characteristics of the file are created with default settings 
     * (i.e. not a directory, not hidden, unknown modification date 
     * and length). Note that the created FileRef is only a reference to a file, the file 
     * itself will not be created.
     * 
     * @param absolutePath  the absolute path that denotes this instance 
     * of <code>FileRef</code>
     */
    public FileRef(String absolutePath) {
        this(absolutePath, false, false, 0, 0);
    }
    
    /**
     * Create a new instance of class <code>FileRef</code> with a given absolute path 
     * and an indicator whether or not the new FileRef denotes a directory. 
     * Other characteristics of the file are created with default settings 
     * (i.e. not hidden, unknown modification date and length). Note that the created 
     * FileRef is only a reference to a file, the file itself will not be created.
     * 
     * @param absolutePath  the absolute path that denotes this instance 
     * of <code>FileRef</code>
     * @param isDirectory  true, if the file to create should denote a directory
     */
    public FileRef(String absolutePath, boolean isDirectory) {
        this(absolutePath, isDirectory, false, 0, 0);
    }
 
  public String getMimetype() {
    return mimetype;
  }
 
  public void setMimetype(String mimetype) {
    this.mimetype = mimetype;
  }
 
    /**
     * get the absolute path that denotes this file
     * @return  the path
     */
    public String getAbsolutePath() {
        return absolutePath;
    }
 
    /**
     * Tests whether the file denoted by this abstract pathname is a
     * directory.
     *
     * @return <code>true</code> if this file is a directory, 
     *          <code>false</code> otherwise
     */
    public boolean isDirectory() {
        return isDirectory;
    }
 
    /**
     * Tests whether the file denoted by this abstract pathname is a
     * file.
     *
     * @return <code>true</code> if this file is a file, 
     *          <code>false</code> otherwise
     */
    public boolean isFile() {
        return !isDirectory;
    }
 
    /**
     * Tests whether the file denoted by this abstract pathname is a
     * hidden file.
     *
     * @return <code>true</code> if this file is a hidden file, 
     *          <code>false</code> otherwise
     */
    public boolean isHidden() {
        return isHidden;
    }
 
    /**
     * Returns the time that this file was
     * last modified.
     *
     * @return  A <code>long</code> value representing the time the file was
     *          last modified, measured in milliseconds since the epoch
     *          (00:00:00 GMT, January 1, 1970)
     */
    public long getLastModified() {
        return lastModified;
    }
 
    /**
     * Returns the length of this file.
     * The return value is unspecified if this file denotes a directory.
     *
     * @return  The length, in bytes, of this file
     */
    public long getLength() {
        return length;
    }
    
    /**
     * get the name of this file without path
     * @param separatorChar  the string that is used to separate directories and file names in 
     * path expressions 
     * @return the name of this file without path
     */
    public String getName(String separatorChar) {
        String path = getAbsolutePath();
        String name = path.substring(path.lastIndexOf(separatorChar) + 1);
        if(name == null || name.length() < 1) {
            name = path;
        }
        return name;
    }
 
    /**
     * get a string representation of this instance of FileRef
     * @return the string representation of this FileRef object
     */
    public String toString() {
        return getAbsolutePath();
    }
 
    /**
     * Indicates whether some object is equal to this instance of class FileRef. Two 
     * GenericFiles are regarded as equal when their absolute paths are equal case independently.
     * 
     * @param  obj  the object to compare with this instance of FileRef
     * @return true, if obj is equal to this instance of FileRef, false if not
     */
    public boolean equals(Object obj) {
        boolean isEqual = false;
        if(obj != null && obj instanceof FileRef) {
            isEqual = ((FileRef) obj).getAbsolutePath().toLowerCase().equals(
                    this.getAbsolutePath().toLowerCase());
        }
        return isEqual;
    }    
}