| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| FrameBodyIPLS |
|
| 1.2;1.2 |
| 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.DataTypes; | |
| 20 | import org.jaudiotagger.tag.datatype.NumberHashMap; | |
| 21 | import org.jaudiotagger.tag.datatype.PairedTextEncodedStringNullTerminated; | |
| 22 | import org.jaudiotagger.tag.datatype.TextEncodedStringSizeTerminated; | |
| 23 | import org.jaudiotagger.tag.id3.ID3v23Frames; | |
| 24 | import org.jaudiotagger.tag.id3.valuepair.TextEncoding; | |
| 25 | ||
| 26 | import java.io.ByteArrayOutputStream; | |
| 27 | import java.nio.ByteBuffer; | |
| 28 | import java.util.StringTokenizer; | |
| 29 | ||
| 30 | /** | |
| 31 | * Involved People List ID3v22/v23 Only | |
| 32 | * <p/> | |
| 33 | * Since there might be a lot of people contributing to an audio file in various ways, such as musicians and technicians, | |
| 34 | * the 'Text information frames' are often insufficient to list everyone involved in a project. | |
| 35 | * The 'Involved people list' is a frame containing the names of those involved, and how they were involved. | |
| 36 | * The body simply contains a terminated string with the involvement directly followed by a terminated string with | |
| 37 | * the involvee followed by a new involvement and so on. There may only be one "IPLS" frame in each tag. | |
| 38 | * <p/> | |
| 39 | * <Header for 'Involved people list', ID: "IPLS"> | |
| 40 | * Text encoding $xx | |
| 41 | * People list strings <text strings according to encoding> | |
| 42 | * <p/> | |
| 43 | * <p>For more details, please refer to the ID3 specifications: | |
| 44 | * <ul> | |
| 45 | * <li><a href="http://www.id3.org/id3v2.3.0.txt">ID3 v2.3.0 Spec</a> | |
| 46 | * </ul> | |
| 47 | * | |
| 48 | * @author : Paul Taylor | |
| 49 | * @author : Eric Farng | |
| 50 | * @version $Id: FrameBodyIPLS.java,v 1.16 2008/11/12 16:41:38 paultaylor Exp $ | |
| 51 | * @TODO currently just allows any number of values, should only really support pairs of values | |
| 52 | */ | |
| 53 | public class FrameBodyIPLS extends AbstractID3v2FrameBody implements ID3v23FrameBody | |
| 54 | { | |
| 55 | /** | |
| 56 | * Creates a new FrameBodyIPLS datatype. | |
| 57 | */ | |
| 58 | public FrameBodyIPLS() | |
| 59 | { | |
| 60 | 0 | super(); |
| 61 | 0 | setObjectValue(DataTypes.OBJ_TEXT_ENCODING, TextEncoding.ISO_8859_1); |
| 62 | 0 | } |
| 63 | ||
| 64 | public FrameBodyIPLS(ByteBuffer byteBuffer, int frameSize) throws InvalidTagException | |
| 65 | { | |
| 66 | 1 | super(byteBuffer, frameSize); |
| 67 | 1 | } |
| 68 | ||
| 69 | /** | |
| 70 | * The ID3v23 frame identifier | |
| 71 | * | |
| 72 | * @return the ID3v23 frame identifier for this frame type | |
| 73 | */ | |
| 74 | public String getIdentifier() | |
| 75 | { | |
| 76 | 2 | return ID3v23Frames.FRAME_ID_V3_IPLS; |
| 77 | } | |
| 78 | ||
| 79 | public FrameBodyIPLS(FrameBodyIPLS body) | |
| 80 | { | |
| 81 | 1 | super(body); |
| 82 | 1 | } |
| 83 | ||
| 84 | /** | |
| 85 | * Convert from V4 to V3 Frame | |
| 86 | */ | |
| 87 | public FrameBodyIPLS(FrameBodyTIPL body) | |
| 88 | 0 | { |
| 89 | 0 | setObjectValue(DataTypes.OBJ_TEXT_ENCODING, body.getTextEncoding()); |
| 90 | ||
| 91 | 0 | String valueAsCommaSeperatedString = (String) body.getObjectValue(DataTypes.OBJ_TEXT); |
| 92 | ||
| 93 | 0 | PairedTextEncodedStringNullTerminated.ValuePairs value = new PairedTextEncodedStringNullTerminated.ValuePairs(); |
| 94 | 0 | StringTokenizer stz = new StringTokenizer(valueAsCommaSeperatedString, ","); |
| 95 | 0 | while (stz.hasMoreTokens()) |
| 96 | { | |
| 97 | 0 | value.add(stz.nextToken()); |
| 98 | } | |
| 99 | 0 | setObjectValue(DataTypes.OBJ_TEXT, value); |
| 100 | 0 | } |
| 101 | ||
| 102 | /** | |
| 103 | * Because have a text encoding we need to check the data values do not contain characters that cannot be encoded in | |
| 104 | * current encoding before we write data. If they do change the encoding. | |
| 105 | */ | |
| 106 | public void write(ByteArrayOutputStream tagBuffer) | |
| 107 | { | |
| 108 | 0 | if (((PairedTextEncodedStringNullTerminated) getObject(DataTypes.OBJ_TEXT)).canBeEncoded() == false) |
| 109 | { | |
| 110 | 0 | this.setTextEncoding(TextEncoding.UTF_16); |
| 111 | } | |
| 112 | 0 | super.write(tagBuffer); |
| 113 | 0 | } |
| 114 | ||
| 115 | /** | |
| 116 | * Consists of a text encoding , and then a series of null terminated Strings, there should be an even number | |
| 117 | * of Strings as they are paired as involvement/involvee | |
| 118 | */ | |
| 119 | protected void setupObjectList() | |
| 120 | { | |
| 121 | 1 | objectList.add(new NumberHashMap(DataTypes.OBJ_TEXT_ENCODING, this, TextEncoding.TEXT_ENCODING_FIELD_SIZE)); |
| 122 | 1 | objectList.add(new PairedTextEncodedStringNullTerminated(DataTypes.OBJ_TEXT, this)); |
| 123 | 1 | } |
| 124 | ||
| 125 | /** | |
| 126 | * Get value at index | |
| 127 | * | |
| 128 | * @param index | |
| 129 | * @return value at index | |
| 130 | */ | |
| 131 | public String getValueAtIndex(int index) | |
| 132 | { | |
| 133 | 2 | PairedTextEncodedStringNullTerminated text = (PairedTextEncodedStringNullTerminated) getObject(DataTypes.OBJ_TEXT); |
| 134 | 2 | return text.getValue().getList().get(index); |
| 135 | } | |
| 136 | ||
| 137 | /** | |
| 138 | * @return number of text values, shopuld be an even number because should make up pairs of values | |
| 139 | */ | |
| 140 | public int getNumberOfValues() | |
| 141 | { | |
| 142 | 1 | PairedTextEncodedStringNullTerminated text = (PairedTextEncodedStringNullTerminated) getObject(DataTypes.OBJ_TEXT); |
| 143 | 1 | return text.getValue().getNumberOfValues(); |
| 144 | } | |
| 145 | ||
| 146 | /** | |
| 147 | * @return number of text pairs | |
| 148 | */ | |
| 149 | public int getNumberOfPairs() | |
| 150 | { | |
| 151 | 1 | PairedTextEncodedStringNullTerminated text = (PairedTextEncodedStringNullTerminated) getObject(DataTypes.OBJ_TEXT); |
| 152 | 1 | return text.getValue().getNumberOfPairs(); |
| 153 | } | |
| 154 | } |