| 1 | package org.farng.mp3.id3; |
| 2 | |
| 3 | import org.farng.mp3.InvalidTagException; |
| 4 | import org.farng.mp3.object.ObjectNumberHashMap; |
| 5 | import org.farng.mp3.object.ObjectStringHashMap; |
| 6 | import org.farng.mp3.object.ObjectStringNullTerminated; |
| 7 | import org.farng.mp3.object.ObjectStringSizeTerminated; |
| 8 | |
| 9 | import java.io.IOException; |
| 10 | import java.io.RandomAccessFile; |
| 11 | |
| 12 | /** |
| 13 | * <h3>4.10. Comments</h3> |
| 14 | * <p/> |
| 15 | * <p> This frame is intended for any kind of full text information that<br> does not fit in |
| 16 | * any other frame. It consists of a frame header<br> followed by encoding, language and content |
| 17 | * descriptors and is ended<br> with the actual comment as a text string. Newline characters are<br> |
| 18 | * allowed in the comment text string. There may be more than one<br> |
| 19 | * <p/> |
| 20 | * comment frame in each tag, but only one with the same language and<br> content |
| 21 | * descriptor.</p> |
| 22 | * <p/> |
| 23 | * <p> <Header for 'Comment', ID: "COMM"><br> Text |
| 24 | * encoding $xx<br> |
| 25 | * <p/> |
| 26 | * Language |
| 27 | * $xx xx xx<br> Short content descrip. <text string according to encoding> $00 (00)<br> |
| 28 | * The actual text <full text string according to |
| 29 | * encoding><br> |
| 30 | * <p/> |
| 31 | * </p> |
| 32 | * |
| 33 | * @author Eric Farng |
| 34 | * @version $Revision: 1.4 $ |
| 35 | */ |
| 36 | public class FrameBodyCOMM extends AbstractID3v2FrameBody { |
| 37 | |
| 38 | /** |
| 39 | * Creates a new FrameBodyCOMM object. |
| 40 | */ |
| 41 | public FrameBodyCOMM() { |
| 42 | super(); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Creates a new FrameBodyCOMM object. |
| 47 | */ |
| 48 | public FrameBodyCOMM(final FrameBodyCOMM body) { |
| 49 | super(body); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Creates a new FrameBodyCOMM object. |
| 54 | */ |
| 55 | public FrameBodyCOMM(final byte textEncoding, final String language, final String description, final String text) { |
| 56 | setObject(ObjectNumberHashMap.TEXT_ENCODING, new Byte(textEncoding)); |
| 57 | setObject(ObjectStringHashMap.LANGUAGE, language); |
| 58 | setObject("Description", description); |
| 59 | setObject("Text", text); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Creates a new FrameBodyCOMM object. |
| 64 | */ |
| 65 | public FrameBodyCOMM(final RandomAccessFile file) throws IOException, InvalidTagException { |
| 66 | this.read(file); |
| 67 | } |
| 68 | |
| 69 | public String getBriefDescription() { |
| 70 | return this.getText(); |
| 71 | } |
| 72 | |
| 73 | public void setDescription(final String description) { |
| 74 | setObject("Description", description); |
| 75 | } |
| 76 | |
| 77 | public String getDescription() { |
| 78 | return (String) getObject("Description"); |
| 79 | } |
| 80 | |
| 81 | public String getIdentifier() { |
| 82 | return "COMM" + ((char) 0) + getLanguage() + ((char) 0) + getDescription(); |
| 83 | } |
| 84 | |
| 85 | public void setLanguage(final String language) { |
| 86 | setObject(ObjectStringHashMap.LANGUAGE, language); |
| 87 | } |
| 88 | |
| 89 | public String getLanguage() { |
| 90 | return (String) getObject(ObjectStringHashMap.LANGUAGE); |
| 91 | } |
| 92 | |
| 93 | public void setText(final String text) { |
| 94 | setObject("Text", text); |
| 95 | } |
| 96 | |
| 97 | public String getText() { |
| 98 | return (String) getObject("Text"); |
| 99 | } |
| 100 | |
| 101 | public void setTextEncoding(final byte textEncoding) { |
| 102 | setObject(ObjectNumberHashMap.TEXT_ENCODING, new Byte(textEncoding)); |
| 103 | } |
| 104 | |
| 105 | public byte getTextEncoding() { |
| 106 | return ((Byte) getObject(ObjectNumberHashMap.TEXT_ENCODING)).byteValue(); |
| 107 | } |
| 108 | |
| 109 | protected void setupObjectList() { |
| 110 | appendToObjectList(new ObjectNumberHashMap(ObjectNumberHashMap.TEXT_ENCODING, 1)); |
| 111 | appendToObjectList(new ObjectStringHashMap(ObjectStringHashMap.LANGUAGE, 3)); |
| 112 | appendToObjectList(new ObjectStringNullTerminated("Description")); |
| 113 | appendToObjectList(new ObjectStringSizeTerminated("Text")); |
| 114 | } |
| 115 | } |