org.jaudiotagger.audio.generic
Class AbstractTag

java.lang.Object
  extended by org.jaudiotagger.audio.generic.AbstractTag
All Implemented Interfaces:
Tag
Direct Known Subclasses:
AsfTag, GenericTag, Mp4Tag, VorbisCommentTag

public abstract class AbstractTag
extends java.lang.Object
implements Tag

This class is the default implementation for Tag and introduces some more useful functionality to be implemented.

Author:
Raphaƫl Slinckx

Field Summary
protected  int commonNumber
          Stores the amount of TagField with TagField.isCommon() true.
protected  java.util.Map<java.lang.String,java.util.List<TagField>> fields
          This map stores the ids of the stored fields to the fields themselves.
 
Constructor Summary
AbstractTag()
           
 
Method Summary
 void addField(Artwork artwork)
          Create field and then add within tag itself
 void addField(FieldKey genericKey, java.lang.String value)
          Create new field and add it to the tag
 void addField(TagField field)
          Add field
abstract  TagField createField(FieldKey genericKey, java.lang.String value)
          Create a new field based on generic key, used internally by the library

 void deleteArtworkField()
          Delete all instance of artwork Field
abstract  void deleteField(FieldKey fieldKey)
          Delete any fields with this key
protected  void deleteField(java.lang.String key)
          Delete all ocurrences of field.
 java.util.List<TagField> get(java.lang.String id)
          Get list of fields within this tag with the specified id
 int getFieldCount()
          Return field count

TODO:There must be a more efficient way to do this.

 java.util.Iterator<TagField> getFields()
          Iterator over all the fields within the tag, handle multiple fields with the same id
 java.util.List<TagField> getFields(FieldKey id)
          Returns a list of TagField objects whose "id" is the specified one.
abstract  java.lang.String getFirst(FieldKey genericKey)
          Retrieve String value of the first tagfield that exists for this generic key
 java.lang.String getFirst(java.lang.String id)
          Retrieve String value of the first value that exists for this format specific key

 Artwork getFirstArtwork()
           
abstract  TagField getFirstField(FieldKey genericKey)
           
 TagField getFirstField(java.lang.String id)
          Retrieve the first field that exists for this format specific key

 boolean hasCommonFields()
          Does this tag contain any comon fields
 boolean hasField(java.lang.String id)
          Does this tag contain a field with the specified id
protected abstract  boolean isAllowedEncoding(java.lang.String enc)
          Determines whether the given charset encoding may be used for the represented tagging system.
 boolean isEmpty()
          Is this tag empty
 boolean setEncoding(java.lang.String enc)
          Set or add encoding
 void setField(Artwork artwork)
          Create field and then set within tag itself
 void setField(FieldKey genericKey, java.lang.String value)
          Create new field and set it in the tag
 void setField(TagField field)
          Set field

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

 java.lang.String toString()
          (overridden)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jaudiotagger.tag.Tag
createField, getArtworkList
 

Field Detail

commonNumber

protected int commonNumber
Stores the amount of TagField with TagField.isCommon() true.


fields

protected java.util.Map<java.lang.String,java.util.List<TagField>> fields
This map stores the ids of the stored fields to the fields themselves. Because a linked hashMap is used the order that they are added in is preserved, the only exception to this rule is when two fields of the same id exist, both will be returned according to when the first item was added to the file.

Constructor Detail

AbstractTag

public AbstractTag()
Method Detail

addField

public void addField(TagField field)
Add field

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

Changed so add empty fields


get

public java.util.List<TagField> get(java.lang.String id)
Get list of fields within this tag with the specified id

Specified by:
get in interface Tag
Parameters:
id - The field id.
Returns:
A list of TagField objects with the given "id".
See Also:
Tag.get(java.lang.String)

getFields

public java.util.List<TagField> getFields(FieldKey id)
                                   throws KeyNotFoundException
Description copied from interface: Tag
Returns a list of TagField objects whose "id" is the specified one.

Specified by:
getFields in interface Tag
Parameters:
id -
Returns:
Throws:
KeyNotFoundException

getFirst

public java.lang.String getFirst(java.lang.String id)
Description copied from interface: Tag
Retrieve String value of the first value that exists for this format specific key

Can be used to retrieve fields with any identifier, useful if the identifier is not within FieldKey

Specified by:
getFirst in interface Tag
Parameters:
id -
Returns:
matches for this audio-specific key

getFirstField

public TagField getFirstField(java.lang.String id)
Description copied from interface: Tag
Retrieve the first field that exists for this format specific key

Can be used to retrieve fields with any identifier, useful if the identifier is not within FieldKey

Specified by:
getFirstField in interface Tag
Parameters:
id - audio specific key
Returns:
tag field or null if doesnt exist

getFields

public java.util.Iterator<TagField> getFields()
Description copied from interface: Tag
Iterator over all the fields within the tag, handle multiple fields with the same id

Specified by:
getFields in interface Tag
Returns:
iterator over whole list
See Also:
Tag.getFields()

getFieldCount

public int getFieldCount()
Return field count

TODO:There must be a more efficient way to do this.

Specified by:
getFieldCount in interface Tag
Returns:
field count

hasCommonFields

public boolean hasCommonFields()
Does this tag contain any comon fields

Specified by:
hasCommonFields in interface Tag
Returns:
true if a common field is present.
See Also:
Tag.hasCommonFields()

hasField

public boolean hasField(java.lang.String id)
Does this tag contain a field with the specified id

Specified by:
hasField in interface Tag
Parameters:
id - The field id to look for.
Returns:
true if tag contains a TagField with the given id.
See Also:
Tag.hasField(java.lang.String)

isAllowedEncoding

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

Parameters:
enc - charset encoding.
Returns:
true if the given encoding can be used.

isEmpty

public boolean isEmpty()
Is this tag empty

Specified by:
isEmpty in interface Tag
Returns:
true if tag contains no field.
See Also:
Tag.isEmpty()

setField

public void setField(FieldKey genericKey,
                     java.lang.String value)
              throws KeyNotFoundException,
                     FieldDataInvalidException
Create new field and set it in the tag

Specified by:
setField in interface Tag
Parameters:
genericKey -
value -
Throws:
KeyNotFoundException
FieldDataInvalidException

addField

public void addField(FieldKey genericKey,
                     java.lang.String value)
              throws KeyNotFoundException,
                     FieldDataInvalidException
Create new field and add it to the tag

Specified by:
addField in interface Tag
Parameters:
genericKey -
value -
Throws:
KeyNotFoundException
FieldDataInvalidException

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
Parameters:
field - The field to add.
See Also:
Tag.setField(org.jaudiotagger.tag.TagField)

setEncoding

public boolean setEncoding(java.lang.String enc)
Set or add encoding

Specified by:
setEncoding in interface Tag
See Also:
Tag.setEncoding(java.lang.String)

toString

public java.lang.String toString()
(overridden)

Specified by:
toString in interface Tag
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

createField

public abstract TagField createField(FieldKey genericKey,
                                     java.lang.String value)
                              throws KeyNotFoundException,
                                     FieldDataInvalidException
Description copied from interface: Tag
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
Parameters:
genericKey -
value -
Returns:
Throws:
KeyNotFoundException
FieldDataInvalidException

getFirst

public abstract java.lang.String getFirst(FieldKey genericKey)
                                   throws KeyNotFoundException
Description copied from interface: Tag
Retrieve String value of the first tagfield that exists for this generic key

Specified by:
getFirst in interface Tag
Parameters:
genericKey -
Returns:
Throws:
KeyNotFoundException

getFirstField

public abstract TagField getFirstField(FieldKey genericKey)
                                throws KeyNotFoundException
Specified by:
getFirstField in interface Tag
Parameters:
genericKey -
Returns:
Throws:
KeyNotFoundException

deleteField

public abstract void deleteField(FieldKey fieldKey)
                          throws KeyNotFoundException
Description copied from interface: Tag
Delete any fields with this key

Specified by:
deleteField in interface Tag
Parameters:
fieldKey -
Throws:
KeyNotFoundException

deleteField

protected void deleteField(java.lang.String key)
Delete all ocurrences of field.

Parameters:
key -

getFirstArtwork

public Artwork getFirstArtwork()
Specified by:
getFirstArtwork in interface Tag
Returns:
first artwork or null if none exist

setField

public void setField(Artwork artwork)
              throws FieldDataInvalidException
Create field and then set within tag itself

Specified by:
setField in interface Tag
Parameters:
artwork -
Throws:
FieldDataInvalidException

addField

public void addField(Artwork artwork)
              throws FieldDataInvalidException
Create field and then add within tag itself

Specified by:
addField in interface Tag
Parameters:
artwork -
Throws:
FieldDataInvalidException

deleteArtworkField

public void deleteArtworkField()
                        throws KeyNotFoundException
Delete all instance of artwork Field

Specified by:
deleteArtworkField in interface Tag
Throws:
KeyNotFoundException