~ubuntu-branches/ubuntu/utopic/libjaudiotagger-java/utopic-proposed

« back to all changes in this revision

Viewing changes to src/org/jaudiotagger/tag/id3/framebody/FrameBodyCOMR.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath, Damien Raude-Morvan, Varun Hiremath
  • Date: 2009-04-01 19:17:56 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090401191756-bygniim270guy7o1
Tags: 1.0.9-1
[ Damien Raude-Morvan ]
* New upstream release
* debian/watch: Use java.net repository (which contains new releases!)
* debian/control:
  - Build-Depends on default-jdk-builddep
  - Bump Standards-Version to 3.8.1 (no changes needed)
  - Change section to "java"
* debian/rules: use default-java as JAVA_HOME
* debina/orig-tar.{sh|excludes}: strip audio and others binary files from ZIP
* debian/build.xml:
  - compile with "nowarn" to keep build log readable
  - exclude LogFormatter from build (use com.sun classes)
* debian/ant.properties: new source directory is "src" in orig.tar.gz
* Add myself as Uploaders

[ Varun Hiremath ]
* Accept changes made by Damien Raude-Morvan (Closes: #522130)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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> &lt;Header for 'Commercial frame', ID: "COMR"&gt;</td></tr>
 
68
 * <tr><td>Text encoding </td><td>$xx                             </td></tr>
 
69
 * <tr><td>Price string  </td><td>&lt;text string&gt; $00         </td></tr>
 
70
 * <tr><td>Valid until   </td><td>&lt;text string&gt;             </td></tr>
 
71
 * <tr><td>Contact URL   </td><td>&lt;text string&gt; $00         </td></tr>
 
72
 * <tr><td>Received as   </td><td>$xx                             </td></tr>
 
73
 * <tr><td>Name of seller</td><td>&lt;text string according to encoding&gt; $00 (00)</td></tr>
 
74
 * <tr><td>Description   </td><td>&lt;text string according to encoding&gt; $00 (00)</td></tr>
 
75
 * <tr><td>Picture MIME type</td><td>&lt;string&gt; $00           </td></tr>
 
76
 * <tr><td>Seller logo   </td><td>&lt;binary data&gt;             </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,v 1.16 2008/07/21 10:45:42 paultaylor Exp $
 
87
 */
 
88
public class FrameBodyCOMR extends AbstractID3v2FrameBody implements ID3v24FrameBody, ID3v23FrameBody
 
89
{
 
90
    /**
 
91
     * Creates a new FrameBodyCOMR datatype.
 
92
     */
 
93
    public FrameBodyCOMR()
 
94
    {
 
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
    }
 
105
 
 
106
    public FrameBodyCOMR(FrameBodyCOMR body)
 
107
    {
 
108
        super(body);
 
109
    }
 
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
    {
 
126
        this.setObjectValue(DataTypes.OBJ_TEXT_ENCODING, textEncoding);
 
127
        this.setObjectValue(DataTypes.OBJ_PRICE_STRING, priceString);
 
128
        this.setObjectValue(DataTypes.OBJ_VALID_UNTIL, validUntil);
 
129
        this.setObjectValue(DataTypes.OBJ_CONTACT_URL, contactUrl);
 
130
        this.setObjectValue(DataTypes.OBJ_RECIEVED_AS, recievedAs);
 
131
        this.setObjectValue(DataTypes.OBJ_SELLER_NAME, nameOfSeller);
 
132
        this.setObjectValue(DataTypes.OBJ_DESCRIPTION, description);
 
133
        this.setObjectValue(DataTypes.OBJ_MIME_TYPE, mimeType);
 
134
        this.setObjectValue(DataTypes.OBJ_SELLER_LOGO, sellerLogo);
 
135
    }
 
136
 
 
137
    /**
 
138
     * Creates a new FrameBodyCOMR datatype.
 
139
     *
 
140
     * @throws InvalidTagException if unable to create framebody from buffer
 
141
     */
 
142
    public FrameBodyCOMR(ByteBuffer byteBuffer, int frameSize) throws InvalidTagException
 
143
    {
 
144
        super(byteBuffer, frameSize);
 
145
    }
 
146
 
 
147
    /**
 
148
     * The ID3v2 frame identifier
 
149
     *
 
150
     * @return the ID3v2 frame identifier  for this frame type
 
151
     */
 
152
    public String getIdentifier()
 
153
    {
 
154
        return ID3v24Frames.FRAME_ID_COMMERCIAL_FRAME;
 
155
    }
 
156
 
 
157
    /**
 
158
     * @return
 
159
     */
 
160
    public String getOwner()
 
161
    {
 
162
        return (String) getObjectValue(DataTypes.OBJ_OWNER);
 
163
    }
 
164
 
 
165
    /**
 
166
     * @param description
 
167
     */
 
168
    public void getOwner(String description)
 
169
    {
 
170
        setObjectValue(DataTypes.OBJ_OWNER, description);
 
171
    }
 
172
 
 
173
    /**
 
174
     * If the seller or description cannot be encoded using current encoder, change the encoder
 
175
     */
 
176
    public void write(ByteArrayOutputStream tagBuffer)
 
177
    {
 
178
        if (((AbstractString) getObject(DataTypes.OBJ_SELLER_NAME)).canBeEncoded() == false)
 
179
        {
 
180
            this.setTextEncoding(TextEncoding.UTF_16);
 
181
        }
 
182
        if (((AbstractString) getObject(DataTypes.OBJ_DESCRIPTION)).canBeEncoded() == false)
 
183
        {
 
184
            this.setTextEncoding(TextEncoding.UTF_16);
 
185
        }
 
186
        super.write(tagBuffer);
 
187
    }
 
188
 
 
189
    /**
 
190
     *
 
191
     */
 
192
    protected void setupObjectList()
 
193
    {
 
194
        objectList.add(new NumberHashMap(DataTypes.OBJ_TEXT_ENCODING, this, TextEncoding.TEXT_ENCODING_FIELD_SIZE));
 
195
        objectList.add(new StringNullTerminated(DataTypes.OBJ_PRICE_STRING, this));
 
196
        objectList.add(new StringDate(DataTypes.OBJ_VALID_UNTIL, this));
 
197
        objectList.add(new StringNullTerminated(DataTypes.OBJ_CONTACT_URL, this));
 
198
        objectList.add(new NumberHashMap(DataTypes.OBJ_RECIEVED_AS, this, 1));
 
199
        objectList.add(new TextEncodedStringNullTerminated(DataTypes.OBJ_SELLER_NAME, this));
 
200
        objectList.add(new TextEncodedStringNullTerminated(DataTypes.OBJ_DESCRIPTION, this));
 
201
        objectList.add(new StringNullTerminated(DataTypes.OBJ_MIME_TYPE, this));
 
202
        objectList.add(new ByteArraySizeTerminated(DataTypes.OBJ_SELLER_LOGO, this));
 
203
    }
 
204
}