Java tutorial
//package com.java2s; /* Copyright (c) 2011-2012, The University of Edinburgh. * All Rights Reserved. * * This file is part of AsciiMathParser. * * AsciiMathParser is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * AsciiMathParser is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License (at http://www.gnu.org/licences/lgpl.html) * for more details. * * You should have received a copy of the GNU General Public License * along with AsciiMathParser. If not, see <http://www.gnu.org/licenses/lgpl.html>. */ import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; public class Main { /** * Helper to turn on indentation for a {@link Transformer} that works correctly for * both Saxon and Xalan. * * @param transformer {@link Transformer} to configure * @param indent required indentation, where 0 or more provides indentation and negative * numbers turns indentation off. */ public static void setIndentation(final Transformer transformer, final int indent) { if (indent >= 0) { final String indentString = String.valueOf(indent); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); /* Set custom properties for both Saxon and Xalan at once. * This appears safe to do without having to check the underlying processor. */ transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", indentString); transformer.setOutputProperty("{http://saxon.sf.net/}indent-spaces", indentString); } else { transformer.setOutputProperty(OutputKeys.INDENT, "no"); } } }