Java XML Transform Usage dumpMetadataToSystemOut(IIOMetadata iiometa)

Here you can find the source of dumpMetadataToSystemOut(IIOMetadata iiometa)

Description

Dumps the content of an IIOMetadata instance to System.out.

License

Apache License

Parameter

Parameter Description
iiometa the metadata

Declaration

public static void dumpMetadataToSystemOut(IIOMetadata iiometa) 

Method Source Code

//package com.java2s;
/*/*from www  .  j  a v  a 2s.c  o m*/
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import javax.imageio.metadata.IIOMetadata;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Node;

public class Main {
    /**
     * Dumps the content of an IIOMetadata instance to System.out.
     * @param iiometa the metadata
     */
    public static void dumpMetadataToSystemOut(IIOMetadata iiometa) {
        String[] metanames = iiometa.getMetadataFormatNames();
        for (int j = 0; j < metanames.length; j++) {
            System.out.println("--->" + metanames[j]);
            dumpNodeToSystemOut(iiometa.getAsTree(metanames[j]));
        }
    }

    /**
     * Serializes a W3C DOM node to a String and dumps it to System.out.
     * @param node a W3C DOM node
     */
    private static void dumpNodeToSystemOut(Node node) {
        try {
            Transformer trans = TransformerFactory.newInstance()
                    .newTransformer();
            trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            trans.setOutputProperty(OutputKeys.INDENT, "yes");
            Source src = new DOMSource(node);
            Result res = new StreamResult(System.out);
            trans.transform(src, res);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related

  1. createStreamResult(File outFile)
  2. createUnixStreamResultForEntry(OutputStream outputEntry)
  3. dateToGregorian(Date date)
  4. DateToXML(Date date)
  5. dumpMetadata(IIOMetadata meta)
  6. encodeBase64(Element elm)
  7. getCalendarAsXsdDateTime(Calendar c)
  8. getContentText(Element element)
  9. getDate(final XMLGregorianCalendar xmlGregorianCalendar)