FileDocCategorySizeDatePackage
FrameBodyCOMM.javaAPI DocJaudiotagger 2.0.49487Wed Mar 30 16:12:04 BST 2011org.jaudiotagger.tag.id3.framebody

FrameBodyCOMM

public class FrameBodyCOMM extends AbstractID3v2FrameBody implements ID3v24FrameBody, ID3v23FrameBody
Comments frame.

This frame is intended for any kind of full text information that does not fit in any other frame. It consists of a frame header followed by encoding, language and content descriptors and is ended with the actual comment as a text string. Newline characters are allowed in the comment text string. There may be more than one comment frame in each tag, but only one with the same language and* content descriptor.

<Header for 'Comment', ID: "COMM">
Text encoding $xx
Language $xx xx xx
Short content descrip.<text string according to encoding> $00 (00)
The actual text <full text string according to encoding>

For more details, please refer to the ID3 specifications:

author
: Paul Taylor
author
: Eric Farng
version
$Id: FrameBodyCOMM.java 926 2010-10-21 15:49:06Z paultaylor $

Fields Summary
public static final String
DEFAULT
public static final String
ITUNES_NORMALIZATION
private static final String
MM_PREFIX
public static final String
MM_CUSTOM1
public static final String
MM_CUSTOM2
public static final String
MM_CUSTOM3
public static final String
MM_CUSTOM4
public static final String
MM_CUSTOM5
public static final String
MM_OCCASION
public static final String
MM_QUALITY
public static final String
MM_TEMPO
Constructors Summary
public FrameBodyCOMM()
Creates a new FrameBodyCOMM datatype.

        setObjectValue(DataTypes.OBJ_TEXT_ENCODING, TextEncoding.ISO_8859_1);
        setObjectValue(DataTypes.OBJ_LANGUAGE, Languages.DEFAULT_ID);
        setObjectValue(DataTypes.OBJ_DESCRIPTION, "");
        setObjectValue(DataTypes.OBJ_TEXT, "");
    
public FrameBodyCOMM(FrameBodyCOMM body)

        super(body);
    
public FrameBodyCOMM(byte textEncoding, String language, String description, String text)
Creates a new FrameBodyCOMM datatype.

param
textEncoding
param
language
param
description
param
text

        setObjectValue(DataTypes.OBJ_TEXT_ENCODING, textEncoding);
        setObjectValue(DataTypes.OBJ_LANGUAGE, language);
        setObjectValue(DataTypes.OBJ_DESCRIPTION, description);
        setObjectValue(DataTypes.OBJ_TEXT, text);
    
public FrameBodyCOMM(ByteBuffer byteBuffer, int frameSize)
Construct a Comment frame body from the buffer

param
byteBuffer
param
frameSize
throws
InvalidTagException if unable to create framebody from buffer

        super(byteBuffer, frameSize);
    
Methods Summary
public java.lang.StringgetDescription()
Get the description field, which describes the type of comment

return
description field

        return (String) getObjectValue(DataTypes.OBJ_DESCRIPTION);
    
public java.lang.StringgetIdentifier()
The ID3v2 frame identifier

return
the ID3v2 frame identifier for this frame type

        return ID3v24Frames.FRAME_ID_COMMENT;
    
public java.lang.StringgetLanguage()
Get the language the comment is written in

return
the language

        return (String) getObjectValue(DataTypes.OBJ_LANGUAGE);
    
public java.lang.StringgetText()
Returns the the text field which holds the comment, adjusted to ensure does not return trailing null which is due to a iTunes bug.

return
the text field

        TextEncodedStringSizeTerminated text = (TextEncodedStringSizeTerminated) getObject(DataTypes.OBJ_TEXT);
        return text.getValueAtIndex(0);
    
public java.lang.StringgetUserFriendlyValue()

        return getText();
    
public booleanisItunesFrame()

        String desc = getDescription();
        if(desc!=null && !(desc.length()==0))
        {
            if(desc.equals(ITUNES_NORMALIZATION))
            {
                return true;
            }
        }
        return false;
    
public booleanisMediaMonkeyFrame()


      
    
        String desc = getDescription();
        if(desc!=null && !(desc.length()==0))
        {
            if(desc.startsWith(MM_PREFIX))
            {
                return true;
            }
        }
        return false;
    
public voidsetDescription(java.lang.String description)
Set the description field, which describes the type of comment

param
description

        if (description == null)
        {
            throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
        }
        setObjectValue(DataTypes.OBJ_DESCRIPTION, description);
    
public voidsetLanguage(java.lang.String language)
Sets the language the comment is written in

param
language

        //TODO not sure if this might break existing code
        /*if(language==null)
        {
             throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
        } */
        setObjectValue(DataTypes.OBJ_LANGUAGE, language);        
    
public voidsetText(java.lang.String text)

param
text

        if (text == null)
        {
            throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
        }
        setObjectValue(DataTypes.OBJ_TEXT, text);
    
protected voidsetupObjectList()

        objectList.add(new NumberHashMap(DataTypes.OBJ_TEXT_ENCODING, this, TextEncoding.TEXT_ENCODING_FIELD_SIZE));
        objectList.add(new StringHashMap(DataTypes.OBJ_LANGUAGE, this, Languages.LANGUAGE_FIELD_SIZE));
        objectList.add(new TextEncodedStringNullTerminated(DataTypes.OBJ_DESCRIPTION, this));
        objectList.add(new TextEncodedStringSizeTerminated(DataTypes.OBJ_TEXT, this));
    
public voidwrite(java.io.ByteArrayOutputStream tagBuffer)
Because COMM have a text encoding we need to check the text String does not contain characters that cannot be encoded in current encoding before we write data. If there are we change the encoding.

        //Ensure valid for type
        setTextEncoding(ID3TextEncodingConversion.getTextEncoding(getHeader(), getTextEncoding()));

        //Ensure valid for data
        if (!((AbstractString) getObject(DataTypes.OBJ_TEXT)).canBeEncoded())
        {
            this.setTextEncoding(ID3TextEncodingConversion.getUnicodeTextEncoding(getHeader()));
        }
        if (!((AbstractString) getObject(DataTypes.OBJ_DESCRIPTION)).canBeEncoded())
        {
            this.setTextEncoding(ID3TextEncodingConversion.getUnicodeTextEncoding(getHeader()));
        }
        super.write(tagBuffer);