| 1 | package org.farng.mp3.id3; |
| 2 | |
| 3 | import org.farng.mp3.InvalidTagException; |
| 4 | import org.farng.mp3.object.ObjectStringFixedLength; |
| 5 | import org.farng.mp3.object.ObjectStringNullTerminated; |
| 6 | import org.farng.mp3.object.ObjectStringSizeTerminated; |
| 7 | |
| 8 | import java.io.IOException; |
| 9 | import java.io.RandomAccessFile; |
| 10 | |
| 11 | /** |
| 12 | * <h3>4.20. Linked information</h3> |
| 13 | * <p/> |
| 14 | * <p> To keep information duplication as low as possible this frame may be<br> used to link |
| 15 | * information from another ID3v2 tag that might reside in<br> another audio file or alone in a binary |
| 16 | * file. It is RECOMMENDED that<br> |
| 17 | * <p/> |
| 18 | * this method is only used when the files are stored on a CD-ROM or<br> other circumstances |
| 19 | * when the risk of file separation is low. The<br> frame contains a frame identifier, which is the frame |
| 20 | * that should be<br> linked into this tag, a URL [URL] field, where a reference to the<br> |
| 21 | * file where the frame is given, and additional ID data, if needed.<br> |
| 22 | * <p/> |
| 23 | * Data should be retrieved from the first tag found in the file to<br> which this link |
| 24 | * points. There may be more than one "LINK" frame in a<br> tag, but only one with the same |
| 25 | * contents. A linked frame is to be<br> considered as part of the tag and has the same restrictions as if |
| 26 | * it<br> |
| 27 | * <p/> |
| 28 | * was a physical part of the tag (i.e. only one "RVRB" frame allowed,<br> whether |
| 29 | * it's linked or not).</p> |
| 30 | * <p/> |
| 31 | * <p> <Header for 'Linked information', ID: "LINK"><br> |
| 32 | * <p/> |
| 33 | * Frame identifier $xx xx xx xx<br> |
| 34 | * URL |
| 35 | * <text string> $00<br> ID and additional data <text string(s)></p> |
| 36 | * <p/> |
| 37 | * <p> Frames that may be linked and need no additional data are "ASPI",<br> |
| 38 | * "ETCO", "EQU2", "MCID", "MLLT", "OWNE", "RVA2", |
| 39 | * "RVRB", "SYTC", the<br> |
| 40 | * <p/> |
| 41 | * text information frames and the URL link frames.</p> |
| 42 | * <p/> |
| 43 | * <p> The "AENC", "APIC", "GEOB" and "TXXX" frames may be linked |
| 44 | * with<br> |
| 45 | * <p/> |
| 46 | * the content descriptor as additional ID data.</p> |
| 47 | * <p/> |
| 48 | * <p> The "USER" frame may be linked with the language field as additional<br> ID |
| 49 | * data.<br> </p> |
| 50 | * <p/> |
| 51 | * <p> The "PRIV" frame may be linked with the owner identifier as<br> additional ID |
| 52 | * data.</p> |
| 53 | * <p/> |
| 54 | * <p> The "COMM", "SYLT" and "USLT" |
| 55 | * <p/> |
| 56 | * frames may be linked with three bytes<br> of language descriptor directly followed by a content |
| 57 | * descriptor as<br> additional ID data.<br> </p> |
| 58 | * |
| 59 | * @author Eric Farng |
| 60 | * @version $Revision: 1.4 $ |
| 61 | */ |
| 62 | public class FrameBodyLINK extends AbstractID3v2FrameBody { |
| 63 | |
| 64 | /** |
| 65 | * Creates a new FrameBodyLINK object. |
| 66 | */ |
| 67 | public FrameBodyLINK() { |
| 68 | super(); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Creates a new FrameBodyLINK object. |
| 73 | */ |
| 74 | public FrameBodyLINK(final FrameBodyLINK body) { |
| 75 | super(body); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Creates a new FrameBodyLINK object. |
| 80 | */ |
| 81 | public FrameBodyLINK(final String frameIdentifier, final String url, final String additionalData) { |
| 82 | setObject("Frame Identifier", frameIdentifier); |
| 83 | setObject("URL", url); |
| 84 | setObject("ID and Additional Data", additionalData); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Creates a new FrameBodyLINK object. |
| 89 | */ |
| 90 | public FrameBodyLINK(final RandomAccessFile file) throws IOException, InvalidTagException { |
| 91 | this.read(file); |
| 92 | } |
| 93 | |
| 94 | public String getAdditionalData() { |
| 95 | return (String) getObject("ID and Additional Data"); |
| 96 | } |
| 97 | |
| 98 | public void getAdditionalData(final String additionalData) { |
| 99 | setObject("ID and Additional Data", additionalData); |
| 100 | } |
| 101 | |
| 102 | public String getFrameIdentifier() { |
| 103 | return (String) getObject("Frame Identifier"); |
| 104 | } |
| 105 | |
| 106 | public void getFrameIdentifier(final String frameIdentifier) { |
| 107 | setObject("Frame Identifier", frameIdentifier); |
| 108 | } |
| 109 | |
| 110 | public String getIdentifier() { |
| 111 | return "LINK" + ((char) 0) + getFrameIdentifier() + ((char) 0) + getAdditionalData(); |
| 112 | } |
| 113 | |
| 114 | protected void setupObjectList() { |
| 115 | appendToObjectList(new ObjectStringFixedLength("Frame Identifier", 4)); |
| 116 | appendToObjectList(new ObjectStringNullTerminated("URL")); |
| 117 | appendToObjectList(new ObjectStringSizeTerminated("ID and Additional Data")); |
| 118 | } |
| 119 | } |