Changeset 13061 in josm for trunk/src/com/drew/metadata/tiff


Ignore:
Timestamp:
2017-10-30T22:46:09+01:00 (7 years ago)
Author:
Don-vip
Message:

fix #15505 - update to metadata-extractor 2.10.1

Location:
trunk/src/com/drew/metadata/tiff
Files:
1 added
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/drew/metadata/tiff/DirectoryTiffHandler.java

    r10862 r13061  
    11/*
    2  * Copyright 2002-2016 Drew Noakes
     2 * Copyright 2002-2017 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    2525import com.drew.lang.annotations.NotNull;
    2626import com.drew.metadata.Directory;
     27import com.drew.metadata.ErrorDirectory;
    2728import com.drew.metadata.Metadata;
     29import com.drew.metadata.StringValue;
    2830
    2931import java.util.Stack;
     
    4143    protected final Metadata _metadata;
    4244
    43     protected DirectoryTiffHandler(Metadata metadata, Class<? extends Directory> initialDirectoryClass)
     45    protected DirectoryTiffHandler(Metadata metadata)
    4446    {
    4547        _metadata = metadata;
     48    }
     49
     50    public void endingIFD()
     51    {
     52        _currentDirectory = _directoryStack.empty() ? null : _directoryStack.pop();
     53    }
     54
     55    protected void pushDirectory(@NotNull Class<? extends Directory> directoryClass)
     56    {
     57        Directory newDirectory = null;
     58
    4659        try {
    47             _currentDirectory = initialDirectoryClass.newInstance();
     60            newDirectory = directoryClass.newInstance();
    4861        } catch (InstantiationException e) {
    4962            throw new RuntimeException(e);
     
    5164            throw new RuntimeException(e);
    5265        }
    53         _metadata.addDirectory(_currentDirectory);
    54     }
    55 
    56     public void endingIFD()
    57     {
    58         _currentDirectory = _directoryStack.empty() ? null : _directoryStack.pop();
    59     }
    60 
    61     protected void pushDirectory(@NotNull Class<? extends Directory> directoryClass)
    62     {
    63         _directoryStack.push(_currentDirectory);
    64         try {
    65             Directory newDirectory = directoryClass.newInstance();
    66             newDirectory.setParent(_currentDirectory);
     66
     67        if (newDirectory != null)
     68        {
     69            // If this is the first directory, don't add to the stack
     70            if (_currentDirectory != null)
     71            {
     72                _directoryStack.push(_currentDirectory);
     73                newDirectory.setParent(_currentDirectory);
     74            }
    6775            _currentDirectory = newDirectory;
    68         } catch (InstantiationException e) {
    69             throw new RuntimeException(e);
    70         } catch (IllegalAccessException e) {
    71             throw new RuntimeException(e);
     76            _metadata.addDirectory(_currentDirectory);
    7277        }
    73         _metadata.addDirectory(_currentDirectory);
    7478    }
    7579
    7680    public void warn(@NotNull String message)
    7781    {
    78         _currentDirectory.addError(message);
     82        getCurrentOrErrorDirectory().addError(message);
    7983    }
    8084
    8185    public void error(@NotNull String message)
    8286    {
    83         _currentDirectory.addError(message);
     87        getCurrentOrErrorDirectory().addError(message);
     88    }
     89
     90    @NotNull
     91    private Directory getCurrentOrErrorDirectory()
     92    {
     93        if (_currentDirectory != null)
     94            return _currentDirectory;
     95        ErrorDirectory error = _metadata.getFirstDirectoryOfType(ErrorDirectory.class);
     96        if (error != null)
     97            return error;
     98        pushDirectory(ErrorDirectory.class);
     99        return _currentDirectory;
    84100    }
    85101
     
    89105    }
    90106
    91     public void setString(int tagId, @NotNull String string)
    92     {
    93         _currentDirectory.setString(tagId, string);
     107    public void setString(int tagId, @NotNull StringValue string)
     108    {
     109        _currentDirectory.setStringValue(tagId, string);
    94110    }
    95111
Note: See TracChangeset for help on using the changeset viewer.