001/* 002 * $RCSfile: TIFFImageMetadataFormat.java,v $ 003 * 004 * 005 * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. 006 * 007 * Redistribution and use in source and binary forms, with or without 008 * modification, are permitted provided that the following conditions 009 * are met: 010 * 011 * - Redistribution of source code must retain the above copyright 012 * notice, this list of conditions and the following disclaimer. 013 * 014 * - Redistribution in binary form must reproduce the above copyright 015 * notice, this list of conditions and the following disclaimer in 016 * the documentation and/or other materials provided with the 017 * distribution. 018 * 019 * Neither the name of Sun Microsystems, Inc. or the names of 020 * contributors may be used to endorse or promote products derived 021 * from this software without specific prior written permission. 022 * 023 * This software is provided "AS IS," without a warranty of any 024 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND 025 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, 026 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY 027 * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL 028 * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF 029 * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS 030 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR 031 * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, 032 * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND 033 * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR 034 * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE 035 * POSSIBILITY OF SUCH DAMAGES. 036 * 037 * You acknowledge that this software is not designed or intended for 038 * use in the design, construction, operation or maintenance of any 039 * nuclear facility. 040 * 041 * $Revision: 1.1 $ 042 * $Date: 2005/02/11 05:01:46 $ 043 * $State: Exp $ 044 */ 045package com.github.jaiimageio.impl.plugins.tiff; 046 047import java.util.Collection; 048import java.util.HashMap; 049import java.util.Iterator; 050import java.util.Locale; 051import java.util.Map; 052import java.util.MissingResourceException; 053import java.util.ResourceBundle; 054 055import javax.imageio.ImageTypeSpecifier; 056import javax.imageio.metadata.IIOMetadataFormat; 057 058import com.github.jaiimageio.plugins.tiff.BaselineTIFFTagSet; 059import com.github.jaiimageio.plugins.tiff.TIFFTag; 060import com.github.jaiimageio.plugins.tiff.TIFFTagSet; 061 062public class TIFFImageMetadataFormat extends TIFFMetadataFormat { 063 064 private static TIFFImageMetadataFormat theInstance = null; 065 066 static { 067 } 068 069 public boolean canNodeAppear(String elementName, 070 ImageTypeSpecifier imageType) { 071 return false; 072 } 073 074 private TIFFImageMetadataFormat() { 075 this.resourceBaseName = 076 "com.github.jaiimageio.impl.plugins.tiff.TIFFImageMetadataFormatResources"; 077 this.rootName = TIFFImageMetadata.nativeMetadataFormatName; 078 079 TIFFElementInfo einfo; 080 TIFFAttrInfo ainfo; 081 String[] empty = new String[0]; 082 String[] childNames; 083 String[] attrNames; 084 085 childNames = new String[] { "TIFFIFD" }; 086 einfo = new TIFFElementInfo(childNames, empty, CHILD_POLICY_SEQUENCE); 087 088 elementInfoMap.put(TIFFImageMetadata.nativeMetadataFormatName, 089 einfo); 090 091 childNames = new String[] { "TIFFField", "TIFFIFD" }; 092 attrNames = 093 new String[] { "tagSets", "parentTagNumber", "parentTagName" }; 094 einfo = new TIFFElementInfo(childNames, attrNames, CHILD_POLICY_SEQUENCE); 095 elementInfoMap.put("TIFFIFD", einfo); 096 097 ainfo = new TIFFAttrInfo(); 098 ainfo.dataType = DATATYPE_STRING; 099 ainfo.isRequired = true; 100 attrInfoMap.put("TIFFIFD/tagSets", ainfo); 101 102 ainfo = new TIFFAttrInfo(); 103 ainfo.dataType = DATATYPE_INTEGER; 104 ainfo.isRequired = false; 105 attrInfoMap.put("TIFFIFD/parentTagNumber", ainfo); 106 107 ainfo = new TIFFAttrInfo(); 108 ainfo.dataType = DATATYPE_STRING; 109 ainfo.isRequired = false; 110 attrInfoMap.put("TIFFIFD/parentTagName", ainfo); 111 112 String[] types = { 113 "TIFFByte", 114 "TIFFAscii", 115 "TIFFShort", 116 "TIFFSShort", 117 "TIFFLong", 118 "TIFFSLong", 119 "TIFFRational", 120 "TIFFSRational", 121 "TIFFFloat", 122 "TIFFDouble", 123 "TIFFUndefined" 124 }; 125 126 attrNames = new String[] { "value", "description" }; 127 String[] attrNamesValueOnly = new String[] { "value" }; 128 TIFFAttrInfo ainfoValue = new TIFFAttrInfo(); 129 TIFFAttrInfo ainfoDescription = new TIFFAttrInfo(); 130 131 for (int i = 0; i < types.length; i++) { 132 if (!types[i].equals("TIFFUndefined")) { 133 childNames = new String[1]; 134 childNames[0] = types[i]; 135 einfo = 136 new TIFFElementInfo(childNames, empty, CHILD_POLICY_SEQUENCE); 137 elementInfoMap.put(types[i] + "s", einfo); 138 } 139 140 boolean hasDescription = 141 !types[i].equals("TIFFUndefined") && 142 !types[i].equals("TIFFAscii") && 143 !types[i].equals("TIFFRational") && 144 !types[i].equals("TIFFSRational") && 145 !types[i].equals("TIFFFloat") && 146 !types[i].equals("TIFFDouble"); 147 148 String[] anames = hasDescription ? attrNames : attrNamesValueOnly; 149 einfo = new TIFFElementInfo(empty, anames, CHILD_POLICY_EMPTY); 150 elementInfoMap.put(types[i], einfo); 151 152 attrInfoMap.put(types[i] + "/value", ainfoValue); 153 if (hasDescription) { 154 attrInfoMap.put(types[i] + "/description", ainfoDescription); 155 } 156 } 157 158 childNames = new String[2*types.length - 1]; 159 for (int i = 0; i < types.length; i++) { 160 childNames[2*i] = types[i]; 161 if (!types[i].equals("TIFFUndefined")) { 162 childNames[2*i + 1] = types[i] + "s"; 163 } 164 } 165 attrNames = new String[] { "number", "name" }; 166 einfo = new TIFFElementInfo(childNames, attrNames, CHILD_POLICY_CHOICE); 167 elementInfoMap.put("TIFFField", einfo); 168 169 ainfo = new TIFFAttrInfo(); 170 ainfo.isRequired = true; 171 attrInfoMap.put("TIFFField/number", ainfo); 172 173 ainfo = new TIFFAttrInfo(); 174 attrInfoMap.put("TIFFField/name", ainfo); 175 } 176 177 public static synchronized IIOMetadataFormat getInstance() { 178 if (theInstance == null) { 179 theInstance = new TIFFImageMetadataFormat(); 180 } 181 return theInstance; 182 } 183}