1 /*
2  * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 package com.sun.imageio.plugins.tiff;
26 
27 import javax.imageio.ImageTypeSpecifier;
28 import javax.imageio.metadata.IIOMetadataFormat;
29 
30 public class TIFFImageMetadataFormat extends TIFFMetadataFormat {
31 
32     private static TIFFImageMetadataFormat theInstance = null;
33 
34     static {
35     }
36 
canNodeAppear(String elementName, ImageTypeSpecifier imageType)37     public boolean canNodeAppear(String elementName,
38                                  ImageTypeSpecifier imageType) {
39         return false;
40     }
41 
TIFFImageMetadataFormat()42     private TIFFImageMetadataFormat() {
43         this.resourceBaseName =
44      "javax.imageio.plugins.tiff.TIFFImageMetadataFormatResources";
45         this.rootName = TIFFImageMetadata.NATIVE_METADATA_FORMAT_NAME;
46 
47         TIFFElementInfo einfo;
48         TIFFAttrInfo ainfo;
49         String[] empty = new String[0];
50         String[] childNames;
51         String[] attrNames;
52 
53         childNames = new String[] { "TIFFIFD" };
54         einfo = new TIFFElementInfo(childNames, empty, CHILD_POLICY_SEQUENCE);
55 
56         elementInfoMap.put(TIFFImageMetadata.NATIVE_METADATA_FORMAT_NAME,
57                            einfo);
58 
59         childNames = new String[] { "TIFFField", "TIFFIFD" };
60         attrNames =
61             new String[] { "tagSets", "parentTagNumber", "parentTagName" };
62         einfo = new TIFFElementInfo(childNames, attrNames, CHILD_POLICY_SEQUENCE);
63         elementInfoMap.put("TIFFIFD", einfo);
64 
65         ainfo = new TIFFAttrInfo();
66         ainfo.dataType = DATATYPE_STRING;
67         ainfo.isRequired = true;
68         attrInfoMap.put("TIFFIFD/tagSets", ainfo);
69 
70         ainfo = new TIFFAttrInfo();
71         ainfo.dataType = DATATYPE_INTEGER;
72         ainfo.isRequired = false;
73         attrInfoMap.put("TIFFIFD/parentTagNumber", ainfo);
74 
75         ainfo = new TIFFAttrInfo();
76         ainfo.dataType = DATATYPE_STRING;
77         ainfo.isRequired = false;
78         attrInfoMap.put("TIFFIFD/parentTagName", ainfo);
79 
80         String[] types = {
81             "TIFFByte",
82             "TIFFAscii",
83             "TIFFShort",
84             "TIFFSShort",
85             "TIFFLong",
86             "TIFFSLong",
87             "TIFFRational",
88             "TIFFSRational",
89             "TIFFFloat",
90             "TIFFDouble",
91             "TIFFUndefined"
92         };
93 
94         attrNames = new String[] { "value", "description" };
95         String[] attrNamesValueOnly = new String[] { "value" };
96         TIFFAttrInfo ainfoValue = new TIFFAttrInfo();
97         TIFFAttrInfo ainfoDescription = new TIFFAttrInfo();
98 
99         for (int i = 0; i < types.length; i++) {
100             if (!types[i].equals("TIFFUndefined")) {
101                 childNames = new String[1];
102                 childNames[0] = types[i];
103                 einfo =
104                     new TIFFElementInfo(childNames, empty, CHILD_POLICY_SEQUENCE);
105                 elementInfoMap.put(types[i] + "s", einfo);
106             }
107 
108             boolean hasDescription =
109                 !types[i].equals("TIFFUndefined") &&
110                 !types[i].equals("TIFFAscii") &&
111                 !types[i].equals("TIFFRational") &&
112                 !types[i].equals("TIFFSRational") &&
113                 !types[i].equals("TIFFFloat") &&
114                 !types[i].equals("TIFFDouble");
115 
116             String[] anames = hasDescription ? attrNames : attrNamesValueOnly;
117             einfo = new TIFFElementInfo(empty, anames, CHILD_POLICY_EMPTY);
118             elementInfoMap.put(types[i], einfo);
119 
120             attrInfoMap.put(types[i] + "/value", ainfoValue);
121             if (hasDescription) {
122                 attrInfoMap.put(types[i] + "/description", ainfoDescription);
123             }
124         }
125 
126         childNames = new String[2*types.length - 1];
127         for (int i = 0; i < types.length; i++) {
128             childNames[2*i] = types[i];
129             if (!types[i].equals("TIFFUndefined")) {
130                 childNames[2*i + 1] = types[i] + "s";
131             }
132         }
133         attrNames = new String[] { "number", "name" };
134         einfo = new TIFFElementInfo(childNames, attrNames, CHILD_POLICY_CHOICE);
135         elementInfoMap.put("TIFFField", einfo);
136 
137         ainfo = new TIFFAttrInfo();
138         ainfo.isRequired = true;
139         attrInfoMap.put("TIFFField/number", ainfo);
140 
141         ainfo = new TIFFAttrInfo();
142         attrInfoMap.put("TIFFField/name", ainfo);
143     }
144 
getInstance()145     public static synchronized IIOMetadataFormat getInstance() {
146         if (theInstance == null) {
147             theInstance = new TIFFImageMetadataFormat();
148         }
149         return theInstance;
150     }
151 }
152