Path: blob/master/test/jdk/javax/imageio/plugins/png/MergeStdCommentTest.java
41155 views
/*1* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 510655026* @summary Merge a comment using the standard metdata format27* and only a minimal set of attributes28*/2930import java.awt.image.BufferedImage;31import javax.imageio.ImageIO;32import javax.imageio.ImageTypeSpecifier;33import javax.imageio.ImageWriter;34import javax.imageio.metadata.IIOMetadata;35import org.w3c.dom.DOMImplementation;36import org.w3c.dom.Document;37import org.w3c.dom.Element;38import org.w3c.dom.bootstrap.DOMImplementationRegistry;3940public class MergeStdCommentTest {4142public static void main(String[] args) throws Exception {43String format = "javax_imageio_1.0";44BufferedImage img =45new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);46ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next();47IIOMetadata meta =48iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null);49DOMImplementationRegistry registry;50registry = DOMImplementationRegistry.newInstance();51DOMImplementation impl = registry.getDOMImplementation("XML 3.0");52Document doc = impl.createDocument(null, format, null);53Element root, text, entry;54root = doc.getDocumentElement();55root.appendChild(text = doc.createElement("Text"));56text.appendChild(entry = doc.createElement("TextEntry"));57// keyword isn't #REQUIRED by the standard metadata format.58// However, it is required by the PNG format, so we include it here.59entry.setAttribute("keyword", "Comment");60entry.setAttribute("value", "Some demo comment");61meta.mergeTree(format, root);62}63}646566