source: josm/trunk/src/com/drew/metadata/Tag.java@ 6887

Last change on this file since 6887 was 6127, checked in by bastiK, 11 years ago

applied #8895 - Upgrade metadata-extractor to v. 2.6.4 (patch by ebourg)

File size: 3.3 KB
Line 
1/*
2 * Copyright 2002-2012 Drew Noakes
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * More information about this project is available at:
17 *
18 * http://drewnoakes.com/code/exif/
19 * http://code.google.com/p/metadata-extractor/
20 */
21package com.drew.metadata;
22
23import com.drew.lang.annotations.NotNull;
24import com.drew.lang.annotations.Nullable;
25
26/**
27 * Models a particular tag within a directory and provides methods for obtaining its value. Note that a Tag instance is
28 * specific to a particular metadata extraction and cannot be reused.
29 *
30 * @author Drew Noakes http://drewnoakes.com
31 */
32public class Tag
33{
34 private final int _tagType;
35 @NotNull
36 private final Directory _directory;
37
38 public Tag(int tagType, @NotNull Directory directory)
39 {
40 _tagType = tagType;
41 _directory = directory;
42 }
43
44 /**
45 * Gets the tag type as an int
46 *
47 * @return the tag type as an int
48 */
49 public int getTagType()
50 {
51 return _tagType;
52 }
53
54 /**
55 * Gets the tag type in hex notation as a String with padded leading
56 * zeroes if necessary (i.e. <code>0x100E</code>).
57 *
58 * @return the tag type as a string in hexadecimal notation
59 */
60 @NotNull
61 public String getTagTypeHex()
62 {
63 String hex = Integer.toHexString(_tagType);
64 while (hex.length() < 4) hex = "0" + hex;
65 return "0x" + hex;
66 }
67
68 /**
69 * Get a description of the tag's value, considering enumerated values
70 * and units.
71 *
72 * @return a description of the tag's value
73 */
74 @Nullable
75 public String getDescription()
76 {
77 return _directory.getDescription(_tagType);
78 }
79
80 /**
81 * Get the name of the tag, such as <code>Aperture</code>, or
82 * <code>InteropVersion</code>.
83 *
84 * @return the tag's name
85 */
86 @NotNull
87 public String getTagName()
88 {
89 return _directory.getTagName(_tagType);
90 }
91
92 /**
93 * Get the name of the directory in which the tag exists, such as
94 * <code>Exif</code>, <code>GPS</code> or <code>Interoperability</code>.
95 *
96 * @return name of the directory in which this tag exists
97 */
98 @NotNull
99 public String getDirectoryName()
100 {
101 return _directory.getName();
102 }
103
104 /**
105 * A basic representation of the tag's type and value. EG: <code>[FNumber] F2.8</code>.
106 *
107 * @return the tag's type and value
108 */
109 @NotNull
110 public String toString()
111 {
112 String description = getDescription();
113 if (description==null)
114 description = _directory.getString(getTagType()) + " (unable to formulate description)";
115 return "[" + _directory.getName() + "] " + getTagName() + " - " + description;
116 }
117}
Note: See TracBrowser for help on using the repository browser.