source: josm/trunk/src/com/drew/metadata/iptc/IptcDescriptor.java@ 13061

Last change on this file since 13061 was 13061, checked in by Don-vip, 7 years ago

fix #15505 - update to metadata-extractor 2.10.1

File size: 9.8 KB
Line 
1/*
2 * Copyright 2002-2017 Drew Noakes
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * More information about this project is available at:
17 *
18 * https://drewnoakes.com/code/exif/
19 * https://github.com/drewnoakes/metadata-extractor
20 */
21package com.drew.metadata.iptc;
22
23import com.drew.lang.StringUtil;
24import com.drew.lang.annotations.NotNull;
25import com.drew.lang.annotations.Nullable;
26import com.drew.metadata.TagDescriptor;
27
28import static com.drew.metadata.iptc.IptcDirectory.*;
29
30/**
31 * Provides human-readable string representations of tag values stored in a {@link IptcDirectory}.
32 * <p>
33 * As the IPTC directory already stores values as strings, this class simply returns the tag's value.
34 *
35 * @author Drew Noakes https://drewnoakes.com
36 */
37@SuppressWarnings("WeakerAccess")
38public class IptcDescriptor extends TagDescriptor<IptcDirectory>
39{
40 public IptcDescriptor(@NotNull IptcDirectory directory)
41 {
42 super(directory);
43 }
44
45 @Override
46 @Nullable
47 public String getDescription(int tagType)
48 {
49 switch (tagType) {
50 case TAG_DATE_CREATED:
51 return getDateCreatedDescription();
52 case TAG_DIGITAL_DATE_CREATED:
53 return getDigitalDateCreatedDescription();
54 case TAG_DATE_SENT:
55 return getDateSentDescription();
56 case TAG_EXPIRATION_DATE:
57 return getExpirationDateDescription();
58 case TAG_EXPIRATION_TIME:
59 return getExpirationTimeDescription();
60 case TAG_FILE_FORMAT:
61 return getFileFormatDescription();
62 case TAG_KEYWORDS:
63 return getKeywordsDescription();
64 case TAG_REFERENCE_DATE:
65 return getReferenceDateDescription();
66 case TAG_RELEASE_DATE:
67 return getReleaseDateDescription();
68 case TAG_RELEASE_TIME:
69 return getReleaseTimeDescription();
70 case TAG_TIME_CREATED:
71 return getTimeCreatedDescription();
72 case TAG_DIGITAL_TIME_CREATED:
73 return getDigitalTimeCreatedDescription();
74 case TAG_TIME_SENT:
75 return getTimeSentDescription();
76 default:
77 return super.getDescription(tagType);
78 }
79 }
80
81 @Nullable
82 public String getDateDescription(int tagType)
83 {
84 String s = _directory.getString(tagType);
85 if (s == null)
86 return null;
87 if (s.length() == 8)
88 return s.substring(0, 4) + ':' + s.substring(4, 6) + ':' + s.substring(6);
89 return s;
90 }
91
92 @Nullable
93 public String getTimeDescription(int tagType)
94 {
95 String s = _directory.getString(tagType);
96 if (s == null)
97 return null;
98 if (s.length() == 6 || s.length() == 11)
99 return s.substring(0, 2) + ':' + s.substring(2, 4) + ':' + s.substring(4);
100 return s;
101 }
102
103 @Nullable
104 public String getFileFormatDescription()
105 {
106 Integer value = _directory.getInteger(TAG_FILE_FORMAT);
107 if (value == null)
108 return null;
109 switch (value) {
110 case 0: return "No ObjectData";
111 case 1: return "IPTC-NAA Digital Newsphoto Parameter Record";
112 case 2: return "IPTC7901 Recommended Message Format";
113 case 3: return "Tagged Image File Format (Adobe/Aldus Image data)";
114 case 4: return "Illustrator (Adobe Graphics data)";
115 case 5: return "AppleSingle (Apple Computer Inc)";
116 case 6: return "NAA 89-3 (ANPA 1312)";
117 case 7: return "MacBinary II";
118 case 8: return "IPTC Unstructured Character Oriented File Format (UCOFF)";
119 case 9: return "United Press International ANPA 1312 variant";
120 case 10: return "United Press International Down-Load Message";
121 case 11: return "JPEG File Interchange (JFIF)";
122 case 12: return "Photo-CD Image-Pac (Eastman Kodak)";
123 case 13: return "Bit Mapped Graphics File [.BMP] (Microsoft)";
124 case 14: return "Digital Audio File [.WAV] (Microsoft & Creative Labs)";
125 case 15: return "Audio plus Moving Video [.AVI] (Microsoft)";
126 case 16: return "PC DOS/Windows Executable Files [.COM][.EXE]";
127 case 17: return "Compressed Binary File [.ZIP] (PKWare Inc)";
128 case 18: return "Audio Interchange File Format AIFF (Apple Computer Inc)";
129 case 19: return "RIFF Wave (Microsoft Corporation)";
130 case 20: return "Freehand (Macromedia/Aldus)";
131 case 21: return "Hypertext Markup Language [.HTML] (The Internet Society)";
132 case 22: return "MPEG 2 Audio Layer 2 (Musicom), ISO/IEC";
133 case 23: return "MPEG 2 Audio Layer 3, ISO/IEC";
134 case 24: return "Portable Document File [.PDF] Adobe";
135 case 25: return "News Industry Text Format (NITF)";
136 case 26: return "Tape Archive [.TAR]";
137 case 27: return "Tidningarnas Telegrambyra NITF version (TTNITF DTD)";
138 case 28: return "Ritzaus Bureau NITF version (RBNITF DTD)";
139 case 29: return "Corel Draw [.CDR]";
140 }
141 return String.format("Unknown (%d)", value);
142 }
143
144 @Nullable
145 public String getByLineDescription()
146 {
147 return _directory.getString(TAG_BY_LINE);
148 }
149
150 @Nullable
151 public String getByLineTitleDescription()
152 {
153 return _directory.getString(TAG_BY_LINE_TITLE);
154 }
155
156 @Nullable
157 public String getCaptionDescription()
158 {
159 return _directory.getString(TAG_CAPTION);
160 }
161
162 @Nullable
163 public String getCategoryDescription()
164 {
165 return _directory.getString(TAG_CATEGORY);
166 }
167
168 @Nullable
169 public String getCityDescription()
170 {
171 return _directory.getString(TAG_CITY);
172 }
173
174 @Nullable
175 public String getCopyrightNoticeDescription()
176 {
177 return _directory.getString(TAG_COPYRIGHT_NOTICE);
178 }
179
180 @Nullable
181 public String getCountryOrPrimaryLocationDescription()
182 {
183 return _directory.getString(TAG_COUNTRY_OR_PRIMARY_LOCATION_NAME);
184 }
185
186 @Nullable
187 public String getCreditDescription()
188 {
189 return _directory.getString(TAG_CREDIT);
190 }
191
192 @Nullable
193 public String getDateCreatedDescription()
194 {
195 return getDateDescription(TAG_DATE_CREATED);
196 }
197
198 @Nullable
199 public String getDigitalDateCreatedDescription()
200 {
201 return getDateDescription(TAG_DIGITAL_DATE_CREATED);
202 }
203
204 @Nullable
205 public String getDateSentDescription()
206 {
207 return getDateDescription(TAG_DATE_SENT);
208 }
209
210 @Nullable
211 public String getExpirationDateDescription()
212 {
213 return getDateDescription(TAG_EXPIRATION_DATE);
214 }
215
216 @Nullable
217 public String getExpirationTimeDescription()
218 {
219 return getTimeDescription(TAG_EXPIRATION_TIME);
220 }
221
222 @Nullable
223 public String getHeadlineDescription()
224 {
225 return _directory.getString(TAG_HEADLINE);
226 }
227
228 @Nullable
229 public String getKeywordsDescription()
230 {
231 final String[] keywords = _directory.getStringArray(TAG_KEYWORDS);
232 if (keywords==null)
233 return null;
234 return StringUtil.join(keywords, ";");
235 }
236
237 @Nullable
238 public String getObjectNameDescription()
239 {
240 return _directory.getString(TAG_OBJECT_NAME);
241 }
242
243 @Nullable
244 public String getOriginalTransmissionReferenceDescription()
245 {
246 return _directory.getString(TAG_ORIGINAL_TRANSMISSION_REFERENCE);
247 }
248
249 @Nullable
250 public String getOriginatingProgramDescription()
251 {
252 return _directory.getString(TAG_ORIGINATING_PROGRAM);
253 }
254
255 @Nullable
256 public String getProvinceOrStateDescription()
257 {
258 return _directory.getString(TAG_PROVINCE_OR_STATE);
259 }
260
261 @Nullable
262 public String getRecordVersionDescription()
263 {
264 return _directory.getString(TAG_APPLICATION_RECORD_VERSION);
265 }
266
267 @Nullable
268 public String getReferenceDateDescription()
269 {
270 return getDateDescription(TAG_REFERENCE_DATE);
271 }
272
273 @Nullable
274 public String getReleaseDateDescription()
275 {
276 return getDateDescription(TAG_RELEASE_DATE);
277 }
278
279 @Nullable
280 public String getReleaseTimeDescription()
281 {
282 return getTimeDescription(TAG_RELEASE_TIME);
283 }
284
285 @Nullable
286 public String getSourceDescription()
287 {
288 return _directory.getString(TAG_SOURCE);
289 }
290
291 @Nullable
292 public String getSpecialInstructionsDescription()
293 {
294 return _directory.getString(TAG_SPECIAL_INSTRUCTIONS);
295 }
296
297 @Nullable
298 public String getSupplementalCategoriesDescription()
299 {
300 return _directory.getString(TAG_SUPPLEMENTAL_CATEGORIES);
301 }
302
303 @Nullable
304 public String getTimeCreatedDescription()
305 {
306 return getTimeDescription(TAG_TIME_CREATED);
307 }
308
309 @Nullable
310 public String getDigitalTimeCreatedDescription()
311 {
312 return getTimeDescription(TAG_DIGITAL_TIME_CREATED);
313 }
314
315 @Nullable
316 public String getTimeSentDescription()
317 {
318 return getTimeDescription(TAG_TIME_SENT);
319 }
320
321 @Nullable
322 public String getUrgencyDescription()
323 {
324 return _directory.getString(TAG_URGENCY);
325 }
326
327 @Nullable
328 public String getWriterDescription()
329 {
330 return _directory.getString(TAG_CAPTION_WRITER);
331 }
332}
Note: See TracBrowser for help on using the repository browser.