| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AbstractTag |
|
| 0.0;0 | ||||
| AbstractTag$1 |
|
| 0.0;0 |
| 1 | /* | |
| 2 | * jaudiotagger library | |
| 3 | * | |
| 4 | * This library is free software; you can redistribute it and/or | |
| 5 | * modify it under the terms of the GNU Lesser General Public | |
| 6 | * License as published by the Free Software Foundation; either | |
| 7 | * version 2.1 of the License, or (at your option) any later version. | |
| 8 | * | |
| 9 | * This library is distributed in the hope that it will be useful, | |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 12 | * Lesser General Public License for more details. | |
| 13 | * | |
| 14 | * You should have received a copy of the GNU Lesser General Public | |
| 15 | * License along with this library; if not, write to the Free Software | |
| 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 17 | */ | |
| 18 | package org.jaudiotagger.audio.generic; | |
| 19 | ||
| 20 | import org.jaudiotagger.tag.*; | |
| 21 | import org.jaudiotagger.tag.datatype.Artwork; | |
| 22 | import org.jaudiotagger.tag.mp4.Mp4TagField; | |
| 23 | import org.jaudiotagger.tag.mp4.Mp4FieldKey; | |
| 24 | ||
| 25 | import java.util.*; | |
| 26 | ||
| 27 | /** | |
| 28 | * This class is the default implementation for | |
| 29 | * {@link org.jaudiotagger.tag.Tag} and introduces some more useful | |
| 30 | * functionality to be implemented.<br> | |
| 31 | * | |
| 32 | * @author Rapha�l Slinckx | |
| 33 | */ | |
| 34 | 293 | public abstract class AbstractTag implements Tag |
| 35 | { | |
| 36 | /** | |
| 37 | * Stores the amount of {@link TagField} with {@link TagField#isCommon()} | |
| 38 | * <code>true</code>. | |
| 39 | */ | |
| 40 | 293 | protected int commonNumber = 0; |
| 41 | ||
| 42 | /** | |
| 43 | * This map stores the {@linkplain TagField#getId() ids} of the stored | |
| 44 | * fields to the {@linkplain TagField fields} themselves. Because a linked hashMap is used the order | |
| 45 | * that they are added in is preserved, the only exception to this rule is when two fields of the same id | |
| 46 | * exist, both will be returned according to when the first item was added to the file. <br> | |
| 47 | */ | |
| 48 | 293 | protected Map<String, List<TagField>> fields = new LinkedHashMap<String, List<TagField>>(); |
| 49 | ||
| 50 | /** | |
| 51 | * Add field | |
| 52 | * | |
| 53 | * @see org.jaudiotagger.tag.Tag#add(org.jaudiotagger.tag.TagField) | |
| 54 | * <p/> | |
| 55 | * Changed so add empty fields | |
| 56 | */ | |
| 57 | public void add(TagField field) | |
| 58 | { | |
| 59 | 2888 | if (field == null) |
| 60 | { | |
| 61 | 0 | return; |
| 62 | } | |
| 63 | ||
| 64 | 2888 | List<TagField> list = fields.get(field.getId()); |
| 65 | ||
| 66 | // There was no previous item | |
| 67 | 2888 | if (list == null) |
| 68 | { | |
| 69 | 2851 | list = new ArrayList<TagField>(); |
| 70 | 2851 | list.add(field); |
| 71 | 2851 | fields.put(field.getId(), list); |
| 72 | 2851 | if (field.isCommon()) |
| 73 | { | |
| 74 | 826 | commonNumber++; |
| 75 | } | |
| 76 | } | |
| 77 | else | |
| 78 | { | |
| 79 | // We append to existing list | |
| 80 | 37 | list.add(field); |
| 81 | } | |
| 82 | 2888 | } |
| 83 | ||
| 84 | /** | |
| 85 | * Add (another) album | |
| 86 | * | |
| 87 | * @see org.jaudiotagger.tag.Tag#addAlbum(java.lang.String) | |
| 88 | */ | |
| 89 | public void addAlbum(String s) | |
| 90 | { | |
| 91 | 4 | add(createAlbumField(s)); |
| 92 | 4 | } |
| 93 | ||
| 94 | /** | |
| 95 | * Add (another) artist | |
| 96 | * | |
| 97 | * @see org.jaudiotagger.tag.Tag#addArtist(java.lang.String) | |
| 98 | */ | |
| 99 | public void addArtist(String s) | |
| 100 | { | |
| 101 | 14 | add(createArtistField(s)); |
| 102 | 14 | } |
| 103 | ||
| 104 | /** | |
| 105 | * Add (another) comment | |
| 106 | * | |
| 107 | * @see org.jaudiotagger.tag.Tag#addComment(java.lang.String) | |
| 108 | */ | |
| 109 | public void addComment(String s) | |
| 110 | { | |
| 111 | 13 | add(createCommentField(s)); |
| 112 | 13 | } |
| 113 | ||
| 114 | /** | |
| 115 | * Add (another) genre | |
| 116 | * | |
| 117 | * @see org.jaudiotagger.tag.Tag#addGenre(java.lang.String) | |
| 118 | */ | |
| 119 | public void addGenre(String s) | |
| 120 | { | |
| 121 | 2 | add(createGenreField(s)); |
| 122 | 2 | } |
| 123 | ||
| 124 | /** | |
| 125 | * Add (another) title | |
| 126 | * | |
| 127 | * @see org.jaudiotagger.tag.Tag#addTitle(java.lang.String) | |
| 128 | */ | |
| 129 | public void addTitle(String s) | |
| 130 | { | |
| 131 | 15 | add(createTitleField(s)); |
| 132 | 15 | } |
| 133 | ||
| 134 | /** | |
| 135 | * Add (another) track | |
| 136 | * | |
| 137 | * @see org.jaudiotagger.tag.Tag#addTrack(java.lang.String) | |
| 138 | */ | |
| 139 | public void addTrack(String s) throws FieldDataInvalidException | |
| 140 | { | |
| 141 | 2 | add(createTrackField(s)); |
| 142 | 2 | } |
| 143 | ||
| 144 | /** | |
| 145 | * (Add (another) year | |
| 146 | * | |
| 147 | * @see org.jaudiotagger.tag.Tag#addYear(java.lang.String) | |
| 148 | */ | |
| 149 | public void addYear(String s) | |
| 150 | { | |
| 151 | 2 | add(createYearField(s)); |
| 152 | 2 | } |
| 153 | ||
| 154 | /** | |
| 155 | * Get list of fields within this tag with the specified id | |
| 156 | * | |
| 157 | * @see org.jaudiotagger.tag.Tag#get(java.lang.String) | |
| 158 | */ | |
| 159 | public List<TagField> get(String id) | |
| 160 | { | |
| 161 | 2547 | List<TagField> list = fields.get(id); |
| 162 | ||
| 163 | 2547 | if (list == null) |
| 164 | { | |
| 165 | 187 | return new ArrayList<TagField>(); |
| 166 | } | |
| 167 | ||
| 168 | 2360 | return list; |
| 169 | } | |
| 170 | ||
| 171 | /** | |
| 172 | * @param id | |
| 173 | * @return | |
| 174 | */ | |
| 175 | ||
| 176 | //Needs to be overridden | |
| 177 | //TODO remove | |
| 178 | public List<TagField> get(TagFieldKey id) throws KeyNotFoundException | |
| 179 | { | |
| 180 | 0 | List<TagField> list = fields.get(id.name()); |
| 181 | 0 | if (list == null) |
| 182 | { | |
| 183 | 0 | return new ArrayList<TagField>(); |
| 184 | } | |
| 185 | 0 | return list; |
| 186 | } | |
| 187 | ||
| 188 | ||
| 189 | /** | |
| 190 | * @param id | |
| 191 | * @return matches for this saudio-specific key | |
| 192 | */ | |
| 193 | public String getFirst(String id) | |
| 194 | { | |
| 195 | 1566 | List<TagField> l = get(id); |
| 196 | 1566 | return (l.size() != 0) ? l.get(0).toString() : ""; |
| 197 | } | |
| 198 | ||
| 199 | public TagField getFirstField(String id) | |
| 200 | { | |
| 201 | 44 | List<TagField> l = get(id); |
| 202 | 44 | return (l.size() != 0) ? l.get(0) : null; |
| 203 | } | |
| 204 | ||
| 205 | ||
| 206 | /** | |
| 207 | * (overridden) | |
| 208 | * | |
| 209 | * @see org.jaudiotagger.tag.Tag#getAlbum() | |
| 210 | */ | |
| 211 | public List<TagField> getAlbum() | |
| 212 | { | |
| 213 | 67 | return get(getAlbumId()); |
| 214 | } | |
| 215 | ||
| 216 | /** | |
| 217 | * Returns the identifier for a field representing the "album"<br> | |
| 218 | * | |
| 219 | * @return identifier for the "album" field. | |
| 220 | * @see TagField#getId() | |
| 221 | */ | |
| 222 | protected abstract String getAlbumId(); | |
| 223 | ||
| 224 | /** | |
| 225 | * Get Artist | |
| 226 | * | |
| 227 | * @see org.jaudiotagger.tag.Tag#getArtist() | |
| 228 | */ | |
| 229 | public List<TagField> getArtist() | |
| 230 | { | |
| 231 | 104 | return get(getArtistId()); |
| 232 | } | |
| 233 | ||
| 234 | /** | |
| 235 | * Returns the identifier for a field representing the "artist"<br> | |
| 236 | * | |
| 237 | * @return identifier for the "artist" field. | |
| 238 | * @see TagField#getId() | |
| 239 | */ | |
| 240 | protected abstract String getArtistId(); | |
| 241 | ||
| 242 | /** | |
| 243 | * Get Comment | |
| 244 | * | |
| 245 | * @see org.jaudiotagger.tag.Tag#getComment() | |
| 246 | */ | |
| 247 | public List<TagField> getComment() | |
| 248 | { | |
| 249 | 65 | return get(getCommentId()); |
| 250 | } | |
| 251 | ||
| 252 | /** | |
| 253 | * Returns the identifier for a field representing the "comment"<br> | |
| 254 | * | |
| 255 | * @return identifier for the "comment" field. | |
| 256 | * @see TagField#getId() | |
| 257 | */ | |
| 258 | protected abstract String getCommentId(); | |
| 259 | ||
| 260 | /** | |
| 261 | * @see org.jaudiotagger.tag.Tag#getFields() | |
| 262 | */ | |
| 263 | public Iterator<TagField> getFields() | |
| 264 | { | |
| 265 | 248 | final Iterator<Map.Entry<String, List<TagField>>> it = this.fields.entrySet().iterator(); |
| 266 | 248 | return new Iterator<TagField>() |
| 267 | { | |
| 268 | private Iterator<TagField> fieldsIt; | |
| 269 | ||
| 270 | private void changeIt() | |
| 271 | { | |
| 272 | 3217 | if (!it.hasNext()) |
| 273 | { | |
| 274 | 30 | return; |
| 275 | } | |
| 276 | ||
| 277 | 3187 | Map.Entry<String, List<TagField>> e = it.next(); |
| 278 | 3187 | List<TagField> l = e.getValue(); |
| 279 | 3187 | fieldsIt = l.iterator(); |
| 280 | 3187 | } |
| 281 | ||
| 282 | public boolean hasNext() | |
| 283 | { | |
| 284 | 3477 | if (fieldsIt == null) |
| 285 | { | |
| 286 | 248 | changeIt(); |
| 287 | } | |
| 288 | 3477 | return it.hasNext() || (fieldsIt != null && fieldsIt.hasNext()); |
| 289 | } | |
| 290 | ||
| 291 | public TagField next() | |
| 292 | { | |
| 293 | 3229 | if (!fieldsIt.hasNext()) |
| 294 | { | |
| 295 | 2969 | changeIt(); |
| 296 | } | |
| 297 | ||
| 298 | 3229 | return fieldsIt.next(); |
| 299 | } | |
| 300 | ||
| 301 | 3477 | public void remove() |
| 302 | { | |
| 303 | 0 | fieldsIt.remove(); |
| 304 | 0 | } |
| 305 | }; | |
| 306 | } | |
| 307 | ||
| 308 | /** | |
| 309 | * Return field count | |
| 310 | * <p/> | |
| 311 | * TODO:There must be a more efficient way to do this. | |
| 312 | * | |
| 313 | * @return field count | |
| 314 | */ | |
| 315 | public int getFieldCount() | |
| 316 | { | |
| 317 | 53 | Iterator it = getFields(); |
| 318 | 53 | int count = 0; |
| 319 | 387 | while (it.hasNext()) |
| 320 | { | |
| 321 | 334 | count++; |
| 322 | 334 | it.next(); |
| 323 | } | |
| 324 | 53 | return count; |
| 325 | } | |
| 326 | ||
| 327 | /** | |
| 328 | * Get the first album or empty string if doesnt exist | |
| 329 | * | |
| 330 | * @see org.jaudiotagger.tag.Tag#getFirstAlbum() | |
| 331 | */ | |
| 332 | public String getFirstAlbum() | |
| 333 | { | |
| 334 | 65 | List<TagField> l = getAlbum(); |
| 335 | 65 | return (l.size() != 0) ? ((TagTextField) l.get(0)).getContent() : ""; |
| 336 | } | |
| 337 | ||
| 338 | /** | |
| 339 | * Get the first artist or empty string if doesnt exist | |
| 340 | * | |
| 341 | * @see org.jaudiotagger.tag.Tag#getFirstArtist() | |
| 342 | */ | |
| 343 | public String getFirstArtist() | |
| 344 | { | |
| 345 | 103 | List<TagField> l = getArtist(); |
| 346 | 103 | return (l.size() != 0) ? ((TagTextField) l.get(0)).getContent() : ""; |
| 347 | } | |
| 348 | ||
| 349 | /** | |
| 350 | * Get the first comment or empty string if doesnt exist | |
| 351 | * | |
| 352 | * @see org.jaudiotagger.tag.Tag#getFirstComment() | |
| 353 | */ | |
| 354 | public String getFirstComment() | |
| 355 | { | |
| 356 | 65 | List<TagField> l = getComment(); |
| 357 | 65 | return (l.size() != 0) ? ((TagTextField) l.get(0)).getContent() : ""; |
| 358 | } | |
| 359 | ||
| 360 | /** | |
| 361 | * Get the first genre or empty string if doesnt exist | |
| 362 | * | |
| 363 | * @see org.jaudiotagger.tag.Tag#getFirstGenre() | |
| 364 | */ | |
| 365 | public String getFirstGenre() | |
| 366 | { | |
| 367 | 60 | List<TagField> l = getGenre(); |
| 368 | 60 | return (l.size() != 0) ? ((TagTextField) l.get(0)).getContent() : ""; |
| 369 | } | |
| 370 | ||
| 371 | /** | |
| 372 | * Get the first title or empty string if doesnt exist | |
| 373 | * | |
| 374 | * @see org.jaudiotagger.tag.Tag#getFirstTitle() | |
| 375 | */ | |
| 376 | public String getFirstTitle() | |
| 377 | { | |
| 378 | 83 | List<TagField> l = getTitle(); |
| 379 | 83 | return (l.size() != 0) ? ((TagTextField) l.get(0)).getContent() : ""; |
| 380 | } | |
| 381 | ||
| 382 | /** | |
| 383 | * Get the first track or empty string if doesnt exist | |
| 384 | * | |
| 385 | * @see org.jaudiotagger.tag.Tag#getFirstTrack() | |
| 386 | */ | |
| 387 | public String getFirstTrack() | |
| 388 | { | |
| 389 | 46 | List<TagField> l = getTrack(); |
| 390 | 46 | return (l.size() != 0) ? ((TagTextField) l.get(0)).getContent() : ""; |
| 391 | } | |
| 392 | ||
| 393 | /** | |
| 394 | * Get the first year or empty string if doesnt exist | |
| 395 | * | |
| 396 | * @see org.jaudiotagger.tag.Tag#getFirstYear() | |
| 397 | */ | |
| 398 | public String getFirstYear() | |
| 399 | { | |
| 400 | 51 | List<TagField> l = getYear(); |
| 401 | 51 | return (l.size() != 0) ? ((TagTextField) l.get(0)).getContent() : ""; |
| 402 | } | |
| 403 | ||
| 404 | /** | |
| 405 | * Get the genres or empty list if none exist | |
| 406 | * | |
| 407 | * @see org.jaudiotagger.tag.Tag#getGenre() | |
| 408 | */ | |
| 409 | public List<TagField> getGenre() | |
| 410 | { | |
| 411 | 37 | return get(getGenreId()); |
| 412 | } | |
| 413 | ||
| 414 | /** | |
| 415 | * Returns the identifier for a field representing the "genre"<br> | |
| 416 | * | |
| 417 | * @return identifier for the "genre" field. | |
| 418 | * @see TagField#getId() | |
| 419 | */ | |
| 420 | protected abstract String getGenreId(); | |
| 421 | ||
| 422 | /** | |
| 423 | * Get the titles or empty list if none exist | |
| 424 | * | |
| 425 | * @see org.jaudiotagger.tag.Tag#getTitle() | |
| 426 | */ | |
| 427 | public List<TagField> getTitle() | |
| 428 | { | |
| 429 | 84 | return get(getTitleId()); |
| 430 | } | |
| 431 | ||
| 432 | /** | |
| 433 | * Returns the identifier for a field representing the "title"<br> | |
| 434 | * | |
| 435 | * @return identifier for the "title" field. | |
| 436 | * @see TagField#getId() | |
| 437 | */ | |
| 438 | protected abstract String getTitleId(); | |
| 439 | ||
| 440 | /** | |
| 441 | * Get the tracks or empty list if none exist | |
| 442 | * | |
| 443 | * @see org.jaudiotagger.tag.Tag#getTrack() | |
| 444 | */ | |
| 445 | public List<TagField> getTrack() | |
| 446 | { | |
| 447 | 47 | return get(getTrackId()); |
| 448 | } | |
| 449 | ||
| 450 | /** | |
| 451 | * Returns the identifier for a field representing the "track"<br> | |
| 452 | * | |
| 453 | * @return identifier for the "track" field. | |
| 454 | * @see TagField#getId() | |
| 455 | */ | |
| 456 | protected abstract String getTrackId(); | |
| 457 | ||
| 458 | /** | |
| 459 | * Get the years or empty list if none exist | |
| 460 | * | |
| 461 | * @see org.jaudiotagger.tag.Tag#getYear() | |
| 462 | */ | |
| 463 | public List<TagField> getYear() | |
| 464 | { | |
| 465 | 52 | return get(getYearId()); |
| 466 | } | |
| 467 | ||
| 468 | /** | |
| 469 | * Returns the identifier for a field representing the "year"<br> | |
| 470 | * | |
| 471 | * @return identifier for the "year" field. | |
| 472 | * @see TagField#getId() | |
| 473 | */ | |
| 474 | protected abstract String getYearId(); | |
| 475 | ||
| 476 | /** | |
| 477 | * Does this tag contain any comon fields | |
| 478 | * | |
| 479 | * @see org.jaudiotagger.tag.Tag#hasCommonFields() | |
| 480 | */ | |
| 481 | public boolean hasCommonFields() | |
| 482 | { | |
| 483 | 0 | return commonNumber != 0; |
| 484 | } | |
| 485 | ||
| 486 | /** | |
| 487 | * Does this tag contain a field with the specified id | |
| 488 | * | |
| 489 | * @see org.jaudiotagger.tag.Tag#hasField(java.lang.String) | |
| 490 | */ | |
| 491 | public boolean hasField(String id) | |
| 492 | { | |
| 493 | 4 | return get(id).size() != 0; |
| 494 | } | |
| 495 | ||
| 496 | /** | |
| 497 | * Determines whether the given charset encoding may be used for the | |
| 498 | * represented tagging system. | |
| 499 | * | |
| 500 | * @param enc charset encoding. | |
| 501 | * @return <code>true</code> if the given encoding can be used. | |
| 502 | */ | |
| 503 | protected abstract boolean isAllowedEncoding(String enc); | |
| 504 | ||
| 505 | /** | |
| 506 | * Is this tag empty | |
| 507 | * | |
| 508 | * @see org.jaudiotagger.tag.Tag#isEmpty() | |
| 509 | */ | |
| 510 | public boolean isEmpty() | |
| 511 | { | |
| 512 | 72 | return fields.size() == 0; |
| 513 | } | |
| 514 | ||
| 515 | /** | |
| 516 | * Set field | |
| 517 | * <p/> | |
| 518 | * Changed:Just because field is empty it doesnt mean it should be deleted. That should be the choice | |
| 519 | * of the developer. (Or does this break things) | |
| 520 | * | |
| 521 | * @see org.jaudiotagger.tag.Tag#set(org.jaudiotagger.tag.TagField) | |
| 522 | */ | |
| 523 | public void set(TagField field) | |
| 524 | { | |
| 525 | 1443 | if (field == null) |
| 526 | { | |
| 527 | 0 | return; |
| 528 | } | |
| 529 | ||
| 530 | // If there is already an existing field with same id | |
| 531 | // and both are TextFields, we replace the first element | |
| 532 | 1443 | List<TagField> list = fields.get(field.getId()); |
| 533 | 1443 | if (list != null) |
| 534 | { | |
| 535 | 189 | list.set(0, field); |
| 536 | 189 | return; |
| 537 | } | |
| 538 | ||
| 539 | // Else we put the new field in the fields. | |
| 540 | 1254 | list = new ArrayList<TagField>(); |
| 541 | 1254 | list.add(field); |
| 542 | 1254 | fields.put(field.getId(), list); |
| 543 | 1254 | if (field.isCommon()) |
| 544 | { | |
| 545 | 217 | commonNumber++; |
| 546 | } | |
| 547 | 1254 | } |
| 548 | ||
| 549 | /** | |
| 550 | * Set or add album | |
| 551 | * | |
| 552 | * @see org.jaudiotagger.tag.Tag#setAlbum(java.lang.String) | |
| 553 | */ | |
| 554 | public void setAlbum(String s) | |
| 555 | { | |
| 556 | 32 | set(createAlbumField(s)); |
| 557 | 32 | } |
| 558 | ||
| 559 | /** | |
| 560 | * Set or add artist | |
| 561 | * | |
| 562 | * @see org.jaudiotagger.tag.Tag#setArtist(java.lang.String) | |
| 563 | */ | |
| 564 | public void setArtist(String s) | |
| 565 | { | |
| 566 | 67 | set(createArtistField(s)); |
| 567 | 67 | } |
| 568 | ||
| 569 | /** | |
| 570 | * Set or add comment | |
| 571 | * | |
| 572 | * @see org.jaudiotagger.tag.Tag#setComment(java.lang.String) | |
| 573 | */ | |
| 574 | public void setComment(String s) | |
| 575 | { | |
| 576 | 39 | set(createCommentField(s)); |
| 577 | 39 | } |
| 578 | ||
| 579 | /** | |
| 580 | * Set or add encoding | |
| 581 | * | |
| 582 | * @see org.jaudiotagger.tag.Tag#setEncoding(java.lang.String) | |
| 583 | */ | |
| 584 | public boolean setEncoding(String enc) | |
| 585 | { | |
| 586 | 0 | if (!isAllowedEncoding(enc)) |
| 587 | { | |
| 588 | 0 | return false; |
| 589 | } | |
| 590 | ||
| 591 | 0 | Iterator it = getFields(); |
| 592 | 0 | while (it.hasNext()) |
| 593 | { | |
| 594 | 0 | TagField field = (TagField) it.next(); |
| 595 | 0 | if (field instanceof TagTextField) |
| 596 | { | |
| 597 | 0 | ((TagTextField) field).setEncoding(enc); |
| 598 | } | |
| 599 | 0 | } |
| 600 | ||
| 601 | 0 | return true; |
| 602 | } | |
| 603 | ||
| 604 | /** | |
| 605 | * Set or add genre | |
| 606 | * | |
| 607 | * @see org.jaudiotagger.tag.Tag#setGenre(java.lang.String) | |
| 608 | */ | |
| 609 | public void setGenre(String s) | |
| 610 | { | |
| 611 | 7 | set(createGenreField(s)); |
| 612 | 7 | } |
| 613 | ||
| 614 | /** | |
| 615 | * Set or add title | |
| 616 | * | |
| 617 | * @see org.jaudiotagger.tag.Tag#setTitle(java.lang.String) | |
| 618 | */ | |
| 619 | public void setTitle(String s) | |
| 620 | { | |
| 621 | 55 | set(createTitleField(s)); |
| 622 | 53 | } |
| 623 | ||
| 624 | /** | |
| 625 | * Set or add track | |
| 626 | * | |
| 627 | * @see org.jaudiotagger.tag.Tag#setTrack(java.lang.String) | |
| 628 | */ | |
| 629 | public void setTrack(String s) throws FieldDataInvalidException | |
| 630 | { | |
| 631 | 4 | set(createTrackField(s)); |
| 632 | 4 | } |
| 633 | ||
| 634 | /** | |
| 635 | * Set or add year | |
| 636 | * | |
| 637 | * @see org.jaudiotagger.tag.Tag#setYear(java.lang.String) | |
| 638 | */ | |
| 639 | public void setYear(String s) | |
| 640 | { | |
| 641 | 8 | set(createYearField(s)); |
| 642 | 8 | } |
| 643 | ||
| 644 | /** | |
| 645 | * (overridden) | |
| 646 | * | |
| 647 | * @see java.lang.Object#toString() | |
| 648 | */ | |
| 649 | public String toString() | |
| 650 | { | |
| 651 | 42 | StringBuffer out = new StringBuffer(); |
| 652 | 42 | out.append("Tag content:\n"); |
| 653 | 42 | Iterator it = getFields(); |
| 654 | 832 | while (it.hasNext()) |
| 655 | { | |
| 656 | 790 | TagField field = (TagField) it.next(); |
| 657 | 790 | out.append("\t"); |
| 658 | 790 | out.append(field.getId()); |
| 659 | 790 | out.append(":"); |
| 660 | 790 | out.append(field.toString()); |
| 661 | 790 | out.append("\n"); |
| 662 | 790 | } |
| 663 | 42 | return out.toString().substring(0, out.length() - 1); |
| 664 | } | |
| 665 | ||
| 666 | /** | |
| 667 | * | |
| 668 | * @param genericKey | |
| 669 | * @param value | |
| 670 | * @return | |
| 671 | * @throws KeyNotFoundException | |
| 672 | * @throws FieldDataInvalidException | |
| 673 | */ | |
| 674 | public abstract TagField createTagField(TagFieldKey genericKey, String value) throws KeyNotFoundException, FieldDataInvalidException; | |
| 675 | ||
| 676 | /** | |
| 677 | * | |
| 678 | * @param genericKey | |
| 679 | * @return | |
| 680 | * @throws KeyNotFoundException | |
| 681 | */ | |
| 682 | public abstract String getFirst(TagFieldKey genericKey) throws KeyNotFoundException; | |
| 683 | ||
| 684 | /** | |
| 685 | * | |
| 686 | * @param genericKey | |
| 687 | * @return | |
| 688 | * @throws KeyNotFoundException | |
| 689 | */ | |
| 690 | public abstract TagField getFirstField(TagFieldKey genericKey) throws KeyNotFoundException; | |
| 691 | ||
| 692 | /** | |
| 693 | * | |
| 694 | * @param tagFieldKey | |
| 695 | * @throws KeyNotFoundException | |
| 696 | */ | |
| 697 | public abstract void deleteTagField(TagFieldKey tagFieldKey) throws KeyNotFoundException; | |
| 698 | ||
| 699 | ||
| 700 | /** | |
| 701 | * Delete all ocurrences of field. | |
| 702 | * | |
| 703 | * @param key | |
| 704 | */ | |
| 705 | protected void deleteField(String key) | |
| 706 | { | |
| 707 | 16 | Object removed = fields.remove(key); |
| 708 | //if (removed != null && field.isCommon()) | |
| 709 | // commonNumber--; | |
| 710 | 16 | return; |
| 711 | } | |
| 712 | ||
| 713 | /** | |
| 714 | * Creates a field which represents the "album".<br> | |
| 715 | * The field will already contain the given content. | |
| 716 | * | |
| 717 | * @param content The content of the created field. | |
| 718 | * @return tagfield representing the "album" | |
| 719 | */ | |
| 720 | public abstract TagField createAlbumField(String content); | |
| 721 | ||
| 722 | /** | |
| 723 | * Creates a field which represents the "artist".<br> | |
| 724 | * The field will already contain the given content. | |
| 725 | * | |
| 726 | * @param content The content of the created field. | |
| 727 | * @return tagfield representing the "artist" | |
| 728 | */ | |
| 729 | public abstract TagField createArtistField(String content); | |
| 730 | ||
| 731 | /** | |
| 732 | * Creates a field which represents the "comment".<br> | |
| 733 | * The field will already contain the given content. | |
| 734 | * | |
| 735 | * @param content The content of the created field. | |
| 736 | * @return tagfield representing the "comment" | |
| 737 | */ | |
| 738 | public abstract TagField createCommentField(String content); | |
| 739 | ||
| 740 | /** | |
| 741 | * Creates a field which represents the "genre".<br> | |
| 742 | * The field will already contain the given content. | |
| 743 | * | |
| 744 | * @param content The content of the created field. | |
| 745 | * @return tagfield representing the "genre" | |
| 746 | */ | |
| 747 | public abstract TagField createGenreField(String content); | |
| 748 | ||
| 749 | /** | |
| 750 | * Creates a field which represents the "title".<br> | |
| 751 | * The field will already contain the given content. | |
| 752 | * | |
| 753 | * @param content The content of the created field. | |
| 754 | * @return tagfield representing the "title" | |
| 755 | */ | |
| 756 | public abstract TagField createTitleField(String content); | |
| 757 | ||
| 758 | /** | |
| 759 | * Creates a field which represents the "track".<br> | |
| 760 | * The field will already contain the given content. | |
| 761 | * | |
| 762 | * @param content The content of the created field. | |
| 763 | * @return tagfield representing the "track" | |
| 764 | */ | |
| 765 | public abstract TagField createTrackField(String content) throws FieldDataInvalidException; | |
| 766 | ||
| 767 | /** | |
| 768 | * Creates a field which represents the "year".<br> | |
| 769 | * The field will already contain the given content. | |
| 770 | * | |
| 771 | * @param content The content of the created field. | |
| 772 | * @return tagfield representing the "year" | |
| 773 | */ | |
| 774 | public abstract TagField createYearField(String content); | |
| 775 | ||
| 776 | public Artwork getFirstArtwork() | |
| 777 | { | |
| 778 | 6 | List<Artwork> artwork = getArtworkList(); |
| 779 | 6 | if(artwork.size()>0) |
| 780 | { | |
| 781 | 6 | return artwork.get(0); |
| 782 | } | |
| 783 | 0 | return null; |
| 784 | } | |
| 785 | ||
| 786 | /** | |
| 787 | * Create field and then set within tag itself | |
| 788 | * | |
| 789 | * @param artwork | |
| 790 | * @throws FieldDataInvalidException | |
| 791 | */ | |
| 792 | public void createAndSetArtworkField(Artwork artwork) throws FieldDataInvalidException | |
| 793 | { | |
| 794 | 4 | this.set(createArtworkField(artwork)); |
| 795 | 2 | } |
| 796 | ||
| 797 | ||
| 798 | ||
| 799 | } |