FileDocCategorySizeDatePackage
AsfTag.javaAPI DocJaudiotagger 2.0.424005Wed Dec 07 10:49:54 GMT 2011org.jaudiotagger.tag.asf

AsfTag

public final class AsfTag extends org.jaudiotagger.audio.generic.AbstractTag
Tag implementation for ASF.
author
Christian Laireiter

Fields Summary
public static final Set
COMMON_FIELDS
Stores a list of field keys, which identify common fields.
private static final EnumMap
tagFieldToAsfField
This map contains the mapping from {@link org.jaudiotagger.tag.FieldKey} to {@link AsfFieldKey}.
private final boolean
copyFields
Constructors Summary
public AsfTag()
Creates an empty instance.

        this(false);
    
public AsfTag(boolean copy)
Creates an instance and sets the field conversion property.

param
copy look at {@link #isCopyingFields()}.

        super();
        this.copyFields = copy;
    
public AsfTag(Tag source, boolean copy)
Creates an instance and copies the fields of the source into the own structure.

param
source source to read tag fields from.
param
copy look at {@link #isCopyingFields()}.
throws
UnsupportedEncodingException {@link TagField#getRawContent()} which may be called

        this(copy);
        copyFrom(source);
    
Methods Summary
public voidaddCopyright(java.lang.String copyRight)
Creates a field for copyright and adds it.

param
copyRight copyright content

        addField(createCopyrightField(copyRight));
    
public voidaddField(TagField field)
{@inheritDoc}

        if (isValidField(field))
        {
            if (AsfFieldKey.isMultiValued(field.getId()))
            {
                super.addField(copyFrom(field));
            }
            else
            {
                super.setField(copyFrom(field));
            }
        }
    
public voidaddRating(java.lang.String rating)
Creates a field for rating and adds it.

param
rating rating.

        addField(createRatingField(rating));
    
private voidcopyFrom(Tag source)
This method copies tag fields from the source.

param
source source to read tag fields from.

        final Iterator<TagField> fieldIterator = source.getFields();
        // iterate over all fields
        while (fieldIterator.hasNext())
        {
            final TagField copy = copyFrom(fieldIterator.next());
            if (copy != null)
            {
                super.addField(copy);
            }
        }
    
private TagFieldcopyFrom(TagField source)
If {@link #isCopyingFields()} is true, Creates a copy of source, if its not empty-
However, plain {@link TagField} objects can only be transformed into binary fields using their {@link TagField#getRawContent()} method.

param
source source field to copy.
return
A copy, which is as close to the source as possible, or null if the field is empty (empty byte[] or blank string}.

        TagField result;
        if (isCopyingFields())
        {
            if (source instanceof AsfTagField)
            {
                try
                {
                    result = (TagField) ((AsfTagField) source).clone();
                }
                catch (CloneNotSupportedException e)
                {
                    result = new AsfTagField(((AsfTagField) source).getDescriptor());
                }
            }
            else if (source instanceof TagTextField)
            {
                final String content = ((TagTextField) source).getContent();
                result = new AsfTagTextField(source.getId(), content);
            }
            else
            {
                throw new RuntimeException("Unknown Asf Tag Field class:" // NOPMD
                        // by
                        // Christian
                        // Laireiter
                        // on
                        // 5/9/09
                        // 5:44
                        // PM
                        + source.getClass());
            }
        }
        else
        {
            result = source;
        }
        return result;
    
public AsfTagCoverFieldcreateArtworkField(byte[] data)
Create artwork field

param
data raw image data
return
creates a default ASF picture field with default {@linkplain PictureTypes#DEFAULT_ID picture type}.

        return new AsfTagCoverField(data, PictureTypes.DEFAULT_ID, null, null);
    
public AsfTagTextFieldcreateCopyrightField(java.lang.String content)
Creates a field for storing the copyright.

param
content Copyright value.
return
{@link AsfTagTextField}

        return new AsfTagTextField(AsfFieldKey.COPYRIGHT, content);
    
public AsfTagTextFieldcreateField(AsfFieldKey asfFieldKey, java.lang.String value)
Create tag text field using ASF key

Uses the correct subclass for the key.

param
asfFieldKey field key to create field for.
param
value string value for the created field.
return
text field with given content.

        if (value == null)
        {
            throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
        }
        if (asfFieldKey == null)
        {
            throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
        }
        switch (asfFieldKey)
        {
            case COVER_ART:
                throw new UnsupportedOperationException("Cover Art cannot be created using this method");
            case BANNER_IMAGE:
                throw new UnsupportedOperationException("Banner Image cannot be created using this method");
            default:
                return new AsfTagTextField(asfFieldKey.getFieldName(), value);
        }
    
public AsfTagTextFieldcreateField(FieldKey genericKey, java.lang.String value)
{@inheritDoc}

        if (value == null)
        {
            throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
        }
        if (genericKey == null)
        {
            throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
        }
        final AsfFieldKey asfFieldKey = tagFieldToAsfField.get(genericKey);
        if (asfFieldKey == null)
        {
            throw new KeyNotFoundException("No ASF fieldkey for " + genericKey.toString());
        }
        return createField(asfFieldKey, value);
    
public AsfTagCoverFieldcreateField(org.jaudiotagger.tag.images.Artwork artwork)
Creates an {@link AsfTagCoverField} from given artwork

param
artwork artwork to create a ASF field from.
return
ASF field capable of storing artwork.

        return new AsfTagCoverField(artwork.getBinaryData(), artwork.getPictureType(), artwork.getDescription(), artwork.getMimeType());
    
public AsfTagTextFieldcreateRatingField(java.lang.String content)
Creates a field for storing the copyright.

param
content Rating value.
return
{@link AsfTagTextField}

        return new AsfTagTextField(AsfFieldKey.RATING, content);
    
public voiddeleteField(AsfFieldKey fieldKey)
Removes all fields which are stored to the provided field key.

param
fieldKey fields to remove.

        super.deleteField(fieldKey.getFieldName());
    
public voiddeleteField(FieldKey fieldKey)
{@inheritDoc}

        if (fieldKey == null)
        {
            throw new KeyNotFoundException();
        }
        super.deleteField(tagFieldToAsfField.get(fieldKey).getFieldName());
    
public java.util.ListgetArtworkList()

return

        final List<TagField> coverartList = getFields(FieldKey.COVER_ART);
        final List<Artwork> artworkList = new ArrayList<Artwork>(coverartList.size());

        for (final TagField next : coverartList)
        {
            final AsfTagCoverField coverArt = (AsfTagCoverField) next;
            final Artwork artwork = ArtworkFactory.getNew();
            artwork.setBinaryData(coverArt.getRawImageData());
            artwork.setMimeType(coverArt.getMimeType());
            artwork.setDescription(coverArt.getDescription());
            artwork.setPictureType(coverArt.getPictureType());
            artworkList.add(artwork);
        }
        return artworkList;
    
public java.util.IteratorgetAsfFields()
This method iterates through all stored fields.
This method can only be used if this class has been created with field conversion turned on.

return
Iterator for iterating through ASF fields.

        if (!isCopyingFields())
        {
            throw new IllegalStateException("Since the field conversion is not enabled, this method cannot be executed");
        }
        return new AsfFieldIterator(getFields());
    
public java.util.ListgetCopyright()
Returns a list of stored copyrights.

return
list of stored copyrights.

        return getFields(AsfFieldKey.COPYRIGHT.getFieldName());
    
public java.util.ListgetFields(FieldKey fieldKey)
{@inheritDoc}

        if (fieldKey == null)
        {
            throw new KeyNotFoundException();
        }
        return super.getFields(tagFieldToAsfField.get(fieldKey).getFieldName());
    
public java.lang.StringgetFirst(FieldKey genericKey)
{@inheritDoc}

        return getValue(genericKey, 0);
    
public java.lang.StringgetFirst(AsfFieldKey asfKey)
Retrieve the first value that exists for this asfkey

param
asfKey
return
throws
org.jaudiotagger.tag.KeyNotFoundException

        if (asfKey == null)
        {
            throw new KeyNotFoundException();
        }
        return super.getFirst(asfKey.getFieldName());
    
public java.lang.StringgetFirstCopyright()
Returns the Copyright.

return
the Copyright.

        return getFirst(AsfFieldKey.COPYRIGHT.getFieldName());
    
public AsfTagFieldgetFirstField(FieldKey genericKey)
{@inheritDoc}

        if (genericKey == null)
        {
            throw new KeyNotFoundException();
        }
        return (AsfTagField) super.getFirstField(tagFieldToAsfField.get(genericKey).getFieldName());
    
public java.lang.StringgetFirstRating()
Returns the Rating.

return
the Rating.

        return getFirst(AsfFieldKey.RATING.getFieldName());
    
public java.util.ListgetRating()
Returns a list of stored ratings.

return
list of stored ratings.

        return getFields(AsfFieldKey.RATING.getFieldName());
    
public java.lang.StringgetValue(FieldKey genericKey, int index)
{@inheritDoc}

        if (genericKey == null)
        {
            throw new KeyNotFoundException();
        }
        return super.getItem(tagFieldToAsfField.get(genericKey).getFieldName(), index);
    
public booleanhasField(FieldKey genericKey)

param
genericKey
return

        AsfFieldKey mp4FieldKey = tagFieldToAsfField.get(genericKey);
        return getFields(mp4FieldKey.getFieldName()).size() != 0;
    
public booleanhasField(AsfFieldKey asfFieldKey)

param
asfFieldKey
return

        return getFields(asfFieldKey.getFieldName()).size() != 0;
    
protected booleanisAllowedEncoding(java.lang.String enc)
{@inheritDoc}

        return AsfHeader.ASF_CHARSET.name().equals(enc);
    
public booleanisCopyingFields()
If true, the {@link #copyFrom(TagField)} method creates a new {@link AsfTagField} instance and copies the content from the source.
This method is utilized by {@link #addField(TagField)} and {@link #setField(TagField)}.
So if true it is ensured that the {@link AsfTag} instance has its own copies of fields, which cannot be modified after assignment (which could pass some checks), and it just stores {@link AsfTagField} objects.
Only then {@link #getAsfFields()} can work. otherwise {@link IllegalStateException} is thrown.

return
state of field conversion.

        return this.copyFields;
    
private booleanisValidField(TagField field)
Check field is valid and can be added to this tag

param
field field to add
return
true if field may be added.

        if (field == null)
        {
            return false;
        }

        if (!(field instanceof AsfTagField))
        {
            return false;
        }

        return !field.isEmpty();
    
public voidsetCopyright(java.lang.String Copyright)
Sets the copyright.

param
Copyright the copyright to set.

        setField(createCopyrightField(Copyright));
    
public voidsetField(TagField field)
{@inheritDoc}

        if (isValidField(field))
        {
            // Copy only occurs if flag setField
            super.setField(copyFrom(field));
        }
    
public voidsetRating(java.lang.String rating)
Sets the Rating.

param
rating the rating to set.

        setField(createRatingField(rating));