1 | package org.farng.mp3.id3; |
2 | |
3 | import org.farng.mp3.InvalidTagException; |
4 | import org.farng.mp3.object.ObjectByteArraySizeTerminated; |
5 | import org.farng.mp3.object.ObjectNumberHashMap; |
6 | import org.farng.mp3.object.ObjectStringDate; |
7 | import org.farng.mp3.object.ObjectStringNullTerminated; |
8 | |
9 | import java.io.IOException; |
10 | import java.io.RandomAccessFile; |
11 | |
12 | /** |
13 | * <h3>4.24. Commercial frame</h3> |
14 | * <p/> |
15 | * <p> This frame enables several competing offers in the same tag by<br> |
16 | * <p/> |
17 | * bundling all needed information. That makes this frame rather complex<br> but it's an |
18 | * easier solution than if one tries to achieve the same<br> result with several frames. The frame begins, |
19 | * after the frame ID,<br> size and encoding fields, with a price string field. A price is<br> |
20 | * constructed by one three character currency code, encoded according<br> |
21 | * <p/> |
22 | * to ISO 4217 [ISO-4217] alphabetic currency code, followed by a<br> numerical value where |
23 | * "." is used as decimal separator. In the price<br> string several prices may be concatenated, |
24 | * separated by a "/"<br> character, but there may only be one currency of each type.</p> |
25 | * <p/> |
26 | * <p> The price string is followed by an 8 character date string in the<br> format YYYYMMDD, |
27 | * describing for how long the price is valid. After<br> that is a contact URL, with which the user can |
28 | * contact the seller,<br> followed by a one byte 'received as' field. It describes how the<br> |
29 | * audio is delivered when bought according to the following list:</p> |
30 | * <p/> |
31 | * <p> $00 Other<br> |
32 | * $01 Standard CD album with other songs<br> $02 Compressed |
33 | * audio on CD<br> |
34 | * <p/> |
35 | * $03 File over the Internet<br> |
36 | * $04 Stream over the Internet<br> |
37 | * $05 As note sheets<br> |
38 | * <p/> |
39 | * $06 As note sheets in a book with other sheets<br> |
40 | * $07 Music on other media<br> |
41 | * $08 Non-musical merchandise</p> |
42 | * <p/> |
43 | * <p> Next follows a terminated string with the name of the seller followed<br> by a |
44 | * terminated string with a short description of the product. The<br> last thing is the ability to include |
45 | * a company logotype. The first of<br> them is the 'Picture MIME type' field containing information |
46 | * about<br> which picture format is used. In the event that the MIME media type<br> |
47 | * <p/> |
48 | * name is omitted, "image/" will be implied. Currently only "image/png"<br> |
49 | * and "image/jpeg" are allowed. This format string is followed by the<br> binary |
50 | * picture data. This two last fields may be omitted if no<br> |
51 | * <p/> |
52 | * picture is attached. There may be more than one 'commercial frame' in<br> a tag, but no two |
53 | * may be identical.</p> |
54 | * <p/> |
55 | * <p> <Header for 'Commercial frame', ID: "COMR"><br> |
56 | * Text encoding $xx<br> |
57 | * <p/> |
58 | * Price string <text string> $00<br> |
59 | * Valid until <text string><br> |
60 | * Contact URL |
61 | * <p/> |
62 | * <text string> $00<br> Received as $xx<br> |
63 | * Name of seller <text string according to encoding> $00 |
64 | * (00)<br> |
65 | * <p/> |
66 | * Description <text string according to |
67 | * encoding> $00 (00)<br> Picture MIME type <string> $00<br> |
68 | * <p/> |
69 | * Seller logo <binary data><br> </p> |
70 | * |
71 | * @author Eric Farng |
72 | * @version $Revision: 1.4 $ |
73 | */ |
74 | public class FrameBodyCOMR extends AbstractID3v2FrameBody { |
75 | |
76 | /** |
77 | * Creates a new FrameBodyCOMR object. |
78 | */ |
79 | public FrameBodyCOMR() { |
80 | super(); |
81 | } |
82 | |
83 | /** |
84 | * Creates a new FrameBodyCOMR object. |
85 | */ |
86 | public FrameBodyCOMR(final FrameBodyCOMR body) { |
87 | super(body); |
88 | } |
89 | |
90 | /** |
91 | * Creates a new FrameBodyCOMR object. |
92 | */ |
93 | public FrameBodyCOMR(final byte textEncoding, |
94 | final String priceString, |
95 | final String validUntil, |
96 | final String contactUrl, |
97 | final byte recievedAs, |
98 | final String nameOfSeller, |
99 | final String description, |
100 | final String mimeType, |
101 | final byte[] sellerLogo) { |
102 | setObject("Text Encoding", new Byte(textEncoding)); |
103 | setObject("Price String", priceString); |
104 | setObject("Valid Until", validUntil); |
105 | setObject("Contact URL", contactUrl); |
106 | setObject("Recieved As", new Byte(recievedAs)); |
107 | setObject("Name Of Seller", nameOfSeller); |
108 | setObject("Description", description); |
109 | setObject("Picture MIME Type", mimeType); |
110 | setObject("Seller Logo", sellerLogo); |
111 | } |
112 | |
113 | /** |
114 | * Creates a new FrameBodyCOMR object. |
115 | */ |
116 | public FrameBodyCOMR(final RandomAccessFile file) throws IOException, InvalidTagException { |
117 | this.read(file); |
118 | } |
119 | |
120 | public String getIdentifier() { |
121 | String str = "COMR"; |
122 | final java.util.Iterator iterator = getObjectListIterator(); |
123 | while (iterator.hasNext()) { |
124 | str += (((char) 0) + getOwner()); |
125 | } |
126 | return str; |
127 | } |
128 | |
129 | public String getOwner() { |
130 | return (String) getObject("Owner"); |
131 | } |
132 | |
133 | public void getOwner(final String description) { |
134 | setObject("Owner", description); |
135 | } |
136 | |
137 | protected void setupObjectList() { |
138 | appendToObjectList(new ObjectNumberHashMap(ObjectNumberHashMap.TEXT_ENCODING, 1)); |
139 | appendToObjectList(new ObjectStringNullTerminated("Price String")); |
140 | appendToObjectList(new ObjectStringDate("Valid Until")); |
141 | appendToObjectList(new ObjectStringNullTerminated("Contact URL")); |
142 | appendToObjectList(new ObjectNumberHashMap(ObjectNumberHashMap.RECIEVED_AS, 1)); |
143 | appendToObjectList(new ObjectStringNullTerminated("Name Of Seller")); |
144 | appendToObjectList(new ObjectStringNullTerminated("Description")); |
145 | appendToObjectList(new ObjectStringNullTerminated("Picture MIME Type")); |
146 | appendToObjectList(new ObjectByteArraySizeTerminated("Seller Logo")); |
147 | } |
148 | } |