| 1 | // Jomic - a viewer for comic book archives. |
| 2 | // Copyright (C) 2004-2008 Thomas Aglassinger |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | package net.sf.jomic; |
| 17 | |
| 18 | import java.io.File; |
| 19 | import java.io.IOException; |
| 20 | import java.io.PrintStream; |
| 21 | |
| 22 | import org.xml.sax.SAXException; |
| 23 | |
| 24 | import net.sf.jomic.tools.XmlTools; |
| 25 | |
| 26 | /** |
| 27 | * Pretty printer for XML files. There are many already, but this one is 100% pure Java and treats |
| 28 | * white space in text properly (unlike Tidy). <p> |
| 29 | * |
| 30 | * Based on code from <a href="http://faq.javaranch.com/view?HowToPrettyPrintXmlWithJava"> |
| 31 | * http://faq.javaranch.com/view?HowToPrettyPrintXmlWithJava</a> .</p> |
| 32 | * |
| 33 | * @author Thomas Aglassinger |
| 34 | */ |
| 35 | public final class XmlPrettyPrinter |
| 36 | { |
| 37 | /** |
| 38 | * Private empty default constructor to make CheckStyle happy. |
| 39 | */ |
| 40 | private XmlPrettyPrinter() { |
| 41 | super(); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Pretty print files passed in <code>arguments</code>. |
| 46 | */ |
| 47 | public static void main(String[] arguments) |
| 48 | throws IOException, SAXException { |
| 49 | boolean skipPrettyPrint = Boolean.getBoolean("net.sf.jomic.skipReformatXml"); |
| 50 | PrintStream statusStream = System.out; |
| 51 | |
| 52 | if (skipPrettyPrint) { |
| 53 | statusStream.println("skip pretty printing"); |
| 54 | } else { |
| 55 | XmlTools xmlTools = XmlTools.instance(); |
| 56 | |
| 57 | // TODO: Use local catalog cache for DTDs. |
| 58 | for (int i = 0; i < arguments.length; i += 1) { |
| 59 | String xmlFilePath = arguments[i]; |
| 60 | File xmlFile = new File(xmlFilePath); |
| 61 | |
| 62 | statusStream.println("pretty print " + xmlFilePath); |
| 63 | xmlTools.prettyPrint(xmlFile); |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | } |