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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2011-04-28 23:52:43 UTC
  • mfrom: (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110428235243-pzalvw6lncis3ukf
Tags: 2.0.3-1
* d/control: Drop Depends on default-jre per Debian Java Policy as its
  a library package.
* d/watch: Fix to directly monitor SVN tags.
* Switch to 3.0 (quilt) format.
* Bump Standards-Version to 3.9.2 (no changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 *  @author : Paul Taylor
3
 
 *  @author : Eric Farng
4
 
 *
5
 
 *  Version @version:$Id: FrameBodyTIPL.java,v 1.13 2009/11/12 13:25:22 paultaylor Exp $
6
 
 *
7
 
 *  MusicTag Copyright (C)2003,2004
8
 
 *
9
 
 *  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
10
 
 *  General Public  License as published by the Free Software Foundation; either version 2.1 of the License,
11
 
 *  or (at your option) any later version.
12
 
 *
13
 
 *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14
 
 *  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 
 *  See the GNU Lesser General Public License for more details.
16
 
 *
17
 
 *  You should have received a copy of the GNU Lesser General Public License along with this library; if not,
18
 
 *  you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software
19
 
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
 
 *
21
 
 * Description:
22
 
 * People List
23
 
 *
24
 
 */
25
 
package org.jaudiotagger.tag.id3.framebody;
26
 
 
27
 
import org.jaudiotagger.tag.InvalidTagException;
28
 
import org.jaudiotagger.tag.datatype.DataTypes;
29
 
import org.jaudiotagger.tag.datatype.PairedTextEncodedStringNullTerminated;
30
 
import org.jaudiotagger.tag.id3.ID3v24Frames;
31
 
 
32
 
import java.nio.ByteBuffer;
33
 
 
34
 
 
35
 
/**
36
 
 * The 'Involved people list' is intended as a mapping between functions like producer and names. Every odd field is a
37
 
 * function and every even is an name or a comma delimited list of names.
38
 
 * <p/>
39
 
 * TODO currently just reads the first String when directly from file, this will be fixed when we add support for
40
 
 * multiple Strings for all ID3v24Frames
41
 
 * <p/>
42
 
 * TODO currently just reads all the values when converted from the corresponding ID3v23 Frame IPLS as a single value
43
 
 * (the individual fields from the IPLS frame will be seperated by commas)
44
 
 */
45
 
public class FrameBodyTIPL extends AbstractFrameBodyTextInfo implements ID3v24FrameBody
46
 
{
47
 
    /**
48
 
     * Creates a new FrameBodyTIPL datatype.
49
 
     */
50
 
    public FrameBodyTIPL()
51
 
    {
52
 
    }
53
 
 
54
 
    public FrameBodyTIPL(FrameBodyTIPL body)
55
 
    {
56
 
        super(body);
57
 
    }
58
 
 
59
 
    /**
60
 
     * Convert from V3 to V4 Frame
61
 
     * @param body
62
 
     */
63
 
    public FrameBodyTIPL(FrameBodyIPLS body)
64
 
    {
65
 
        setObjectValue(DataTypes.OBJ_TEXT_ENCODING, body.getTextEncoding());
66
 
 
67
 
        PairedTextEncodedStringNullTerminated.ValuePairs value = (PairedTextEncodedStringNullTerminated.ValuePairs) body.getObjectValue(DataTypes.OBJ_TEXT);
68
 
        setObjectValue(DataTypes.OBJ_TEXT, value.toString());
69
 
    }
70
 
 
71
 
    /**
72
 
     * Creates a new FrameBodyTIPL datatype.
73
 
     *
74
 
     * @param textEncoding
75
 
     * @param text
76
 
     */
77
 
    public FrameBodyTIPL(byte textEncoding, String text)
78
 
    {
79
 
        super(textEncoding, text);
80
 
    }
81
 
 
82
 
    /**
83
 
     * Creates a new FrameBodyTIPL datatype.
84
 
     *
85
 
     * @param byteBuffer
86
 
     * @param frameSize
87
 
     * @throws InvalidTagException
88
 
     */
89
 
    public FrameBodyTIPL(ByteBuffer byteBuffer, int frameSize) throws InvalidTagException
90
 
    {
91
 
        super(byteBuffer, frameSize);
92
 
    }
93
 
 
94
 
    /**
95
 
     * The ID3v2 frame identifier
96
 
     *
97
 
     * @return the ID3v2 frame identifier  for this frame type
98
 
     */
99
 
    public String getIdentifier()
100
 
    {
101
 
        return ID3v24Frames.FRAME_ID_INVOLVED_PEOPLE;
102
 
    }
103
 
}
 
1
/**
 
2
 *  @author : Paul Taylor
 
3
 *  @author : Eric Farng
 
4
 *
 
5
 *  Version @version:$Id: FrameBodyTIPL.java 929 2010-11-17 12:36:46Z paultaylor $
 
6
 *
 
7
 *  MusicTag Copyright (C)2003,2004
 
8
 *
 
9
 *  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
 
10
 *  General Public  License as published by the Free Software Foundation; either version 2.1 of the License,
 
11
 *  or (at your option) any later version.
 
12
 *
 
13
 *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 
14
 *  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
15
 *  See the GNU Lesser General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU Lesser General Public License along with this library; if not,
 
18
 *  you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software
 
19
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
20
 *
 
21
 * Description:
 
22
 * People List
 
23
 *
 
24
 */
 
25
package org.jaudiotagger.tag.id3.framebody;
 
26
 
 
27
import org.jaudiotagger.tag.InvalidTagException;
 
28
import org.jaudiotagger.tag.datatype.DataTypes;
 
29
import org.jaudiotagger.tag.datatype.NumberHashMap;
 
30
import org.jaudiotagger.tag.datatype.Pair;
 
31
import org.jaudiotagger.tag.datatype.PairedTextEncodedStringNullTerminated;
 
32
import org.jaudiotagger.tag.id3.ID3v24Frames;
 
33
import org.jaudiotagger.tag.id3.valuepair.TextEncoding;
 
34
 
 
35
import java.io.ByteArrayOutputStream;
 
36
import java.nio.ByteBuffer;
 
37
import java.util.Map;
 
38
import java.util.StringTokenizer;
 
39
 
 
40
 
 
41
/**
 
42
 * The 'Involved people list' is intended as a mapping between functions like producer and names. Every odd field is a
 
43
 * function and every even is an name or a comma delimited list of names.
 
44
 * <p/>
 
45
 */
 
46
public class FrameBodyTIPL extends AbstractID3v2FrameBody implements ID3v24FrameBody
 
47
{
 
48
    //Standard function names, taken from Picard Mapping
 
49
    public static final String ENGINEER = "engineer";
 
50
    public static final String MIXER = "mix";
 
51
    public static final String DJMIXER = "DJ-mix";
 
52
    public static final String PRODUCER = "producer";
 
53
    public static final String ARRANGER = "arranger";
 
54
 
 
55
    /**
 
56
     * Creates a new FrameBodyTIPL datatype.
 
57
     */
 
58
    public FrameBodyTIPL()
 
59
    {
 
60
        setObjectValue(DataTypes.OBJ_TEXT_ENCODING, TextEncoding.ISO_8859_1);
 
61
    }
 
62
 
 
63
    /**
 
64
     * Creates a new FrameBodyTIPL data type.
 
65
     *
 
66
     * @param textEncoding
 
67
     * @param text
 
68
     */
 
69
    public FrameBodyTIPL(byte textEncoding, String text)
 
70
    {
 
71
        setObjectValue(DataTypes.OBJ_TEXT_ENCODING, textEncoding);
 
72
        setText(text);
 
73
    }
 
74
 
 
75
    /**
 
76
     * Creates a new FrameBodyTIPL data type.
 
77
     *
 
78
     * @param byteBuffer
 
79
     * @param frameSize
 
80
     * @throws InvalidTagException
 
81
     */
 
82
    public FrameBodyTIPL(ByteBuffer byteBuffer, int frameSize) throws InvalidTagException
 
83
    {
 
84
        super(byteBuffer, frameSize);
 
85
    }
 
86
 
 
87
    /**
 
88
     * Convert from V3 to V4 Frame
 
89
     *
 
90
     * @param body
 
91
     */
 
92
    public FrameBodyTIPL(FrameBodyIPLS body)
 
93
    {
 
94
        setObjectValue(DataTypes.OBJ_TEXT_ENCODING, body.getTextEncoding());
 
95
        setObjectValue(DataTypes.OBJ_TEXT, body.getPairing());
 
96
    }
 
97
 
 
98
    /**
 
99
     * The ID3v2 frame identifier
 
100
     *
 
101
     * @return the ID3v2 frame identifier  for this frame type
 
102
     */
 
103
    public String getIdentifier()
 
104
    {
 
105
        return ID3v24Frames.FRAME_ID_INVOLVED_PEOPLE;
 
106
    }
 
107
 
 
108
    /**
 
109
     * Set the text, decoded as pairs of involvee - involvment
 
110
     *
 
111
     * @param text
 
112
     */
 
113
    public void setText(String text)
 
114
    {
 
115
        PairedTextEncodedStringNullTerminated.ValuePairs value = new PairedTextEncodedStringNullTerminated.ValuePairs();
 
116
        StringTokenizer stz = new StringTokenizer(text, "\0");
 
117
 
 
118
        while (stz.hasMoreTokens())
 
119
        {
 
120
            String key =stz.nextToken();
 
121
            if(stz.hasMoreTokens())
 
122
            {
 
123
                value.add(key, stz.nextToken());
 
124
            }
 
125
            
 
126
        }
 
127
        setObjectValue(DataTypes.OBJ_TEXT, value);
 
128
    }
 
129
 
 
130
    public void addPair(String text)
 
131
    {
 
132
        PairedTextEncodedStringNullTerminated.ValuePairs value = ((PairedTextEncodedStringNullTerminated) getObject(DataTypes.OBJ_TEXT)).getValue();
 
133
        StringTokenizer stz = new StringTokenizer(text, "\0");
 
134
        if (stz.hasMoreTokens())
 
135
        {
 
136
            value.add(stz.nextToken(),stz.nextToken());
 
137
        }
 
138
    }
 
139
 
 
140
    /**
 
141
     * Because have a text encoding we need to check the data values do not contain characters that cannot be encoded in
 
142
     * current encoding before we write data. If they do change the encoding.
 
143
     */
 
144
    public void write(ByteArrayOutputStream tagBuffer)
 
145
    {
 
146
        if (!((PairedTextEncodedStringNullTerminated) getObject(DataTypes.OBJ_TEXT)).canBeEncoded())
 
147
        {
 
148
            this.setTextEncoding(TextEncoding.UTF_16);
 
149
        }
 
150
        super.write(tagBuffer);
 
151
    }
 
152
 
 
153
    /**
 
154
     * Consists of a text encoding , and then a series of null terminated Strings, there should be an even number
 
155
     * of Strings as they are paired as involvement/involvee
 
156
     */
 
157
    protected void setupObjectList()
 
158
    {
 
159
        objectList.add(new NumberHashMap(DataTypes.OBJ_TEXT_ENCODING, this, TextEncoding.TEXT_ENCODING_FIELD_SIZE));
 
160
        objectList.add(new PairedTextEncodedStringNullTerminated(DataTypes.OBJ_TEXT, this));
 
161
    }
 
162
 
 
163
    public PairedTextEncodedStringNullTerminated.ValuePairs getPairing()
 
164
    {
 
165
        return (PairedTextEncodedStringNullTerminated.ValuePairs) getObject(DataTypes.OBJ_TEXT).getValue();
 
166
    }
 
167
 
 
168
    /**
 
169
     * Get key at index
 
170
     *
 
171
     * @param index
 
172
     * @return value at index
 
173
     */
 
174
    public String getKeyAtIndex(int index)
 
175
    {
 
176
        PairedTextEncodedStringNullTerminated text = (PairedTextEncodedStringNullTerminated) getObject(DataTypes.OBJ_TEXT);
 
177
        return (String) text.getValue().getMapping().get(index).getKey();
 
178
    }
 
179
 
 
180
    /**
 
181
     * Get value at index
 
182
     *
 
183
     * @param index
 
184
     * @return value at index
 
185
     */
 
186
    public String getValueAtIndex(int index)
 
187
    {
 
188
        PairedTextEncodedStringNullTerminated text = (PairedTextEncodedStringNullTerminated) getObject(DataTypes.OBJ_TEXT);
 
189
        return (String) text.getValue().getMapping().get(index).getValue();
 
190
    }
 
191
 
 
192
    /**
 
193
     * @return number of text pairs
 
194
     */
 
195
    public int getNumberOfPairs()
 
196
    {
 
197
        PairedTextEncodedStringNullTerminated text = (PairedTextEncodedStringNullTerminated) getObject(DataTypes.OBJ_TEXT);
 
198
        return text.getValue().getNumberOfPairs();
 
199
    }
 
200
 
 
201
    public String getText()
 
202
    {
 
203
        PairedTextEncodedStringNullTerminated text = (PairedTextEncodedStringNullTerminated) getObject(DataTypes.OBJ_TEXT);
 
204
        StringBuilder sb = new StringBuilder();
 
205
        int count = 1;
 
206
        for (Pair entry : text.getValue().getMapping())
 
207
        {
 
208
            sb.append(entry.getKey() + '\0' + entry.getValue());
 
209
            if (count != getNumberOfPairs())
 
210
            {
 
211
                sb.append('\0');
 
212
            }
 
213
            count++;
 
214
        }
 
215
        return sb.toString();
 
216
    }
 
217
 
 
218
    public String getUserFriendlyValue()
 
219
    {
 
220
        return getText();
 
221
    }
 
222
}