View Javadoc
1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
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 General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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      //--- Constant(s) ---
35  
36      //--- Data field(s) ---
37  
38      private String name;
39      private String realm;
40      private HashSet extensions = new HashSet();
41  
42      //--- Constructor(s) ---
43  
44      public DefaultMediaType(String realm, String name)
45      {
46  		this.realm = realm;
47  		this.name = name;
48      }
49  
50      //--- Method(s) ---
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