Changeset 13061 in josm for trunk/src/com/drew/metadata/tiff
- Timestamp:
- 2017-10-30T22:46:09+01:00 (7 years ago)
- 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 1 1 /* 2 * Copyright 2002-201 6Drew Noakes2 * Copyright 2002-2017 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 25 25 import com.drew.lang.annotations.NotNull; 26 26 import com.drew.metadata.Directory; 27 import com.drew.metadata.ErrorDirectory; 27 28 import com.drew.metadata.Metadata; 29 import com.drew.metadata.StringValue; 28 30 29 31 import java.util.Stack; … … 41 43 protected final Metadata _metadata; 42 44 43 protected DirectoryTiffHandler(Metadata metadata , Class<? extends Directory> initialDirectoryClass)45 protected DirectoryTiffHandler(Metadata metadata) 44 46 { 45 47 _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 46 59 try { 47 _currentDirectory = initialDirectoryClass.newInstance();60 newDirectory = directoryClass.newInstance(); 48 61 } catch (InstantiationException e) { 49 62 throw new RuntimeException(e); … … 51 64 throw new RuntimeException(e); 52 65 } 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 } 67 75 _currentDirectory = newDirectory; 68 } catch (InstantiationException e) { 69 throw new RuntimeException(e); 70 } catch (IllegalAccessException e) { 71 throw new RuntimeException(e); 76 _metadata.addDirectory(_currentDirectory); 72 77 } 73 _metadata.addDirectory(_currentDirectory);74 78 } 75 79 76 80 public void warn(@NotNull String message) 77 81 { 78 _currentDirectory.addError(message);82 getCurrentOrErrorDirectory().addError(message); 79 83 } 80 84 81 85 public void error(@NotNull String message) 82 86 { 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; 84 100 } 85 101 … … 89 105 } 90 106 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); 94 110 } 95 111
Note:
See TracChangeset
for help on using the changeset viewer.