| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
package org.jaudiotagger.audio.asf.data; |
| 20 | |
|
| 21 | |
import org.jaudiotagger.audio.asf.util.Utils; |
| 22 | |
|
| 23 | |
import java.io.IOException; |
| 24 | |
import java.io.OutputStream; |
| 25 | |
import java.math.BigInteger; |
| 26 | |
import java.util.Arrays; |
| 27 | |
import java.util.HashSet; |
| 28 | |
import java.util.Set; |
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
public final class ContentDescription extends MetadataContainer { |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
public final static Set<String> ALLOWED; |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
public final static String KEY_AUTHOR = "AUTHOR"; |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
public final static String KEY_COPYRIGHT = "COPYRIGHT"; |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
public final static String KEY_DESCRIPTION = "DESCRIPTION"; |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
public final static String KEY_RATING = "RATING"; |
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
public final static String KEY_TITLE = "TITLE"; |
| 67 | |
|
| 68 | |
static { |
| 69 | 4 | ALLOWED = new HashSet<String>(Arrays.asList(KEY_AUTHOR, |
| 70 | |
KEY_COPYRIGHT, KEY_DESCRIPTION, KEY_RATING, KEY_TITLE)); |
| 71 | 4 | } |
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
public ContentDescription() { |
| 77 | 4 | this(0, BigInteger.ZERO); |
| 78 | 4 | } |
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
public ContentDescription(final long pos,final BigInteger chunkLen) { |
| 89 | 504 | super(ContainerType.CONTENT_DESCRIPTION, pos, chunkLen); |
| 90 | 488 | } |
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
public String getAuthor() { |
| 96 | 473 | return getValueFor(KEY_AUTHOR); |
| 97 | |
} |
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
public String getComment() { |
| 103 | 473 | return getValueFor(KEY_DESCRIPTION); |
| 104 | |
} |
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
public String getCopyRight() { |
| 110 | 473 | return getValueFor(KEY_COPYRIGHT); |
| 111 | |
} |
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
@Override |
| 117 | |
public long getCurrentAsfChunkSize() { |
| 118 | 279 | long result = 44; |
| 119 | |
|
| 120 | |
|
| 121 | 279 | result += getAuthor().length() * 2; |
| 122 | 279 | result += getComment().length() * 2; |
| 123 | 279 | result += getRating().length() * 2; |
| 124 | 279 | result += getTitle().length() * 2; |
| 125 | 279 | result += getCopyRight().length() * 2; |
| 126 | 279 | return result; |
| 127 | |
} |
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
public String getRating() { |
| 133 | 473 | return getValueFor(KEY_RATING); |
| 134 | |
} |
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
public String getTitle() { |
| 140 | 473 | return getValueFor(KEY_TITLE); |
| 141 | |
} |
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
@Override |
| 147 | |
public boolean isAddSupported(final MetadataDescriptor descriptor) { |
| 148 | 4174 | return ALLOWED.contains(descriptor.getName()) |
| 149 | |
&& super.isAddSupported(descriptor); |
| 150 | |
} |
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
@Override |
| 157 | |
public String prettyPrint(final String prefix) { |
| 158 | 0 | final StringBuilder result = new StringBuilder(super.prettyPrint(prefix)); |
| 159 | 0 | result.append(prefix).append(" |->Title : ").append(getTitle()) |
| 160 | |
.append(Utils.LINE_SEPARATOR); |
| 161 | 0 | result.append(prefix).append(" |->Author : ").append(getAuthor()) |
| 162 | |
.append(Utils.LINE_SEPARATOR); |
| 163 | 0 | result.append(prefix).append(" |->Copyright : ").append( |
| 164 | |
getCopyRight()).append(Utils.LINE_SEPARATOR); |
| 165 | 0 | result.append(prefix).append(" |->Description: ").append(getComment()) |
| 166 | |
.append(Utils.LINE_SEPARATOR); |
| 167 | 0 | result.append(prefix).append(" |->Rating :").append(getRating()) |
| 168 | |
.append(Utils.LINE_SEPARATOR); |
| 169 | 0 | return result.toString(); |
| 170 | |
} |
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
public void setAuthor(final String fileAuthor) throws IllegalArgumentException { |
| 180 | 307 | setStringValue(KEY_AUTHOR, fileAuthor); |
| 181 | 303 | } |
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
public void setComment(final String tagComment) throws IllegalArgumentException { |
| 191 | 295 | setStringValue(KEY_DESCRIPTION, tagComment); |
| 192 | 291 | } |
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | |
public void setCopyright(final String cpright) throws IllegalArgumentException { |
| 202 | 293 | setStringValue(KEY_COPYRIGHT, cpright); |
| 203 | 289 | } |
| 204 | |
|
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
public void setRating(final String ratingText) throws IllegalArgumentException { |
| 213 | 157 | setStringValue(KEY_RATING, ratingText); |
| 214 | 153 | } |
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
public void setTitle(final String songTitle) throws IllegalArgumentException { |
| 224 | 307 | setStringValue(KEY_TITLE, songTitle); |
| 225 | 303 | } |
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | |
@Override |
| 231 | |
public long writeInto(final OutputStream out) throws IOException { |
| 232 | 93 | final long chunkSize = getCurrentAsfChunkSize(); |
| 233 | |
|
| 234 | 93 | out.write(this.getGuid().getBytes()); |
| 235 | 93 | Utils.writeUINT64(getCurrentAsfChunkSize(), out); |
| 236 | |
|
| 237 | |
|
| 238 | 93 | Utils.writeUINT16(getTitle().length() * 2 + 2, out); |
| 239 | 93 | Utils.writeUINT16(getAuthor().length() * 2 + 2, out); |
| 240 | 93 | Utils.writeUINT16(getCopyRight().length() * 2 + 2, out); |
| 241 | 93 | Utils.writeUINT16(getComment().length() * 2 + 2, out); |
| 242 | 93 | Utils.writeUINT16(getRating().length() * 2 + 2, out); |
| 243 | |
|
| 244 | 93 | out.write(Utils.getBytes(getTitle(), AsfHeader.ASF_CHARSET)); |
| 245 | 93 | out.write(AsfHeader.ZERO_TERM); |
| 246 | 93 | out.write(Utils.getBytes(getAuthor(), AsfHeader.ASF_CHARSET)); |
| 247 | 93 | out.write(AsfHeader.ZERO_TERM); |
| 248 | 93 | out.write(Utils.getBytes(getCopyRight(), AsfHeader.ASF_CHARSET)); |
| 249 | 93 | out.write(AsfHeader.ZERO_TERM); |
| 250 | 93 | out.write(Utils.getBytes(getComment(), AsfHeader.ASF_CHARSET)); |
| 251 | 93 | out.write(AsfHeader.ZERO_TERM); |
| 252 | 93 | out.write(Utils.getBytes(getRating(), AsfHeader.ASF_CHARSET)); |
| 253 | 93 | out.write(AsfHeader.ZERO_TERM); |
| 254 | 93 | return chunkSize; |
| 255 | |
} |
| 256 | |
} |