1 | /*
|
---|
2 | * This is public domain software - that is, you can do whatever you want
|
---|
3 | * with it, and include it software that is licensed under the GNU or the
|
---|
4 | * BSD license, or whatever other licence you choose, including proprietary
|
---|
5 | * closed source licenses. I do ask that you leave this header in tact.
|
---|
6 | *
|
---|
7 | * If you make modifications to this code that you think would benefit the
|
---|
8 | * wider community, please send me a copy and I'll post it on my site.
|
---|
9 | *
|
---|
10 | * If you make use of this code, I'd appreciate hearing about it.
|
---|
11 | * drew@drewnoakes.com
|
---|
12 | * Latest version of this software kept at
|
---|
13 | * http://drewnoakes.com/
|
---|
14 | *
|
---|
15 | * Created by dnoakes on 26-Nov-2002 18:29:12 using IntelliJ IDEA.
|
---|
16 | */
|
---|
17 | package com.drew.metadata;
|
---|
18 |
|
---|
19 | import java.io.Serializable;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | *
|
---|
23 | */
|
---|
24 | public class Tag implements Serializable
|
---|
25 | {
|
---|
26 | private final int _tagType;
|
---|
27 | private final Directory _directory;
|
---|
28 |
|
---|
29 | public Tag(int tagType, Directory directory)
|
---|
30 | {
|
---|
31 | _tagType = tagType;
|
---|
32 | _directory = directory;
|
---|
33 | }
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Gets the tag type as an int
|
---|
37 | * @return the tag type as an int
|
---|
38 | */
|
---|
39 | public int getTagType()
|
---|
40 | {
|
---|
41 | return _tagType;
|
---|
42 | }
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Gets the tag type in hex notation as a String with padded leading
|
---|
46 | * zeroes if necessary (i.e. <code>0x100E</code>).
|
---|
47 | * @return the tag type as a string in hexadecimal notation
|
---|
48 | */
|
---|
49 | public String getTagTypeHex()
|
---|
50 | {
|
---|
51 | String hex = Integer.toHexString(_tagType);
|
---|
52 | while (hex.length() < 4) hex = "0" + hex;
|
---|
53 | return "0x" + hex;
|
---|
54 | }
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Get a description of the tag's value, considering enumerated values
|
---|
58 | * and units.
|
---|
59 | * @return a description of the tag's value
|
---|
60 | */
|
---|
61 | public String getDescription() throws MetadataException
|
---|
62 | {
|
---|
63 | return _directory.getDescription(_tagType);
|
---|
64 | }
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Get the name of the tag, such as <code>Aperture</code>, or
|
---|
68 | * <code>InteropVersion</code>.
|
---|
69 | * @return the tag's name
|
---|
70 | */
|
---|
71 | public String getTagName()
|
---|
72 | {
|
---|
73 | return _directory.getTagName(_tagType);
|
---|
74 | }
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Get the name of the directory in which the tag exists, such as
|
---|
78 | * <code>Exif</code>, <code>GPS</code> or <code>Interoperability</code>.
|
---|
79 | * @return name of the directory in which this tag exists
|
---|
80 | */
|
---|
81 | public String getDirectoryName()
|
---|
82 | {
|
---|
83 | return _directory.getName();
|
---|
84 | }
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * A basic representation of the tag's type and value in format:
|
---|
88 | * <code>FNumber - F2.8</code>.
|
---|
89 | * @return the tag's type and value
|
---|
90 | */
|
---|
91 | public String toString()
|
---|
92 | {
|
---|
93 | String description;
|
---|
94 | try {
|
---|
95 | description = getDescription();
|
---|
96 | } catch (MetadataException e) {
|
---|
97 | description = _directory.getString(getTagType()) + " (unable to formulate description)";
|
---|
98 | }
|
---|
99 | return "[" + _directory.getName() + "] " + getTagName() + " - " + description;
|
---|
100 | }
|
---|
101 | }
|
---|