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