1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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  }