Search in sources :

Example 1 with IIOMetadataNode

use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.

the class MyAttrNode method test1.

public static void test1() {
    IIOMetadataNode parent = new IIOMetadataNode("parent");
    IIOMetadataNode elem = new IIOMetadataNode("elem");
    MyAttrNode attrNode = new MyAttrNode("name", "value");
    elem.setAttributeNode(attrNode);
    attrNode.setOwnerElement(elem);
    try {
        parent.setAttributeNode(attrNode);
    } catch (DOMException e) {
        if (e.code != DOMException.INUSE_ATTRIBUTE_ERR) {
            throw new RuntimeException("Test 1 failed: " + "Invalid exception code: " + e.code);
        }
        return;
    }
    throw new RuntimeException("Test 1 failed: DOMException not thrown");
}
Also used : DOMException(org.w3c.dom.DOMException) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode)

Example 2 with IIOMetadataNode

use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.

the class MyAttrNode method test2.

public static void test2() {
    String name = "attr";
    String oldValue = "old value";
    String newValue = "new value";
    Attr retAttr;
    IIOMetadataNode parent = new IIOMetadataNode("parent");
    MyAttrNode attrNode1 = new MyAttrNode(name, oldValue);
    MyAttrNode attrNode2 = new MyAttrNode(name, newValue);
    retAttr = parent.setAttributeNode(attrNode1);
    retAttr = parent.setAttributeNode(attrNode2);
    String actName = retAttr.getNodeName();
    String actValue = retAttr.getValue();
    if (!actName.equals(name) || !actValue.equals(oldValue)) {
        throw new RuntimeException("Test 2 failed: Invalid attribute " + "returned: " + "(name: " + actName + ", value: " + actValue + ")");
    }
}
Also used : IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) Attr(org.w3c.dom.Attr)

Example 3 with IIOMetadataNode

use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.

the class WriteMetadataTest method testWritableMetadata.

public static void testWritableMetadata(IIOMetadata m) {
    String nativeFormatName = m.getNativeMetadataFormatName();
    System.out.println("Format: " + nativeFormatName);
    IIOMetadataNode root = (IIOMetadataNode) m.getAsTree(nativeFormatName);
    if (m.isReadOnly()) {
        throw new RuntimeException("Metadata is read only!");
    }
    try {
        m.setFromTree(nativeFormatName, root);
    } catch (IIOInvalidTreeException e) {
        e.printStackTrace();
        throw new RuntimeException("Test failed!", e);
    } catch (IllegalStateException e) {
        throw new RuntimeException("Test failed!", e);
    }
    System.out.println("Test passed.\n\n");
}
Also used : IIOInvalidTreeException(javax.imageio.metadata.IIOInvalidTreeException) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode)

Example 4 with IIOMetadataNode

use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.

the class ITXtTest method writeTo.

private static void writeTo(File f, ITXtTest t) {
    BufferedImage src = createBufferedImage();
    try {
        ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(f);
        ImageTypeSpecifier imageTypeSpecifier = new ImageTypeSpecifier(src);
        ImageWriter imageWriter = ImageIO.getImageWritersByFormatName("PNG").next();
        imageWriter.setOutput(imageOutputStream);
        IIOMetadata m = imageWriter.getDefaultImageMetadata(imageTypeSpecifier, null);
        String format = m.getNativeMetadataFormatName();
        Node root = m.getAsTree(format);
        IIOMetadataNode iTXt = t.getNode();
        root.appendChild(iTXt);
        m.setFromTree(format, root);
        imageWriter.write(new IIOImage(src, null, m));
        imageOutputStream.close();
        System.out.println("Writing done.");
    } catch (Throwable e) {
        throw new RuntimeException("Writing test failed.", e);
    }
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) Node(org.w3c.dom.Node) ImageWriter(javax.imageio.ImageWriter) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) BufferedImage(java.awt.image.BufferedImage) ImageOutputStream(javax.imageio.stream.ImageOutputStream) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier) IIOImage(javax.imageio.IIOImage)

Example 5 with IIOMetadataNode

use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.

the class BMPMetadata method addChildNode.

private IIOMetadataNode addChildNode(IIOMetadataNode root, String name, Object object) {
    IIOMetadataNode child = new IIOMetadataNode(name);
    if (object != null) {
        child.setUserObject(object);
        child.setNodeValue(ImageUtil.convertObjectToString(object));
    }
    root.appendChild(child);
    return child;
}
Also used : IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode)

Aggregations

IIOMetadataNode (javax.imageio.metadata.IIOMetadataNode)133 Node (org.w3c.dom.Node)20 IIOMetadata (javax.imageio.metadata.IIOMetadata)13 NodeList (org.w3c.dom.NodeList)12 TIFFField (it.geosolutions.imageio.plugins.tiff.TIFFField)10 Iterator (java.util.Iterator)9 BufferedImage (java.awt.image.BufferedImage)8 ArrayList (java.util.ArrayList)8 ASOCBoxMetadataNode (it.geosolutions.imageio.plugins.jp2k.box.ASOCBoxMetadataNode)5 UUIDBoxMetadataNode (it.geosolutions.imageio.plugins.jp2k.box.UUIDBoxMetadataNode)5 XMLBoxMetadataNode (it.geosolutions.imageio.plugins.jp2k.box.XMLBoxMetadataNode)5 IOException (java.io.IOException)5 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)5 ImageOutputStream (javax.imageio.stream.ImageOutputStream)5 File (java.io.File)4 IIOImage (javax.imageio.IIOImage)4 ImageWriter (javax.imageio.ImageWriter)4 TIFFTag (it.geosolutions.imageio.plugins.tiff.TIFFTag)3 Color (java.awt.Color)3 Point (java.awt.Point)3