1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.capabilities.impl;
18
19 import java.util.ArrayList;
20 import java.util.Collection;
21
22 import org.apache.commons.collections.CollectionUtils;
23 import org.apache.jetspeed.capabilities.Capability;
24 import org.apache.jetspeed.capabilities.MediaType;
25 import org.apache.jetspeed.capabilities.MimeType;
26
27 /***
28 * Default bean like implementation of MediaTypeEntry interface
29 * suitable for serializing with Castor
30 *
31 * @author <a href="mailto:raphael@apache.org">Rapha\u00ebl Luta</a>
32 * @version $Id: MediaTypeImpl.java 516448 2007-03-09 16:25:47Z ate $
33 */
34 public class MediaTypeImpl
35 implements MediaType
36 {
37 protected String characterSet;
38 private Collection capabilities;
39 private Collection mimetypes;
40 private int mediatypeId;
41 private String title;
42 private String description;
43
44 private String name;
45
46 public MediaTypeImpl()
47 {}
48
49 public MediaTypeImpl(long id,
50 String name,
51 int _hidden,
52 String mimeType,
53 String title,
54 String description,
55 String image,
56 String role)
57 {
58 this.mimetypes.add(mimeType);
59 }
60
61 /***
62 * Implements the equals operation so that 2 elements are equal if
63 * all their member values are equal.
64 */
65 public boolean equals(Object object)
66 {
67 if (this == object)
68 return true;
69 if (object==null)
70 return false;
71
72 MediaTypeImpl obj = (MediaTypeImpl)object;
73
74
75 if (this.name!=null)
76 {
77 if (!name.equals(obj.name))
78 {
79 return false;
80 }
81 }
82 else
83 {
84 if (obj.name!=null)
85 {
86 return false;
87 }
88 }
89
90 if (this.description!=null)
91 {
92 if (!description.equals(obj.description))
93 {
94 return false;
95 }
96 }
97 else
98 {
99 if (obj.description!=null)
100 {
101 return false;
102 }
103 }
104
105 if (characterSet!=null)
106 {
107 if (!characterSet.equals(obj.characterSet))
108 {
109 return false;
110 }
111 }
112 else
113 {
114 if (obj.characterSet!=null)
115 {
116 return false;
117 }
118 }
119
120
121 if (this.title!=null)
122 {
123 if (!title.equals(obj.title))
124 {
125 return false;
126 }
127 }
128 else
129 {
130 if (obj.title!=null)
131 {
132 return false;
133 }
134 }
135
136
137 if (mimetypes != null)
138 {
139 if (!CollectionUtils.isEqualCollection(mimetypes, obj.mimetypes))
140 {
141 return false;
142 }
143 }
144 else
145 {
146 if (obj.mimetypes != null)
147 {
148 return false;
149 }
150 }
151
152 if (capabilities != null)
153 {
154 if (!(CollectionUtils.isEqualCollection(capabilities,obj.capabilities )))
155 return false;
156 }
157 else
158 {
159 if (obj.capabilities != null)
160 {
161 return false;
162 }
163 }
164
165 return true;
166 }
167
168
169 /*** @return the character set associated with this MediaType */
170 public String getCharacterSet()
171 {
172 return this.characterSet;
173 }
174
175 /*** Sets the character set associated with this MediaType */
176 public void setCharacterSet( String charSet)
177 {
178 this.characterSet = charSet;
179 }
180
181
182 public Collection getCapabilities()
183 {
184 return this.capabilities;
185 }
186
187 public void setCapabilities(Collection capabilities)
188 {
189 this.capabilities = capabilities;
190 }
191
192
193 public Collection getMimetypes()
194 {
195 return this.mimetypes;
196 }
197
198 public void setMimetypes(Collection mimetypes)
199 {
200 this.mimetypes = mimetypes;
201 }
202
203 public void addMimetype(MimeType mimeType)
204 {
205 if (mimetypes == null)
206 mimetypes = new ArrayList();
207 if (!mimetypes.contains(mimeType.getName()))
208 {
209 mimetypes.add(mimeType);
210 }
211 }
212
213
214 public void addCapability(Capability capability)
215 {
216 if (capabilities == null)
217 capabilities = new ArrayList();
218 if (!capabilities.contains(capability.getName()))
219 {
220 capabilities.add(capability);
221 }
222 }
223
224 public void removeMimetype(String name)
225 {
226 mimetypes.remove(name);
227 }
228
229 /***
230 * Set MediaType ID -- Assigns ID
231 * @param id
232 */
233 public void setMediatypeId(int id)
234 {
235 this.mediatypeId = id;
236 }
237
238 /***
239 * Get MediaType ID -- Return ID
240 * @return MediaTypeID
241 */
242 public int getMediatypeId()
243 {
244 return this.mediatypeId;
245 }
246
247 /***
248 * Set name ob MediaTypeEntry
249 */
250 public void setName(String name)
251 {
252 this.name = name;
253 }
254
255 /***
256 * Get name ob MediaTypeEntry
257 */
258
259 public String getName()
260 {
261 return this.name;
262 }
263
264 public String getTitle()
265 {
266 return this.title;
267 }
268
269 public void setTitle(String title)
270 {
271 this.title = title;
272 }
273
274 public String getDescription()
275 {
276 return this.description;
277 }
278
279
280 public void setDescription(String desc)
281 {
282 this.description = desc;
283 }
284 }