View Javadoc
1   /*
2    * XML Format Maven Plugin (https://github.com/acegi/xml-format-maven-plugin)
3    *
4    * Copyright 2011-2025 Acegi Technology Pty Limited.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      https://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package au.com.acegi.xmlformat;
19  
20  import org.dom4j.io.OutputFormat;
21  
22  /**
23   * Extended DOM4J configuration.
24   * <ul>
25   * <li>Defaults to pretty print.
26   * <li>Adds an option to keep blank lines.
27   * </ul>
28   */
29  public class XmlOutputFormat extends OutputFormat {
30  
31      private boolean keepBlankLines;
32  
33      /**
34       * Instantiates a new xml output format.
35       */
36      public XmlOutputFormat() {
37          // same as pretty print
38          setIndentSize(2);
39          setNewlines(true);
40          setTrimText(true);
41          setPadText(true);
42      }
43  
44      /**
45       * When set to true, preserves at most one blank line between tags, if it was alredy present in the input file.
46       * Defaults to <code>false</code>.
47       *
48       * @return Whether blank lines are preserved, or not.
49       */
50      public boolean isKeepBlankLines() {
51          return keepBlankLines;
52      }
53  
54      /**
55       * When set to true, preserves at most one blank line between tags, if it was alredy present in the input file.
56       *
57       * @param keepBlankLines
58       *            true to preserve at most one blank line, false to remove all blank lines.
59       */
60      public void setKeepBlankLines(final boolean keepBlankLines) {
61          this.keepBlankLines = keepBlankLines;
62      }
63  }