1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.formats.png;
18
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.Objects;
22
23 import org.apache.commons.imaging.common.ImageMetadata;
24 import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
25 import org.apache.commons.imaging.internal.Debug;
26
27
28
29
30 public class PngImageMetadata implements ImageMetadata {
31
32 private static final String NEWLINE = System.lineSeparator();
33
34 private final ImageMetadata textualInformation;
35 private final TiffImageMetadata exif;
36
37 public PngImageMetadata(final ImageMetadata textualInformation) {
38 this(textualInformation, null);
39 }
40
41 public PngImageMetadata(final ImageMetadata textualInformation, final TiffImageMetadata exif) {
42 this.textualInformation = Objects.requireNonNull(textualInformation);
43 this.exif = exif;
44 }
45
46 public void dump() {
47 Debug.debug(this.toString());
48 }
49
50 public TiffImageMetadata getExif() {
51 return exif;
52 }
53
54 @Override
55 public List<? extends ImageMetadataItem> getItems() {
56 if (exif == null) {
57 return textualInformation.getItems();
58 }
59
60 final ArrayList<ImageMetadataItem> result = new ArrayList<>(textualInformation.getItems());
61 result.addAll(exif.getItems());
62 return result;
63 }
64
65 public ImageMetadata getTextualInformation() {
66 return textualInformation;
67 }
68
69 @Override
70 public String toString() {
71 return toString(null);
72 }
73
74 @Override
75 public String toString(String prefix) {
76 if (prefix == null) {
77 prefix = "";
78 }
79
80 final StringBuilder result = new StringBuilder();
81
82 result.append(prefix);
83 result.append("Textual information:");
84 result.append(NEWLINE);
85 result.append(textualInformation.toString("\t"));
86
87 if (exif != null) {
88 result.append(NEWLINE);
89 result.append(prefix);
90 result.append("Exif metadata:");
91 result.append(NEWLINE);
92 result.append(exif.toString("\t"));
93 }
94
95 return result.toString();
96 }
97 }