Source code: com/drew/metadata/Tag.java
1 /*
2 * Created by dnoakes on 26-Nov-2002 18:29:12 using IntelliJ IDEA.
3 */
4 package com.drew.metadata;
5
6 import java.io.Serializable;
7
8 /**
9 *
10 */
11 public class Tag implements Serializable
12 {
13 private final int _tagType;
14 private final Directory _directory;
15
16 public Tag(int tagType, Directory directory)
17 {
18 _tagType = tagType;
19 _directory = directory;
20 }
21
22 /**
23 * Gets the tag type as an int
24 * @return the tag type as an int
25 */
26 public int getTagType()
27 {
28 return _tagType;
29 }
30
31 /**
32 * Gets the tag type in hex notation as a String with padded leading
33 * zeroes if necessary (i.e. <code>0x100E</code>).
34 * @return the tag type as a string in hexadecimal notation
35 */
36 public String getTagTypeHex()
37 {
38 String hex = Integer.toHexString(_tagType);
39 while (hex.length() < 4) hex = "0" + hex;
40 return "0x" + hex;
41 }
42
43 /**
44 * Get a description of the tag's value, considering enumerated values
45 * and units.
46 * @return a description of the tag's value
47 */
48 public String getDescription() throws MetadataException
49 {
50 return _directory.getDescription(_tagType);
51 }
52
53 /**
54 * Get the name of the tag, such as <code>Aperture</code>, or
55 * <code>InteropVersion</code>.
56 * @return the tag's name
57 */
58 public String getTagName()
59 {
60 return _directory.getTagName(_tagType);
61 }
62
63 /**
64 * Get the name of the directory in which the tag exists, such as
65 * <code>Exif</code>, <code>GPS</code> or <code>Interoperability</code>.
66 * @return name of the directory in which this tag exists
67 */
68 public String getDirectoryName()
69 {
70 return _directory.getName();
71 }
72
73 /**
74 * A basic representation of the tag's type and value in format:
75 * <code>FNumber - F2.8</code>.
76 * @return the tag's type and value
77 */
78 public String toString()
79 {
80 String description;
81 try {
82 description = getDescription();
83 } catch (MetadataException e) {
84 description = _directory.getString(getTagType()) + " (unable to formulate description)";
85 }
86 return "[" + _directory.getName() + "] " + getTagName() + " - " + description;
87 }
88 }