| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| FrameBodyCOMR |
|
| 1.2222222222222223;1.222 |
| 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.ID3v24Frames; | |
| 21 | import org.jaudiotagger.tag.id3.valuepair.TextEncoding; | |
| 22 | ||
| 23 | import java.io.ByteArrayOutputStream; | |
| 24 | import java.nio.ByteBuffer; | |
| 25 | ||
| 26 | /** | |
| 27 | * Commercial frame. | |
| 28 | * <p/> | |
| 29 | * <p/> | |
| 30 | * This frame enables several competing offers in the same tag by | |
| 31 | * bundling all needed information. That makes this frame rather complex | |
| 32 | * but it's an easier solution than if one tries to achieve the same | |
| 33 | * result with several frames. The frame begins, after the frame ID, | |
| 34 | * size and encoding fields, with a price string field. A price is | |
| 35 | * constructed by one three character currency code, encoded according | |
| 36 | * to ISO-4217 alphabetic currency code, followed by a | |
| 37 | * numerical value where "." is used as decimal seperator. In the price | |
| 38 | * string several prices may be concatenated, seperated by a "/" | |
| 39 | * character, but there may only be one currency of each type. | |
| 40 | * </p><p> | |
| 41 | * The price string is followed by an 8 character date string in the | |
| 42 | * format YYYYMMDD, describing for how long the price is valid. After | |
| 43 | * that is a contact URL, with which the user can contact the seller, | |
| 44 | * followed by a one byte 'received as' field. It describes how the | |
| 45 | * audio is delivered when bought according to the following list: | |
| 46 | * </p><p><table border=0 width="70%"> | |
| 47 | * <tr><td>$00 </td><td>Other </td></tr> | |
| 48 | * <tr><td>$01 </td><td>Standard CD album with other songs </td></tr> | |
| 49 | * <tr><td>$02 </td><td>Compressed audio on CD </td></tr> | |
| 50 | * <tr><td>$03 </td><td>File over the Internet </td></tr> | |
| 51 | * <tr><td>$04 </td><td>Stream over the Internet </td></tr> | |
| 52 | * <tr><td>$05 </td><td>As note sheets </td></tr> | |
| 53 | * <tr><td>$06 </td><td>As note sheets in a book with other sheets </td></tr> | |
| 54 | * <tr><td>$07 </td><td>Music on other media </td></tr> | |
| 55 | * <tr><td>$08 </td><td>Non-musical merchandise </td></tr> | |
| 56 | * </table></p><p> | |
| 57 | * Next follows a terminated string with the name of the seller followed | |
| 58 | * by a terminated string with a short description of the product. The | |
| 59 | * last thing is the ability to include a company logotype. The first of | |
| 60 | * them is the 'Picture MIME type' field containing information about | |
| 61 | * which picture format is used. In the event that the MIME media type | |
| 62 | * name is omitted, "image/" will be implied. Currently only "image/png" | |
| 63 | * and "image/jpeg" are allowed. This format string is followed by the | |
| 64 | * binary picture data. This two last fields may be omitted if no | |
| 65 | * picture is to attach. | |
| 66 | * </p><p><table border=0 width="70%"> | |
| 67 | * <tr><td colspan=2> <Header for 'Commercial frame', ID: "COMR"></td></tr> | |
| 68 | * <tr><td>Text encoding </td><td>$xx </td></tr> | |
| 69 | * <tr><td>Price string </td><td><text string> $00 </td></tr> | |
| 70 | * <tr><td>Valid until </td><td><text string> </td></tr> | |
| 71 | * <tr><td>Contact URL </td><td><text string> $00 </td></tr> | |
| 72 | * <tr><td>Received as </td><td>$xx </td></tr> | |
| 73 | * <tr><td>Name of seller</td><td><text string according to encoding> $00 (00)</td></tr> | |
| 74 | * <tr><td>Description </td><td><text string according to encoding> $00 (00)</td></tr> | |
| 75 | * <tr><td>Picture MIME type</td><td><string> $00 </td></tr> | |
| 76 | * <tr><td>Seller logo </td><td><binary data> </td></tr> | |
| 77 | * </table></p> | |
| 78 | * <p/> | |
| 79 | * <p>For more details, please refer to the ID3 specifications: | |
| 80 | * <ul> | |
| 81 | * <li><a href="http://www.id3.org/id3v2.3.0.txt">ID3 v2.3.0 Spec</a> | |
| 82 | * </ul> | |
| 83 | * | |
| 84 | * @author : Paul Taylor | |
| 85 | * @author : Eric Farng | |
| 86 | * @version $Id: FrameBodyCOMR.java 836 2009-11-12 15:44:07Z paultaylor $ | |
| 87 | */ | |
| 88 | public class FrameBodyCOMR extends AbstractID3v2FrameBody implements ID3v24FrameBody, ID3v23FrameBody | |
| 89 | { | |
| 90 | /** | |
| 91 | * Creates a new FrameBodyCOMR datatype. | |
| 92 | */ | |
| 93 | public FrameBodyCOMR() | |
| 94 | 0 | { |
| 95 | // this.setObject("Text Encoding", new Byte((byte) 0)); | |
| 96 | // this.setObject("Price String", ""); | |
| 97 | // this.setObject("Valid Until", ""); | |
| 98 | // this.setObject("Contact URL", ""); | |
| 99 | // this.setObject("Recieved As", new Byte((byte) 0)); | |
| 100 | // this.setObject("Name Of Seller", ""); | |
| 101 | // this.setObject(ObjectTypes.OBJ_DESCRIPTION, ""); | |
| 102 | // this.setObject("Picture MIME Type", ""); | |
| 103 | // this.setObject("Seller Logo", new byte[0]); | |
| 104 | 0 | } |
| 105 | ||
| 106 | public FrameBodyCOMR(FrameBodyCOMR body) | |
| 107 | { | |
| 108 | 0 | super(body); |
| 109 | 0 | } |
| 110 | ||
| 111 | /** | |
| 112 | * Creates a new FrameBodyCOMR datatype. | |
| 113 | * | |
| 114 | * @param textEncoding | |
| 115 | * @param priceString | |
| 116 | * @param validUntil | |
| 117 | * @param contactUrl | |
| 118 | * @param recievedAs | |
| 119 | * @param nameOfSeller | |
| 120 | * @param description | |
| 121 | * @param mimeType | |
| 122 | * @param sellerLogo | |
| 123 | */ | |
| 124 | public FrameBodyCOMR(byte textEncoding, String priceString, String validUntil, String contactUrl, byte recievedAs, String nameOfSeller, String description, String mimeType, byte[] sellerLogo) | |
| 125 | 0 | { |
| 126 | 0 | this.setObjectValue(DataTypes.OBJ_TEXT_ENCODING, textEncoding); |
| 127 | 0 | this.setObjectValue(DataTypes.OBJ_PRICE_STRING, priceString); |
| 128 | 0 | this.setObjectValue(DataTypes.OBJ_VALID_UNTIL, validUntil); |
| 129 | 0 | this.setObjectValue(DataTypes.OBJ_CONTACT_URL, contactUrl); |
| 130 | 0 | this.setObjectValue(DataTypes.OBJ_RECIEVED_AS, recievedAs); |
| 131 | 0 | this.setObjectValue(DataTypes.OBJ_SELLER_NAME, nameOfSeller); |
| 132 | 0 | this.setObjectValue(DataTypes.OBJ_DESCRIPTION, description); |
| 133 | 0 | this.setObjectValue(DataTypes.OBJ_MIME_TYPE, mimeType); |
| 134 | 0 | this.setObjectValue(DataTypes.OBJ_SELLER_LOGO, sellerLogo); |
| 135 | 0 | } |
| 136 | ||
| 137 | /** | |
| 138 | * Creates a new FrameBodyCOMR datatype. | |
| 139 | * | |
| 140 | * @param byteBuffer | |
| 141 | * @param frameSize | |
| 142 | * @throws InvalidTagException if unable to create framebody from buffer | |
| 143 | */ | |
| 144 | public FrameBodyCOMR(ByteBuffer byteBuffer, int frameSize) throws InvalidTagException | |
| 145 | { | |
| 146 | 0 | super(byteBuffer, frameSize); |
| 147 | 0 | } |
| 148 | ||
| 149 | /** | |
| 150 | * The ID3v2 frame identifier | |
| 151 | * | |
| 152 | * @return the ID3v2 frame identifier for this frame type | |
| 153 | */ | |
| 154 | public String getIdentifier() | |
| 155 | { | |
| 156 | 0 | return ID3v24Frames.FRAME_ID_COMMERCIAL_FRAME; |
| 157 | } | |
| 158 | ||
| 159 | /** | |
| 160 | * @return | |
| 161 | */ | |
| 162 | public String getOwner() | |
| 163 | { | |
| 164 | 0 | return (String) getObjectValue(DataTypes.OBJ_OWNER); |
| 165 | } | |
| 166 | ||
| 167 | /** | |
| 168 | * @param description | |
| 169 | */ | |
| 170 | public void getOwner(String description) | |
| 171 | { | |
| 172 | 0 | setObjectValue(DataTypes.OBJ_OWNER, description); |
| 173 | 0 | } |
| 174 | ||
| 175 | /** | |
| 176 | * If the seller or description cannot be encoded using current encoder, change the encoder | |
| 177 | */ | |
| 178 | public void write(ByteArrayOutputStream tagBuffer) | |
| 179 | { | |
| 180 | 0 | if (!((AbstractString) getObject(DataTypes.OBJ_SELLER_NAME)).canBeEncoded()) |
| 181 | { | |
| 182 | 0 | this.setTextEncoding(TextEncoding.UTF_16); |
| 183 | } | |
| 184 | 0 | if (!((AbstractString) getObject(DataTypes.OBJ_DESCRIPTION)).canBeEncoded()) |
| 185 | { | |
| 186 | 0 | this.setTextEncoding(TextEncoding.UTF_16); |
| 187 | } | |
| 188 | 0 | super.write(tagBuffer); |
| 189 | 0 | } |
| 190 | ||
| 191 | /** | |
| 192 | * | |
| 193 | */ | |
| 194 | protected void setupObjectList() | |
| 195 | { | |
| 196 | 0 | objectList.add(new NumberHashMap(DataTypes.OBJ_TEXT_ENCODING, this, TextEncoding.TEXT_ENCODING_FIELD_SIZE)); |
| 197 | 0 | objectList.add(new StringNullTerminated(DataTypes.OBJ_PRICE_STRING, this)); |
| 198 | 0 | objectList.add(new StringDate(DataTypes.OBJ_VALID_UNTIL, this)); |
| 199 | 0 | objectList.add(new StringNullTerminated(DataTypes.OBJ_CONTACT_URL, this)); |
| 200 | 0 | objectList.add(new NumberHashMap(DataTypes.OBJ_RECIEVED_AS, this, 1)); |
| 201 | 0 | objectList.add(new TextEncodedStringNullTerminated(DataTypes.OBJ_SELLER_NAME, this)); |
| 202 | 0 | objectList.add(new TextEncodedStringNullTerminated(DataTypes.OBJ_DESCRIPTION, this)); |
| 203 | 0 | objectList.add(new StringNullTerminated(DataTypes.OBJ_MIME_TYPE, this)); |
| 204 | 0 | objectList.add(new ByteArraySizeTerminated(DataTypes.OBJ_SELLER_LOGO, this)); |
| 205 | 0 | } |
| 206 | } |