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


Ignore:
Timestamp:
2013-08-09T18:05:11+02:00 (12 years ago)
Author:
bastiK
Message:

applied #8895 - Upgrade metadata-extractor to v. 2.6.4 (patch by ebourg)

Location:
trunk/src/com/drew/metadata/iptc
Files:
1 deleted
3 edited

Legend:

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

    r4231 r6127  
    11/*
    2  * This is public domain software - that is, you can do whatever you want
    3  * with it, and include it software that is licensed under the GNU or the
    4  * BSD license, or whatever other licence you choose, including proprietary
    5  * closed source licenses.  I do ask that you leave this header in tact.
    6  *
    7  * If you make modifications to this code that you think would benefit the
    8  * wider community, please send me a copy and I'll post it on my site.
    9  *
    10  * If you make use of this code, I'd appreciate hearing about it.
    11  *   drew@drewnoakes.com
    12  * Latest version of this software kept at
    13  *   http://drewnoakes.com/
    14  *
    15  * Created by dnoakes on 21-Nov-2002 17:58:19 using IntelliJ IDEA.
     2 * Copyright 2002-2012 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 *    http://drewnoakes.com/code/exif/
     19 *    http://code.google.com/p/metadata-extractor/
    1620 */
    1721package com.drew.metadata.iptc;
    1822
    19 import com.drew.metadata.Directory;
     23import com.drew.lang.StringUtil;
     24import com.drew.lang.annotations.NotNull;
     25import com.drew.lang.annotations.Nullable;
    2026import com.drew.metadata.TagDescriptor;
    2127
    2228/**
    23  *
     29 * Provides human-readable string representations of tag values stored in a <code>IptcDirectory</code>.
     30 * <p/>
     31 * As the IPTC directory already stores values as strings, this class simply returns the tag's value.
     32 *
     33 * @author Drew Noakes http://drewnoakes.com
    2434 */
    25 public class IptcDescriptor extends TagDescriptor
     35public class IptcDescriptor extends TagDescriptor<IptcDirectory>
    2636{
    27     public IptcDescriptor(Directory directory)
     37    public IptcDescriptor(@NotNull IptcDirectory directory)
    2838    {
    2939        super(directory);
    3040    }
    3141
     42    @Nullable
    3243    public String getDescription(int tagType)
    3344    {
    34         return _directory.getString(tagType);
     45        switch (tagType) {
     46            case IptcDirectory.TAG_FILE_FORMAT:
     47                return getFileFormatDescription();
     48            case IptcDirectory.TAG_KEYWORDS:
     49                return getKeywordsDescription();
     50            default:
     51                return super.getDescription(tagType);
     52        }
     53    }
     54
     55    @Nullable
     56    public String getFileFormatDescription()
     57    {
     58        Integer value = _directory.getInteger(IptcDirectory.TAG_FILE_FORMAT);
     59        if (value == null)
     60            return null;
     61        switch (value) {
     62            case 0: return "No ObjectData";
     63            case 1: return "IPTC-NAA Digital Newsphoto Parameter Record";
     64            case 2: return "IPTC7901 Recommended Message Format";
     65            case 3: return "Tagged Image File Format (Adobe/Aldus Image data)";
     66            case 4: return "Illustrator (Adobe Graphics data)";
     67            case 5: return "AppleSingle (Apple Computer Inc)";
     68            case 6: return "NAA 89-3 (ANPA 1312)";
     69            case 7: return "MacBinary II";
     70            case 8: return "IPTC Unstructured Character Oriented File Format (UCOFF)";
     71            case 9: return "United Press International ANPA 1312 variant";
     72            case 10: return "United Press International Down-Load Message";
     73            case 11: return "JPEG File Interchange (JFIF)";
     74            case 12: return "Photo-CD Image-Pac (Eastman Kodak)";
     75            case 13: return "Bit Mapped Graphics File [.BMP] (Microsoft)";
     76            case 14: return "Digital Audio File [.WAV] (Microsoft & Creative Labs)";
     77            case 15: return "Audio plus Moving Video [.AVI] (Microsoft)";
     78            case 16: return "PC DOS/Windows Executable Files [.COM][.EXE]";
     79            case 17: return "Compressed Binary File [.ZIP] (PKWare Inc)";
     80            case 18: return "Audio Interchange File Format AIFF (Apple Computer Inc)";
     81            case 19: return "RIFF Wave (Microsoft Corporation)";
     82            case 20: return "Freehand (Macromedia/Aldus)";
     83            case 21: return "Hypertext Markup Language [.HTML] (The Internet Society)";
     84            case 22: return "MPEG 2 Audio Layer 2 (Musicom), ISO/IEC";
     85            case 23: return "MPEG 2 Audio Layer 3, ISO/IEC";
     86            case 24: return "Portable Document File [.PDF] Adobe";
     87            case 25: return "News Industry Text Format (NITF)";
     88            case 26: return "Tape Archive [.TAR]";
     89            case 27: return "Tidningarnas Telegrambyra NITF version (TTNITF DTD)";
     90            case 28: return "Ritzaus Bureau NITF version (RBNITF DTD)";
     91            case 29: return "Corel Draw [.CDR]";
     92        }
     93        return String.format("Unknown (%d)", value);
     94    }
     95
     96    @Nullable
     97    public String getByLineDescription()
     98    {
     99        return _directory.getString(IptcDirectory.TAG_BY_LINE);
     100    }
     101
     102    @Nullable
     103    public String getByLineTitleDescription()
     104    {
     105        return _directory.getString(IptcDirectory.TAG_BY_LINE_TITLE);
     106    }
     107
     108    @Nullable
     109    public String getCaptionDescription()
     110    {
     111        return _directory.getString(IptcDirectory.TAG_CAPTION);
     112    }
     113
     114    @Nullable
     115    public String getCategoryDescription()
     116    {
     117        return _directory.getString(IptcDirectory.TAG_CATEGORY);
     118    }
     119
     120    @Nullable
     121    public String getCityDescription()
     122    {
     123        return _directory.getString(IptcDirectory.TAG_CITY);
     124    }
     125
     126    @Nullable
     127    public String getCopyrightNoticeDescription()
     128    {
     129        return _directory.getString(IptcDirectory.TAG_COPYRIGHT_NOTICE);
     130    }
     131
     132    @Nullable
     133    public String getCountryOrPrimaryLocationDescription()
     134    {
     135        return _directory.getString(IptcDirectory.TAG_COUNTRY_OR_PRIMARY_LOCATION_NAME);
     136    }
     137
     138    @Nullable
     139    public String getCreditDescription()
     140    {
     141        return _directory.getString(IptcDirectory.TAG_CREDIT);
     142    }
     143
     144    @Nullable
     145    public String getDateCreatedDescription()
     146    {
     147        return _directory.getString(IptcDirectory.TAG_DATE_CREATED);
     148    }
     149
     150    @Nullable
     151    public String getHeadlineDescription()
     152    {
     153        return _directory.getString(IptcDirectory.TAG_HEADLINE);
     154    }
     155
     156    @Nullable
     157    public String getKeywordsDescription()
     158    {
     159        final String[] keywords = _directory.getStringArray(IptcDirectory.TAG_KEYWORDS);
     160        if (keywords==null)
     161            return null;
     162        return StringUtil.join(keywords, ";");
     163    }
     164
     165    @Nullable
     166    public String getObjectNameDescription()
     167    {
     168        return _directory.getString(IptcDirectory.TAG_OBJECT_NAME);
     169    }
     170
     171    @Nullable
     172    public String getOriginalTransmissionReferenceDescription()
     173    {
     174        return _directory.getString(IptcDirectory.TAG_ORIGINAL_TRANSMISSION_REFERENCE);
     175    }
     176
     177    @Nullable
     178    public String getOriginatingProgramDescription()
     179    {
     180        return _directory.getString(IptcDirectory.TAG_ORIGINATING_PROGRAM);
     181    }
     182
     183    @Nullable
     184    public String getProvinceOrStateDescription()
     185    {
     186        return _directory.getString(IptcDirectory.TAG_PROVINCE_OR_STATE);
     187    }
     188
     189    @Nullable
     190    public String getRecordVersionDescription()
     191    {
     192        return _directory.getString(IptcDirectory.TAG_APPLICATION_RECORD_VERSION);
     193    }
     194
     195    @Nullable
     196    public String getReleaseDateDescription()
     197    {
     198        return _directory.getString(IptcDirectory.TAG_RELEASE_DATE);
     199    }
     200
     201    @Nullable
     202    public String getReleaseTimeDescription()
     203    {
     204        return _directory.getString(IptcDirectory.TAG_RELEASE_TIME);
     205    }
     206
     207    @Nullable
     208    public String getSourceDescription()
     209    {
     210        return _directory.getString(IptcDirectory.TAG_SOURCE);
     211    }
     212
     213    @Nullable
     214    public String getSpecialInstructionsDescription()
     215    {
     216        return _directory.getString(IptcDirectory.TAG_SPECIAL_INSTRUCTIONS);
     217    }
     218
     219    @Nullable
     220    public String getSupplementalCategoriesDescription()
     221    {
     222        return _directory.getString(IptcDirectory.TAG_SUPPLEMENTAL_CATEGORIES);
     223    }
     224
     225    @Nullable
     226    public String getTimeCreatedDescription()
     227    {
     228        return _directory.getString(IptcDirectory.TAG_TIME_CREATED);
     229    }
     230
     231    @Nullable
     232    public String getUrgencyDescription()
     233    {
     234        return _directory.getString(IptcDirectory.TAG_URGENCY);
     235    }
     236
     237    @Nullable
     238    public String getWriterDescription()
     239    {
     240        return _directory.getString(IptcDirectory.TAG_CAPTION_WRITER);
    35241    }
    36242}
  • trunk/src/com/drew/metadata/iptc/IptcDirectory.java

    r4231 r6127  
    11/*
    2  * This is public domain software - that is, you can do whatever you want
    3  * with it, and include it software that is licensed under the GNU or the
    4  * BSD license, or whatever other licence you choose, including proprietary
    5  * closed source licenses.  I do ask that you leave this header in tact.
    6  *
    7  * If you make modifications to this code that you think would benefit the
    8  * wider community, please send me a copy and I'll post it on my site.
    9  *
    10  * If you make use of this code, I'd appreciate hearing about it.
    11  *   drew@drewnoakes.com
    12  * Latest version of this software kept at
    13  *   http://drewnoakes.com/
    14  *
    15  * Created by dnoakes on 26-Nov-2002 01:26:39 using IntelliJ IDEA.
     2 * Copyright 2002-2012 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 *    http://drewnoakes.com/code/exif/
     19 *    http://code.google.com/p/metadata-extractor/
    1620 */
    1721package com.drew.metadata.iptc;
    1822
     23import com.drew.lang.annotations.NotNull;
     24import com.drew.lang.annotations.Nullable;
    1925import com.drew.metadata.Directory;
    2026
     27import java.util.Arrays;
    2128import java.util.HashMap;
     29import java.util.List;
    2230
    2331/**
    24  *
     32 * Describes tags used by the International Press Telecommunications Council (IPTC) metadata format.
     33 *
     34 * @author Drew Noakes http://drewnoakes.com
    2535 */
    2636public class IptcDirectory extends Directory
    2737{
    28     public static final int TAG_RECORD_VERSION = 0x0200;
    29     public static final int TAG_CAPTION = 0x0278;
    30     public static final int TAG_WRITER = 0x027a;
    31     public static final int TAG_HEADLINE = 0x0269;
    32     public static final int TAG_SPECIAL_INSTRUCTIONS = 0x0228;
    33     public static final int TAG_BY_LINE = 0x0250;
    34     public static final int TAG_BY_LINE_TITLE = 0x0255;
    35     public static final int TAG_CREDIT = 0x026e;
    36     public static final int TAG_SOURCE = 0x0273;
    37     public static final int TAG_OBJECT_NAME = 0x0205;
    38     public static final int TAG_DATE_CREATED = 0x0237;
    39     public static final int TAG_CITY = 0x025a;
    40     public static final int TAG_PROVINCE_OR_STATE = 0x025f;
    41     public static final int TAG_COUNTRY_OR_PRIMARY_LOCATION = 0x0265;
    42     public static final int TAG_ORIGINAL_TRANSMISSION_REFERENCE = 0x0267;
    43     public static final int TAG_CATEGORY = 0x020f;
    44     public static final int TAG_SUPPLEMENTAL_CATEGORIES = 0x0214;
    45     public static final int TAG_URGENCY = 0x0200 | 10;
    46     public static final int TAG_KEYWORDS = 0x0200 | 25;
    47     public static final int TAG_COPYRIGHT_NOTICE = 0x0274;
    48     public static final int TAG_RELEASE_DATE = 0x0200 | 30;
    49     public static final int TAG_RELEASE_TIME = 0x0200 | 35;
    50     public static final int TAG_TIME_CREATED = 0x0200 | 60;
    51     public static final int TAG_ORIGINATING_PROGRAM = 0x0200 | 65;
    52 
    53     protected static final HashMap tagNameMap = new HashMap();
     38    // IPTC EnvelopeRecord Tags
     39    public static final int TAG_ENVELOPE_RECORD_VERSION          = 0x0100; // 0 + 0x0100
     40    public static final int TAG_DESTINATION                      = 0x0105; // 5
     41    public static final int TAG_FILE_FORMAT                      = 0x0114; // 20
     42    public static final int TAG_FILE_VERSION                     = 0x0116; // 22
     43    public static final int TAG_SERVICE_ID                       = 0x011E; // 30
     44    public static final int TAG_ENVELOPE_NUMBER                  = 0x0128; // 40
     45    public static final int TAG_PRODUCT_ID                       = 0x0132; // 50
     46    public static final int TAG_ENVELOPE_PRIORITY                = 0x013C; // 60
     47    public static final int TAG_DATE_SENT                        = 0x0146; // 70
     48    public static final int TAG_TIME_SENT                        = 0x0150; // 80
     49    public static final int TAG_CODED_CHARACTER_SET              = 0x015A; // 90
     50    public static final int TAG_UNIQUE_OBJECT_NAME               = 0x0164; // 100
     51    public static final int TAG_ARM_IDENTIFIER                   = 0x0178; // 120
     52    public static final int TAG_ARM_VERSION                      = 0x017a; // 122
     53
     54    // IPTC ApplicationRecord Tags
     55    public static final int TAG_APPLICATION_RECORD_VERSION       = 0x0200; // 0 + 0x0200
     56    public static final int TAG_OBJECT_TYPE_REFERENCE            = 0x0203; // 3
     57    public static final int TAG_OBJECT_ATTRIBUTE_REFERENCE       = 0x0204; // 4
     58    public static final int TAG_OBJECT_NAME                      = 0x0205; // 5
     59    public static final int TAG_EDIT_STATUS                      = 0x0207; // 7
     60    public static final int TAG_EDITORIAL_UPDATE                 = 0x0208; // 8
     61    public static final int TAG_URGENCY                          = 0X020A; // 10
     62    public static final int TAG_SUBJECT_REFERENCE                = 0X020C; // 12
     63    public static final int TAG_CATEGORY                         = 0x020F; // 15
     64    public static final int TAG_SUPPLEMENTAL_CATEGORIES          = 0x0214; // 20
     65    public static final int TAG_FIXTURE_ID                       = 0x0216; // 22
     66    public static final int TAG_KEYWORDS                         = 0x0219; // 25
     67    public static final int TAG_CONTENT_LOCATION_CODE            = 0x021A; // 26
     68    public static final int TAG_CONTENT_LOCATION_NAME            = 0x021B; // 27
     69    public static final int TAG_RELEASE_DATE                     = 0X021E; // 30
     70    public static final int TAG_RELEASE_TIME                     = 0x0223; // 35
     71    public static final int TAG_EXPIRATION_DATE                  = 0x0225; // 37
     72    public static final int TAG_EXPIRATION_TIME                  = 0x0226; // 38
     73    public static final int TAG_SPECIAL_INSTRUCTIONS             = 0x0228; // 40
     74    public static final int TAG_ACTION_ADVISED                   = 0x022A; // 42
     75    public static final int TAG_REFERENCE_SERVICE                = 0x022D; // 45
     76    public static final int TAG_REFERENCE_DATE                   = 0x022F; // 47
     77    public static final int TAG_REFERENCE_NUMBER                 = 0x0232; // 50
     78    public static final int TAG_DATE_CREATED                     = 0x0237; // 55
     79    public static final int TAG_TIME_CREATED                     = 0X023C; // 60
     80    public static final int TAG_DIGITAL_DATE_CREATED             = 0x023E; // 62
     81    public static final int TAG_DIGITAL_TIME_CREATED             = 0x023F; // 63
     82    public static final int TAG_ORIGINATING_PROGRAM              = 0x0241; // 65
     83    public static final int TAG_PROGRAM_VERSION                  = 0x0246; // 70
     84    public static final int TAG_OBJECT_CYCLE                     = 0x024B; // 75
     85    public static final int TAG_BY_LINE                          = 0x0250; // 80
     86    public static final int TAG_BY_LINE_TITLE                    = 0x0255; // 85
     87    public static final int TAG_CITY                             = 0x025A; // 90
     88    public static final int TAG_SUB_LOCATION                     = 0x025C; // 92
     89    public static final int TAG_PROVINCE_OR_STATE                = 0x025F; // 95
     90    public static final int TAG_COUNTRY_OR_PRIMARY_LOCATION_CODE = 0x0264; // 100
     91    public static final int TAG_COUNTRY_OR_PRIMARY_LOCATION_NAME = 0x0265; // 101
     92    public static final int TAG_ORIGINAL_TRANSMISSION_REFERENCE  = 0x0267; // 103
     93    public static final int TAG_HEADLINE                         = 0x0269; // 105
     94    public static final int TAG_CREDIT                           = 0x026E; // 110
     95    public static final int TAG_SOURCE                           = 0x0273; // 115
     96    public static final int TAG_COPYRIGHT_NOTICE                 = 0x0274; // 116
     97    public static final int TAG_CONTACT                          = 0x0276; // 118
     98    public static final int TAG_CAPTION                          = 0x0278; // 120
     99    public static final int TAG_LOCAL_CAPTION                    = 0x0279; // 121
     100    public static final int TAG_CAPTION_WRITER                   = 0x027A; // 122
     101    public static final int TAG_RASTERIZED_CAPTION               = 0x027D; // 125
     102    public static final int TAG_IMAGE_TYPE                       = 0x0282; // 130
     103    public static final int TAG_IMAGE_ORIENTATION                = 0x0283; // 131
     104    public static final int TAG_LANGUAGE_IDENTIFIER              = 0x0287; // 135
     105    public static final int TAG_AUDIO_TYPE                       = 0x0296; // 150
     106    public static final int TAG_AUDIO_SAMPLING_RATE              = 0x0297; // 151
     107    public static final int TAG_AUDIO_SAMPLING_RESOLUTION        = 0x0298; // 152
     108    public static final int TAG_AUDIO_DURATION                   = 0x0299; // 153
     109    public static final int TAG_AUDIO_OUTCUE                     = 0x029A; // 154
     110
     111    public static final int TAG_JOB_ID                           = 0x02B8; // 184
     112    public static final int TAG_MASTER_DOCUMENT_ID               = 0x02B9; // 185
     113    public static final int TAG_SHORT_DOCUMENT_ID                = 0x02BA; // 186
     114    public static final int TAG_UNIQUE_DOCUMENT_ID               = 0x02BB; // 187
     115    public static final int TAG_OWNER_ID                         = 0x02BC; // 188
     116
     117    public static final int TAG_OBJECT_PREVIEW_FILE_FORMAT       = 0x02C8; // 200
     118    public static final int TAG_OBJECT_PREVIEW_FILE_FORMAT_VERSION  = 0x02C9; // 201
     119    public static final int TAG_OBJECT_PREVIEW_DATA              = 0x02CA; // 202
     120
     121    @NotNull
     122    protected static final HashMap<Integer, String> _tagNameMap = new HashMap<Integer, String>();
    54123
    55124    static
    56125    {
    57         tagNameMap.put(new Integer(TAG_RECORD_VERSION), "Directory Version");
    58         tagNameMap.put(new Integer(TAG_CAPTION), "Caption/Abstract");
    59         tagNameMap.put(new Integer(TAG_WRITER), "Writer/Editor");
    60         tagNameMap.put(new Integer(TAG_HEADLINE), "Headline");
    61         tagNameMap.put(new Integer(TAG_SPECIAL_INSTRUCTIONS), "Special Instructions");
    62         tagNameMap.put(new Integer(TAG_BY_LINE), "By-line");
    63         tagNameMap.put(new Integer(TAG_BY_LINE_TITLE), "By-line Title");
    64         tagNameMap.put(new Integer(TAG_CREDIT), "Credit");
    65         tagNameMap.put(new Integer(TAG_SOURCE), "Source");
    66         tagNameMap.put(new Integer(TAG_OBJECT_NAME), "Object Name");
    67         tagNameMap.put(new Integer(TAG_DATE_CREATED), "Date Created");
    68         tagNameMap.put(new Integer(TAG_CITY), "City");
    69         tagNameMap.put(new Integer(TAG_PROVINCE_OR_STATE), "Province/State");
    70         tagNameMap.put(new Integer(TAG_COUNTRY_OR_PRIMARY_LOCATION), "Country/Primary Location");
    71         tagNameMap.put(new Integer(TAG_ORIGINAL_TRANSMISSION_REFERENCE), "Original Transmission Reference");
    72         tagNameMap.put(new Integer(TAG_CATEGORY), "Category");
    73         tagNameMap.put(new Integer(TAG_SUPPLEMENTAL_CATEGORIES), "Supplemental Category(s)");
    74         tagNameMap.put(new Integer(TAG_URGENCY), "Urgency");
    75         tagNameMap.put(new Integer(TAG_KEYWORDS), "Keywords");
    76         tagNameMap.put(new Integer(TAG_COPYRIGHT_NOTICE), "Copyright Notice");
    77         tagNameMap.put(new Integer(TAG_RELEASE_DATE), "Release Date");
    78         tagNameMap.put(new Integer(TAG_RELEASE_TIME), "Release Time");
    79         tagNameMap.put(new Integer(TAG_TIME_CREATED), "Time Created");
    80         tagNameMap.put(new Integer(TAG_ORIGINATING_PROGRAM), "Originating Program");
     126        _tagNameMap.put(TAG_ENVELOPE_RECORD_VERSION, "Enveloped Record Version");
     127        _tagNameMap.put(TAG_DESTINATION, "Destination");
     128        _tagNameMap.put(TAG_FILE_FORMAT, "File Format");
     129        _tagNameMap.put(TAG_FILE_VERSION, "File Version");
     130        _tagNameMap.put(TAG_SERVICE_ID, "Service Identifier");
     131        _tagNameMap.put(TAG_ENVELOPE_NUMBER, "Envelope Number");
     132        _tagNameMap.put(TAG_PRODUCT_ID, "Product Identifier");
     133        _tagNameMap.put(TAG_ENVELOPE_PRIORITY, "Envelope Priority");
     134        _tagNameMap.put(TAG_DATE_SENT, "Date Sent");
     135        _tagNameMap.put(TAG_TIME_SENT, "Time Sent");
     136        _tagNameMap.put(TAG_CODED_CHARACTER_SET, "Coded Character Set");
     137        _tagNameMap.put(TAG_UNIQUE_OBJECT_NAME, "Unique Object Name");
     138        _tagNameMap.put(TAG_ARM_IDENTIFIER, "ARM Identifier");
     139        _tagNameMap.put(TAG_ARM_VERSION, "ARM Version");
     140
     141        _tagNameMap.put(TAG_APPLICATION_RECORD_VERSION, "Application Record Version");
     142        _tagNameMap.put(TAG_OBJECT_TYPE_REFERENCE, "Object Type Reference");
     143        _tagNameMap.put(TAG_OBJECT_ATTRIBUTE_REFERENCE, "Object Attribute Reference");
     144        _tagNameMap.put(TAG_OBJECT_NAME, "Object Name");
     145        _tagNameMap.put(TAG_EDIT_STATUS, "Edit Status");
     146        _tagNameMap.put(TAG_EDITORIAL_UPDATE, "Editorial Update");
     147        _tagNameMap.put(TAG_URGENCY, "Urgency");
     148        _tagNameMap.put(TAG_SUBJECT_REFERENCE, "Subject Reference");
     149        _tagNameMap.put(TAG_CATEGORY, "Category");
     150        _tagNameMap.put(TAG_SUPPLEMENTAL_CATEGORIES, "Supplemental Category(s)");
     151        _tagNameMap.put(TAG_FIXTURE_ID, "Fixture Identifier");
     152        _tagNameMap.put(TAG_KEYWORDS, "Keywords");
     153        _tagNameMap.put(TAG_CONTENT_LOCATION_CODE, "Content Location Code");
     154        _tagNameMap.put(TAG_CONTENT_LOCATION_NAME, "Content Location Name");
     155        _tagNameMap.put(TAG_RELEASE_DATE, "Release Date");
     156        _tagNameMap.put(TAG_RELEASE_TIME, "Release Time");
     157        _tagNameMap.put(TAG_EXPIRATION_DATE, "Expiration Date");
     158        _tagNameMap.put(TAG_EXPIRATION_TIME, "Expiration Time");
     159        _tagNameMap.put(TAG_SPECIAL_INSTRUCTIONS, "Special Instructions");
     160        _tagNameMap.put(TAG_ACTION_ADVISED, "Action Advised");
     161        _tagNameMap.put(TAG_REFERENCE_SERVICE, "Reference Service");
     162        _tagNameMap.put(TAG_REFERENCE_DATE, "Reference Date");
     163        _tagNameMap.put(TAG_REFERENCE_NUMBER, "Reference Number");
     164        _tagNameMap.put(TAG_DATE_CREATED, "Date Created");
     165        _tagNameMap.put(TAG_TIME_CREATED, "Time Created");
     166        _tagNameMap.put(TAG_DIGITAL_DATE_CREATED, "Digital Date Created");
     167        _tagNameMap.put(TAG_DIGITAL_TIME_CREATED, "Digital Time Created");
     168        _tagNameMap.put(TAG_ORIGINATING_PROGRAM, "Originating Program");
     169        _tagNameMap.put(TAG_PROGRAM_VERSION, "Program Version");
     170        _tagNameMap.put(TAG_OBJECT_CYCLE, "Object Cycle");
     171        _tagNameMap.put(TAG_BY_LINE, "By-line");
     172        _tagNameMap.put(TAG_BY_LINE_TITLE, "By-line Title");
     173        _tagNameMap.put(TAG_CITY, "City");
     174        _tagNameMap.put(TAG_SUB_LOCATION, "Sub-location");
     175        _tagNameMap.put(TAG_PROVINCE_OR_STATE, "Province/State");
     176        _tagNameMap.put(TAG_COUNTRY_OR_PRIMARY_LOCATION_CODE, "Country/Primary Location Code");
     177        _tagNameMap.put(TAG_COUNTRY_OR_PRIMARY_LOCATION_NAME, "Country/Primary Location Name");
     178        _tagNameMap.put(TAG_ORIGINAL_TRANSMISSION_REFERENCE, "Original Transmission Reference");
     179        _tagNameMap.put(TAG_HEADLINE, "Headline");
     180        _tagNameMap.put(TAG_CREDIT, "Credit");
     181        _tagNameMap.put(TAG_SOURCE, "Source");
     182        _tagNameMap.put(TAG_COPYRIGHT_NOTICE, "Copyright Notice");
     183        _tagNameMap.put(TAG_CONTACT, "Contact");
     184        _tagNameMap.put(TAG_CAPTION, "Caption/Abstract");
     185        _tagNameMap.put(TAG_LOCAL_CAPTION, "Local Caption");
     186        _tagNameMap.put(TAG_CAPTION_WRITER, "Caption Writer/Editor");
     187        _tagNameMap.put(TAG_RASTERIZED_CAPTION, "Rasterized Caption");
     188        _tagNameMap.put(TAG_IMAGE_TYPE, "Image Type");
     189        _tagNameMap.put(TAG_IMAGE_ORIENTATION, "Image Orientation");
     190        _tagNameMap.put(TAG_LANGUAGE_IDENTIFIER, "Language Identifier");
     191        _tagNameMap.put(TAG_AUDIO_TYPE, "Audio Type");
     192        _tagNameMap.put(TAG_AUDIO_SAMPLING_RATE, "Audio Sampling Rate");
     193        _tagNameMap.put(TAG_AUDIO_SAMPLING_RESOLUTION, "Audio Sampling Resolution");
     194        _tagNameMap.put(TAG_AUDIO_DURATION, "Audio Duration");
     195        _tagNameMap.put(TAG_AUDIO_OUTCUE, "Audio Outcue");
     196
     197        _tagNameMap.put(TAG_JOB_ID, "Job Identifier");
     198        _tagNameMap.put(TAG_MASTER_DOCUMENT_ID, "Master Document Identifier");
     199        _tagNameMap.put(TAG_SHORT_DOCUMENT_ID, "Short Document Identifier");
     200        _tagNameMap.put(TAG_UNIQUE_DOCUMENT_ID, "Unique Document Identifier");
     201        _tagNameMap.put(TAG_OWNER_ID, "Owner Identifier");
     202
     203        _tagNameMap.put(TAG_OBJECT_PREVIEW_FILE_FORMAT, "Object Data Preview File Format");
     204        _tagNameMap.put(TAG_OBJECT_PREVIEW_FILE_FORMAT_VERSION, "Object Data Preview File Format Version");
     205        _tagNameMap.put(TAG_OBJECT_PREVIEW_DATA, "Object Data Preview Data");
    81206    }
    82207
     
    86211    }
    87212
     213    @NotNull
    88214    public String getName()
    89215    {
     
    91217    }
    92218
    93     protected HashMap getTagNameMap()
    94     {
    95         return tagNameMap;
     219    @NotNull
     220    protected HashMap<Integer, String> getTagNameMap()
     221    {
     222        return _tagNameMap;
     223    }
     224
     225    /**
     226     * Returns any keywords contained in the IPTC data.  This value may be <code>null</code>.
     227     */
     228    @Nullable
     229    public List<String> getKeywords()
     230    {
     231        final String[] array = getStringArray(IptcDirectory.TAG_KEYWORDS);
     232        if (array==null)
     233            return null;
     234        return Arrays.asList(array);
    96235    }
    97236}
  • trunk/src/com/drew/metadata/iptc/IptcReader.java

    r4231 r6127  
    11/*
    2  * This is public domain software - that is, you can do whatever you want
    3  * with it, and include it software that is licensed under the GNU or the
    4  * BSD license, or whatever other licence you choose, including proprietary
    5  * closed source licenses.  I do ask that you leave this header in tact.
     2 * Copyright 2002-2012 Drew Noakes
    63 *
    7  * If you make modifications to this code that you think would benefit the
    8  * wider community, please send me a copy and I'll post it on my site.
     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
    97 *
    10  * If you make use of this code, I'd appreciate hearing about it.
    11  *   drew@drewnoakes.com
    12  * Latest version of this software kept at
    13  *   http://drewnoakes.com/
     8 *        http://www.apache.org/licenses/LICENSE-2.0
    149 *
    15  * Created by dnoakes on 12-Nov-2002 19:00:03 using IntelliJ IDEA.
     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 *    http://drewnoakes.com/code/exif/
     19 *    http://code.google.com/p/metadata-extractor/
    1620 */
    1721package com.drew.metadata.iptc;
    1822
    19 import com.drew.imaging.jpeg.JpegProcessingException;
    20 import com.drew.imaging.jpeg.JpegSegmentReader;
     23import com.drew.lang.BufferBoundsException;
     24import com.drew.lang.BufferReader;
     25import com.drew.lang.annotations.NotNull;
    2126import com.drew.metadata.Directory;
    2227import com.drew.metadata.Metadata;
    23 import com.drew.metadata.MetadataException;
    2428import com.drew.metadata.MetadataReader;
    2529
    26 import java.io.File;
    27 import java.io.InputStream;
    2830import java.util.Date;
    2931
    3032/**
     33 * Decodes IPTC binary data, populating a <code>Metadata</code> object with tag values in an <code>IptcDirectory</code>.
    3134 *
     35 * @author Drew Noakes http://drewnoakes.com
    3236 */
    3337public class IptcReader implements MetadataReader
    3438{
     39    // TODO consider breaking the IPTC section up into multiple directories and providing segregation of each IPTC directory
    3540/*
    3641    public static final int DIRECTORY_IPTC = 2;
     
    4651    public static final int POST_DATA_RECORD = 9;
    4752*/
    48     /**
    49      * The Iptc data segment.
    50      */
    51     private final byte[] _data;
    5253
    53     /**
    54      * Creates a new IptcReader for the specified Jpeg jpegFile.
    55      */
    56     public IptcReader(File jpegFile) throws JpegProcessingException
     54    /** Performs the IPTC data extraction, adding found values to the specified instance of <code>Metadata</code>. */
     55    public void extract(@NotNull final BufferReader reader, @NotNull final Metadata metadata)
    5756    {
    58         this(new JpegSegmentReader(jpegFile).readSegment(JpegSegmentReader.SEGMENT_APPD));
    59     }
     57        IptcDirectory directory = metadata.getOrCreateDirectory(IptcDirectory.class);
    6058
    61     /** Creates an IptcReader for a JPEG stream.
    62      *
    63      * @param is JPEG stream. Stream will be closed.
    64      */
    65     public IptcReader(InputStream is) throws JpegProcessingException
    66     {
    67         this(new JpegSegmentReader(is).readSegment(JpegSegmentReader.SEGMENT_APPD));
    68     }
     59        int offset = 0;
    6960
    70     public IptcReader(byte[] data)
    71     {
    72         _data = data;
    73     }
    74 
    75     /**
    76      * Performs the Exif data extraction, returning a new instance of <code>Metadata</code>.
    77      */
    78     public Metadata extract()
    79     {
    80         return extract(new Metadata());
    81     }
    82 
    83     /**
    84      * Performs the Exif data extraction, adding found values to the specified
    85      * instance of <code>Metadata</code>.
    86      */
    87     public Metadata extract(Metadata metadata)
    88     {
    89         if (_data == null) {
    90             return metadata;
     61/*
     62        // find start-of-segment marker (potentially need to skip some ASCII photoshop header info)
     63        try {
     64            while (offset < data.length - 1 && reader.getUInt16(offset) != 0x1c01 && reader.getUInt16(offset) != 0x1c02)
     65                offset++;
     66        } catch (BufferBoundsException e) {
     67            directory.addError("Couldn't find start of IPTC data (invalid segment)");
     68            return;
    9169        }
    92 
    93         Directory directory = metadata.getDirectory(IptcDirectory.class);
    94 
    95         // find start of data
    96         int offset = 0;
    97         try {
    98             while (offset < _data.length - 1 && get32Bits(offset) != 0x1c02) {
    99                 offset++;
    100             }
    101         } catch (MetadataException e) {
    102             directory.addError("Couldn't find start of Iptc data (invalid segment)");
    103             return metadata;
    104         }
     70*/
    10571
    10672        // for each tag
    107         while (offset < _data.length) {
     73        while (offset < reader.getLength()) {
     74
    10875            // identifies start of a tag
    109             if (_data[offset] != 0x1c) {
     76            short startByte;
     77            try {
     78                startByte = reader.getUInt8(offset);
     79            } catch (BufferBoundsException e) {
     80                directory.addError("Unable to read starting byte of IPTC tag");
    11081                break;
    11182            }
     83
     84            if (startByte != 0x1c) {
     85                directory.addError("Invalid start to IPTC tag");
     86                break;
     87            }
     88
    11289            // we need at least five bytes left to read a tag
    113             if ((offset + 5) >= _data.length) {
     90            if (offset + 5 >= reader.getLength()) {
     91                directory.addError("Too few bytes remain for a valid IPTC tag");
    11492                break;
    11593            }
     
    12199            int tagByteCount;
    122100            try {
    123                 directoryType = _data[offset++];
    124                 tagType = _data[offset++];
    125                 tagByteCount = get32Bits(offset);
    126             } catch (MetadataException e) {
    127                 directory.addError("Iptc data segment ended mid-way through tag descriptor");
    128                 return metadata;
     101                directoryType = reader.getUInt8(offset++);
     102                tagType = reader.getUInt8(offset++);
     103                tagByteCount = reader.getUInt16(offset);
     104                offset += 2;
     105            } catch (BufferBoundsException e) {
     106                directory.addError("IPTC data segment ended mid-way through tag descriptor");
     107                return;
    129108            }
    130             offset += 2;
    131             if ((offset + tagByteCount) > _data.length) {
    132                 directory.addError("data for tag extends beyond end of iptc segment");
     109
     110            if (offset + tagByteCount > reader.getLength()) {
     111                directory.addError("Data for tag extends beyond end of IPTC segment");
    133112                break;
    134113            }
    135114
    136             processTag(directory, directoryType, tagType, offset, tagByteCount);
     115            try {
     116                processTag(reader, directory, directoryType, tagType, offset, tagByteCount);
     117            } catch (BufferBoundsException e) {
     118                directory.addError("Error processing IPTC tag");
     119                break;
     120            }
     121
    137122            offset += tagByteCount;
    138123        }
    139 
    140         return metadata;
    141124    }
    142125
    143     /**
    144      * Returns an int calculated from two bytes of data at the specified offset (MSB, LSB).
    145      * @param offset position within the data buffer to read first byte
    146      * @return the 32 bit int value, between 0x0000 and 0xFFFF
    147      */
    148     private int get32Bits(int offset) throws MetadataException
    149     {
    150         if (offset >= _data.length) {
    151             throw new MetadataException("Attempt to read bytes from outside Iptc data buffer");
    152         }
    153         return ((_data[offset] & 255) << 8) | (_data[offset + 1] & 255);
    154     }
    155 
    156     /**
    157      * This method serves as marsheller of objects for dataset. It converts from IPTC
    158      * octets to relevant java object.
    159      */
    160     private void processTag(Directory directory, int directoryType, int tagType, int offset, int tagByteCount)
     126    private void processTag(@NotNull BufferReader reader, @NotNull Directory directory, int directoryType, int tagType, int offset, int tagByteCount) throws BufferBoundsException
    161127    {
    162128        int tagIdentifier = tagType | (directoryType << 8);
    163129
    164130        switch (tagIdentifier) {
    165             case IptcDirectory.TAG_RECORD_VERSION:
     131            case IptcDirectory.TAG_APPLICATION_RECORD_VERSION:
    166132                // short
    167                 short shortValue = (short)((_data[offset] << 8) | _data[offset + 1]);
     133                int shortValue = reader.getUInt16(offset);
    168134                directory.setInt(tagIdentifier, shortValue);
    169135                return;
    170136            case IptcDirectory.TAG_URGENCY:
    171137                // byte
    172                 directory.setInt(tagIdentifier, _data[offset]);
     138                directory.setInt(tagIdentifier, reader.getUInt8(offset));
    173139                return;
    174140            case IptcDirectory.TAG_RELEASE_DATE:
     
    176142                // Date object
    177143                if (tagByteCount >= 8) {
    178                     String dateStr = new String(_data, offset, tagByteCount);
     144                    String dateStr = reader.getString(offset, tagByteCount);
    179145                    try {
    180146                        int year = Integer.parseInt(dateStr.substring(0, 4));
    181147                        int month = Integer.parseInt(dateStr.substring(4, 6)) - 1;
    182148                        int day = Integer.parseInt(dateStr.substring(6, 8));
    183                         Date date = (new java.util.GregorianCalendar(year, month, day)).getTime();
     149                        Date date = new java.util.GregorianCalendar(year, month, day).getTime();
    184150                        directory.setDate(tagIdentifier, date);
    185151                        return;
     
    194160                // fall through
    195161        }
    196         // If no special handling by now, treat it as a string
     162
     163        // If we haven't returned yet, treat it as a string
    197164        String str;
    198165        if (tagByteCount < 1) {
    199166            str = "";
    200167        } else {
    201             str = new String(_data, offset, tagByteCount);
     168            str = reader.getString(offset, tagByteCount, System.getProperty("file.encoding")); // "ISO-8859-1"
    202169        }
     170
    203171        if (directory.containsTag(tagIdentifier)) {
    204             String[] oldStrings;
     172            // this fancy string[] business avoids using an ArrayList for performance reasons
     173            String[] oldStrings = directory.getStringArray(tagIdentifier);
    205174            String[] newStrings;
    206             try {
    207                 oldStrings = directory.getStringArray(tagIdentifier);
    208             } catch (MetadataException e) {
    209                 oldStrings = null;
    210             }
    211175            if (oldStrings == null) {
    212176                newStrings = new String[1];
    213177            } else {
    214178                newStrings = new String[oldStrings.length + 1];
    215                 for (int i = 0; i < oldStrings.length; i++) {
    216                     newStrings[i] = oldStrings[i];
    217                 }
     179                System.arraycopy(oldStrings, 0, newStrings, 0, oldStrings.length);
    218180            }
    219181            newStrings[newStrings.length - 1] = str;
Note: See TracChangeset for help on using the changeset viewer.