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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
/**
* ======================== legal notice ======================
*
* File: AbstractMediaNode.java Created: 13. June 2012, 04:57 Author: <a
* href="mailto:geronimo013@gmx.de">Geronimo</a> Project: cmpc - a java frontend
* (client) part of compound media player uses external players to play the
* media
*
* CMP - compound media player
*
* is a client/server mediaplayer intended to play any media from any
* workstation without the need to export or mount shares. cmps is an easy to
* use backend with a (ready to use) HTML-interface. Additionally the backend
* supports authentication via HTTP-digest authorization. cmpc is a client with
* vdr-like osd-menues.
*
* Copyright (c) 2012 Reinhard Mantey, some rights reserved! published under
* Creative Commons by-sa For details see
* http://creativecommons.org/licenses/by-sa/3.0/
*
* The cmp project's homepage is at
* http://projects.vdr-developer.org/projects/cmp
*
* --------------------------------------------------------------
*/
package de.schwarzrot.media.domain;
import java.io.File;
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.util.Map;
import java.util.TreeMap;
public abstract class AbstractMediaNode implements Serializable, Comparable<AbstractMediaNode> {
public static final String FORMAT_PROPERTY = "format";
public static final String NAME_PROPERTY = "name";
public static final String PATH_PROPERTY = "path";
public static final String TYPE_PROPERTY = "type";
public static final String SEARCH_PROPERTY = "search";
private static final long serialVersionUID = 713L;
public enum SupportedMediaType {
Genre, //
Audio, //
Movie, IMovie, DVDImage, IDVDImage, //
LegacyVdrRecording, ILegacyVdrRecording, VdrRecording, IVdrRecording, //
Picture, //
Unknown
}
protected AbstractMediaNode(AbstractMediaNode parent, SupportedMediaType type, String mimeType, File path) {
properties = new TreeMap<String, Object>();
setParent(parent);
setType(type);
setMimeType(mimeType);
setRealPath(path);
originalPath = realPath;
}
@Override
public int compareTo(AbstractMediaNode o) {
if (o == null)
return -1;
if (this != o) {
int rv = type.ordinal() - o.getType().ordinal();
if (rv == 0)
rv = getName().compareToIgnoreCase(o.getName());
return rv;
}
return 0;
}
public String getFormat() {
return format;
}
public String getMimeType() {
return mimeType;
}
public String getName() {
return name;
}
public File getOriginalPath() {
return originalPath;
}
public AbstractMediaNode getParent() {
return parent;
}
public Map<String, Object> getProperties() {
return properties;
}
public File getRealPath() {
return realPath;
}
public String getSearch() {
return search;
}
public SupportedMediaType getType() {
return type;
}
public URI getURI() {
return uri;
}
public void setFormat(String format) {
this.format = format;
properties.put(FORMAT_PROPERTY, format);
}
public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}
public void setName(String name) {
this.name = name;
properties.put(NAME_PROPERTY, name);
refresh();
}
public void setParent(AbstractMediaNode parent) {
if ((this.parent = parent) != null)
refresh();
}
public void setPath(String path) {
if (uri == null) {
try {
// properties.put(PATH_PROPERTY, path);
uri = new URI(path);
properties.put(PATH_PROPERTY, uri.toString());
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
try {
File tmp = new File(URLDecoder.decode(path, "UTF-8"));
if (path != null && originalPath == null)
originalPath = tmp;
setRealPath(tmp);
} catch (Throwable t) {
t.printStackTrace();
}
}
public void setProperty(String key, Object value) {
properties.put(key, value);
}
public void setRealPath(File realPath) {
this.realPath = realPath;
if (name == null && realPath != null)
setName(realPath.getName());
}
public void setSearch(String search) {
this.search = search;
properties.put(SEARCH_PROPERTY, search);
}
public void setType(int type) {
if (type == SupportedMediaType.Audio.ordinal())
this.type = SupportedMediaType.Audio;
else if (type == SupportedMediaType.Movie.ordinal())
this.type = SupportedMediaType.Movie;
else if (type == SupportedMediaType.IMovie.ordinal())
this.type = SupportedMediaType.IMovie;
else if (type == SupportedMediaType.DVDImage.ordinal())
this.type = SupportedMediaType.DVDImage;
else if (type == SupportedMediaType.IDVDImage.ordinal())
this.type = SupportedMediaType.IDVDImage;
else if (type == SupportedMediaType.LegacyVdrRecording.ordinal())
this.type = SupportedMediaType.LegacyVdrRecording;
else if (type == SupportedMediaType.ILegacyVdrRecording.ordinal())
this.type = SupportedMediaType.ILegacyVdrRecording;
else if (type == SupportedMediaType.VdrRecording.ordinal())
this.type = SupportedMediaType.VdrRecording;
else if (type == SupportedMediaType.IVdrRecording.ordinal())
this.type = SupportedMediaType.IVdrRecording;
else if (type == SupportedMediaType.Picture.ordinal())
this.type = SupportedMediaType.Picture;
else
throw new EnumConstantNotPresentException(SupportedMediaType.class, "unknown ordinal #" + type);
properties.put(TYPE_PROPERTY, this.type);
}
@Override
public String toString() {
return getName();
}
protected void refresh() {
if (parent != null && realPath != null)
realPath = new File(parent.getRealPath(), getName());
}
protected void setType(SupportedMediaType type) {
this.type = type;
properties.put(TYPE_PROPERTY, this.type);
}
private File realPath;
private File originalPath;
private URI uri;
private SupportedMediaType type;
private AbstractMediaNode parent;
private String name;
private String mimeType;
private String search;
private String format;
private Map<String, Object> properties;
}
|