Coverage Report - org.jaudiotagger.tag.id3.framebody.FrameBodyUSLT
 
Classes in this File Line Coverage Branch Coverage Complexity
FrameBodyUSLT
87%
35/40
75%
3/4
1.125
 
 1  
 /*
 2  
  *  MusicTag Copyright (C)2003,2004
 3  
  *
 4  
  *  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
 5  
  *  General Public  License as published by the Free Software Foundation; either version 2.1 of the License,
 6  
  *  or (at your option) any later version.
 7  
  *
 8  
  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 9  
  *  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 10  
  *  See the GNU Lesser General Public License for more details.
 11  
  *
 12  
  *  You should have received a copy of the GNU Lesser General Public License along with this library; if not,
 13  
  *  you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software
 14  
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 15  
  */
 16  
 package org.jaudiotagger.tag.id3.framebody;
 17  
 
 18  
 import org.jaudiotagger.tag.InvalidTagException;
 19  
 import org.jaudiotagger.tag.datatype.*;
 20  
 import org.jaudiotagger.tag.id3.ID3TextEncodingConversion;
 21  
 import org.jaudiotagger.tag.id3.ID3v24Frames;
 22  
 import org.jaudiotagger.tag.id3.valuepair.TextEncoding;
 23  
 import org.jaudiotagger.tag.reference.Languages;
 24  
 
 25  
 import java.io.ByteArrayOutputStream;
 26  
 import java.nio.ByteBuffer;
 27  
 
 28  
 /**
 29  
  * Unsychronised lyrics/text transcription frame.
 30  
  * <p/>
 31  
  * <p/>
 32  
  * This frame contains the lyrics of the song or a text transcription of
 33  
  * other vocal activities. The head includes an encoding descriptor and
 34  
  * a content descriptor. The body consists of the actual text. The
 35  
  * 'Content descriptor' is a terminated string. If no descriptor is
 36  
  * entered, 'Content descriptor' is $00 (00) only. Newline characters
 37  
  * are allowed in the text. There may be more than one 'Unsynchronised
 38  
  * lyrics/text transcription' frame in each tag, but only one with the
 39  
  * same language and content descriptor.
 40  
  * </p><p><table border=0 width="70%">
 41  
  * <tr><td colspan=2>&lt;Header for 'Unsynchronised lyrics/text transcription', ID: "USLT"&gt;</td></tr>
 42  
  * <tr><td>Text encoding     </td><td width="80%">$xx</td></tr>
 43  
  * <tr><td>Language          </td><td>$xx xx xx</td></tr>
 44  
  * <tr><td>Content descriptor</td><td>&lt;text string according to encoding&gt; $00 (00)</td></tr>
 45  
  * <tr><td>Lyrics/text       </td><td>&lt;full text string according to encoding&gt;</td></tr>
 46  
  * </table></p>
 47  
  * <p/>
 48  
  * You can retrieve the first value without the null terminator using {@link #getFirstTextValue}
 49  
  * <p/>
 50  
  * <p>For more details, please refer to the ID3 specifications:
 51  
  * <ul>
 52  
  * <li><a href="http://www.id3.org/id3v2.3.0.txt">ID3 v2.3.0 Spec</a>
 53  
  * </ul>
 54  
  *
 55  
  * @author : Paul Taylor
 56  
  * @author : Eric Farng
 57  
  * @version $Id: FrameBodyUSLT.java 836 2009-11-12 15:44:07Z paultaylor $
 58  
  */
 59  
 public class FrameBodyUSLT extends AbstractID3v2FrameBody implements ID3v23FrameBody, ID3v24FrameBody
 60  
 {
 61  
     /**
 62  
      * Creates a new FrameBodyUSLT datatype.
 63  
      */
 64  
     public FrameBodyUSLT()
 65  44
     {
 66  
         //        setObject("Text Encoding", new Byte((byte) 0));
 67  
         //        setObject("Language", "");
 68  
         //        setObject(ObjectTypes.OBJ_DESCRIPTION, "");
 69  
         //        setObject("Lyrics/Text", "");
 70  44
     }
 71  
 
 72  
     /**
 73  
      * Copy constructor
 74  
      *
 75  
      * @param body
 76  
      */
 77  
     public FrameBodyUSLT(FrameBodyUSLT body)
 78  
     {
 79  35
         super(body);
 80  35
     }
 81  
 
 82  
     /**
 83  
      * Creates a new FrameBodyUSLT datatype.
 84  
      *
 85  
      * @param textEncoding
 86  
      * @param language
 87  
      * @param description
 88  
      * @param text
 89  
      */
 90  
     public FrameBodyUSLT(byte textEncoding, String language, String description, String text)
 91  4
     {
 92  4
         setObjectValue(DataTypes.OBJ_TEXT_ENCODING, textEncoding);
 93  4
         setObjectValue(DataTypes.OBJ_LANGUAGE, language);
 94  4
         setObjectValue(DataTypes.OBJ_DESCRIPTION, description);
 95  4
         setObjectValue(DataTypes.OBJ_LYRICS, text);
 96  4
     }
 97  
 
 98  
     /**
 99  
      * Creates a new FrameBodyUSLT datatype, populated from buffer
 100  
      *
 101  
      * @param byteBuffer
 102  
      * @param frameSize
 103  
      * @throws InvalidTagException
 104  
      * @throws InvalidTagException
 105  
      */
 106  
     public FrameBodyUSLT(ByteBuffer byteBuffer, int frameSize) throws InvalidTagException
 107  
     {
 108  66
         super(byteBuffer, frameSize);
 109  66
     }
 110  
 
 111  
     /**
 112  
      * Set a description field
 113  
      *
 114  
      * @param description
 115  
      */
 116  
     public void setDescription(String description)
 117  
     {
 118  40
         setObjectValue(DataTypes.OBJ_DESCRIPTION, description);
 119  40
     }
 120  
 
 121  
     /**
 122  
      * Get a description field
 123  
      *
 124  
      * @return description
 125  
      */
 126  
     public String getDescription()
 127  
     {
 128  72
         return (String) getObjectValue(DataTypes.OBJ_DESCRIPTION);
 129  
     }
 130  
 
 131  
     /**
 132  
      * The ID3v2 frame identifier
 133  
      *
 134  
      * @return the ID3v2 frame identifier  for this frame type
 135  
      */
 136  
     public String getIdentifier()
 137  
     {
 138  238
         return ID3v24Frames.FRAME_ID_UNSYNC_LYRICS;
 139  
     }
 140  
 
 141  
     /**
 142  
      * Set the language field
 143  
      *
 144  
      * @param language
 145  
      */
 146  
     public void setLanguage(String language)
 147  
     {
 148  20
         setObjectValue(DataTypes.OBJ_LANGUAGE, language);
 149  20
     }
 150  
 
 151  
     /**
 152  
      * Get the language field
 153  
      *
 154  
      * @return language
 155  
      */
 156  
     public String getLanguage()
 157  
     {
 158  32
         return (String) getObjectValue(DataTypes.OBJ_LANGUAGE);
 159  
     }
 160  
 
 161  
     /**
 162  
      * Set the lyric field
 163  
      *
 164  
      * @param lyric
 165  
      */
 166  
     public void setLyric(String lyric)
 167  
     {
 168  40
         setObjectValue(DataTypes.OBJ_LYRICS, lyric);
 169  40
     }
 170  
 
 171  
     /**
 172  
      * Get the lyric field
 173  
      *
 174  
      * @return lyrics
 175  
      */
 176  
     public String getLyric()
 177  
     {
 178  32
         return (String) getObjectValue(DataTypes.OBJ_LYRICS);
 179  
     }
 180  
 
 181  
     /**
 182  
      * Get first value
 183  
      *
 184  
      * @return value at index 0
 185  
      */
 186  
     public String getFirstTextValue()
 187  
     {
 188  12
         TextEncodedStringSizeTerminated text = (TextEncodedStringSizeTerminated) getObject(DataTypes.OBJ_LYRICS);
 189  12
         return text.getValueAtIndex(0);
 190  
     }
 191  
 
 192  
     /**
 193  
      * Add additional lyric to the lyric field
 194  
      *
 195  
      * @param text
 196  
      */
 197  
     public void addLyric(String text)
 198  
     {
 199  0
         setLyric(getLyric() + text);
 200  0
         }
 201  
 
 202  
     /**
 203  
      * @param line
 204  
      */
 205  
     public void addLyric(Lyrics3Line line)
 206  
     {
 207  0
         setLyric(getLyric() + line.writeString());
 208  0
     }
 209  
 
 210  
 
 211  
     public void write(ByteArrayOutputStream tagBuffer)
 212  
     {
 213  
 
 214  
         //Ensure valid for type
 215  53
         this.setTextEncoding(ID3TextEncodingConversion.getTextEncoding(getHeader(), TextEncoding.ISO_8859_1));
 216  
 
 217  
         //Ensure valid for data                    
 218  53
         if (!((AbstractString) getObject(DataTypes.OBJ_DESCRIPTION)).canBeEncoded())
 219  
         {
 220  0
             this.setTextEncoding(ID3TextEncodingConversion.getUnicodeTextEncoding(getHeader()));
 221  
         }
 222  53
         if (!((AbstractString) getObject(DataTypes.OBJ_LYRICS)).canBeEncoded())
 223  
         {
 224  36
             this.setTextEncoding(ID3TextEncodingConversion.getUnicodeTextEncoding(getHeader()));
 225  
         }
 226  53
         super.write(tagBuffer);
 227  53
     }
 228  
 
 229  
     /**
 230  
      *
 231  
      */
 232  
     protected void setupObjectList()
 233  
     {
 234  114
         objectList.add(new NumberHashMap(DataTypes.OBJ_TEXT_ENCODING, this, TextEncoding.TEXT_ENCODING_FIELD_SIZE));
 235  114
         objectList.add(new StringHashMap(DataTypes.OBJ_LANGUAGE, this, Languages.LANGUAGE_FIELD_SIZE));
 236  114
         objectList.add(new TextEncodedStringNullTerminated(DataTypes.OBJ_DESCRIPTION, this));
 237  114
         objectList.add(new TextEncodedStringSizeTerminated(DataTypes.OBJ_LYRICS, this));
 238  114
     }
 239  
 
 240  
 }