Changeset 10862 in josm for trunk/src/com/drew/metadata/iptc
- Timestamp:
- 2016-08-20T20:58:03+02:00 (8 years ago)
- Location:
- trunk/src/com/drew/metadata/iptc
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/drew/metadata/iptc/IptcDescriptor.java
r8243 r10862 1 1 /* 2 * Copyright 2002-201 5Drew Noakes2 * Copyright 2002-2016 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 26 26 import com.drew.metadata.TagDescriptor; 27 27 28 import static com.drew.metadata.iptc.IptcDirectory.*; 29 28 30 /** 29 31 * Provides human-readable string representations of tag values stored in a {@link IptcDirectory}. … … 45 47 { 46 48 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: 48 60 return getFileFormatDescription(); 49 case IptcDirectory.TAG_KEYWORDS:61 case TAG_KEYWORDS: 50 62 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: 52 70 return getTimeCreatedDescription(); 53 case IptcDirectory.TAG_DIGITAL_TIME_CREATED:71 case TAG_DIGITAL_TIME_CREATED: 54 72 return getDigitalTimeCreatedDescription(); 73 case TAG_TIME_SENT: 74 return getTimeSentDescription(); 55 75 default: 56 76 return super.getDescription(tagType); … … 59 79 60 80 @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 61 103 public String getFileFormatDescription() 62 104 { 63 Integer value = _directory.getInteger( IptcDirectory.TAG_FILE_FORMAT);105 Integer value = _directory.getInteger(TAG_FILE_FORMAT); 64 106 if (value == null) 65 107 return null; … … 102 144 public String getByLineDescription() 103 145 { 104 return _directory.getString( IptcDirectory.TAG_BY_LINE);146 return _directory.getString(TAG_BY_LINE); 105 147 } 106 148 … … 108 150 public String getByLineTitleDescription() 109 151 { 110 return _directory.getString( IptcDirectory.TAG_BY_LINE_TITLE);152 return _directory.getString(TAG_BY_LINE_TITLE); 111 153 } 112 154 … … 114 156 public String getCaptionDescription() 115 157 { 116 return _directory.getString( IptcDirectory.TAG_CAPTION);158 return _directory.getString(TAG_CAPTION); 117 159 } 118 160 … … 120 162 public String getCategoryDescription() 121 163 { 122 return _directory.getString( IptcDirectory.TAG_CATEGORY);164 return _directory.getString(TAG_CATEGORY); 123 165 } 124 166 … … 126 168 public String getCityDescription() 127 169 { 128 return _directory.getString( IptcDirectory.TAG_CITY);170 return _directory.getString(TAG_CITY); 129 171 } 130 172 … … 132 174 public String getCopyrightNoticeDescription() 133 175 { 134 return _directory.getString( IptcDirectory.TAG_COPYRIGHT_NOTICE);176 return _directory.getString(TAG_COPYRIGHT_NOTICE); 135 177 } 136 178 … … 138 180 public String getCountryOrPrimaryLocationDescription() 139 181 { 140 return _directory.getString( IptcDirectory.TAG_COUNTRY_OR_PRIMARY_LOCATION_NAME);182 return _directory.getString(TAG_COUNTRY_OR_PRIMARY_LOCATION_NAME); 141 183 } 142 184 … … 144 186 public String getCreditDescription() 145 187 { 146 return _directory.getString( IptcDirectory.TAG_CREDIT);188 return _directory.getString(TAG_CREDIT); 147 189 } 148 190 … … 150 192 public String getDateCreatedDescription() 151 193 { 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); 153 219 } 154 220 … … 156 222 public String getHeadlineDescription() 157 223 { 158 return _directory.getString( IptcDirectory.TAG_HEADLINE);224 return _directory.getString(TAG_HEADLINE); 159 225 } 160 226 … … 162 228 public String getKeywordsDescription() 163 229 { 164 final String[] keywords = _directory.getStringArray( IptcDirectory.TAG_KEYWORDS);230 final String[] keywords = _directory.getStringArray(TAG_KEYWORDS); 165 231 if (keywords==null) 166 232 return null; … … 171 237 public String getObjectNameDescription() 172 238 { 173 return _directory.getString( IptcDirectory.TAG_OBJECT_NAME);239 return _directory.getString(TAG_OBJECT_NAME); 174 240 } 175 241 … … 177 243 public String getOriginalTransmissionReferenceDescription() 178 244 { 179 return _directory.getString( IptcDirectory.TAG_ORIGINAL_TRANSMISSION_REFERENCE);245 return _directory.getString(TAG_ORIGINAL_TRANSMISSION_REFERENCE); 180 246 } 181 247 … … 183 249 public String getOriginatingProgramDescription() 184 250 { 185 return _directory.getString( IptcDirectory.TAG_ORIGINATING_PROGRAM);251 return _directory.getString(TAG_ORIGINATING_PROGRAM); 186 252 } 187 253 … … 189 255 public String getProvinceOrStateDescription() 190 256 { 191 return _directory.getString( IptcDirectory.TAG_PROVINCE_OR_STATE);257 return _directory.getString(TAG_PROVINCE_OR_STATE); 192 258 } 193 259 … … 195 261 public String getRecordVersionDescription() 196 262 { 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); 198 270 } 199 271 … … 201 273 public String getReleaseDateDescription() 202 274 { 203 return _directory.getString(IptcDirectory.TAG_RELEASE_DATE);275 return getDateDescription(TAG_RELEASE_DATE); 204 276 } 205 277 … … 207 279 public String getReleaseTimeDescription() 208 280 { 209 return _directory.getString(IptcDirectory.TAG_RELEASE_TIME);281 return getTimeDescription(TAG_RELEASE_TIME); 210 282 } 211 283 … … 213 285 public String getSourceDescription() 214 286 { 215 return _directory.getString( IptcDirectory.TAG_SOURCE);287 return _directory.getString(TAG_SOURCE); 216 288 } 217 289 … … 219 291 public String getSpecialInstructionsDescription() 220 292 { 221 return _directory.getString( IptcDirectory.TAG_SPECIAL_INSTRUCTIONS);293 return _directory.getString(TAG_SPECIAL_INSTRUCTIONS); 222 294 } 223 295 … … 225 297 public String getSupplementalCategoriesDescription() 226 298 { 227 return _directory.getString( IptcDirectory.TAG_SUPPLEMENTAL_CATEGORIES);299 return _directory.getString(TAG_SUPPLEMENTAL_CATEGORIES); 228 300 } 229 301 … … 231 303 public String getTimeCreatedDescription() 232 304 { 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); 239 306 } 240 307 … … 242 309 public String getDigitalTimeCreatedDescription() 243 310 { 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); 250 318 } 251 319 … … 253 321 public String getUrgencyDescription() 254 322 { 255 return _directory.getString( IptcDirectory.TAG_URGENCY);323 return _directory.getString(TAG_URGENCY); 256 324 } 257 325 … … 259 327 public String getWriterDescription() 260 328 { 261 return _directory.getString( IptcDirectory.TAG_CAPTION_WRITER);329 return _directory.getString(TAG_CAPTION_WRITER); 262 330 } 263 331 } -
trunk/src/com/drew/metadata/iptc/IptcDirectory.java
r8132 r10862 1 1 /* 2 * Copyright 2002-201 5Drew Noakes2 * Copyright 2002-2016 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 25 25 import com.drew.metadata.Directory; 26 26 27 import java.text.DateFormat; 28 import java.text.ParseException; 29 import java.text.SimpleDateFormat; 27 30 import java.util.Arrays; 31 import java.util.Date; 28 32 import java.util.HashMap; 29 33 import java.util.List; … … 231 235 public List<String> getKeywords() 232 236 { 233 final String[] array = getStringArray( IptcDirectory.TAG_KEYWORDS);237 final String[] array = getStringArray(TAG_KEYWORDS); 234 238 if (array==null) 235 239 return null; 236 240 return Arrays.asList(array); 237 241 } 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 } 238 317 } -
trunk/src/com/drew/metadata/iptc/IptcReader.java
r8243 r10862 1 1 /* 2 * Copyright 2002-201 5Drew Noakes2 * Copyright 2002-2016 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 26 26 import com.drew.lang.SequentialReader; 27 27 import com.drew.lang.annotations.NotNull; 28 import com.drew.lang.annotations.Nullable; 28 29 import com.drew.metadata.Directory; 29 30 import com.drew.metadata.Metadata; 30 31 31 32 import java.io.IOException; 32 import java.util.Arrays; 33 import java.util.Date; 33 import java.util.Collections; 34 34 35 35 /** … … 60 60 public Iterable<JpegSegmentType> getSegmentTypes() 61 61 { 62 return Arrays.asList(JpegSegmentType.APPD);62 return Collections.singletonList(JpegSegmentType.APPD); 63 63 } 64 64 … … 78 78 public void extract(@NotNull final SequentialReader reader, @NotNull final Metadata metadata, long length) 79 79 { 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 { 80 88 IptcDirectory directory = new IptcDirectory(); 81 89 metadata.addDirectory(directory); 90 91 if (parentDirectory != null) 92 directory.setParent(parentDirectory); 82 93 83 94 int offset = 0; … … 105 116 106 117 // we need at least five bytes left to read a tag 107 if (offset + 5 > =length) {118 if (offset + 5 > length) { 108 119 directory.addError("Too few bytes remain for a valid IPTC tag"); 109 120 return; … … 184 195 reader.skip(tagByteCount - 1); 185 196 return; 186 case IptcDirectory.TAG_RELEASE_DATE:187 case IptcDirectory.TAG_DATE_CREATED:188 // Date object189 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 below200 }201 } else {202 reader.skip(tagByteCount);203 }204 case IptcDirectory.TAG_RELEASE_TIME:205 case IptcDirectory.TAG_TIME_CREATED:206 // time...207 197 default: 208 198 // fall through … … 227 217 String[] newStrings; 228 218 if (oldStrings == null) { 219 // TODO hitting this block means any prior value(s) are discarded 229 220 newStrings = new String[1]; 230 221 } 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 */ 1 21 package com.drew.metadata.iptc; 2 22 … … 40 60 /** 41 61 * Attempts to guess the encoding of a string provided as a byte array. 42 * <p />62 * <p> 43 63 * Encodings trialled are, in order: 44 64 * <ul> … … 47 67 * <li>ISO-8859-1</li> 48 68 * </ul> 49 * <p />69 * <p> 50 70 * Its only purpose is to guess the encoding if and only if iptc tag coded character set is not set. If the 51 71 * encoding is not UTF-8, the tag should be set. Otherwise it is bad practice. This method tries to 52 72 * workaround this issue since some metadata manipulating tools do not prevent such bad practice. 53 * <p />73 * <p> 54 74 * About the reliability of this method: The check if some bytes are UTF-8 or not has a very high reliability. 55 75 * The two other checks are less reliable. -
trunk/src/com/drew/metadata/iptc/package.html
r8132 r10862 1 1 <!-- 2 ~ Copyright 2002-201 5Drew Noakes2 ~ Copyright 2002-2016 Drew Noakes 3 3 ~ 4 4 ~ Licensed under the Apache License, Version 2.0 (the "License");
Note:
See TracChangeset
for help on using the changeset viewer.