org.jaudiotagger.audio.asf.tag
Class AsfTag

java.lang.Object
  extended by org.jaudiotagger.audio.generic.AbstractTag
      extended by org.jaudiotagger.audio.asf.tag.AsfTag
All Implemented Interfaces:
Tag

public final class AsfTag
extends AbstractTag

Tag implementation for ASF.

Author:
Christian Laireiter

Nested Class Summary
private static class AsfTag.AsfFieldIterator
          This iterator is used to iterator an Iterator with TagField objects and returns them by casting to AsfTagField.
 
Field Summary
static java.util.Set<AsfFieldKey> COMMON_FIELDS
          Stores a list of field keys, which identify common fields.
private  boolean copyFields
           
private static java.util.EnumMap<FieldKey,AsfFieldKey> TAGFIELD_TO_ASFFIELD
          This map contains the mapping from FieldKey to AsfFieldKey.
 
Fields inherited from class org.jaudiotagger.audio.generic.AbstractTag
commonNumber, fields
 
Constructor Summary
AsfTag()
          Creates an empty instance.
AsfTag(boolean copy)
          Creates an instance and sets the field conversion property.
AsfTag(Tag source, boolean copy)
          Creates an instance and copies the fields of the source into the own structure.
 
Method Summary
 void addCopyright(java.lang.String copyRight)
          Creates a field for copyright and adds it.
 void addField(TagField field)
          Add field
 void addRating(java.lang.String rating)
          Creates a field for rating and adds it.
private  void copyFrom(Tag source)
          This method copies tag fields from the source.
private  TagField copyFrom(TagField source)
          If isCopyingFields() is true, Creates a copy of source, if its not empty-
However, plain TagField objects can only be transformed into binary fields using their TagField.getRawContent() method.
 AsfTagCoverField createArtworkField(byte[] data)
          Create artwork field
 AsfTagTextField createCopyrightField(java.lang.String content)
          Creates a field for storing the copyright.
 AsfTagCoverField createField(Artwork artwork)
          Creates an AsfTagCoverField from given artwork
 AsfTagTextField createField(FieldKey genericKey, java.lang.String value)
          Create a new field based on generic key, used internally by the library

 AsfTagTextField createRatingField(java.lang.String content)
          Creates a field for storing the copyright.
 AsfTagTextField createTagField(AsfFieldKey asfFieldKey, java.lang.String value)
          Create tag text field using ASF key

Uses the correct subclass for the key.

 void deleteField(FieldKey fieldKey)
          Delete any fields with this key
 void deleteTagField(AsfFieldKey fieldKey)
          Removes all fields which are stored to the provided field key.
 java.util.List<Artwork> getArtworkList()
           
 java.util.Iterator<AsfTagField> getAsfFields()
          This method iterates through all stored fields.
This method can only be used if this class has been created with field conversion turned on.
 java.util.List<TagField> getCopyright()
          Returns a list of stored copyrights.
 java.util.List<TagField> getFields(FieldKey fieldKey)
          Returns a list of TagField objects whose "id" is the specified one.
 java.lang.String getFirst(FieldKey genericKey)
          Retrieve String value of the first tagfield that exists for this generic key
 java.lang.String getFirstCopyright()
          Returns the Copyright.
 AsfTagField getFirstField(FieldKey genericKey)
          
 java.lang.String getFirstRating()
          Returns the Rating.
 java.util.List<TagField> getRating()
          Returns a list of stored ratings.
protected  boolean isAllowedEncoding(java.lang.String enc)
          Determines whether the given charset encoding may be used for the represented tagging system.
 boolean isCopyingFields()
          If true, the copyFrom(TagField) method creates a new AsfTagField instance and copies the content from the source.
This method is utilized by addField(TagField) and setField(TagField).
So if true it is ensured that the AsfTag instance has its own copies of fields, which cannot be modified after assignment (which could pass some checks), and it just stores AsfTagField objects.
Only then getAsfFields() can work.
private  boolean isValidField(TagField field)
          Check field is valid and can be added to this tag
 void setCopyright(java.lang.String Copyright)
          Sets the copyright.
 void setField(TagField field)
          Set field

Changed:Just because field is empty it doesnt mean it should be deleted.

 void setRating(java.lang.String rating)
          Sets the Rating.
 
Methods inherited from class org.jaudiotagger.audio.generic.AbstractTag
addField, addField, deleteArtworkField, deleteField, get, getFieldCount, getFields, getFirst, getFirstArtwork, getFirstField, hasCommonFields, hasField, isEmpty, setEncoding, setField, setField, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COMMON_FIELDS

public static final java.util.Set<AsfFieldKey> COMMON_FIELDS
Stores a list of field keys, which identify common fields.


TAGFIELD_TO_ASFFIELD

private static final java.util.EnumMap<FieldKey,AsfFieldKey> TAGFIELD_TO_ASFFIELD
This map contains the mapping from FieldKey to AsfFieldKey.


copyFields

private final boolean copyFields
See Also:
isCopyingFields()
Constructor Detail

AsfTag

public AsfTag()
Creates an empty instance.


AsfTag

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

Parameters:
copy - look at isCopyingFields().

AsfTag

public AsfTag(Tag source,
              boolean copy)
       throws java.io.UnsupportedEncodingException
Creates an instance and copies the fields of the source into the own structure.

Parameters:
source - source to read tag fields from.
copy - look at isCopyingFields().
Throws:
java.io.UnsupportedEncodingException - TagField.getRawContent() which may be called
Method Detail

addField

public void addField(TagField field)
Add field

Specified by:
addField in interface Tag
Overrides:
addField in class AbstractTag
Parameters:
field - The field to add.
See Also:

Changed so add empty fields


addCopyright

public void addCopyright(java.lang.String copyRight)
Creates a field for copyright and adds it.

Parameters:
copyRight - copyright content

addRating

public void addRating(java.lang.String rating)
Creates a field for rating and adds it.

Parameters:
rating - rating.

copyFrom

private void copyFrom(Tag source)
This method copies tag fields from the source.

Parameters:
source - source to read tag fields from.

copyFrom

private TagField copyFrom(TagField source)
If isCopyingFields() is true, Creates a copy of source, if its not empty-
However, plain TagField objects can only be transformed into binary fields using their TagField.getRawContent() method.

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

createField

public AsfTagCoverField createField(Artwork artwork)
Creates an AsfTagCoverField from given artwork

Parameters:
artwork - artwork to create a ASF field from.
Returns:
ASF field capable of storing artwork.

createArtworkField

public AsfTagCoverField createArtworkField(byte[] data)
Create artwork field

Parameters:
data - raw image data
Returns:
creates a default ASF picture field with default picture type.

createCopyrightField

public AsfTagTextField createCopyrightField(java.lang.String content)
Creates a field for storing the copyright.

Parameters:
content - Copyright value.
Returns:
AsfTagTextField

createRatingField

public AsfTagTextField createRatingField(java.lang.String content)
Creates a field for storing the copyright.

Parameters:
content - Rating value.
Returns:
AsfTagTextField

createTagField

public AsfTagTextField createTagField(AsfFieldKey asfFieldKey,
                                      java.lang.String value)
Create tag text field using ASF key

Uses the correct subclass for the key.

Parameters:
asfFieldKey - field key to create field for.
value - string value for the created field.
Returns:
text field with given content.

createField

public AsfTagTextField createField(FieldKey genericKey,
                                   java.lang.String value)
                            throws KeyNotFoundException,
                                   FieldDataInvalidException
Create a new field based on generic key, used internally by the library

Only textual data supported at the moment. The genericKey will be mapped to the correct implementation key and return a TagField.

It is not recommended to use this method for normal use of the audiolibrary, this is snot added to the structure

Specified by:
createField in interface Tag
Specified by:
createField in class AbstractTag
Parameters:
genericKey - is the generic key
value - to store
Returns:
Throws:
KeyNotFoundException
FieldDataInvalidException

deleteTagField

public void deleteTagField(AsfFieldKey fieldKey)
Removes all fields which are stored to the provided field key.

Parameters:
fieldKey - fields to remove.

deleteField

public void deleteField(FieldKey fieldKey)
                 throws KeyNotFoundException
Delete any fields with this key

Specified by:
deleteField in interface Tag
Specified by:
deleteField in class AbstractTag
Throws:
KeyNotFoundException

getFields

public java.util.List<TagField> getFields(FieldKey fieldKey)
                                   throws KeyNotFoundException
Returns a list of TagField objects whose "id" is the specified one.

Specified by:
getFields in interface Tag
Overrides:
getFields in class AbstractTag
Parameters:
fieldKey - The field id.
Returns:
A list of TagField objects with the given "id".
Throws:
KeyNotFoundException

getArtworkList

public java.util.List<Artwork> getArtworkList()
Returns:

getAsfFields

public java.util.Iterator<AsfTagField> getAsfFields()
This method iterates through all stored fields.
This method can only be used if this class has been created with field conversion turned on.

Returns:
Iterator for iterating through ASF fields.

getCopyright

public java.util.List<TagField> getCopyright()
Returns a list of stored copyrights.

Returns:
list of stored copyrights.

getFirst

public java.lang.String getFirst(FieldKey genericKey)
                          throws KeyNotFoundException
Retrieve String value of the first tagfield that exists for this generic key

Specified by:
getFirst in interface Tag
Specified by:
getFirst in class AbstractTag
Returns:
String value or empty string
Throws:
KeyNotFoundException

getFirstCopyright

public java.lang.String getFirstCopyright()
Returns the Copyright.

Returns:
the Copyright.

getFirstField

public AsfTagField getFirstField(FieldKey genericKey)
                          throws KeyNotFoundException

Specified by:
getFirstField in interface Tag
Specified by:
getFirstField in class AbstractTag
Returns:
the first field that matches this generic key
Throws:
KeyNotFoundException

getFirstRating

public java.lang.String getFirstRating()
Returns the Rating.

Returns:
the Rating.

getRating

public java.util.List<TagField> getRating()
Returns a list of stored ratings.

Returns:
list of stored ratings.

isAllowedEncoding

protected boolean isAllowedEncoding(java.lang.String enc)
Determines whether the given charset encoding may be used for the represented tagging system.

Specified by:
isAllowedEncoding in class AbstractTag
Parameters:
enc - charset encoding.
Returns:
true if the given encoding can be used.

isCopyingFields

public boolean isCopyingFields()
If true, the copyFrom(TagField) method creates a new AsfTagField instance and copies the content from the source.
This method is utilized by addField(TagField) and setField(TagField).
So if true it is ensured that the AsfTag instance has its own copies of fields, which cannot be modified after assignment (which could pass some checks), and it just stores AsfTagField objects.
Only then getAsfFields() can work. otherwise IllegalStateException is thrown.

Returns:
state of field conversion.

isValidField

private boolean isValidField(TagField field)
Check field is valid and can be added to this tag

Parameters:
field - field to add
Returns:
true if field may be added.

setField

public void setField(TagField field)
Set field

Changed:Just because field is empty it doesnt mean it should be deleted. That should be the choice of the developer. (Or does this break things)

Specified by:
setField in interface Tag
Overrides:
setField in class AbstractTag
Parameters:
field - The field to add.
See Also:
Tag.setField(org.jaudiotagger.tag.TagField)

setCopyright

public void setCopyright(java.lang.String Copyright)
Sets the copyright.

Parameters:
Copyright - the copyright to set.

setRating

public void setRating(java.lang.String rating)
Sets the Rating.

Parameters:
rating - the rating to set.