1. /*
  2. * @(#)WBMPMetadata.java 1.3 04/03/19 12:28:42
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.imageio.plugins.wbmp;
  8. import java.io.UnsupportedEncodingException;
  9. import java.util.ArrayList;
  10. import java.util.Iterator;
  11. import java.util.List;
  12. import javax.imageio.ImageTypeSpecifier;
  13. import javax.imageio.metadata.IIOMetadata;
  14. import javax.imageio.metadata.IIOMetadataNode;
  15. import javax.imageio.metadata.IIOMetadataFormat;
  16. import javax.imageio.metadata.IIOMetadataFormatImpl;
  17. import org.w3c.dom.Node;
  18. import com.sun.imageio.plugins.common.I18N;
  19. import com.sun.imageio.plugins.common.ImageUtil;
  20. public class WBMPMetadata extends IIOMetadata {
  21. static final String nativeMetadataFormatName =
  22. "javax_imageio_wbmp_1.0";
  23. public int wbmpType;
  24. public int width;
  25. public int height;
  26. public WBMPMetadata() {
  27. super(true,
  28. nativeMetadataFormatName,
  29. "com.sun.imageio.plugins.wbmp.WBMPMetadataFormat",
  30. null, null);
  31. }
  32. public boolean isReadOnly() {
  33. return true;
  34. }
  35. public Node getAsTree(String formatName) {
  36. if (formatName.equals(nativeMetadataFormatName)) {
  37. return getNativeTree();
  38. } else if (formatName.equals
  39. (IIOMetadataFormatImpl.standardMetadataFormatName)) {
  40. return getStandardTree();
  41. } else {
  42. throw new IllegalArgumentException(I18N.getString("WBMPMetadata0"));
  43. }
  44. }
  45. private Node getNativeTree() {
  46. IIOMetadataNode root =
  47. new IIOMetadataNode(nativeMetadataFormatName);
  48. addChildNode(root, "WBMPType", new Integer(wbmpType));
  49. addChildNode(root, "Width", new Integer(width));
  50. addChildNode(root, "Height", new Integer(height));
  51. return root;
  52. }
  53. public void setFromTree(String formatName, Node root) {
  54. throw new IllegalStateException(I18N.getString("WBMPMetadata1"));
  55. }
  56. public void mergeTree(String formatName, Node root) {
  57. throw new IllegalStateException(I18N.getString("WBMPMetadata1"));
  58. }
  59. public void reset() {
  60. throw new IllegalStateException(I18N.getString("WBMPMetadata1"));
  61. }
  62. private IIOMetadataNode addChildNode(IIOMetadataNode root,
  63. String name,
  64. Object object) {
  65. IIOMetadataNode child = new IIOMetadataNode(name);
  66. if (object != null) {
  67. child.setUserObject(object);
  68. child.setNodeValue(ImageUtil.convertObjectToString(object));
  69. }
  70. root.appendChild(child);
  71. return child;
  72. }
  73. protected IIOMetadataNode getStandardChromaNode() {
  74. IIOMetadataNode node = new IIOMetadataNode("Chroma");
  75. IIOMetadataNode subNode = new IIOMetadataNode("BlackIsZero");
  76. subNode.setAttribute("value", "TRUE");
  77. node.appendChild(subNode);
  78. return node;
  79. }
  80. protected IIOMetadataNode getStandardDimensionNode() {
  81. IIOMetadataNode dimension_node = new IIOMetadataNode("Dimension");
  82. IIOMetadataNode node = null; // scratch node
  83. // PixelAspectRatio not in image
  84. node = new IIOMetadataNode("ImageOrientation");
  85. node.setAttribute("value", "Normal");
  86. dimension_node.appendChild(node);
  87. return dimension_node;
  88. }
  89. }