[8132] | 1 | /*
|
---|
| 2 | * Copyright 2002-2015 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 | */
|
---|
| 21 | package com.drew.metadata.iptc;
|
---|
| 22 |
|
---|
| 23 | import com.drew.lang.StringUtil;
|
---|
| 24 | import com.drew.lang.annotations.NotNull;
|
---|
| 25 | import com.drew.lang.annotations.Nullable;
|
---|
| 26 | import com.drew.metadata.TagDescriptor;
|
---|
| 27 |
|
---|
| 28 | /**
|
---|
| 29 | * Provides human-readable string representations of tag values stored in a {@link IptcDirectory}.
|
---|
| 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 https://drewnoakes.com
|
---|
| 34 | */
|
---|
| 35 | public class IptcDescriptor extends TagDescriptor<IptcDirectory>
|
---|
| 36 | {
|
---|
| 37 | public IptcDescriptor(@NotNull IptcDirectory directory)
|
---|
| 38 | {
|
---|
| 39 | super(directory);
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | @Override
|
---|
| 43 | @Nullable
|
---|
| 44 | public String getDescription(int tagType)
|
---|
| 45 | {
|
---|
| 46 | switch (tagType) {
|
---|
| 47 | case IptcDirectory.TAG_FILE_FORMAT:
|
---|
| 48 | return getFileFormatDescription();
|
---|
| 49 | case IptcDirectory.TAG_KEYWORDS:
|
---|
| 50 | return getKeywordsDescription();
|
---|
[8243] | 51 | case IptcDirectory.TAG_TIME_CREATED:
|
---|
| 52 | return getTimeCreatedDescription();
|
---|
| 53 | case IptcDirectory.TAG_DIGITAL_TIME_CREATED:
|
---|
| 54 | return getDigitalTimeCreatedDescription();
|
---|
[8132] | 55 | default:
|
---|
| 56 | return super.getDescription(tagType);
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | @Nullable
|
---|
| 61 | public String getFileFormatDescription()
|
---|
| 62 | {
|
---|
| 63 | Integer value = _directory.getInteger(IptcDirectory.TAG_FILE_FORMAT);
|
---|
| 64 | if (value == null)
|
---|
| 65 | return null;
|
---|
| 66 | switch (value) {
|
---|
| 67 | case 0: return "No ObjectData";
|
---|
| 68 | case 1: return "IPTC-NAA Digital Newsphoto Parameter Record";
|
---|
| 69 | case 2: return "IPTC7901 Recommended Message Format";
|
---|
| 70 | case 3: return "Tagged Image File Format (Adobe/Aldus Image data)";
|
---|
| 71 | case 4: return "Illustrator (Adobe Graphics data)";
|
---|
| 72 | case 5: return "AppleSingle (Apple Computer Inc)";
|
---|
| 73 | case 6: return "NAA 89-3 (ANPA 1312)";
|
---|
| 74 | case 7: return "MacBinary II";
|
---|
| 75 | case 8: return "IPTC Unstructured Character Oriented File Format (UCOFF)";
|
---|
| 76 | case 9: return "United Press International ANPA 1312 variant";
|
---|
| 77 | case 10: return "United Press International Down-Load Message";
|
---|
| 78 | case 11: return "JPEG File Interchange (JFIF)";
|
---|
| 79 | case 12: return "Photo-CD Image-Pac (Eastman Kodak)";
|
---|
| 80 | case 13: return "Bit Mapped Graphics File [.BMP] (Microsoft)";
|
---|
| 81 | case 14: return "Digital Audio File [.WAV] (Microsoft & Creative Labs)";
|
---|
| 82 | case 15: return "Audio plus Moving Video [.AVI] (Microsoft)";
|
---|
| 83 | case 16: return "PC DOS/Windows Executable Files [.COM][.EXE]";
|
---|
| 84 | case 17: return "Compressed Binary File [.ZIP] (PKWare Inc)";
|
---|
| 85 | case 18: return "Audio Interchange File Format AIFF (Apple Computer Inc)";
|
---|
| 86 | case 19: return "RIFF Wave (Microsoft Corporation)";
|
---|
| 87 | case 20: return "Freehand (Macromedia/Aldus)";
|
---|
| 88 | case 21: return "Hypertext Markup Language [.HTML] (The Internet Society)";
|
---|
| 89 | case 22: return "MPEG 2 Audio Layer 2 (Musicom), ISO/IEC";
|
---|
| 90 | case 23: return "MPEG 2 Audio Layer 3, ISO/IEC";
|
---|
| 91 | case 24: return "Portable Document File [.PDF] Adobe";
|
---|
| 92 | case 25: return "News Industry Text Format (NITF)";
|
---|
| 93 | case 26: return "Tape Archive [.TAR]";
|
---|
| 94 | case 27: return "Tidningarnas Telegrambyra NITF version (TTNITF DTD)";
|
---|
| 95 | case 28: return "Ritzaus Bureau NITF version (RBNITF DTD)";
|
---|
| 96 | case 29: return "Corel Draw [.CDR]";
|
---|
| 97 | }
|
---|
| 98 | return String.format("Unknown (%d)", value);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | @Nullable
|
---|
| 102 | public String getByLineDescription()
|
---|
| 103 | {
|
---|
| 104 | return _directory.getString(IptcDirectory.TAG_BY_LINE);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | @Nullable
|
---|
| 108 | public String getByLineTitleDescription()
|
---|
| 109 | {
|
---|
| 110 | return _directory.getString(IptcDirectory.TAG_BY_LINE_TITLE);
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | @Nullable
|
---|
| 114 | public String getCaptionDescription()
|
---|
| 115 | {
|
---|
| 116 | return _directory.getString(IptcDirectory.TAG_CAPTION);
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | @Nullable
|
---|
| 120 | public String getCategoryDescription()
|
---|
| 121 | {
|
---|
| 122 | return _directory.getString(IptcDirectory.TAG_CATEGORY);
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | @Nullable
|
---|
| 126 | public String getCityDescription()
|
---|
| 127 | {
|
---|
| 128 | return _directory.getString(IptcDirectory.TAG_CITY);
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | @Nullable
|
---|
| 132 | public String getCopyrightNoticeDescription()
|
---|
| 133 | {
|
---|
| 134 | return _directory.getString(IptcDirectory.TAG_COPYRIGHT_NOTICE);
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | @Nullable
|
---|
| 138 | public String getCountryOrPrimaryLocationDescription()
|
---|
| 139 | {
|
---|
| 140 | return _directory.getString(IptcDirectory.TAG_COUNTRY_OR_PRIMARY_LOCATION_NAME);
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | @Nullable
|
---|
| 144 | public String getCreditDescription()
|
---|
| 145 | {
|
---|
| 146 | return _directory.getString(IptcDirectory.TAG_CREDIT);
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | @Nullable
|
---|
| 150 | public String getDateCreatedDescription()
|
---|
| 151 | {
|
---|
| 152 | return _directory.getString(IptcDirectory.TAG_DATE_CREATED);
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | @Nullable
|
---|
| 156 | public String getHeadlineDescription()
|
---|
| 157 | {
|
---|
| 158 | return _directory.getString(IptcDirectory.TAG_HEADLINE);
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | @Nullable
|
---|
| 162 | public String getKeywordsDescription()
|
---|
| 163 | {
|
---|
| 164 | final String[] keywords = _directory.getStringArray(IptcDirectory.TAG_KEYWORDS);
|
---|
| 165 | if (keywords==null)
|
---|
| 166 | return null;
|
---|
| 167 | return StringUtil.join(keywords, ";");
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | @Nullable
|
---|
| 171 | public String getObjectNameDescription()
|
---|
| 172 | {
|
---|
| 173 | return _directory.getString(IptcDirectory.TAG_OBJECT_NAME);
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | @Nullable
|
---|
| 177 | public String getOriginalTransmissionReferenceDescription()
|
---|
| 178 | {
|
---|
| 179 | return _directory.getString(IptcDirectory.TAG_ORIGINAL_TRANSMISSION_REFERENCE);
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | @Nullable
|
---|
| 183 | public String getOriginatingProgramDescription()
|
---|
| 184 | {
|
---|
| 185 | return _directory.getString(IptcDirectory.TAG_ORIGINATING_PROGRAM);
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | @Nullable
|
---|
| 189 | public String getProvinceOrStateDescription()
|
---|
| 190 | {
|
---|
| 191 | return _directory.getString(IptcDirectory.TAG_PROVINCE_OR_STATE);
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | @Nullable
|
---|
| 195 | public String getRecordVersionDescription()
|
---|
| 196 | {
|
---|
| 197 | return _directory.getString(IptcDirectory.TAG_APPLICATION_RECORD_VERSION);
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | @Nullable
|
---|
| 201 | public String getReleaseDateDescription()
|
---|
| 202 | {
|
---|
| 203 | return _directory.getString(IptcDirectory.TAG_RELEASE_DATE);
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | @Nullable
|
---|
| 207 | public String getReleaseTimeDescription()
|
---|
| 208 | {
|
---|
| 209 | return _directory.getString(IptcDirectory.TAG_RELEASE_TIME);
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | @Nullable
|
---|
| 213 | public String getSourceDescription()
|
---|
| 214 | {
|
---|
| 215 | return _directory.getString(IptcDirectory.TAG_SOURCE);
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | @Nullable
|
---|
| 219 | public String getSpecialInstructionsDescription()
|
---|
| 220 | {
|
---|
| 221 | return _directory.getString(IptcDirectory.TAG_SPECIAL_INSTRUCTIONS);
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | @Nullable
|
---|
| 225 | public String getSupplementalCategoriesDescription()
|
---|
| 226 | {
|
---|
| 227 | return _directory.getString(IptcDirectory.TAG_SUPPLEMENTAL_CATEGORIES);
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | @Nullable
|
---|
| 231 | public String getTimeCreatedDescription()
|
---|
| 232 | {
|
---|
[8243] | 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;
|
---|
[8132] | 239 | }
|
---|
| 240 |
|
---|
| 241 | @Nullable
|
---|
[8243] | 242 | public String getDigitalTimeCreatedDescription()
|
---|
| 243 | {
|
---|
| 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;
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 | @Nullable
|
---|
[8132] | 253 | public String getUrgencyDescription()
|
---|
| 254 | {
|
---|
| 255 | return _directory.getString(IptcDirectory.TAG_URGENCY);
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | @Nullable
|
---|
| 259 | public String getWriterDescription()
|
---|
| 260 | {
|
---|
| 261 | return _directory.getString(IptcDirectory.TAG_CAPTION_WRITER);
|
---|
| 262 | }
|
---|
| 263 | }
|
---|