1 /* 2 * Copyright (c) 2003, 2004, 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 26 package com.sun.imageio.plugins.wbmp; 27 28 import java.io.UnsupportedEncodingException; 29 import java.util.ArrayList; 30 import java.util.Iterator; 31 import java.util.List; 32 import javax.imageio.ImageTypeSpecifier; 33 import javax.imageio.metadata.IIOMetadata; 34 import javax.imageio.metadata.IIOMetadataNode; 35 import javax.imageio.metadata.IIOMetadataFormat; 36 import javax.imageio.metadata.IIOMetadataFormatImpl; 37 import org.w3c.dom.Node; 38 import com.sun.imageio.plugins.common.I18N; 39 40 import com.sun.imageio.plugins.common.ImageUtil; 41 42 public class WBMPMetadata extends IIOMetadata { 43 44 static final String nativeMetadataFormatName = 45 "javax_imageio_wbmp_1.0"; 46 47 public int wbmpType; 48 49 public int width; 50 public int height; 51 WBMPMetadata()52 public WBMPMetadata() { 53 super(true, 54 nativeMetadataFormatName, 55 "com.sun.imageio.plugins.wbmp.WBMPMetadataFormat", 56 null, null); 57 } 58 isReadOnly()59 public boolean isReadOnly() { 60 return true; 61 } 62 getAsTree(String formatName)63 public Node getAsTree(String formatName) { 64 if (formatName.equals(nativeMetadataFormatName)) { 65 return getNativeTree(); 66 } else if (formatName.equals 67 (IIOMetadataFormatImpl.standardMetadataFormatName)) { 68 return getStandardTree(); 69 } else { 70 throw new IllegalArgumentException(I18N.getString("WBMPMetadata0")); 71 } 72 } 73 getNativeTree()74 private Node getNativeTree() { 75 IIOMetadataNode root = 76 new IIOMetadataNode(nativeMetadataFormatName); 77 78 addChildNode(root, "WBMPType", new Integer(wbmpType)); 79 addChildNode(root, "Width", new Integer(width)); 80 addChildNode(root, "Height", new Integer(height)); 81 82 return root; 83 } 84 setFromTree(String formatName, Node root)85 public void setFromTree(String formatName, Node root) { 86 throw new IllegalStateException(I18N.getString("WBMPMetadata1")); 87 } 88 mergeTree(String formatName, Node root)89 public void mergeTree(String formatName, Node root) { 90 throw new IllegalStateException(I18N.getString("WBMPMetadata1")); 91 } 92 reset()93 public void reset() { 94 throw new IllegalStateException(I18N.getString("WBMPMetadata1")); 95 } 96 addChildNode(IIOMetadataNode root, String name, Object object)97 private IIOMetadataNode addChildNode(IIOMetadataNode root, 98 String name, 99 Object object) { 100 IIOMetadataNode child = new IIOMetadataNode(name); 101 if (object != null) { 102 child.setUserObject(object); 103 child.setNodeValue(ImageUtil.convertObjectToString(object)); 104 } 105 root.appendChild(child); 106 return child; 107 } 108 109 getStandardChromaNode()110 protected IIOMetadataNode getStandardChromaNode() { 111 112 IIOMetadataNode node = new IIOMetadataNode("Chroma"); 113 IIOMetadataNode subNode = new IIOMetadataNode("BlackIsZero"); 114 subNode.setAttribute("value", "TRUE"); 115 116 node.appendChild(subNode); 117 return node; 118 } 119 120 getStandardDimensionNode()121 protected IIOMetadataNode getStandardDimensionNode() { 122 IIOMetadataNode dimension_node = new IIOMetadataNode("Dimension"); 123 IIOMetadataNode node = null; // scratch node 124 125 // PixelAspectRatio not in image 126 127 node = new IIOMetadataNode("ImageOrientation"); 128 node.setAttribute("value", "Normal"); 129 dimension_node.appendChild(node); 130 131 return dimension_node; 132 } 133 134 } 135