This repository has been archived by the owner on Feb 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 227
/
VirtualFolder.java
135 lines (119 loc) · 3.95 KB
/
VirtualFolder.java
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
/*
* PS3 Media Server, for streaming any medias to your PS3.
* Copyright (C) 2008 A.Brochard
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2
* of the License only.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package net.pms.dlna.virtual;
import java.io.IOException;
import java.io.InputStream;
import net.pms.dlna.DLNAResource;
import net.pms.network.HTTPResource;
/**
* Represents a container (folder). This is widely used by the UPNP ContentBrowser service. Child objects are expected in this folder.
*/
public class VirtualFolder extends DLNAResource {
protected String name;
protected String thumbnailIcon;
protected String thumbnailContentType;
/**Constructor for this class. The constructor does not add any child to the container. This is the only
* chance to set the name of this container.
* @param name String to be shown in the ContentBrowser service
* @param thumbnailIcon Represents a thumbnail to be shown. The String represents an absolute
* path. Use null if none is available or desired.
* @see #addChild(DLNAResource)
*/
public VirtualFolder(String name, String thumbnailIcon) {
this.name = name;
this.thumbnailIcon = thumbnailIcon;
if (thumbnailIcon != null && thumbnailIcon.toLowerCase().endsWith(".png")) {
thumbnailContentType = HTTPResource.PNG_TYPEMIME;
} else {
thumbnailContentType = HTTPResource.JPEG_TYPEMIME;
}
}
/**Because a container cannot be streamed, this function always returns null.
* @return null
* @see net.pms.dlna.DLNAResource#getInputStream()
*/
@Override
public InputStream getInputStream() throws IOException {
return null;
}
/**Returns a string representing the container. This string is used in
* the UPNP ContentBrowser service.
* @see net.pms.dlna.DLNAResource#getName()
*/
@Override
public String getName() {
return name;
}
/**Returns true in this case, as this is a folder.
* @return true
* @see net.pms.dlna.DLNAResource#isFolder()
*/
@Override
public boolean isFolder() {
return true;
}
/**Returns zero as this is a folder (container).
* @see net.pms.dlna.DLNAResource#length()
*/
@Override
public long length() {
return 0;
}
/**Containers are likely not to be modified, so this one returns zero.
* TODO: (botijo) When is this used then? Is this a prototype?
* @return Zero
*/
public long lastModified() {
return 0;
}
@Override
public String getSystemName() {
return getName();
}
/**Returns a {@link InputStream} that represents the thumbnail used.
* @see net.pms.dlna.DLNAResource#getThumbnailInputStream()
*/
@Override
public InputStream getThumbnailInputStream() {
return getResourceInputStream(thumbnailIcon);
}
/**Returns the thumbnailContentType associated to the thumbnail associated to this container.
* @see net.pms.dlna.DLNAResource#getThumbnailContentType()
* @see #thumbnailContentType
*/
@Override
public String getThumbnailContentType() {
return thumbnailContentType;
}
/**Returns true, as a container is always a valid item to add to another container.
* @see net.pms.dlna.DLNAResource#isValid()
*/
@Override
public boolean isValid() {
return true;
}
public void setThumbnail(String thumbnailIcon) {
this.thumbnailIcon = thumbnailIcon;
if (thumbnailIcon != null && thumbnailIcon.toLowerCase().endsWith(".png")) {
thumbnailContentType = HTTPResource.PNG_TYPEMIME;
} else {
thumbnailContentType = HTTPResource.JPEG_TYPEMIME;
}
}
}