File: IptcDirectory.java

package info (click to toggle)
libmetadata-extractor-java 2.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 6,416 kB
  • sloc: java: 35,343; xml: 200; sh: 11; makefile: 2
file content (318 lines) | stat: -rw-r--r-- 16,213 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*
 * Copyright 2002-2017 Drew Noakes
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 *
 * More information about this project is available at:
 *
 *    https://drewnoakes.com/code/exif/
 *    https://github.com/drewnoakes/metadata-extractor
 */
package com.drew.metadata.iptc;

import com.drew.lang.annotations.NotNull;
import com.drew.lang.annotations.Nullable;
import com.drew.metadata.Directory;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * Describes tags used by the International Press Telecommunications Council (IPTC) metadata format.
 *
 * @author Drew Noakes https://drewnoakes.com
 */
@SuppressWarnings("WeakerAccess")
public class IptcDirectory extends Directory
{
    // IPTC EnvelopeRecord Tags
    public static final int TAG_ENVELOPE_RECORD_VERSION          = 0x0100; // 0 + 0x0100
    public static final int TAG_DESTINATION                      = 0x0105; // 5
    public static final int TAG_FILE_FORMAT                      = 0x0114; // 20
    public static final int TAG_FILE_VERSION                     = 0x0116; // 22
    public static final int TAG_SERVICE_ID                       = 0x011E; // 30
    public static final int TAG_ENVELOPE_NUMBER                  = 0x0128; // 40
    public static final int TAG_PRODUCT_ID                       = 0x0132; // 50
    public static final int TAG_ENVELOPE_PRIORITY                = 0x013C; // 60
    public static final int TAG_DATE_SENT                        = 0x0146; // 70
    public static final int TAG_TIME_SENT                        = 0x0150; // 80
    public static final int TAG_CODED_CHARACTER_SET              = 0x015A; // 90
    public static final int TAG_UNIQUE_OBJECT_NAME               = 0x0164; // 100
    public static final int TAG_ARM_IDENTIFIER                   = 0x0178; // 120
    public static final int TAG_ARM_VERSION                      = 0x017a; // 122

    // IPTC ApplicationRecord Tags
    public static final int TAG_APPLICATION_RECORD_VERSION       = 0x0200; // 0 + 0x0200
    public static final int TAG_OBJECT_TYPE_REFERENCE            = 0x0203; // 3
    public static final int TAG_OBJECT_ATTRIBUTE_REFERENCE       = 0x0204; // 4
    public static final int TAG_OBJECT_NAME                      = 0x0205; // 5
    public static final int TAG_EDIT_STATUS                      = 0x0207; // 7
    public static final int TAG_EDITORIAL_UPDATE                 = 0x0208; // 8
    public static final int TAG_URGENCY                          = 0X020A; // 10
    public static final int TAG_SUBJECT_REFERENCE                = 0X020C; // 12
    public static final int TAG_CATEGORY                         = 0x020F; // 15
    public static final int TAG_SUPPLEMENTAL_CATEGORIES          = 0x0214; // 20
    public static final int TAG_FIXTURE_ID                       = 0x0216; // 22
    public static final int TAG_KEYWORDS                         = 0x0219; // 25
    public static final int TAG_CONTENT_LOCATION_CODE            = 0x021A; // 26
    public static final int TAG_CONTENT_LOCATION_NAME            = 0x021B; // 27
    public static final int TAG_RELEASE_DATE                     = 0X021E; // 30
    public static final int TAG_RELEASE_TIME                     = 0x0223; // 35
    public static final int TAG_EXPIRATION_DATE                  = 0x0225; // 37
    public static final int TAG_EXPIRATION_TIME                  = 0x0226; // 38
    public static final int TAG_SPECIAL_INSTRUCTIONS             = 0x0228; // 40
    public static final int TAG_ACTION_ADVISED                   = 0x022A; // 42
    public static final int TAG_REFERENCE_SERVICE                = 0x022D; // 45
    public static final int TAG_REFERENCE_DATE                   = 0x022F; // 47
    public static final int TAG_REFERENCE_NUMBER                 = 0x0232; // 50
    public static final int TAG_DATE_CREATED                     = 0x0237; // 55
    public static final int TAG_TIME_CREATED                     = 0X023C; // 60
    public static final int TAG_DIGITAL_DATE_CREATED             = 0x023E; // 62
    public static final int TAG_DIGITAL_TIME_CREATED             = 0x023F; // 63
    public static final int TAG_ORIGINATING_PROGRAM              = 0x0241; // 65
    public static final int TAG_PROGRAM_VERSION                  = 0x0246; // 70
    public static final int TAG_OBJECT_CYCLE                     = 0x024B; // 75
    public static final int TAG_BY_LINE                          = 0x0250; // 80
    public static final int TAG_BY_LINE_TITLE                    = 0x0255; // 85
    public static final int TAG_CITY                             = 0x025A; // 90
    public static final int TAG_SUB_LOCATION                     = 0x025C; // 92
    public static final int TAG_PROVINCE_OR_STATE                = 0x025F; // 95
    public static final int TAG_COUNTRY_OR_PRIMARY_LOCATION_CODE = 0x0264; // 100
    public static final int TAG_COUNTRY_OR_PRIMARY_LOCATION_NAME = 0x0265; // 101
    public static final int TAG_ORIGINAL_TRANSMISSION_REFERENCE  = 0x0267; // 103
    public static final int TAG_HEADLINE                         = 0x0269; // 105
    public static final int TAG_CREDIT                           = 0x026E; // 110
    public static final int TAG_SOURCE                           = 0x0273; // 115
    public static final int TAG_COPYRIGHT_NOTICE                 = 0x0274; // 116
    public static final int TAG_CONTACT                          = 0x0276; // 118
    public static final int TAG_CAPTION                          = 0x0278; // 120
    public static final int TAG_LOCAL_CAPTION                    = 0x0279; // 121
    public static final int TAG_CAPTION_WRITER                   = 0x027A; // 122
    public static final int TAG_RASTERIZED_CAPTION               = 0x027D; // 125
    public static final int TAG_IMAGE_TYPE                       = 0x0282; // 130
    public static final int TAG_IMAGE_ORIENTATION                = 0x0283; // 131
    public static final int TAG_LANGUAGE_IDENTIFIER              = 0x0287; // 135
    public static final int TAG_AUDIO_TYPE                       = 0x0296; // 150
    public static final int TAG_AUDIO_SAMPLING_RATE              = 0x0297; // 151
    public static final int TAG_AUDIO_SAMPLING_RESOLUTION        = 0x0298; // 152
    public static final int TAG_AUDIO_DURATION                   = 0x0299; // 153
    public static final int TAG_AUDIO_OUTCUE                     = 0x029A; // 154

    public static final int TAG_JOB_ID                           = 0x02B8; // 184
    public static final int TAG_MASTER_DOCUMENT_ID               = 0x02B9; // 185
    public static final int TAG_SHORT_DOCUMENT_ID                = 0x02BA; // 186
    public static final int TAG_UNIQUE_DOCUMENT_ID               = 0x02BB; // 187
    public static final int TAG_OWNER_ID                         = 0x02BC; // 188

    public static final int TAG_OBJECT_PREVIEW_FILE_FORMAT       = 0x02C8; // 200
    public static final int TAG_OBJECT_PREVIEW_FILE_FORMAT_VERSION  = 0x02C9; // 201
    public static final int TAG_OBJECT_PREVIEW_DATA              = 0x02CA; // 202

    @NotNull
    protected static final HashMap<Integer, String> _tagNameMap = new HashMap<Integer, String>();

    static
    {
        _tagNameMap.put(TAG_ENVELOPE_RECORD_VERSION, "Enveloped Record Version");
        _tagNameMap.put(TAG_DESTINATION, "Destination");
        _tagNameMap.put(TAG_FILE_FORMAT, "File Format");
        _tagNameMap.put(TAG_FILE_VERSION, "File Version");
        _tagNameMap.put(TAG_SERVICE_ID, "Service Identifier");
        _tagNameMap.put(TAG_ENVELOPE_NUMBER, "Envelope Number");
        _tagNameMap.put(TAG_PRODUCT_ID, "Product Identifier");
        _tagNameMap.put(TAG_ENVELOPE_PRIORITY, "Envelope Priority");
        _tagNameMap.put(TAG_DATE_SENT, "Date Sent");
        _tagNameMap.put(TAG_TIME_SENT, "Time Sent");
        _tagNameMap.put(TAG_CODED_CHARACTER_SET, "Coded Character Set");
        _tagNameMap.put(TAG_UNIQUE_OBJECT_NAME, "Unique Object Name");
        _tagNameMap.put(TAG_ARM_IDENTIFIER, "ARM Identifier");
        _tagNameMap.put(TAG_ARM_VERSION, "ARM Version");

        _tagNameMap.put(TAG_APPLICATION_RECORD_VERSION, "Application Record Version");
        _tagNameMap.put(TAG_OBJECT_TYPE_REFERENCE, "Object Type Reference");
        _tagNameMap.put(TAG_OBJECT_ATTRIBUTE_REFERENCE, "Object Attribute Reference");
        _tagNameMap.put(TAG_OBJECT_NAME, "Object Name");
        _tagNameMap.put(TAG_EDIT_STATUS, "Edit Status");
        _tagNameMap.put(TAG_EDITORIAL_UPDATE, "Editorial Update");
        _tagNameMap.put(TAG_URGENCY, "Urgency");
        _tagNameMap.put(TAG_SUBJECT_REFERENCE, "Subject Reference");
        _tagNameMap.put(TAG_CATEGORY, "Category");
        _tagNameMap.put(TAG_SUPPLEMENTAL_CATEGORIES, "Supplemental Category(s)");
        _tagNameMap.put(TAG_FIXTURE_ID, "Fixture Identifier");
        _tagNameMap.put(TAG_KEYWORDS, "Keywords");
        _tagNameMap.put(TAG_CONTENT_LOCATION_CODE, "Content Location Code");
        _tagNameMap.put(TAG_CONTENT_LOCATION_NAME, "Content Location Name");
        _tagNameMap.put(TAG_RELEASE_DATE, "Release Date");
        _tagNameMap.put(TAG_RELEASE_TIME, "Release Time");
        _tagNameMap.put(TAG_EXPIRATION_DATE, "Expiration Date");
        _tagNameMap.put(TAG_EXPIRATION_TIME, "Expiration Time");
        _tagNameMap.put(TAG_SPECIAL_INSTRUCTIONS, "Special Instructions");
        _tagNameMap.put(TAG_ACTION_ADVISED, "Action Advised");
        _tagNameMap.put(TAG_REFERENCE_SERVICE, "Reference Service");
        _tagNameMap.put(TAG_REFERENCE_DATE, "Reference Date");
        _tagNameMap.put(TAG_REFERENCE_NUMBER, "Reference Number");
        _tagNameMap.put(TAG_DATE_CREATED, "Date Created");
        _tagNameMap.put(TAG_TIME_CREATED, "Time Created");
        _tagNameMap.put(TAG_DIGITAL_DATE_CREATED, "Digital Date Created");
        _tagNameMap.put(TAG_DIGITAL_TIME_CREATED, "Digital Time Created");
        _tagNameMap.put(TAG_ORIGINATING_PROGRAM, "Originating Program");
        _tagNameMap.put(TAG_PROGRAM_VERSION, "Program Version");
        _tagNameMap.put(TAG_OBJECT_CYCLE, "Object Cycle");
        _tagNameMap.put(TAG_BY_LINE, "By-line");
        _tagNameMap.put(TAG_BY_LINE_TITLE, "By-line Title");
        _tagNameMap.put(TAG_CITY, "City");
        _tagNameMap.put(TAG_SUB_LOCATION, "Sub-location");
        _tagNameMap.put(TAG_PROVINCE_OR_STATE, "Province/State");
        _tagNameMap.put(TAG_COUNTRY_OR_PRIMARY_LOCATION_CODE, "Country/Primary Location Code");
        _tagNameMap.put(TAG_COUNTRY_OR_PRIMARY_LOCATION_NAME, "Country/Primary Location Name");
        _tagNameMap.put(TAG_ORIGINAL_TRANSMISSION_REFERENCE, "Original Transmission Reference");
        _tagNameMap.put(TAG_HEADLINE, "Headline");
        _tagNameMap.put(TAG_CREDIT, "Credit");
        _tagNameMap.put(TAG_SOURCE, "Source");
        _tagNameMap.put(TAG_COPYRIGHT_NOTICE, "Copyright Notice");
        _tagNameMap.put(TAG_CONTACT, "Contact");
        _tagNameMap.put(TAG_CAPTION, "Caption/Abstract");
        _tagNameMap.put(TAG_LOCAL_CAPTION, "Local Caption");
        _tagNameMap.put(TAG_CAPTION_WRITER, "Caption Writer/Editor");
        _tagNameMap.put(TAG_RASTERIZED_CAPTION, "Rasterized Caption");
        _tagNameMap.put(TAG_IMAGE_TYPE, "Image Type");
        _tagNameMap.put(TAG_IMAGE_ORIENTATION, "Image Orientation");
        _tagNameMap.put(TAG_LANGUAGE_IDENTIFIER, "Language Identifier");
        _tagNameMap.put(TAG_AUDIO_TYPE, "Audio Type");
        _tagNameMap.put(TAG_AUDIO_SAMPLING_RATE, "Audio Sampling Rate");
        _tagNameMap.put(TAG_AUDIO_SAMPLING_RESOLUTION, "Audio Sampling Resolution");
        _tagNameMap.put(TAG_AUDIO_DURATION, "Audio Duration");
        _tagNameMap.put(TAG_AUDIO_OUTCUE, "Audio Outcue");

        _tagNameMap.put(TAG_JOB_ID, "Job Identifier");
        _tagNameMap.put(TAG_MASTER_DOCUMENT_ID, "Master Document Identifier");
        _tagNameMap.put(TAG_SHORT_DOCUMENT_ID, "Short Document Identifier");
        _tagNameMap.put(TAG_UNIQUE_DOCUMENT_ID, "Unique Document Identifier");
        _tagNameMap.put(TAG_OWNER_ID, "Owner Identifier");

        _tagNameMap.put(TAG_OBJECT_PREVIEW_FILE_FORMAT, "Object Data Preview File Format");
        _tagNameMap.put(TAG_OBJECT_PREVIEW_FILE_FORMAT_VERSION, "Object Data Preview File Format Version");
        _tagNameMap.put(TAG_OBJECT_PREVIEW_DATA, "Object Data Preview Data");
    }

    public IptcDirectory()
    {
        this.setDescriptor(new IptcDescriptor(this));
    }

    @Override
    @NotNull
    public String getName()
    {
        return "IPTC";
    }

    @Override
    @NotNull
    protected HashMap<Integer, String> getTagNameMap()
    {
        return _tagNameMap;
    }

    /**
     * Returns any keywords contained in the IPTC data.  This value may be <code>null</code>.
     */
    @Nullable
    public List<String> getKeywords()
    {
        final String[] array = getStringArray(TAG_KEYWORDS);
        if (array==null)
            return null;
        return Arrays.asList(array);
    }

    /**
     * Parses the Date Sent tag and the Time Sent tag to obtain a single Date object representing the
     * date and time when the service sent this image.
     * @return A Date object representing when the service sent this image, if possible, otherwise null
     */
    @Nullable
    public Date getDateSent()
    {
        return getDate(TAG_DATE_SENT, TAG_TIME_SENT);
    }

    /**
     * Parses the Release Date tag and the Release Time tag to obtain a single Date object representing the
     * date and time when this image was released.
     * @return A Date object representing when this image was released, if possible, otherwise null
     */
    @Nullable
    public Date getReleaseDate()
    {
        return getDate(TAG_RELEASE_DATE, TAG_RELEASE_TIME);
    }

    /**
     * Parses the Expiration Date tag and the Expiration Time tag to obtain a single Date object representing
     * that this image should not used after this date and time.
     * @return A Date object representing when this image was released, if possible, otherwise null
     */
    @Nullable
    public Date getExpirationDate()
    {
        return getDate(TAG_EXPIRATION_DATE, TAG_EXPIRATION_TIME);
    }

    /**
     * Parses the Date Created tag and the Time Created tag to obtain a single Date object representing the
     * date and time when this image was captured.
     * @return A Date object representing when this image was captured, if possible, otherwise null
     */
    @Nullable
    public Date getDateCreated()
    {
        return getDate(TAG_DATE_CREATED, TAG_TIME_CREATED);
    }

    /**
     * Parses the Digital Date Created tag and the Digital Time Created tag to obtain a single Date object
     * representing the date and time when the digital representation of this image was created.
     * @return A Date object representing when the digital representation of this image was created,
     * if possible, otherwise null
     */
    @Nullable
    public Date getDigitalDateCreated()
    {
        return getDate(TAG_DIGITAL_DATE_CREATED, TAG_DIGITAL_TIME_CREATED);
    }

    @Nullable
    private Date getDate(int dateTagType, int timeTagType)
    {
        String date = getString(dateTagType);
        String time = getString(timeTagType);

        if (date == null)
            return null;
        if (time == null)
            return null;

        try {
            DateFormat parser = new SimpleDateFormat("yyyyMMddHHmmssZ");
            return parser.parse(date + time);
        } catch (ParseException e) {
            return null;
        }
    }
}