| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Mp4TagTextField |
|
| 1.0769230769230769;1.077 |
| 1 | /* | |
| 2 | * Entagged Audio Tag library | |
| 3 | * Copyright (c) 2003-2005 Raphaƫl Slinckx <raphael@slinckx.net> | |
| 4 | * | |
| 5 | * This library is free software; you can redistribute it and/or | |
| 6 | * modify it under the terms of the GNU Lesser General Public | |
| 7 | * License as published by the Free Software Foundation; either | |
| 8 | * version 2.1 of the License, or (at your option) any later version. | |
| 9 | * | |
| 10 | * This library is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | * Lesser General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU Lesser General Public | |
| 16 | * License along with this library; if not, write to the Free Software | |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 18 | */ | |
| 19 | package org.jaudiotagger.tag.mp4.field; | |
| 20 | ||
| 21 | import org.jaudiotagger.audio.mp4.atom.Mp4BoxHeader; | |
| 22 | import org.jaudiotagger.tag.TagField; | |
| 23 | import org.jaudiotagger.tag.TagTextField; | |
| 24 | import org.jaudiotagger.tag.mp4.Mp4TagField; | |
| 25 | import org.jaudiotagger.tag.mp4.atom.Mp4DataBox; | |
| 26 | ||
| 27 | import java.io.UnsupportedEncodingException; | |
| 28 | import java.nio.ByteBuffer; | |
| 29 | ||
| 30 | /** | |
| 31 | * Represents a single text field | |
| 32 | * <p/> | |
| 33 | * <p>Mp4 metadata normally held as follows: | |
| 34 | * <pre> | |
| 35 | * MP4Box Parent contains | |
| 36 | * :length (includes length of data child) (4 bytes) | |
| 37 | * :name (4 bytes) | |
| 38 | * :child with | |
| 39 | * :length (4 bytes) | |
| 40 | * :name 'Data' (4 bytes) | |
| 41 | * :atom version (1 byte) | |
| 42 | * :atom type flags (3 bytes) | |
| 43 | * :null field (4 bytes) | |
| 44 | * :data | |
| 45 | * </pre> | |
| 46 | * <p/> | |
| 47 | * <p>Note:This class is initilized with the child data atom only, the parent data has already been processed, this may | |
| 48 | * change as it seems that code should probably be enscapulated into this. Whereas the raw content returned by the | |
| 49 | * getRawContent() contais the byte data for parent and child. | |
| 50 | */ | |
| 51 | public class Mp4TagTextField extends Mp4TagField implements TagTextField | |
| 52 | { | |
| 53 | protected int dataSize; | |
| 54 | protected String content; | |
| 55 | ||
| 56 | /** | |
| 57 | * Construct from File | |
| 58 | * | |
| 59 | * @param id parent id | |
| 60 | * @param data atom data | |
| 61 | * @throws UnsupportedEncodingException | |
| 62 | */ | |
| 63 | public Mp4TagTextField(String id, ByteBuffer data) throws UnsupportedEncodingException | |
| 64 | { | |
| 65 | 5801 | super(id, data); |
| 66 | 5801 | } |
| 67 | ||
| 68 | /** | |
| 69 | * Construct new Field | |
| 70 | * | |
| 71 | * @param id parent id | |
| 72 | * @param content data atom data | |
| 73 | */ | |
| 74 | public Mp4TagTextField(String id, String content) | |
| 75 | { | |
| 76 | 622 | super(id); |
| 77 | 622 | this.content = content; |
| 78 | 622 | } |
| 79 | ||
| 80 | protected void build(ByteBuffer data) throws UnsupportedEncodingException | |
| 81 | { | |
| 82 | //Data actually contains a 'Data' Box so process data using this | |
| 83 | 4156 | Mp4BoxHeader header = new Mp4BoxHeader(data); |
| 84 | 4156 | Mp4DataBox databox = new Mp4DataBox(header, data); |
| 85 | 4156 | dataSize = header.getDataLength(); |
| 86 | 4156 | content = databox.getContent(); |
| 87 | 4156 | } |
| 88 | ||
| 89 | public void copyContent(TagField field) | |
| 90 | { | |
| 91 | 0 | if (field instanceof Mp4TagTextField) |
| 92 | { | |
| 93 | 0 | this.content = ((Mp4TagTextField) field).getContent(); |
| 94 | } | |
| 95 | 0 | } |
| 96 | ||
| 97 | public String getContent() | |
| 98 | { | |
| 99 | 202 | return content; |
| 100 | } | |
| 101 | ||
| 102 | protected byte[] getDataBytes() throws UnsupportedEncodingException | |
| 103 | { | |
| 104 | 1934 | return content.getBytes(getEncoding()); |
| 105 | } | |
| 106 | ||
| 107 | public Mp4FieldType getFieldType() | |
| 108 | { | |
| 109 | 1934 | return Mp4FieldType.TEXT; |
| 110 | } | |
| 111 | ||
| 112 | public String getEncoding() | |
| 113 | { | |
| 114 | 1934 | return Mp4BoxHeader.CHARSET_UTF_8; |
| 115 | } | |
| 116 | ||
| 117 | ||
| 118 | public boolean isBinary() | |
| 119 | { | |
| 120 | 0 | return false; |
| 121 | } | |
| 122 | ||
| 123 | public boolean isEmpty() | |
| 124 | { | |
| 125 | 0 | return this.content.trim().equals(""); |
| 126 | } | |
| 127 | ||
| 128 | public void setContent(String s) | |
| 129 | { | |
| 130 | 0 | this.content = s; |
| 131 | 0 | } |
| 132 | ||
| 133 | public void setEncoding(String s) | |
| 134 | { | |
| 135 | /* Not allowed */ | |
| 136 | 0 | } |
| 137 | ||
| 138 | public String toString() | |
| 139 | { | |
| 140 | 4933 | return content; |
| 141 | } | |
| 142 | } |