Source code: com/flexstor/flexdbserver/services/asset/iptc/TIFFParser.java
1 /*
2 * TIFFParser.java
3 *
4 * Copyright $Date: 2003/08/11 02:22:34 $ FLEXSTOR.net Inc.
5 *
6 * This work is licensed for use and distribution under license terms found at
7 * http://www.flexstor.org/license.html
8 *
9 */
10
11 package com.flexstor.flexdbserver.services.asset.iptc;
12
13 import com.flexstor.common.io.xfile.FlexXFile;
14
15 /**
16 *
17 *
18 */
19 public class TIFFParser extends IPTCParser implements IIPTCParser
20 {
21 FlexXFile refXFile = null;
22
23
24 /**
25 *
26 *
27 */
28 public TIFFParser(FlexXFile refXFile)
29 {
30 this.refXFile = refXFile;
31 } // constructor
32
33
34 /**
35 *
36 *
37 */
38 public boolean parseFile()
39 {
40
41 // There are serveral resource tiff tags in the tiff file. Use tag 33723 d (0x83bb h)
42 // which is the tiff tag suggested in the Adobe Photoshop Software Development Kit.
43 // The IPTC-NAA record 2 information is stored in this tiff tag.
44 // Caption data is stored in tag 270 d (0x010e h) however this is straight text without
45 // the IPTC tag information.
46 int nTagID = 0x83bb;
47
48 BGPDebug("Parsing TIFF IPTC data....");
49
50 // Create a tiff processing instance
51 TiffFile refTiffFile = new TiffFile(refXFile);
52
53 // Ask the tiff processor to look only for the desired tiff tag
54 refTiffFile.addIncludeTagId(nTagID);
55
56 // Load the tag directory and parse it
57 if (refTiffFile.loadTagDirectory() == false)
58 {
59 BGPError("Could not load tag directory");
60 return false;
61 }
62
63 // Get the tag data for the id requested if it exists
64 byte[] anTagValue = refTiffFile.getTagData(nTagID);
65 if ((anTagValue == null) || (anTagValue.length == 0))
66 {
67 BGPError("Could not retrieve tag: " + nTagID);
68 return false;
69 }
70
71 // Parse the tiff tag data into IPTC tag data
72 if (parseIPTCdata(anTagValue) == false)
73 {
74 BGPError("Error parsing TIFF IPTC data.");
75 return false;
76 }
77
78 BGPDebug("TIFF IPTC data parsed.");
79 return true;
80 } // parseEFS
81
82
83
84
85 /** Obtain the value for the specified Dataset number.
86 * @return the Dataset number value.
87 * @param sDatasetID The IPTC Dataset ID number (A:BB)
88 */
89 public String getDatasetValue( String sDatasetID )
90 {
91 return (String) hDataSets.get( sDatasetID );
92 } // end of getDataset
93
94
95 /**
96 * Debug code
97 *
98 */
99 protected void printTagData(byte[] anTagData)
100 {
101 // Print out the contents of the tag data buffer
102 // Use the hard way since printing as a string does'nt work well due
103 // to the various wierd characters that it may contain.
104 // Replace all chars < 0x02 (except for 0x0d) with an asterisk
105 // Note that the replaced characters are important for this application.
106 // They are the tags.
107 String sBuffer = "";
108 for (int i=0; i<anTagData.length; i++)
109 {
110 byte nChar = anTagData[i];
111 if ((nChar < 0x20) && (nChar != 0x0d))
112 {
113 nChar = 0x2a;
114 }
115
116 sBuffer += (char)nChar;
117 } // for i
118
119 BGPDebug(sBuffer);
120 } // printTagData
121
122
123
124 /**
125 *
126 *
127 */
128 public void debugPrintHash()
129 {
130
131 BGPDebug("");
132 String sValue = getDatasetValue("2:120"); // Caption
133 if (sValue != null)
134 {
135 BGPDebug(sValue);
136 BGPDebug("String Size: " + sValue.length());
137 }
138 sValue = getDatasetValue("2:25"); // Keyword
139 if (sValue != null)
140 {
141 BGPDebug(sValue);
142 BGPDebug("String Size: " + sValue.length());
143 }
144 sValue = getDatasetValue("2:55"); // Date created
145 if (sValue != null)
146 {
147 BGPDebug(sValue);
148 BGPDebug("String Size: " + sValue.length());
149 }
150 } // debugPrintHash
151
152
153 } // class TIFFParser