Author: rdonkin
Date: Fri Aug 5 03:26:18 2005
New Revision: 230426
URL: http://svn.apache.org/viewcvs?rev=230426&view=rev
Log:
Added support for configuration of initial indent value for pretty printing.
Contributed by Alex Ieong. Issue #36053.
Modified:
jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/io/BeanWriter.java
jakarta/commons/proper/betwixt/trunk/xdocs/guide/writing.xml
jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml
Modified:
jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/io/BeanWriter.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/io/BeanWriter.java?rev=230426&r1=230425&r2=230426&view=diff
==============================================================================
---
jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/io/BeanWriter.java
(original)
+++
jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/io/BeanWriter.java
Fri Aug 5 03:26:18 2005
@@ -102,6 +102,8 @@
private static final String EOL = getEOL();
/** text used for end of lines. Defaults to <code>\n</code>*/
private String endOfLine = EOL;
+ /** Initial level of indentation (starts at 1 with the first element by
default) */
+ private int initialIndentLevel = 1;
/** indentation text */
private String indent;
@@ -117,7 +119,7 @@
private boolean closedStartTag = true;
/** Should an end tag be added for empty elements? */
private boolean addEndTagForEmptyElement = false;
- /** Current level of indentation (starts at 1 with the first element) */
+ /** Current level of indentation */
private int indentLevel;
/** USed to determine how body content should be encoded before being
output*/
private MixedContentEncodingStrategy mixedContentEncodingStrategy
@@ -250,6 +252,24 @@
}
/**
+ * Gets the initial indent level
+ *
+ * @return the initial level for indentation
+ */
+ public int getInitialIndentLevel() {
+ return initialIndentLevel;
+ }
+
+ /**
+ * Sets the initial indent level used for pretty print indents
+ * @param indent use this <code>int</code> to start with
+ */
+ public void setInitialIndentLevel(int initialIndentLevel) {
+ this.initialIndentLevel = initialIndentLevel;
+ }
+
+
+ /**
* Gets the indent string
*
* @return the string used for indentation
@@ -478,7 +498,7 @@
*/
private void indent() throws IOException {
if ( indent != null ) {
- for ( int i = 0; i < indentLevel; i++ ) {
+ for ( int i = 1 - initialIndentLevel; i < indentLevel; i++ ) {
writer.write( getIndent() );
}
}
Modified: jakarta/commons/proper/betwixt/trunk/xdocs/guide/writing.xml
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/xdocs/guide/writing.xml?rev=230426&r1=230425&r2=230426&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/xdocs/guide/writing.xml (original)
+++ jakarta/commons/proper/betwixt/trunk/xdocs/guide/writing.xml Fri Aug 5
03:26:18 2005
@@ -113,5 +113,31 @@
</p>
</subsection>
</section>
+<section name='Pretty Print'>
+ <subsection name='Pretty Printing'>
+ <p>
+<code>BeanWriter</code> supports pretty printing. When pretty printing, extra
white space will be inserted
+with the aim of making the xml produced more readible by humans. Pretty
printing is off by default.
+Call <code>enablePrettyPrint</code> to switch it on. For example:
+ </p>
+<source>
+ BeanWriter writer = ...
+ ...
+ writer.enablePrettyPrinting();
+</source>
+ </subsection>
+ <subsection name='Setting Initial Indent'>
+ <p>
+Pretty printing indents elements so that the xml can be read more easily. The
number of indentations
+for the root element defaults to one. Some users may prefer this to start at
zero. This value is configurable through
+the <code>initialIndentLevel</code> property of <code>BeanWriter</code>. For
example
+ </p>
+<source>
+ BeanWriter writer = ...
+ ...
+ writer.setInitialIndentLevel(0);
+</source>
+ </subsection>
+</section>
</body>
</document>
Modified: jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml?rev=230426&r1=230425&r2=230426&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml (original)
+++ jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml Fri Aug 5 03:26:18
2005
@@ -190,6 +190,9 @@
<section name='Completed'>
<subsection name='Since 0.7'>
<ul>
+ <li>
+Made intitial indent level used for pretty printing configurable.
+ </li>
<li>Added guess-name attribute to addDefaults element in dot betwixt
file.
This allows mixed collections to be used with add-adders and
addDefaults.</li>
</ul>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]