Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;

import javax.xml.transform.TransformerFactory;

public class Main {
    private static final Integer DEFAULT_INDENT = Integer.valueOf(4);

    public static Transformer newTransformer(boolean indented) {

        String indentFlag = (indented) ? "yes" : "no";

        try {

            TransformerFactory factory = TransformerFactory.newInstance();
            factory.setAttribute("indent-number", DEFAULT_INDENT);

            Transformer transformer;
            transformer = factory.newTransformer();
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
            transformer.setOutputProperty(OutputKeys.INDENT, indentFlag);
            transformer.setOutputProperty(OutputKeys.METHOD, "xml");

            return transformer;

        } catch (TransformerConfigurationException e) {
            throw new RuntimeException(e);
        }
    }
}