| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| FrameBodyUSLT |
|
| 1.125;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><Header for 'Unsynchronised lyrics/text transcription', ID: "USLT"></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><text string according to encoding> $00 (00)</td></tr> | |
| 45 | * <tr><td>Lyrics/text </td><td><full text string according to encoding></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,v 1.23 2008/07/21 10:45:46 paultaylor Exp $ | |
| 58 | */ | |
| 59 | public class FrameBodyUSLT extends AbstractID3v2FrameBody implements ID3v23FrameBody, ID3v24FrameBody | |
| 60 | { | |
| 61 | /** | |
| 62 | * Creates a new FrameBodyUSLT datatype. | |
| 63 | */ | |
| 64 | public FrameBodyUSLT() | |
| 65 | 11 | { |
| 66 | // setObject("Text Encoding", new Byte((byte) 0)); | |
| 67 | // setObject("Language", ""); | |
| 68 | // setObject(ObjectTypes.OBJ_DESCRIPTION, ""); | |
| 69 | // setObject("Lyrics/Text", ""); | |
| 70 | 11 | } |
| 71 | ||
| 72 | /** | |
| 73 | * Copy constructor | |
| 74 | * | |
| 75 | * @param body | |
| 76 | */ | |
| 77 | public FrameBodyUSLT(FrameBodyUSLT body) | |
| 78 | { | |
| 79 | 11 | super(body); |
| 80 | 11 | } |
| 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 | 1 | { |
| 92 | 1 | setObjectValue(DataTypes.OBJ_TEXT_ENCODING, textEncoding); |
| 93 | 1 | setObjectValue(DataTypes.OBJ_LANGUAGE, language); |
| 94 | 1 | setObjectValue(DataTypes.OBJ_DESCRIPTION, description); |
| 95 | 1 | setObjectValue(DataTypes.OBJ_LYRICS, text); |
| 96 | 1 | } |
| 97 | ||
| 98 | /** | |
| 99 | * Creates a new FrameBodyUSLT datatype, populated from buffer | |
| 100 | * | |
| 101 | * @param byteBuffer | |
| 102 | * @throws InvalidTagException | |
| 103 | * @throws InvalidTagException | |
| 104 | */ | |
| 105 | public FrameBodyUSLT(ByteBuffer byteBuffer, int frameSize) throws InvalidTagException | |
| 106 | { | |
| 107 | 18 | super(byteBuffer, frameSize); |
| 108 | 18 | } |
| 109 | ||
| 110 | /** | |
| 111 | * Set a description field | |
| 112 | * | |
| 113 | * @param description | |
| 114 | */ | |
| 115 | public void setDescription(String description) | |
| 116 | { | |
| 117 | 10 | setObjectValue(DataTypes.OBJ_DESCRIPTION, description); |
| 118 | 10 | } |
| 119 | ||
| 120 | /** | |
| 121 | * Get a description field | |
| 122 | * | |
| 123 | * @return description | |
| 124 | */ | |
| 125 | public String getDescription() | |
| 126 | { | |
| 127 | 18 | return (String) getObjectValue(DataTypes.OBJ_DESCRIPTION); |
| 128 | } | |
| 129 | ||
| 130 | /** | |
| 131 | * The ID3v2 frame identifier | |
| 132 | * | |
| 133 | * @return the ID3v2 frame identifier for this frame type | |
| 134 | */ | |
| 135 | public String getIdentifier() | |
| 136 | { | |
| 137 | 64 | return ID3v24Frames.FRAME_ID_UNSYNC_LYRICS; |
| 138 | } | |
| 139 | ||
| 140 | /** | |
| 141 | * Set the language field | |
| 142 | * | |
| 143 | * @param language | |
| 144 | */ | |
| 145 | public void setLanguage(String language) | |
| 146 | { | |
| 147 | 5 | setObjectValue(DataTypes.OBJ_LANGUAGE, language); |
| 148 | 5 | } |
| 149 | ||
| 150 | /** | |
| 151 | * Get the language field | |
| 152 | * | |
| 153 | * @return language | |
| 154 | */ | |
| 155 | public String getLanguage() | |
| 156 | { | |
| 157 | 8 | return (String) getObjectValue(DataTypes.OBJ_LANGUAGE); |
| 158 | } | |
| 159 | ||
| 160 | /** | |
| 161 | * Set the lyric field | |
| 162 | * | |
| 163 | * @param lyric | |
| 164 | */ | |
| 165 | public void setLyric(String lyric) | |
| 166 | { | |
| 167 | 10 | setObjectValue(DataTypes.OBJ_LYRICS, lyric); |
| 168 | 10 | } |
| 169 | ||
| 170 | /** | |
| 171 | * Get the lyric field | |
| 172 | * | |
| 173 | * @return lyrics | |
| 174 | */ | |
| 175 | public String getLyric() | |
| 176 | { | |
| 177 | 8 | return (String) getObjectValue(DataTypes.OBJ_LYRICS); |
| 178 | } | |
| 179 | ||
| 180 | /** | |
| 181 | * Get first value | |
| 182 | * | |
| 183 | * @return value at index 0 | |
| 184 | */ | |
| 185 | public String getFirstTextValue() | |
| 186 | { | |
| 187 | 3 | TextEncodedStringSizeTerminated text = (TextEncodedStringSizeTerminated) getObject(DataTypes.OBJ_LYRICS); |
| 188 | 3 | return text.getValueAtIndex(0); |
| 189 | } | |
| 190 | ||
| 191 | /** | |
| 192 | * Add additional lyric to the lyric field | |
| 193 | * | |
| 194 | * @param text | |
| 195 | */ | |
| 196 | public void addLyric(String text) | |
| 197 | { | |
| 198 | 0 | setLyric(getLyric() + text); |
| 199 | ; | |
| 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 | 14 | this.setTextEncoding(ID3TextEncodingConversion.getTextEncoding(getHeader(), TextEncoding.ISO_8859_1)); |
| 216 | ||
| 217 | //Ensure valid for data | |
| 218 | 14 | if (((AbstractString) getObject(DataTypes.OBJ_DESCRIPTION)).canBeEncoded() == false) |
| 219 | { | |
| 220 | 0 | this.setTextEncoding(ID3TextEncodingConversion.getUnicodeTextEncoding(getHeader())); |
| 221 | } | |
| 222 | 14 | if (((AbstractString) getObject(DataTypes.OBJ_LYRICS)).canBeEncoded() == false) |
| 223 | { | |
| 224 | 9 | this.setTextEncoding(ID3TextEncodingConversion.getUnicodeTextEncoding(getHeader())); |
| 225 | } | |
| 226 | 14 | super.write(tagBuffer); |
| 227 | 14 | } |
| 228 | ||
| 229 | /** | |
| 230 | * | |
| 231 | */ | |
| 232 | protected void setupObjectList() | |
| 233 | { | |
| 234 | 30 | objectList.add(new NumberHashMap(DataTypes.OBJ_TEXT_ENCODING, this, TextEncoding.TEXT_ENCODING_FIELD_SIZE)); |
| 235 | 30 | objectList.add(new StringHashMap(DataTypes.OBJ_LANGUAGE, this, Languages.LANGUAGE_FIELD_SIZE)); |
| 236 | 30 | objectList.add(new TextEncodedStringNullTerminated(DataTypes.OBJ_DESCRIPTION, this)); |
| 237 | 30 | objectList.add(new TextEncodedStringSizeTerminated(DataTypes.OBJ_LYRICS, this)); |
| 238 | 30 | } |
| 239 | ||
| 240 | } |