jdk/test/javax/imageio/plugins/png/MergeStdCommentTest.java
changeset 2368 5a872c1edd4f
child 5506 202f599c92aa
equal deleted inserted replaced
1741:f02cad8a9114 2368:5a872c1edd4f
       
     1 /*
       
     2  * Copyright 2008 Sun Microsystems, Inc.  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.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    21  * have any questions.
       
    22  */
       
    23 
       
    24 /**
       
    25  * @test
       
    26  * @bug 5106550
       
    27  * @summary Merge a comment using the standard metdata format
       
    28  *          and only a minimal set of attributes
       
    29  */
       
    30 
       
    31 import java.awt.image.BufferedImage;
       
    32 import javax.imageio.ImageIO;
       
    33 import javax.imageio.ImageTypeSpecifier;
       
    34 import javax.imageio.ImageWriter;
       
    35 import javax.imageio.metadata.IIOMetadata;
       
    36 import org.w3c.dom.DOMImplementation;
       
    37 import org.w3c.dom.Document;
       
    38 import org.w3c.dom.Element;
       
    39 import org.w3c.dom.bootstrap.DOMImplementationRegistry;
       
    40 
       
    41 public class MergeStdCommentTest {
       
    42 
       
    43     public static void main(String[] args) throws Exception {
       
    44         String format = "javax_imageio_1.0";
       
    45         BufferedImage img =
       
    46             new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
       
    47         ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next();
       
    48         IIOMetadata meta =
       
    49             iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null);
       
    50         DOMImplementationRegistry registry;
       
    51         registry = DOMImplementationRegistry.newInstance();
       
    52         DOMImplementation impl = registry.getDOMImplementation("XML 3.0");
       
    53         Document doc = impl.createDocument(null, format, null);
       
    54         Element root, text, entry;
       
    55         root = doc.getDocumentElement();
       
    56         root.appendChild(text = doc.createElement("Text"));
       
    57         text.appendChild(entry = doc.createElement("TextEntry"));
       
    58         // keyword isn't #REQUIRED by the standard metadata format.
       
    59         // However, it is required by the PNG format, so we include it here.
       
    60         entry.setAttribute("keyword", "Comment");
       
    61         entry.setAttribute("value", "Some demo comment");
       
    62         meta.mergeTree(format, root);
       
    63     }
       
    64 }