1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package entagged.audioformats.generic;
20
21 /***
22 * This is a complete impelementation of
23 * {@link entagged.audioformats.generic.AbstractTag}.<br>
24 * The identifiers of commonly used fields is defined by {@link #keys}.<br>
25 *
26 * @author Raphaël Slinckx
27 */
28 public class GenericTag extends AbstractTag {
29
30 /***
31 * Implementations of {@link TagTextField} for use with
32 * "ISO-8859-1" strings.
33 *
34 * @author Raphaël Slinckx
35 */
36 private class GenericTagTextField implements TagTextField {
37
38 /***
39 * Stores the string.
40 */
41 private String content;
42
43 /***
44 * Stores the identifier.
45 */
46 private final String id;
47
48 /***
49 * Creates an instance.
50 *
51 * @param fieldId
52 * The identifier.
53 * @param initialContent
54 * The string.
55 */
56 public GenericTagTextField(String fieldId, String initialContent) {
57 this.id = fieldId;
58 this.content = initialContent;
59 }
60
61 /***
62 * (overridden)
63 *
64 * @see entagged.audioformats.generic.TagField#copyContent(entagged.audioformats.generic.TagField)
65 */
66 public void copyContent(TagField field) {
67 if (field instanceof TagTextField) {
68 this.content = ((TagTextField) field).getContent();
69 }
70 }
71
72 /***
73 * (overridden)
74 *
75 * @see entagged.audioformats.generic.TagTextField#getContent()
76 */
77 public String getContent() {
78 return this.content;
79 }
80
81 /***
82 * (overridden)
83 *
84 * @see entagged.audioformats.generic.TagTextField#getEncoding()
85 */
86 public String getEncoding() {
87 return "ISO-8859-1";
88 }
89
90 /***
91 * (overridden)
92 *
93 * @see entagged.audioformats.generic.TagField#getId()
94 */
95 public String getId() {
96 return id;
97 }
98
99 /***
100 * (overridden)
101 *
102 * @see entagged.audioformats.generic.TagField#getRawContent()
103 */
104 public byte[] getRawContent() {
105 return this.content == null ? new byte[] {} : this.content
106 .getBytes();
107 }
108
109 /***
110 * (overridden)
111 *
112 * @see entagged.audioformats.generic.TagField#isBinary()
113 */
114 public boolean isBinary() {
115 return false;
116 }
117
118 /***
119 * (overridden)
120 *
121 * @see entagged.audioformats.generic.TagField#isBinary(boolean)
122 */
123 public void isBinary(boolean b) {
124
125 }
126
127 /***
128 * (overridden)
129 *
130 * @see entagged.audioformats.generic.TagField#isCommon()
131 */
132 public boolean isCommon() {
133 return true;
134 }
135
136 /***
137 * (overridden)
138 *
139 * @see entagged.audioformats.generic.TagField#isEmpty()
140 */
141 public boolean isEmpty() {
142 return this.content.equals("");
143 }
144
145 /***
146 * (overridden)
147 *
148 * @see entagged.audioformats.generic.TagTextField#setContent(java.lang.String)
149 */
150 public void setContent(String s) {
151 this.content = s;
152 }
153
154 /***
155 * (overridden)
156 *
157 * @see entagged.audioformats.generic.TagTextField#setEncoding(java.lang.String)
158 */
159 public void setEncoding(String s) {
160
161 }
162
163 /***
164 * (overridden)
165 *
166 * @see java.lang.Object#toString()
167 */
168 public String toString() {
169 return getId() + " : " + getContent();
170 }
171 }
172
173 /***
174 * Index for the "album"-identifier in {@link #keys}.
175 */
176 public static final int ALBUM = 1;
177
178 /***
179 * Index for the "artist"-identifier in {@link #keys}.
180 */
181 public static final int ARTIST = 0;
182
183 /***
184 * Index for the "comment"-identifier in {@link #keys}.
185 */
186 public static final int COMMENT = 6;
187
188 /***
189 * Index for the "genre"-identifier in {@link #keys}.
190 */
191 public static final int GENRE = 5;
192
193 /***
194 * Stores the generic identifiers of commonly used fields.
195 */
196 private final static String[] keys = { "ARTIST", "ALBUM", "TITLE", "TRACK",
197 "YEAR", "GENRE", "COMMENT", };
198
199 /***
200 * Index for the "title"-identifier in {@link #keys}.
201 */
202 public static final int TITLE = 2;
203
204 /***
205 * Index for the "track"-identifier in {@link #keys}.
206 */
207 public static final int TRACK = 3;
208
209 /***
210 * Index for the "year"-identifier in {@link #keys}.
211 */
212 public static final int YEAR = 4;
213
214 /***
215 * (overridden)
216 *
217 * @see entagged.audioformats.generic.AbstractTag#createAlbumField(java.lang.String)
218 */
219 protected TagField createAlbumField(String content) {
220 return new GenericTagTextField(keys[ALBUM], content);
221 }
222
223 /***
224 * (overridden)
225 *
226 * @see entagged.audioformats.generic.AbstractTag#createArtistField(java.lang.String)
227 */
228 protected TagField createArtistField(String content) {
229 return new GenericTagTextField(keys[ARTIST], content);
230 }
231
232 /***
233 * (overridden)
234 *
235 * @see entagged.audioformats.generic.AbstractTag#createCommentField(java.lang.String)
236 */
237 protected TagField createCommentField(String content) {
238 return new GenericTagTextField(keys[COMMENT], content);
239 }
240
241 /***
242 * (overridden)
243 *
244 * @see entagged.audioformats.generic.AbstractTag#createGenreField(java.lang.String)
245 */
246 protected TagField createGenreField(String content) {
247 return new GenericTagTextField(keys[GENRE], content);
248 }
249
250 /***
251 * (overridden)
252 *
253 * @see entagged.audioformats.generic.AbstractTag#createTitleField(java.lang.String)
254 */
255 protected TagField createTitleField(String content) {
256 return new GenericTagTextField(keys[TITLE], content);
257 }
258
259 /***
260 * (overridden)
261 *
262 * @see entagged.audioformats.generic.AbstractTag#createTrackField(java.lang.String)
263 */
264 protected TagField createTrackField(String content) {
265 return new GenericTagTextField(keys[TRACK], content);
266 }
267
268 /***
269 * (overridden)
270 *
271 * @see entagged.audioformats.generic.AbstractTag#createYearField(java.lang.String)
272 */
273 protected TagField createYearField(String content) {
274 return new GenericTagTextField(keys[YEAR], content);
275 }
276
277 /***
278 * (overridden)
279 *
280 * @see entagged.audioformats.generic.AbstractTag#getAlbumId()
281 */
282 protected String getAlbumId() {
283 return keys[ALBUM];
284 }
285
286 /***
287 * (overridden)
288 *
289 * @see entagged.audioformats.generic.AbstractTag#getArtistId()
290 */
291 protected String getArtistId() {
292 return keys[ARTIST];
293 }
294
295 /***
296 * (overridden)
297 *
298 * @see entagged.audioformats.generic.AbstractTag#getCommentId()
299 */
300 protected String getCommentId() {
301 return keys[COMMENT];
302 }
303
304 /***
305 * (overridden)
306 *
307 * @see entagged.audioformats.generic.AbstractTag#getGenreId()
308 */
309 protected String getGenreId() {
310 return keys[GENRE];
311 }
312
313 /***
314 * (overridden)
315 *
316 * @see entagged.audioformats.generic.AbstractTag#getTitleId()
317 */
318 protected String getTitleId() {
319 return keys[TITLE];
320 }
321
322 /***
323 * (overridden)
324 *
325 * @see entagged.audioformats.generic.AbstractTag#getTrackId()
326 */
327 protected String getTrackId() {
328 return keys[TRACK];
329 }
330
331 /***
332 * (overridden)
333 *
334 * @see entagged.audioformats.generic.AbstractTag#getYearId()
335 */
336 protected String getYearId() {
337 return keys[YEAR];
338 }
339
340 /***
341 * (overridden)
342 *
343 * @see entagged.audioformats.generic.AbstractTag#isAllowedEncoding(java.lang.String)
344 */
345 protected boolean isAllowedEncoding(String enc) {
346 return true;
347 }
348 }