01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /* $Id: ImageIODebugUtil.java 496561 2007-01-16 01:17:01Z cam $ */
19:
20: package org.apache.xmlgraphics.util;
21:
22: import javax.imageio.metadata.IIOMetadata;
23: import javax.imageio.metadata.IIOMetadataFormatImpl;
24: import javax.xml.transform.OutputKeys;
25: import javax.xml.transform.Result;
26: import javax.xml.transform.Source;
27: import javax.xml.transform.Transformer;
28: import javax.xml.transform.TransformerFactory;
29: import javax.xml.transform.dom.DOMSource;
30: import javax.xml.transform.stream.StreamResult;
31:
32: import org.w3c.dom.Node;
33:
34: /**
35: * Helper class for debugging stuff in Image I/O.
36: *
37: * @version $Id: ImageIODebugUtil.java 496561 2007-01-16 01:17:01Z cam $
38: */
39: public class ImageIODebugUtil {
40:
41: public static void dumpMetadata(IIOMetadata meta,
42: boolean nativeFormat) {
43: String format;
44: if (nativeFormat) {
45: format = meta.getNativeMetadataFormatName();
46: } else {
47: format = IIOMetadataFormatImpl.standardMetadataFormatName;
48: }
49: Node node = meta.getAsTree(format);
50: dumpNode(node);
51: }
52:
53: public static void dumpNode(Node node) {
54: try {
55: TransformerFactory tf = TransformerFactory.newInstance();
56: Transformer t = tf.newTransformer();
57: t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
58: Source src = new DOMSource(node);
59: Result res = new StreamResult(System.out);
60: t.transform(src, res);
61: System.out.println();
62: } catch (Exception e) {
63: e.printStackTrace();
64: }
65: }
66:
67: }
|