Coverage Report - org.jaudiotagger.audio.asf.tag.AsfTag
 
Classes in this File Line Coverage Branch Coverage Complexity
AsfTag
89%
170/190
62%
29/47
0
AsfTag$1
60%
3/5
N/A
0
AsfTag$2
100%
1/1
N/A
0
 
 1  
 package org.jaudiotagger.audio.asf.tag;
 2  
 
 3  
 import org.jaudiotagger.audio.asf.data.AsfHeader;
 4  
 import org.jaudiotagger.audio.asf.data.ContentDescriptor;
 5  
 import org.jaudiotagger.audio.asf.util.Utils;
 6  
 import org.jaudiotagger.audio.generic.AbstractTag;
 7  
 import org.jaudiotagger.logging.ErrorMessage;
 8  
 import org.jaudiotagger.tag.*;
 9  
 import org.jaudiotagger.tag.datatype.Artwork;
 10  
 import org.jaudiotagger.tag.reference.PictureTypes;
 11  
 
 12  
 import java.io.UnsupportedEncodingException;
 13  
 import java.util.*;
 14  
 
 15  
 /**
 16  
  * Tag implementation for ASF.<br>
 17  
  *
 18  
  * @author Christian Laireiter
 19  
  */
 20  1
 public final class AsfTag extends AbstractTag
 21  
 {
 22  
     /**
 23  
      * Stores a list of field keys, which identify common fields.<br>
 24  
      */
 25  
     public final static Set<AsfFieldKey> COMMON_FIELDS;
 26  
 
 27  
     /**
 28  
      * List of {@link AsfFieldKey} items, identifying contents that are stored in the
 29  
      * content description chunk (or unit) of ASF files.
 30  
      */
 31  
     public final static Set<AsfFieldKey> DESCRIPTION_FIELDS;
 32  
 
 33  6
     static EnumMap<TagFieldKey, AsfFieldKey> tagFieldToAsfField = new EnumMap<TagFieldKey, AsfFieldKey>(TagFieldKey.class);
 34  
 
 35  
     //Mapping from generic key to mp4 key
 36  
     static
 37  
     {
 38  6
         tagFieldToAsfField.put(TagFieldKey.ARTIST, AsfFieldKey.ARTIST);
 39  6
         tagFieldToAsfField.put(TagFieldKey.ALBUM, AsfFieldKey.ALBUM);
 40  6
         tagFieldToAsfField.put(TagFieldKey.TITLE, AsfFieldKey.TITLE);
 41  6
         tagFieldToAsfField.put(TagFieldKey.TRACK, AsfFieldKey.TRACK);
 42  6
         tagFieldToAsfField.put(TagFieldKey.YEAR, AsfFieldKey.YEAR);
 43  6
         tagFieldToAsfField.put(TagFieldKey.GENRE, AsfFieldKey.GENRE);
 44  6
         tagFieldToAsfField.put(TagFieldKey.COMMENT, AsfFieldKey.COMMENT);
 45  6
         tagFieldToAsfField.put(TagFieldKey.ALBUM_ARTIST, AsfFieldKey.ALBUM_ARTIST);
 46  6
         tagFieldToAsfField.put(TagFieldKey.COMPOSER, AsfFieldKey.COMPOSER);
 47  6
         tagFieldToAsfField.put(TagFieldKey.GROUPING, AsfFieldKey.GROUPING);
 48  6
         tagFieldToAsfField.put(TagFieldKey.DISC_NO, AsfFieldKey.DISC_NO);
 49  6
         tagFieldToAsfField.put(TagFieldKey.BPM, AsfFieldKey.BPM);
 50  6
         tagFieldToAsfField.put(TagFieldKey.ENCODER, AsfFieldKey.ENCODER);
 51  6
         tagFieldToAsfField.put(TagFieldKey.MUSICBRAINZ_ARTISTID, AsfFieldKey.MUSICBRAINZ_ARTISTID);
 52  6
         tagFieldToAsfField.put(TagFieldKey.MUSICBRAINZ_RELEASEID, AsfFieldKey.MUSICBRAINZ_RELEASEID);
 53  6
         tagFieldToAsfField.put(TagFieldKey.MUSICBRAINZ_RELEASEARTISTID, AsfFieldKey.MUSICBRAINZ_RELEASEARTISTID);
 54  6
         tagFieldToAsfField.put(TagFieldKey.MUSICBRAINZ_TRACK_ID, AsfFieldKey.MUSICBRAINZ_TRACK_ID);
 55  6
         tagFieldToAsfField.put(TagFieldKey.MUSICBRAINZ_DISC_ID, AsfFieldKey.MUSICBRAINZ_DISC_ID);
 56  6
         tagFieldToAsfField.put(TagFieldKey.MUSICIP_ID, AsfFieldKey.MUSICIP_ID);
 57  6
         tagFieldToAsfField.put(TagFieldKey.AMAZON_ID, AsfFieldKey.AMAZON_ID);
 58  6
         tagFieldToAsfField.put(TagFieldKey.MUSICBRAINZ_RELEASE_STATUS, AsfFieldKey.MUSICBRAINZ_RELEASE_STATUS);
 59  6
         tagFieldToAsfField.put(TagFieldKey.MUSICBRAINZ_RELEASE_TYPE, AsfFieldKey.MUSICBRAINZ_RELEASE_TYPE);
 60  6
         tagFieldToAsfField.put(TagFieldKey.MUSICBRAINZ_RELEASE_COUNTRY, AsfFieldKey.MUSICBRAINZ_RELEASE_COUNTRY);
 61  6
         tagFieldToAsfField.put(TagFieldKey.LYRICS, AsfFieldKey.LYRICS);
 62  6
         tagFieldToAsfField.put(TagFieldKey.IS_COMPILATION, AsfFieldKey.IS_COMPILATION);
 63  6
         tagFieldToAsfField.put(TagFieldKey.ARTIST_SORT, AsfFieldKey.ARTIST_SORT);
 64  6
         tagFieldToAsfField.put(TagFieldKey.ALBUM_ARTIST_SORT, AsfFieldKey.ALBUM_ARTIST_SORT);
 65  6
         tagFieldToAsfField.put(TagFieldKey.ALBUM_SORT, AsfFieldKey.ALBUM_SORT);
 66  6
         tagFieldToAsfField.put(TagFieldKey.TITLE_SORT, AsfFieldKey.TITLE_SORT);
 67  6
         tagFieldToAsfField.put(TagFieldKey.COMPOSER_SORT, AsfFieldKey.COMPOSER_SORT);
 68  6
         tagFieldToAsfField.put(TagFieldKey.COVER_ART, AsfFieldKey.COVER_ART);
 69  6
         tagFieldToAsfField.put(TagFieldKey.ISRC, AsfFieldKey.ISRC);
 70  6
         tagFieldToAsfField.put(TagFieldKey.CATALOG_NO, AsfFieldKey.CATALOG_NO);
 71  6
         tagFieldToAsfField.put(TagFieldKey.BARCODE, AsfFieldKey.BARCODE);
 72  6
         tagFieldToAsfField.put(TagFieldKey.RECORD_LABEL, AsfFieldKey.RECORD_LABEL);
 73  6
         tagFieldToAsfField.put(TagFieldKey.LYRICIST, AsfFieldKey.LYRICIST);
 74  6
         tagFieldToAsfField.put(TagFieldKey.CONDUCTOR, AsfFieldKey.CONDUCTOR);
 75  6
         tagFieldToAsfField.put(TagFieldKey.REMIXER, AsfFieldKey.REMIXER);
 76  6
         tagFieldToAsfField.put(TagFieldKey.MOOD, AsfFieldKey.MOOD);
 77  6
         tagFieldToAsfField.put(TagFieldKey.MEDIA, AsfFieldKey.MEDIA);
 78  6
         tagFieldToAsfField.put(TagFieldKey.URL_OFFICIAL_RELEASE_SITE, AsfFieldKey.URL_OFFICIAL_RELEASE_SITE);
 79  6
         tagFieldToAsfField.put(TagFieldKey.URL_DISCOGS_RELEASE_SITE, AsfFieldKey.URL_DISCOGS_RELEASE_SITE);
 80  6
         tagFieldToAsfField.put(TagFieldKey.URL_WIKIPEDIA_RELEASE_SITE, AsfFieldKey.URL_WIKIPEDIA_RELEASE_SITE);
 81  6
         tagFieldToAsfField.put(TagFieldKey.URL_OFFICIAL_ARTIST_SITE, AsfFieldKey.URL_OFFICIAL_ARTIST_SITE);
 82  6
         tagFieldToAsfField.put(TagFieldKey.URL_DISCOGS_ARTIST_SITE, AsfFieldKey.URL_DISCOGS_ARTIST_SITE);
 83  6
         tagFieldToAsfField.put(TagFieldKey.URL_WIKIPEDIA_ARTIST_SITE, AsfFieldKey.URL_WIKIPEDIA_ARTIST_SITE);
 84  6
         tagFieldToAsfField.put(TagFieldKey.LANGUAGE, AsfFieldKey.LANGUAGE);
 85  6
         tagFieldToAsfField.put(TagFieldKey.KEY, AsfFieldKey.KEY);
 86  
     }
 87  
 
 88  
     static
 89  
     {
 90  6
         COMMON_FIELDS = new HashSet<AsfFieldKey>();
 91  6
         COMMON_FIELDS.add(AsfFieldKey.ALBUM);
 92  6
         COMMON_FIELDS.add(AsfFieldKey.ARTIST);
 93  6
         COMMON_FIELDS.add(AsfFieldKey.COMMENT);
 94  6
         COMMON_FIELDS.add(AsfFieldKey.GENRE);
 95  6
         COMMON_FIELDS.add(AsfFieldKey.TITLE);
 96  6
         COMMON_FIELDS.add(AsfFieldKey.TRACK);
 97  6
         COMMON_FIELDS.add(AsfFieldKey.YEAR);
 98  6
         DESCRIPTION_FIELDS = new HashSet<AsfFieldKey>();
 99  6
         DESCRIPTION_FIELDS.add(AsfFieldKey.ARTIST);
 100  6
         DESCRIPTION_FIELDS.add(AsfFieldKey.COPYRIGHT);
 101  6
         DESCRIPTION_FIELDS.add(AsfFieldKey.COMMENT);
 102  6
         DESCRIPTION_FIELDS.add(AsfFieldKey.RATING);
 103  6
         DESCRIPTION_FIELDS.add(AsfFieldKey.TITLE);
 104  6
     }
 105  
 
 106  
     /**
 107  
      * Determines if the {@linkplain ContentDescriptor#getName() name} equals an {@link AsfFieldKey} which
 108  
      * is {@linkplain #DESCRIPTION_FIELDS listed} to be stored in the content description chunk.
 109  
      *
 110  
      * @param contentDesc Descriptor to test.
 111  
      * @return see description.
 112  
      */
 113  
     public static boolean storesDescriptor(ContentDescriptor contentDesc)
 114  
     {
 115  898
         AsfFieldKey asfFieldKey = AsfFieldKey.getAsfFieldKey(contentDesc.getName());
 116  898
         return DESCRIPTION_FIELDS.contains(asfFieldKey);
 117  
     }
 118  
 
 119  
 
 120  
     /**
 121  
      * @see #isCopyingFields()
 122  
      */
 123  
     private final boolean copyFields;
 124  
 
 125  
     /**
 126  
      * Creates an empty instance.
 127  
      */
 128  
     public AsfTag()
 129  
     {
 130  4
         this(false);
 131  4
     }
 132  
 
 133  
     /**
 134  
      * Creates an instance and sets the field conversion property.<br>
 135  
      *
 136  
      * @param copyFields look at {@link #isCopyingFields()}.
 137  
      */
 138  
     public AsfTag(boolean copyFields)
 139  88
     {
 140  88
         this.copyFields = copyFields;
 141  88
     }
 142  
 
 143  
 
 144  
     /**
 145  
      * Creates an instance and copies the fields of the source into the own
 146  
      * structure.<br>
 147  
      *
 148  
      * @param source     source to read tag fields from.
 149  
      * @param copyFields look at {@link #isCopyingFields()}.
 150  
      * @throws UnsupportedEncodingException {@link TagField#getRawContent()} which may be called
 151  
      */
 152  
     public AsfTag(Tag source, boolean copyFields) throws UnsupportedEncodingException
 153  
     {
 154  25
         this(copyFields);
 155  25
         copyFrom(source);
 156  25
     }
 157  
 
 158  
 
 159  
     /**
 160  
      * Creates a field for copyright and adds it.<br>
 161  
      *
 162  
      * @param copyRight copyright content
 163  
      */
 164  
     public void addCopyright(String copyRight)
 165  
     {
 166  2
         add(createCopyrightField(copyRight));
 167  2
     }
 168  
 
 169  
     /**
 170  
      * Creates a field for rating and adds it.<br>
 171  
      *
 172  
      * @param rating rating.
 173  
      */
 174  
     public void addRating(String rating)
 175  
     {
 176  2
         add(createRatingField(rating));
 177  2
     }
 178  
 
 179  
     /**
 180  
      * This method copies tag fields from the source.<br>
 181  
      *
 182  
      * @param source source to read tag fields from.
 183  
      * @throws UnsupportedEncodingException {@link TagField#getRawContent()} which may be called
 184  
      */
 185  
     private void copyFrom(Tag source) throws UnsupportedEncodingException
 186  
     {
 187  25
         if (source == null)
 188  
         {
 189  0
             throw new NullPointerException();
 190  
         }
 191  25
         final Iterator<TagField> fieldIterator = source.getFields();
 192  
         // iterate over all fields 
 193  387
         while (fieldIterator.hasNext())
 194  
         {
 195  362
             TagField copy = copyFrom(fieldIterator.next());
 196  362
             if (copy != null)
 197  
             {
 198  362
                 super.add(copy);
 199  
             }
 200  362
         }
 201  25
     }
 202  
 
 203  
     /**
 204  
      * If {@link #isCopyingFields()} is <code>true</code>,
 205  
      * Creates a copy of <code>source</code>, if its not empty-<br>
 206  
      * However, plain {@link TagField} objects can only be transformed into binary fields using their
 207  
      * {@link TagField#getRawContent()} method.<br>
 208  
      *
 209  
      * @param source source field to copy.
 210  
      * @return A copy, which is as close to the source as possible, or <code>null</code> if the field is empty
 211  
      *         (empty byte[] or blank string}.
 212  
      * @throws UnsupportedEncodingException upon {@link TagField#getRawContent()}.
 213  
      */
 214  
     //TODO Add support for cover art field
 215  
     private TagField copyFrom(TagField source)
 216  
     {
 217  1452
         TagField result = null;
 218  1452
         if (isCopyingFields())
 219  
         {
 220  
             // Get the ASF internal key, where it applies
 221  1450
             String internalId = source.getId();
 222  1450
             if (source instanceof TagTextField)
 223  
             {
 224  1427
                 String content = ((TagTextField) source).getContent();
 225  1427
                 result = new AsfTagTextField(internalId, content);
 226  1427
             }
 227  23
             else if (source instanceof AsfTagField)
 228  
             {
 229  23
                 result = new AsfTagCoverField(((AsfTagCoverField) source).getDescriptor());
 230  
             }
 231  0
             else if (source instanceof AsfTagField)
 232  
             {
 233  0
                 result = new AsfTagField(((AsfTagField) source).getDescriptor());
 234  
             }
 235  
             else
 236  
             {
 237  0
                 throw new RuntimeException("Unknown Asf Tag Field class:"+source.getClass());
 238  
             }
 239  1450
         }
 240  
         else
 241  
         {
 242  2
             result = source;
 243  
         }
 244  1452
         return result;
 245  
     }
 246  
 
 247  
 
 248  
     /**
 249  
      * {@inheritDoc}
 250  
      */
 251  
     @Override
 252  
     public TagField createAlbumField(String content)
 253  
     {
 254  4
         return new AsfTagTextField(getAlbumId(), content);
 255  
     }
 256  
 
 257  
     /**
 258  
      * {@inheritDoc}
 259  
      */
 260  
     @Override
 261  
     public TagField createArtistField(String content)
 262  
     {
 263  37
         return new AsfTagTextField(getArtistId(), content);
 264  
     }
 265  
 
 266  
     /**
 267  
      * {@inheritDoc}
 268  
      */
 269  
     @Override
 270  
     public TagField createCommentField(String content)
 271  
     {
 272  36
         return new AsfTagTextField(getCommentId(), content);
 273  
     }
 274  
 
 275  
     /**
 276  
      * Creates a field for storing the copyright.<br>
 277  
      *
 278  
      * @param content Copyright value.
 279  
      * @return {@link AsfTagTextField}
 280  
      */
 281  
     public TagField createCopyrightField(String content)
 282  
     {
 283  40
         return new AsfTagTextField(AsfFieldKey.COPYRIGHT.getFieldName(), content);
 284  
     }
 285  
 
 286  
     /**
 287  
      * {@inheritDoc}
 288  
      */
 289  
     @Override
 290  
     public TagField createGenreField(String content)
 291  
     {
 292  1
         return new AsfTagTextField(getGenreId(), content);
 293  
     }
 294  
 
 295  
     /**
 296  
      * Creates a field for storing the copyright.<br>
 297  
      *
 298  
      * @param content Rating value.
 299  
      * @return {@link AsfTagTextField}
 300  
      */
 301  
     public TagField createRatingField(String content)
 302  
     {
 303  40
         return new AsfTagTextField(AsfFieldKey.RATING.getFieldName(), content);
 304  
     }
 305  
 
 306  
     /**
 307  
      * {@inheritDoc}
 308  
      */
 309  
     @Override
 310  
     public TagField createTagField(TagFieldKey genericKey, String value) throws KeyNotFoundException, FieldDataInvalidException
 311  
     {
 312  146
         if (value == null)
 313  
         {
 314  0
             throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
 315  
         }
 316  146
         if (genericKey == null)
 317  
         {
 318  0
             throw new KeyNotFoundException();
 319  
         }
 320  146
         return createTagField(tagFieldToAsfField.get(genericKey), value);
 321  
     }
 322  
 
 323  
     /**
 324  
      * Create Tag Field using asf key
 325  
      * <p/>
 326  
      * Uses the correct subclass for the key
 327  
      *
 328  
      * @param asfFieldKey
 329  
      * @param value
 330  
      * @return
 331  
      * @throws KeyNotFoundException
 332  
      * @throws FieldDataInvalidException
 333  
      */
 334  
     public TagField createTagField(AsfFieldKey asfFieldKey, String value) throws KeyNotFoundException, FieldDataInvalidException
 335  
     {
 336  154
         if (value == null)
 337  
         {
 338  0
             throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
 339  
         }
 340  154
         if (asfFieldKey == null)
 341  
         {
 342  0
             throw new KeyNotFoundException("key not found for value:" + value);
 343  
         }
 344  
 
 345  154
         switch (asfFieldKey)
 346  
         {
 347  
             default:
 348  154
                 return new AsfTagTextField(asfFieldKey.getFieldName(), value);
 349  
         }
 350  
     }
 351  
 
 352  
     /**
 353  
      * {@inheritDoc}
 354  
      */
 355  
     @Override
 356  
     public TagField createTitleField(String content)
 357  
     {
 358  38
         return new AsfTagTextField(getTitleId(), content);
 359  
     }
 360  
 
 361  
     /**
 362  
      * {@inheritDoc}
 363  
      */
 364  
     @Override
 365  
     public TagField createTrackField(String content) throws FieldDataInvalidException
 366  
     {
 367  1
         return new AsfTagTextField(getTrackId(), content);
 368  
     }
 369  
 
 370  
     /**
 371  
      * {@inheritDoc}
 372  
      */
 373  
     @Override
 374  
     public TagField createYearField(String content)
 375  
     {
 376  1
         return new AsfTagTextField(getYearId(), content);
 377  
     }
 378  
 
 379  
     /**
 380  
      * Create artwork field
 381  
      *
 382  
      * @param data raw image data
 383  
      * @return
 384  
      */
 385  
     public TagField createArtworkField(byte[] data) throws FieldDataInvalidException
 386  
     {
 387  1
         return new AsfTagCoverField(data, PictureTypes.DEFAULT_ID, null);
 388  
     }
 389  
 
 390  
     /**
 391  
      * Create artwork field
 392  
      *
 393  
      * @return
 394  
      */
 395  
     public TagField createArtworkField(Artwork artwork) throws FieldDataInvalidException
 396  
     {
 397  1
         return new AsfTagCoverField(artwork.getBinaryData(), artwork.getPictureType(), artwork.getDescription());
 398  
     }
 399  
 
 400  
     /**
 401  
      * Removes all fields which are stored to the provided field key.
 402  
      *
 403  
      * @param fieldKey fields to remove.
 404  
      */
 405  
     public void deleteTagField(AsfFieldKey fieldKey)
 406  
     {
 407  5
         super.deleteField(fieldKey.getFieldName());
 408  5
     }
 409  
 
 410  
 
 411  
     /**
 412  
      * {@inheritDoc}
 413  
      */
 414  
     @Override
 415  
     public void deleteTagField(TagFieldKey tagFieldKey) throws KeyNotFoundException
 416  
     {
 417  0
         if (tagFieldKey == null)
 418  
         {
 419  0
             throw new KeyNotFoundException();
 420  
         }
 421  0
         super.deleteField(tagFieldToAsfField.get(tagFieldKey).getFieldName());
 422  0
     }
 423  
 
 424  
     /**
 425  
      * {@inheritDoc}
 426  
      */
 427  
     @Override
 428  
     public List<TagField> get(TagFieldKey id) throws KeyNotFoundException
 429  
     {
 430  210
         if (id == null)
 431  
         {
 432  0
             throw new KeyNotFoundException();
 433  
         }
 434  210
         return super.get(tagFieldToAsfField.get(id).getFieldName());
 435  
     }
 436  
 
 437  
     /**
 438  
      * {@inheritDoc}
 439  
      */
 440  
     @Override
 441  
     protected String getAlbumId()
 442  
     {
 443  30
         return AsfFieldKey.ALBUM.getFieldName();
 444  
     }
 445  
 
 446  
     /**
 447  
      * {@inheritDoc}
 448  
      */
 449  
     @Override
 450  
     protected String getArtistId()
 451  
     {
 452  88
         return AsfFieldKey.ARTIST.getFieldName();
 453  
     }
 454  
 
 455  
     /**
 456  
      * This method iterates through all stored fields.<br>
 457  
      * This method can only be used if this class has been created with field conversion turned on.
 458  
      *
 459  
      * @param <F>
 460  
      * @return Iterator for iterating through ASF fields.
 461  
      */
 462  
     public <F extends AsfTagField> Iterator<F> getAsfFields()
 463  
     {
 464  38
         if (!isCopyingFields())
 465  
         {
 466  0
             throw new IllegalStateException("Since the field conversion is not enabled, this method cannot be executed");
 467  
         }
 468  38
         final Iterator<TagField> it = getFields();
 469  38
         return new Iterator<F>()
 470  
         {
 471  
 
 472  
             public boolean hasNext()
 473  
             {
 474  446
                 return it.hasNext();
 475  
             }
 476  
 
 477  
             @SuppressWarnings("unchecked")
 478  
             public F next()
 479  
             {
 480  408
                 return (F) it.next();
 481  
             }
 482  
 
 483  446
             public void remove()
 484  
             {
 485  0
                 it.remove();
 486  0
             }
 487  
         };
 488  
     }
 489  
 
 490  
     /**
 491  
      * {@inheritDoc}
 492  
      */
 493  
     @Override
 494  
     protected String getCommentId()
 495  
     {
 496  72
         return AsfFieldKey.COMMENT.getFieldName();
 497  
     }
 498  
 
 499  
     /**
 500  
      * Returns a list of stored copyrights.
 501  
      *
 502  
      * @return list of stored copyrights.
 503  
      */
 504  
     public List<TagField> getCopyright()
 505  
     {
 506  2
         return get(AsfFieldKey.COPYRIGHT.getFieldName());
 507  
     }
 508  
 
 509  
     /**
 510  
      * {@inheritDoc}
 511  
      */
 512  
     @Override
 513  
     public String getFirst(TagFieldKey genericKey) throws KeyNotFoundException
 514  
     {
 515  232
         if (genericKey == null)
 516  
         {
 517  0
             throw new KeyNotFoundException();
 518  
         }
 519  232
         return super.getFirst(tagFieldToAsfField.get(genericKey).getFieldName());
 520  
     }
 521  
 
 522  
     public AsfTagField getFirstField(TagFieldKey genericKey) throws KeyNotFoundException
 523  
     {
 524  1
         if (genericKey == null)
 525  
         {
 526  0
             throw new KeyNotFoundException();
 527  
         }
 528  1
         return (AsfTagField) super.getFirstField(tagFieldToAsfField.get(genericKey).getFieldName());
 529  
     }
 530  
 
 531  
     /**
 532  
      * Returns the Copyright.
 533  
      *
 534  
      * @return the Copyright.
 535  
      */
 536  
     public String getFirstCopyright()
 537  
     {
 538  35
         return getFirst(AsfFieldKey.COPYRIGHT.getFieldName());
 539  
     }
 540  
 
 541  
     /**
 542  
      * Returns the Rating.
 543  
      *
 544  
      * @return the Rating.
 545  
      */
 546  
     public String getFirstRating()
 547  
     {
 548  34
         return getFirst(AsfFieldKey.RATING.getFieldName());
 549  
     }
 550  
 
 551  
     /**
 552  
      * {@inheritDoc}
 553  
      */
 554  
     @Override
 555  
     protected String getGenreId()
 556  
     {
 557  34
         return AsfFieldKey.GENRE.getFieldName();
 558  
     }
 559  
 
 560  
     /**
 561  
      * Returns a list of stored ratings.
 562  
      *
 563  
      * @return list of stored ratings.
 564  
      */
 565  
     public List<TagField> getRating()
 566  
     {
 567  2
         return get(AsfFieldKey.RATING.getFieldName());
 568  
     }
 569  
 
 570  
     /**
 571  
      * {@inheritDoc}
 572  
      */
 573  
     @Override
 574  
     protected String getTitleId()
 575  
     {
 576  75
         return AsfFieldKey.TITLE.getFieldName();
 577  
     }
 578  
 
 579  
     /**
 580  
      * {@inheritDoc}
 581  
      */
 582  
     @Override
 583  
     protected String getTrackId()
 584  
     {
 585  26
         return AsfFieldKey.TRACK.getFieldName();
 586  
     }
 587  
 
 588  
     /**
 589  
      * {@inheritDoc}
 590  
      */
 591  
     @Override
 592  
     protected String getYearId()
 593  
     {
 594  26
         return AsfFieldKey.YEAR.getFieldName();
 595  
     }
 596  
 
 597  
     /**
 598  
      * {@inheritDoc}
 599  
      */
 600  
     @Override
 601  
     protected boolean isAllowedEncoding(String enc)
 602  
     {
 603  0
         return AsfHeader.ASF_CHARSET.name().equals(enc);
 604  
     }
 605  
 
 606  
     /**
 607  
      * If <code>true</code>, the {@link #copyFrom(TagField)} method creates a new {@link AsfTagField} instance and
 608  
      * copies the content from the source.<br>
 609  
      * This method is utilized by {@link #add(TagField)} and {@link #set(TagField)}.<br>
 610  
      * So if <code>true</code> it is ensured that the {@link AsfTag} instance has its own copies of fields, which cannot
 611  
      * be modified after assignment (which could pass some checks), and it just stores {@link AsfTagField} objects.<br>
 612  
      * Only then {@link #getAsfFields()} can work. otherwise {@link IllegalStateException} is thrown.
 613  
      *
 614  
      * @return state of field conversion.
 615  
      */
 616  
     public boolean isCopyingFields()
 617  
     {
 618  1490
         return this.copyFields;
 619  
     }
 620  
 
 621  
     /**
 622  
      * Check field is valid and can be added to this tag
 623  
      * @param field
 624  
      * @return
 625  
      */
 626  
     //TODO introduce this concept to all formats
 627  
     private boolean isValidField(TagField field)
 628  
     {
 629  1170
         if (field == null)
 630  
         {
 631  0
             return false;
 632  
         }
 633  
 
 634  1170
         if (!(field instanceof AsfTagField))
 635  
         {
 636  0
             return false;
 637  
         }
 638  
 
 639  1170
         if (field.isEmpty())
 640  
         {
 641  80
             return false;
 642  
         }
 643  1090
         return true;
 644  
     }
 645  
 
 646  
     /**
 647  
      * {@inheritDoc}
 648  
      */
 649  
     @Override
 650  
     //TODO introduce copy idea to all formats
 651  
     public void add(TagField field)
 652  
     {
 653  972
         if (isValidField(field))
 654  
         {
 655  
             //Copy only occUrs if flag set
 656  967
             field = copyFrom(field);
 657  967
             if (AsfFieldKey.isMultiValued(field.getId()))
 658  
             {
 659  0
                 super.add(field);
 660  
             }
 661  
             else
 662  
             {
 663  967
                 super.set(field);
 664  
             }
 665  
         }
 666  972
     }
 667  
 
 668  
     /**
 669  
      * {@inheritDoc}
 670  
      */
 671  
     @Override
 672  
     //TODO introduce copy idea to all formats
 673  
     public void set(TagField field)
 674  
     {
 675  198
         if (isValidField(field))
 676  
         {
 677  
             //Copy only occors if flag set
 678  123
             field = copyFrom(field);
 679  123
             super.set(field);
 680  
         }
 681  198
     }
 682  
 
 683  
     /**
 684  
      * Sets the copyright.<br>
 685  
      *
 686  
      * @param Copyright the copyright to set.
 687  
      */
 688  
     public void setCopyright(String Copyright)
 689  
     {
 690  38
         set(createCopyrightField(Copyright));
 691  38
     }
 692  
 
 693  
     /**
 694  
      * Sets the Rating.<br>
 695  
      *
 696  
      * @param rating the rating to set.
 697  
      */
 698  
     public void setRating(String rating)
 699  
     {
 700  38
         set(createRatingField(rating));
 701  38
     }
 702  
 
 703  
     /**
 704  
      * @return
 705  
      */
 706  
     public List<Artwork> getArtworkList()
 707  
     {
 708  6
         List<TagField> coverartList = get(TagFieldKey.COVER_ART);
 709  6
         List<Artwork> artworkList = new ArrayList<Artwork>(coverartList.size());
 710  
 
 711  6
         for (TagField next : coverartList)
 712  
         {
 713  6
             AsfTagCoverField coverArt = (AsfTagCoverField) next;
 714  6
             Artwork artwork = new Artwork();
 715  6
             artwork.setBinaryData(coverArt.getRawImageData());
 716  6
             artwork.setMimeType(coverArt.getMimeType());
 717  6
             artwork.setDescription(coverArt.getDescription());
 718  6
             artwork.setPictureType(coverArt.getPictureType());
 719  6
             artworkList.add(artwork);
 720  6
         }
 721  6
         return artworkList;
 722  
     }
 723  
 }