Changeset 10862 in josm for trunk/src/com/drew/metadata/iptc


Ignore:
Timestamp:
2016-08-20T20:58:03+02:00 (5 years ago)
Author:
Don-vip
Message:

update to metadata-extractor 2.9.1

Location:
trunk/src/com/drew/metadata/iptc
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/drew/metadata/iptc/IptcDescriptor.java

    r8243 r10862  
    11/*
    2  * Copyright 2002-2015 Drew Noakes
     2 * Copyright 2002-2016 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    2626import com.drew.metadata.TagDescriptor;
    2727
     28import static com.drew.metadata.iptc.IptcDirectory.*;
     29
    2830/**
    2931 * Provides human-readable string representations of tag values stored in a {@link IptcDirectory}.
     
    4547    {
    4648        switch (tagType) {
    47             case IptcDirectory.TAG_FILE_FORMAT:
     49            case TAG_DATE_CREATED:
     50                return getDateCreatedDescription();
     51            case TAG_DIGITAL_DATE_CREATED:
     52                return getDigitalDateCreatedDescription();
     53            case TAG_DATE_SENT:
     54                return getDateSentDescription();
     55            case TAG_EXPIRATION_DATE:
     56                return getExpirationDateDescription();
     57            case TAG_EXPIRATION_TIME:
     58                return getExpirationTimeDescription();
     59            case TAG_FILE_FORMAT:
    4860                return getFileFormatDescription();
    49             case IptcDirectory.TAG_KEYWORDS:
     61            case TAG_KEYWORDS:
    5062                return getKeywordsDescription();
    51             case IptcDirectory.TAG_TIME_CREATED:
     63            case TAG_REFERENCE_DATE:
     64                return getReferenceDateDescription();
     65            case TAG_RELEASE_DATE:
     66                return getReleaseDateDescription();
     67            case TAG_RELEASE_TIME:
     68                return getReleaseTimeDescription();
     69            case TAG_TIME_CREATED:
    5270                return getTimeCreatedDescription();
    53             case IptcDirectory.TAG_DIGITAL_TIME_CREATED:
     71            case TAG_DIGITAL_TIME_CREATED:
    5472                return getDigitalTimeCreatedDescription();
     73            case TAG_TIME_SENT:
     74                return getTimeSentDescription();
    5575            default:
    5676                return super.getDescription(tagType);
     
    5979
    6080    @Nullable
     81    public String getDateDescription(int tagType)
     82    {
     83        String s = _directory.getString(tagType);
     84        if (s == null)
     85            return null;
     86        if (s.length() == 8)
     87            return s.substring(0, 4) + ':' + s.substring(4, 6) + ':' + s.substring(6);
     88        return s;
     89    }
     90
     91    @Nullable
     92    public String getTimeDescription(int tagType)
     93    {
     94        String s = _directory.getString(tagType);
     95        if (s == null)
     96            return null;
     97        if (s.length() == 6 || s.length() == 11)
     98            return s.substring(0, 2) + ':' + s.substring(2, 4) + ':' + s.substring(4);
     99        return s;
     100    }
     101
     102    @Nullable
    61103    public String getFileFormatDescription()
    62104    {
    63         Integer value = _directory.getInteger(IptcDirectory.TAG_FILE_FORMAT);
     105        Integer value = _directory.getInteger(TAG_FILE_FORMAT);
    64106        if (value == null)
    65107            return null;
     
    102144    public String getByLineDescription()
    103145    {
    104         return _directory.getString(IptcDirectory.TAG_BY_LINE);
     146        return _directory.getString(TAG_BY_LINE);
    105147    }
    106148
     
    108150    public String getByLineTitleDescription()
    109151    {
    110         return _directory.getString(IptcDirectory.TAG_BY_LINE_TITLE);
     152        return _directory.getString(TAG_BY_LINE_TITLE);
    111153    }
    112154
     
    114156    public String getCaptionDescription()
    115157    {
    116         return _directory.getString(IptcDirectory.TAG_CAPTION);
     158        return _directory.getString(TAG_CAPTION);
    117159    }
    118160
     
    120162    public String getCategoryDescription()
    121163    {
    122         return _directory.getString(IptcDirectory.TAG_CATEGORY);
     164        return _directory.getString(TAG_CATEGORY);
    123165    }
    124166
     
    126168    public String getCityDescription()
    127169    {
    128         return _directory.getString(IptcDirectory.TAG_CITY);
     170        return _directory.getString(TAG_CITY);
    129171    }
    130172
     
    132174    public String getCopyrightNoticeDescription()
    133175    {
    134         return _directory.getString(IptcDirectory.TAG_COPYRIGHT_NOTICE);
     176        return _directory.getString(TAG_COPYRIGHT_NOTICE);
    135177    }
    136178
     
    138180    public String getCountryOrPrimaryLocationDescription()
    139181    {
    140         return _directory.getString(IptcDirectory.TAG_COUNTRY_OR_PRIMARY_LOCATION_NAME);
     182        return _directory.getString(TAG_COUNTRY_OR_PRIMARY_LOCATION_NAME);
    141183    }
    142184
     
    144186    public String getCreditDescription()
    145187    {
    146         return _directory.getString(IptcDirectory.TAG_CREDIT);
     188        return _directory.getString(TAG_CREDIT);
    147189    }
    148190
     
    150192    public String getDateCreatedDescription()
    151193    {
    152         return _directory.getString(IptcDirectory.TAG_DATE_CREATED);
     194        return getDateDescription(TAG_DATE_CREATED);
     195    }
     196
     197    @Nullable
     198    public String getDigitalDateCreatedDescription()
     199    {
     200        return getDateDescription(TAG_DIGITAL_DATE_CREATED);
     201    }
     202
     203    @Nullable
     204    public String getDateSentDescription()
     205    {
     206        return getDateDescription(TAG_DATE_SENT);
     207    }
     208
     209    @Nullable
     210    public String getExpirationDateDescription()
     211    {
     212        return getDateDescription(TAG_EXPIRATION_DATE);
     213    }
     214
     215    @Nullable
     216    public String getExpirationTimeDescription()
     217    {
     218        return getTimeDescription(TAG_EXPIRATION_TIME);
    153219    }
    154220
     
    156222    public String getHeadlineDescription()
    157223    {
    158         return _directory.getString(IptcDirectory.TAG_HEADLINE);
     224        return _directory.getString(TAG_HEADLINE);
    159225    }
    160226
     
    162228    public String getKeywordsDescription()
    163229    {
    164         final String[] keywords = _directory.getStringArray(IptcDirectory.TAG_KEYWORDS);
     230        final String[] keywords = _directory.getStringArray(TAG_KEYWORDS);
    165231        if (keywords==null)
    166232            return null;
     
    171237    public String getObjectNameDescription()
    172238    {
    173         return _directory.getString(IptcDirectory.TAG_OBJECT_NAME);
     239        return _directory.getString(TAG_OBJECT_NAME);
    174240    }
    175241
     
    177243    public String getOriginalTransmissionReferenceDescription()
    178244    {
    179         return _directory.getString(IptcDirectory.TAG_ORIGINAL_TRANSMISSION_REFERENCE);
     245        return _directory.getString(TAG_ORIGINAL_TRANSMISSION_REFERENCE);
    180246    }
    181247
     
    183249    public String getOriginatingProgramDescription()
    184250    {
    185         return _directory.getString(IptcDirectory.TAG_ORIGINATING_PROGRAM);
     251        return _directory.getString(TAG_ORIGINATING_PROGRAM);
    186252    }
    187253
     
    189255    public String getProvinceOrStateDescription()
    190256    {
    191         return _directory.getString(IptcDirectory.TAG_PROVINCE_OR_STATE);
     257        return _directory.getString(TAG_PROVINCE_OR_STATE);
    192258    }
    193259
     
    195261    public String getRecordVersionDescription()
    196262    {
    197         return _directory.getString(IptcDirectory.TAG_APPLICATION_RECORD_VERSION);
     263        return _directory.getString(TAG_APPLICATION_RECORD_VERSION);
     264    }
     265
     266    @Nullable
     267    public String getReferenceDateDescription()
     268    {
     269        return getDateDescription(TAG_REFERENCE_DATE);
    198270    }
    199271
     
    201273    public String getReleaseDateDescription()
    202274    {
    203         return _directory.getString(IptcDirectory.TAG_RELEASE_DATE);
     275        return getDateDescription(TAG_RELEASE_DATE);
    204276    }
    205277
     
    207279    public String getReleaseTimeDescription()
    208280    {
    209         return _directory.getString(IptcDirectory.TAG_RELEASE_TIME);
     281        return getTimeDescription(TAG_RELEASE_TIME);
    210282    }
    211283
     
    213285    public String getSourceDescription()
    214286    {
    215         return _directory.getString(IptcDirectory.TAG_SOURCE);
     287        return _directory.getString(TAG_SOURCE);
    216288    }
    217289
     
    219291    public String getSpecialInstructionsDescription()
    220292    {
    221         return _directory.getString(IptcDirectory.TAG_SPECIAL_INSTRUCTIONS);
     293        return _directory.getString(TAG_SPECIAL_INSTRUCTIONS);
    222294    }
    223295
     
    225297    public String getSupplementalCategoriesDescription()
    226298    {
    227         return _directory.getString(IptcDirectory.TAG_SUPPLEMENTAL_CATEGORIES);
     299        return _directory.getString(TAG_SUPPLEMENTAL_CATEGORIES);
    228300    }
    229301
     
    231303    public String getTimeCreatedDescription()
    232304    {
    233         String s = _directory.getString(IptcDirectory.TAG_TIME_CREATED);
    234         if (s == null)
    235             return null;
    236         if (s.length() == 6 || s.length() == 11)
    237             return s.substring(0, 2) + ':' + s.substring(2, 4) + ':' + s.substring(4);
    238         return s;
     305        return getTimeDescription(TAG_TIME_CREATED);
    239306    }
    240307
     
    242309    public String getDigitalTimeCreatedDescription()
    243310    {
    244         String s = _directory.getString(IptcDirectory.TAG_DIGITAL_TIME_CREATED);
    245         if (s == null)
    246             return null;
    247         if (s.length() == 6 || s.length() == 11)
    248             return s.substring(0, 2) + ':' + s.substring(2, 4) + ':' + s.substring(4);
    249         return s;
     311        return getTimeDescription(TAG_DIGITAL_TIME_CREATED);
     312    }
     313
     314    @Nullable
     315    public String getTimeSentDescription()
     316    {
     317        return getTimeDescription(TAG_TIME_SENT);
    250318    }
    251319
     
    253321    public String getUrgencyDescription()
    254322    {
    255         return _directory.getString(IptcDirectory.TAG_URGENCY);
     323        return _directory.getString(TAG_URGENCY);
    256324    }
    257325
     
    259327    public String getWriterDescription()
    260328    {
    261         return _directory.getString(IptcDirectory.TAG_CAPTION_WRITER);
     329        return _directory.getString(TAG_CAPTION_WRITER);
    262330    }
    263331}
  • trunk/src/com/drew/metadata/iptc/IptcDirectory.java

    r8132 r10862  
    11/*
    2  * Copyright 2002-2015 Drew Noakes
     2 * Copyright 2002-2016 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    2525import com.drew.metadata.Directory;
    2626
     27import java.text.DateFormat;
     28import java.text.ParseException;
     29import java.text.SimpleDateFormat;
    2730import java.util.Arrays;
     31import java.util.Date;
    2832import java.util.HashMap;
    2933import java.util.List;
     
    231235    public List<String> getKeywords()
    232236    {
    233         final String[] array = getStringArray(IptcDirectory.TAG_KEYWORDS);
     237        final String[] array = getStringArray(TAG_KEYWORDS);
    234238        if (array==null)
    235239            return null;
    236240        return Arrays.asList(array);
    237241    }
     242
     243    /**
     244     * Parses the Date Sent tag and the Time Sent tag to obtain a single Date object representing the
     245     * date and time when the service sent this image.
     246     * @return A Date object representing when the service sent this image, if possible, otherwise null
     247     */
     248    @Nullable
     249    public Date getDateSent()
     250    {
     251        return getDate(TAG_DATE_SENT, TAG_TIME_SENT);
     252    }
     253
     254    /**
     255     * Parses the Release Date tag and the Release Time tag to obtain a single Date object representing the
     256     * date and time when this image was released.
     257     * @return A Date object representing when this image was released, if possible, otherwise null
     258     */
     259    @Nullable
     260    public Date getReleaseDate()
     261    {
     262        return getDate(TAG_RELEASE_DATE, TAG_RELEASE_TIME);
     263    }
     264
     265    /**
     266     * Parses the Expiration Date tag and the Expiration Time tag to obtain a single Date object representing
     267     * that this image should not used after this date and time.
     268     * @return A Date object representing when this image was released, if possible, otherwise null
     269     */
     270    @Nullable
     271    public Date getExpirationDate()
     272    {
     273        return getDate(TAG_EXPIRATION_DATE, TAG_EXPIRATION_TIME);
     274    }
     275
     276    /**
     277     * Parses the Date Created tag and the Time Created tag to obtain a single Date object representing the
     278     * date and time when this image was captured.
     279     * @return A Date object representing when this image was captured, if possible, otherwise null
     280     */
     281    @Nullable
     282    public Date getDateCreated()
     283    {
     284        return getDate(TAG_DATE_CREATED, TAG_TIME_CREATED);
     285    }
     286
     287    /**
     288     * Parses the Digital Date Created tag and the Digital Time Created tag to obtain a single Date object
     289     * representing the date and time when the digital representation of this image was created.
     290     * @return A Date object representing when the digital representation of this image was created,
     291     * if possible, otherwise null
     292     */
     293    @Nullable
     294    public Date getDigitalDateCreated()
     295    {
     296        return getDate(TAG_DIGITAL_DATE_CREATED, TAG_DIGITAL_TIME_CREATED);
     297    }
     298
     299    @Nullable
     300    private Date getDate(int dateTagType, int timeTagType)
     301    {
     302        String date = getString(dateTagType);
     303        String time = getString(timeTagType);
     304
     305        if (date == null)
     306            return null;
     307        if (time == null)
     308            return null;
     309
     310        try {
     311            DateFormat parser = new SimpleDateFormat("yyyyMMddHHmmssZ");
     312            return parser.parse(date + time);
     313        } catch (ParseException e) {
     314            return null;
     315        }
     316    }
    238317}
  • trunk/src/com/drew/metadata/iptc/IptcReader.java

    r8243 r10862  
    11/*
    2  * Copyright 2002-2015 Drew Noakes
     2 * Copyright 2002-2016 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    2626import com.drew.lang.SequentialReader;
    2727import com.drew.lang.annotations.NotNull;
     28import com.drew.lang.annotations.Nullable;
    2829import com.drew.metadata.Directory;
    2930import com.drew.metadata.Metadata;
    3031
    3132import java.io.IOException;
    32 import java.util.Arrays;
    33 import java.util.Date;
     33import java.util.Collections;
    3434
    3535/**
     
    6060    public Iterable<JpegSegmentType> getSegmentTypes()
    6161    {
    62         return Arrays.asList(JpegSegmentType.APPD);
     62        return Collections.singletonList(JpegSegmentType.APPD);
    6363    }
    6464
     
    7878    public void extract(@NotNull final SequentialReader reader, @NotNull final Metadata metadata, long length)
    7979    {
     80        extract(reader, metadata, length, null);
     81    }
     82
     83    /**
     84     * Performs the IPTC data extraction, adding found values to the specified instance of {@link Metadata}.
     85     */
     86    public void extract(@NotNull final SequentialReader reader, @NotNull final Metadata metadata, long length, @Nullable Directory parentDirectory)
     87    {
    8088        IptcDirectory directory = new IptcDirectory();
    8189        metadata.addDirectory(directory);
     90
     91        if (parentDirectory != null)
     92            directory.setParent(parentDirectory);
    8293
    8394        int offset = 0;
     
    105116
    106117            // we need at least five bytes left to read a tag
    107             if (offset + 5 >= length) {
     118            if (offset + 5 > length) {
    108119                directory.addError("Too few bytes remain for a valid IPTC tag");
    109120                return;
     
    184195                reader.skip(tagByteCount - 1);
    185196                return;
    186             case IptcDirectory.TAG_RELEASE_DATE:
    187             case IptcDirectory.TAG_DATE_CREATED:
    188                 // Date object
    189                 if (tagByteCount >= 8) {
    190                     string = reader.getString(tagByteCount);
    191                     try {
    192                         int year = Integer.parseInt(string.substring(0, 4));
    193                         int month = Integer.parseInt(string.substring(4, 6)) - 1;
    194                         int day = Integer.parseInt(string.substring(6, 8));
    195                         Date date = new java.util.GregorianCalendar(year, month, day).getTime();
    196                         directory.setDate(tagIdentifier, date);
    197                         return;
    198                     } catch (NumberFormatException e) {
    199                         // fall through and we'll process the 'string' value below
    200                     }
    201                 } else {
    202                     reader.skip(tagByteCount);
    203                 }
    204             case IptcDirectory.TAG_RELEASE_TIME:
    205             case IptcDirectory.TAG_TIME_CREATED:
    206                 // time...
    207197            default:
    208198                // fall through
     
    227217            String[] newStrings;
    228218            if (oldStrings == null) {
     219                // TODO hitting this block means any prior value(s) are discarded
    229220                newStrings = new String[1];
    230221            } else {
  • trunk/src/com/drew/metadata/iptc/Iso2022Converter.java

    r8132 r10862  
     1/*
     2 * Copyright 2002-2016 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 */
    121package com.drew.metadata.iptc;
    222
     
    4060    /**
    4161     * Attempts to guess the encoding of a string provided as a byte array.
    42      * <p/>
     62     * <p>
    4363     * Encodings trialled are, in order:
    4464     * <ul>
     
    4767     *     <li>ISO-8859-1</li>
    4868     * </ul>
    49      * <p/>
     69     * <p>
    5070     * Its only purpose is to guess the encoding if and only if iptc tag coded character set is not set. If the
    5171     * encoding is not UTF-8, the tag should be set. Otherwise it is bad practice. This method tries to
    5272     * workaround this issue since some metadata manipulating tools do not prevent such bad practice.
    53      * <p/>
     73     * <p>
    5474     * About the reliability of this method: The check if some bytes are UTF-8 or not has a very high reliability.
    5575     * The two other checks are less reliable.
  • trunk/src/com/drew/metadata/iptc/package.html

    r8132 r10862  
    11<!--
    2   ~ Copyright 2002-2015 Drew Noakes
     2  ~ Copyright 2002-2016 Drew Noakes
    33  ~
    44  ~    Licensed under the Apache License, Version 2.0 (the "License");
Note: See TracChangeset for help on using the changeset viewer.