/** * Pretty prints the given node using default styles * * @param node the node, usually a document, to be printed * @param endWithNewline if true, ensure that the printed output ends with a newline * @return the resulting formatted string */ @NonNull public static String prettyPrint(@NonNull Node node, boolean endWithNewline) { return prettyPrint( node, XmlFormatPreferences.defaults(), XmlFormatStyle.get(node), SdkUtils.getLineSeparator(), endWithNewline); }
/** Command line driver */ public static void main(String[] args) { if (args.length == 0) { printUsage(); } List<File> files = Lists.newArrayList(); XmlFormatPreferences prefs = XmlFormatPreferences.defaults(); boolean stdout = false; for (String arg : args) { if (arg.startsWith("--")) { if ("--stdout".equals(arg)) { stdout = true; } else if ("--removeEmptyLines".equals(arg)) { prefs.removeEmptyLines = true; } else if ("--noAttributeOnFirstLine".equals(arg)) { prefs.oneAttributeOnFirstLine = false; } else if ("--noSpaceBeforeClose".equals(arg)) { prefs.spaceBeforeClose = false; } else { System.err.println("Unknown flag " + arg); printUsage(); } } else { File file = new File(arg).getAbsoluteFile(); if (!file.exists()) { System.err.println("Can't find file " + file); System.exit(1); } else { files.add(file); } } } for (File file : files) { formatFile(prefs, file, stdout); } System.exit(0); }