976N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
976N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
976N/A *
976N/A * This code is free software; you can redistribute it and/or modify it
976N/A * under the terms of the GNU General Public License version 2 only, as
976N/A * published by the Free Software Foundation.
976N/A *
976N/A * This code is distributed in the hope that it will be useful, but WITHOUT
976N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
976N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
976N/A * version 2 for more details (a copy is included in the LICENSE file that
976N/A * accompanied this code).
976N/A *
976N/A * You should have received a copy of the GNU General Public License version
976N/A * 2 along with this work; if not, write to the Free Software Foundation,
976N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
976N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
976N/A */
976N/A
976N/A/**
976N/A * @test
976N/A * @bug 5106550
976N/A * @summary Merge a comment using the standard metdata format
976N/A * and only a minimal set of attributes
976N/A */
976N/A
976N/Aimport java.awt.image.BufferedImage;
976N/Aimport javax.imageio.ImageIO;
976N/Aimport javax.imageio.ImageTypeSpecifier;
976N/Aimport javax.imageio.ImageWriter;
976N/Aimport javax.imageio.metadata.IIOMetadata;
976N/Aimport org.w3c.dom.DOMImplementation;
976N/Aimport org.w3c.dom.Document;
976N/Aimport org.w3c.dom.Element;
976N/Aimport org.w3c.dom.bootstrap.DOMImplementationRegistry;
976N/A
976N/Apublic class MergeStdCommentTest {
976N/A
976N/A public static void main(String[] args) throws Exception {
976N/A String format = "javax_imageio_1.0";
976N/A BufferedImage img =
976N/A new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
976N/A ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next();
976N/A IIOMetadata meta =
976N/A iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null);
976N/A DOMImplementationRegistry registry;
976N/A registry = DOMImplementationRegistry.newInstance();
976N/A DOMImplementation impl = registry.getDOMImplementation("XML 3.0");
976N/A Document doc = impl.createDocument(null, format, null);
976N/A Element root, text, entry;
976N/A root = doc.getDocumentElement();
976N/A root.appendChild(text = doc.createElement("Text"));
976N/A text.appendChild(entry = doc.createElement("TextEntry"));
976N/A // keyword isn't #REQUIRED by the standard metadata format.
976N/A // However, it is required by the PNG format, so we include it here.
976N/A entry.setAttribute("keyword", "Comment");
976N/A entry.setAttribute("value", "Some demo comment");
976N/A meta.mergeTree(format, root);
976N/A }
976N/A}