1 16 17 package org.springframework.web.servlet.view.xslt; 18 19 import javax.xml.transform.OutputKeys ; 20 import javax.xml.transform.Transformer ; 21 22 import org.springframework.util.Assert; 23 24 30 public abstract class TransformerUtils { 31 32 37 public static final int DEFAULT_INDENT_AMOUNT = 2; 38 39 40 50 public static void enableIndenting(Transformer transformer) { 51 enableIndenting(transformer, DEFAULT_INDENT_AMOUNT); 52 } 53 54 66 public static void enableIndenting(Transformer transformer, int indentAmount) { 67 Assert.notNull(transformer); 68 Assert.isTrue(indentAmount > -1, "The indent amount cannot be less than zero : got " + indentAmount); 69 transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 70 try { 71 transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(indentAmount)); 73 } 74 catch (IllegalArgumentException ignored) { 75 } 76 } 77 78 84 public static void disableIndenting(Transformer transformer) { 85 Assert.notNull(transformer); 86 transformer.setOutputProperty(OutputKeys.INDENT, "no"); 87 } 88 89 } 90 | Popular Tags |