Package com.norconex.commons.lang.xml
Class XMLFormatter.Builder
- java.lang.Object
-
- com.norconex.commons.lang.xml.XMLFormatter.Builder
-
- Enclosing class:
- XMLFormatter
public static class XMLFormatter.Builder extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classXMLFormatter.Builder.AttributeWrap
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description XMLFormatter.BuilderattributeIndent(String indent)String to use for indenting attributed, when wrapped.XMLFormatter.BuilderattributeWrapping(XMLFormatter.Builder.AttributeWrap attributeWrapping)Attribute wrapping strategy.XMLFormatter.BuilderblankLineAfterComment()Inserts a blank line after a comment.XMLFormatter.BuilderblankLineBeforeComment()Inserts a blank line before a comment.XMLFormatterbuild()Creates an immutable, thread-safe XML formatter instance using this builder.XMLFormatter.BuildercloseWrappingTagOnOwnLine()Put the closing angle bracket of tags with wrapping attributes on its own line, aligned with opening angle bracket.XMLFormatter.BuilderelementIndent(String indent)String to use for indenting elements.XMLFormatter.BuildermaxLineLength(int charQty)Maximum length a line can have before wrapping is performed.XMLFormatter.BuilderminTextLength(int charQty)Minimum length for text on any line before text can be wrapped.XMLFormatter.BuilderpreserveTextIndent()Preserves indentation found in element or comment text.XMLFormatter.BuilderselfCloseEmptyElements()Self-close elements with no or blank values.
-
-
-
Method Detail
-
elementIndent
public XMLFormatter.Builder elementIndent(String indent)
String to use for indenting elements. Repeated as needed to match the current hierarchical depth of the element. Defaults to two spaces.- Parameters:
indent- string to use as indent- Returns:
- this builder
-
attributeIndent
public XMLFormatter.Builder attributeIndent(String indent)
String to use for indenting attributed, when wrapped. Defaults to four spaces.- Parameters:
indent- string to use as indent- Returns:
- this builder
-
attributeWrapping
public XMLFormatter.Builder attributeWrapping(XMLFormatter.Builder.AttributeWrap attributeWrapping)
Attribute wrapping strategy. Defaults toXMLFormatter.Builder.AttributeWrap.ALL.- Parameters:
attributeWrapping- attribute wrapping strategy- Returns:
- this builder
-
closeWrappingTagOnOwnLine
public XMLFormatter.Builder closeWrappingTagOnOwnLine()
Put the closing angle bracket of tags with wrapping attributes on its own line, aligned with opening angle bracket. Defaults to adding it the closing angle bracket at the end of the last attribute.- Returns:
- this builder
-
maxLineLength
public XMLFormatter.Builder maxLineLength(int charQty)
Maximum length a line can have before wrapping is performed. Tries to do smart break when possible. When not possible, (e.g., a very long word) it will not wrap.minTextLength(int)andXMLFormatter.Builder.AttributeWrap.NONEboth take precedence over this value.- Parameters:
charQty- maximum number of characters.- Returns:
- this builder
-
minTextLength
public XMLFormatter.Builder minTextLength(int charQty)
Minimum length for text on any line before text can be wrapped. This takes precedence overmaxLineLength.- Parameters:
charQty- minimum number of characters.- Returns:
- this builder
-
blankLineBeforeComment
public XMLFormatter.Builder blankLineBeforeComment()
Inserts a blank line before a comment.- Returns:
- this builder
-
blankLineAfterComment
public XMLFormatter.Builder blankLineAfterComment()
Inserts a blank line after a comment.- Returns:
- this builder
-
selfCloseEmptyElements
public XMLFormatter.Builder selfCloseEmptyElements()
Self-close elements with no or blank values.- Returns:
- this builder
-
preserveTextIndent
public XMLFormatter.Builder preserveTextIndent()
Preserves indentation found in element or comment text. By default all lines are trimmed. When this option is set, indentations (relative to the shorted indent) are kept.- Returns:
- this builder
-
build
public XMLFormatter build()
Creates an immutable, thread-safe XML formatter instance using this builder.- Returns:
- XML formatter
-
-