1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.tools;
16  
17  import com.liferay.portal.kernel.util.FileUtil;
18  import com.liferay.portal.kernel.util.GetterUtil;
19  import com.liferay.portal.kernel.util.HtmlUtil;
20  import com.liferay.portal.kernel.util.Validator;
21  import com.liferay.portal.util.InitUtil;
22  
23  /**
24   * <a href="XMLFormatter.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Brian Wing Shun Chan
27   */
28  public class XMLFormatter {
29  
30      public static void main(String[] args) {
31          InitUtil.initWithSpring();
32  
33          String fileName = System.getProperty("xml.formatter.file");
34          boolean stripComments = GetterUtil.getBoolean(
35              System.getProperty("xml.formatter.strip.comments"));
36  
37          if (Validator.isNull(fileName)) {
38              throw new IllegalArgumentException();
39          }
40  
41          try {
42              String xml = FileUtil.read(fileName);
43  
44              if (stripComments) {
45                  xml = HtmlUtil.stripComments(xml);
46              }
47  
48              xml = com.liferay.util.xml.XMLFormatter.toString(xml);
49  
50              FileUtil.write(fileName, xml);
51          }
52          catch (Exception e) {
53              e.printStackTrace();
54          }
55      }
56  
57  }