1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.search;
21
22 import java.io.Serializable;
23 import java.util.HashSet;
24
25 import org.xnap.util.FileHelper;
26
27 /***
28 * Provides a default implementation for the {@link MediaType}
29 * interface.
30 */
31 public class DefaultMediaType implements MediaType, Serializable
32 {
33
34
35
36
37
38 private String name;
39 private String realm;
40 private HashSet extensions = new HashSet();
41
42
43
44 public DefaultMediaType(String realm, String name)
45 {
46 this.realm = realm;
47 this.name = name;
48 }
49
50
51
52 /***
53 * Adds <code>extension</code> to the list of extensions.
54 */
55 public void add(String extension)
56 {
57 extensions.add(extension);
58 }
59
60 /***
61 * Returns the name of the media type that is shown to the user.
62 */
63 public String getName()
64 {
65 return name;
66 }
67
68 /***
69 * Returns the realm. This can be "anything", "audio", "video"...
70 */
71 public String getRealm()
72 {
73 return realm;
74 }
75
76 /***
77 * Returns true if <code>filename</code> is of this media type.
78 */
79 public boolean matches(String filename)
80 {
81 return extensions.contains(FileHelper.extension(filename));
82 }
83
84 /***
85 * Returns the value of {@link #getName()}.
86 */
87 public String toString()
88 {
89 return getName();
90 }
91
92 }
93