Package com.helger.xml.serialize.write
Class XMLWriterSettings
java.lang.Object
com.helger.xml.serialize.write.XMLWriterSettings
- All Implemented Interfaces:
com.helger.commons.lang.ICloneable<XMLWriterSettings>,IXMLWriterSettings
@NotThreadSafe
public class XMLWriterSettings
extends Object
implements IXMLWriterSettings, com.helger.commons.lang.ICloneable<XMLWriterSettings>
Default implementation of the
Describes the export settings for the MicroWriter. Defaults to indented and aligned XML in the UTF-8 charset.
IXMLWriterSettings interface.Describes the export settings for the MicroWriter. Defaults to indented and aligned XML in the UTF-8 charset.
- Author:
- Philip Helger
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanBy default namespaces are written.static final EXMLIncorrectCharacterHandlingBy default invalid characters are not written and a log message is emittedstatic final StringBy default indentation happens with 2 spacesstatic final booleanBy default a newline character is emitted afterwardsstatic final booleanBy default the insertion order of attributes is maintainedstatic final booleanBy default namespace context prefixes are put inside the root elementstatic final EXMLSerializeCommentsBy default comments are emittedstatic final EXMLSerializeDocTypeBy default the document type is emittedstatic final EXMLSerializeIndentBy default the output is indented and aligned (newlines are added)static final EXMLSerializeXMLDeclarationBy default all fields of the XML declaration are emittedstatic final booleanBy default a leading space is inserted before a self closed element (e.g.static final booleanBy default double quotes are used to wrap attribute valuesstatic final booleanBy default CDATA children are emitted as CDATAstatic final StringThe default charset is UTF-8static final CharsetThe default charset is UTF-8static final EXMLSerializeVersionDefault default XML version is 1.0static final IXMLWriterSettingsThe default settings to use - last constant -
Constructor Summary
ConstructorsConstructorDescriptionCreates a default settings object with the following settings: XML version 1.0 with XML declaration with document type with comments Indented and aligned Writing invalid characters to the file as is - may result in invalid XML files Default character set UTF-8 No namespace contextXMLWriterSettings(IXMLWriterSettings aOther) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic XMLWriterSettingsThe canonical form of an XML document is physical representation of the document produced by the method described in this specification.static XMLWriterSettingsstatic XMLWriterSettingsstatic XMLWriterSettingsbooleangetClone()com.helger.commons.system.ENewLineModeinthashCode()booleanDetermine if namespaces should be emitted or not.booleanbooleanDetermine if attributes of elements and namespaces should be emitted in alphabetical order or not.booleanCheck if the flag for putting all namespace prefixes specified in the namespace context should be put in the root document.booleanDetermine if a self closed element (an element having no children) should be emitted with a space at the end (<br />) or not (<br/>)booleanbooleanCheck if all CDATA children should be emitted as normal text or not.final XMLWriterSettingssetBracketModeDeterminator(IXMLBracketModeDeterminator aBracketModeDeterminator) final XMLWriterSettingssetCharset(Charset aCharset) Set the serialization charset.final XMLWriterSettingssetEmitNamespaces(boolean bEmitNamespaces) final XMLWriterSettingssetIncorrectCharacterHandling(EXMLIncorrectCharacterHandling eIncorrectCharacterHandling) Set the way how to handle invalid characters.final XMLWriterSettingssetIndent(EXMLSerializeIndent eIndent) Set the way how to indent/alignfinal XMLWriterSettingssetIndentationString(String sIndentationString) final XMLWriterSettingssetIndentDeterminator(IXMLIndentDeterminator aIndentDeterminator) Set the dynamic (per-element) indent determinator to be used.final XMLWriterSettingssetNamespaceContext(NamespaceContext aNamespaceContext) Set the namespace context to be used.final XMLWriterSettingssetNewLineAfterXMLDeclaration(boolean bNewLineAfterXMLDeclaration) Change whether a newline should be printed after the XML declaration or not.final XMLWriterSettingssetNewLineMode(com.helger.commons.system.ENewLineMode eNewLineMode) final XMLWriterSettingssetOrderAttributesAndNamespaces(boolean bOrderAttributesAndNamespaces) final XMLWriterSettingssetPutNamespaceContextPrefixesInRoot(boolean bPutNamespaceContextPrefixesInRoot) final XMLWriterSettingssetSerializeComments(EXMLSerializeComments eSerializeComments) Set the way how comments should be handled.final XMLWriterSettingssetSerializeDocType(EXMLSerializeDocType eSerializeDocType) Set the way how to handle the doc type.final XMLWriterSettingssetSerializeVersion(EXMLSerializeVersion eSerializeVersion) Set the preferred XML version to use.final XMLWriterSettingssetSerializeXMLDeclaration(EXMLSerializeXMLDeclaration eSerializeXMLDecl) Set the way how to handle the XML declaration.final XMLWriterSettingssetSpaceOnSelfClosedElement(boolean bSpaceOnSelfClosedElement) final XMLWriterSettingssetUseDoubleQuotesForAttributes(boolean bUseDoubleQuotesForAttributes) final XMLWriterSettingssetWriteCDATAAsText(boolean bWriteCDATAAsText) toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.xml.serialize.write.IXMLWriterSettings
getNewLineString
-
Field Details
-
DEFAULT_XML_SERIALIZE_VERSION
Default default XML version is 1.0 -
DEFAULT_SERIALIZE_XML_DECLARATION
By default all fields of the XML declaration are emitted -
DEFAULT_NEW_LINE_AFTER_XML_DECLARATION
public static final boolean DEFAULT_NEW_LINE_AFTER_XML_DECLARATIONBy default a newline character is emitted afterwards- See Also:
-
DEFAULT_SERIALIZE_DOC_TYPE
By default the document type is emitted -
DEFAULT_SERIALIZE_COMMENTS
By default comments are emitted -
DEFAULT_SERIALIZE_INDENT
By default the output is indented and aligned (newlines are added) -
DEFAULT_INCORRECT_CHARACTER_HANDLING
By default invalid characters are not written and a log message is emitted -
DEFAULT_XML_CHARSET_OBJ
The default charset is UTF-8 -
DEFAULT_XML_CHARSET
The default charset is UTF-8 -
DEFAULT_USE_DOUBLE_QUOTES_FOR_ATTRIBUTES
public static final boolean DEFAULT_USE_DOUBLE_QUOTES_FOR_ATTRIBUTESBy default double quotes are used to wrap attribute values- See Also:
-
DEFAULT_SPACE_ON_SELF_CLOSED_ELEMENT
public static final boolean DEFAULT_SPACE_ON_SELF_CLOSED_ELEMENTBy default a leading space is inserted before a self closed element (e.g.<b />in contrast to<b/>).- See Also:
-
DEFAULT_INDENTATION_STRING
By default indentation happens with 2 spaces- See Also:
-
DEFAULT_EMIT_NAMESPACES
public static final boolean DEFAULT_EMIT_NAMESPACESBy default namespaces are written.- See Also:
-
DEFAULT_PUT_NAMESPACE_CONTEXT_PREFIXES_IN_ROOT
public static final boolean DEFAULT_PUT_NAMESPACE_CONTEXT_PREFIXES_IN_ROOTBy default namespace context prefixes are put inside the root element- See Also:
-
DEFAULT_WRITE_CDATA_AS_TEXT
public static final boolean DEFAULT_WRITE_CDATA_AS_TEXTBy default CDATA children are emitted as CDATA- See Also:
-
DEFAULT_ORDER_ATTRIBUTES_AND_NAMESPACES
public static final boolean DEFAULT_ORDER_ATTRIBUTES_AND_NAMESPACESBy default the insertion order of attributes is maintained- See Also:
-
DEFAULT_XML_SETTINGS
The default settings to use - last constant
-
-
Constructor Details
-
XMLWriterSettings
public XMLWriterSettings()Creates a default settings object with the following settings:- XML version 1.0
- with XML declaration
- with document type
- with comments
- Indented and aligned
- Writing invalid characters to the file as is - may result in invalid XML files
- Default character set UTF-8
- No namespace context
-
XMLWriterSettings
Copy constructor.- Parameters:
aOther- The object to copy the settings from. May not benull.
-
-
Method Details
-
getXMLVersion
- Specified by:
getXMLVersionin interfaceIXMLWriterSettings- Returns:
- The XML version to use. Default is
1.0
-
getSerializeVersion
- Specified by:
getSerializeVersionin interfaceIXMLWriterSettings- Returns:
- The XML serialize version to use. Default is
XML 1.0
-
setSerializeVersion
@Nonnull public final XMLWriterSettings setSerializeVersion(@Nonnull EXMLSerializeVersion eSerializeVersion) Set the preferred XML version to use.- Parameters:
eSerializeVersion- The XML serialize version. May not benull.- Returns:
- this
-
getSerializeXMLDeclaration
- Specified by:
getSerializeXMLDeclarationin interfaceIXMLWriterSettings- Returns:
- Write XML declaration? Default is
true.
-
setSerializeXMLDeclaration
@Nonnull public final XMLWriterSettings setSerializeXMLDeclaration(@Nonnull EXMLSerializeXMLDeclaration eSerializeXMLDecl) Set the way how to handle the XML declaration.- Parameters:
eSerializeXMLDecl- XML declaration handling. May not benull.- Returns:
- this
-
isNewLineAfterXMLDeclaration
public boolean isNewLineAfterXMLDeclaration()- Specified by:
isNewLineAfterXMLDeclarationin interfaceIXMLWriterSettings- Returns:
trueif a newline should be added after the XML declaration or not. Defaults totrue.
-
setNewLineAfterXMLDeclaration
@Nonnull public final XMLWriterSettings setNewLineAfterXMLDeclaration(boolean bNewLineAfterXMLDeclaration) Change whether a newline should be printed after the XML declaration or not.- Parameters:
bNewLineAfterXMLDeclaration-trueto print it,falseto not print a new line.- Returns:
- this for chaining
-
getSerializeDocType
- Specified by:
getSerializeDocTypein interfaceIXMLWriterSettings- Returns:
- Write document type? Default is
true.
-
setSerializeDocType
@Nonnull public final XMLWriterSettings setSerializeDocType(@Nonnull EXMLSerializeDocType eSerializeDocType) Set the way how to handle the doc type.- Parameters:
eSerializeDocType- Doc type handling. May not benull.- Returns:
- this
-
getSerializeComments
- Specified by:
getSerializeCommentsin interfaceIXMLWriterSettings- Returns:
- Write comments? Default is
true.
-
setSerializeComments
@Nonnull public final XMLWriterSettings setSerializeComments(@Nonnull EXMLSerializeComments eSerializeComments) Set the way how comments should be handled.- Parameters:
eSerializeComments- The comment handling. May not benull.- Returns:
- this
-
getIndent
- Specified by:
getIndentin interfaceIXMLWriterSettings- Returns:
- Indent and/or align code? Default is
indent and aligned.
-
setIndent
Set the way how to indent/align- Parameters:
eIndent- Indent and align definition. May not benull.- Returns:
- this
-
getIndentDeterminator
- Specified by:
getIndentDeterminatorin interfaceIXMLWriterSettings- Returns:
- The dynamic (per-element) indentation determinator. This must be
changed when e.g. serializing HTML. Never
null.
-
setIndentDeterminator
@Nonnull public final XMLWriterSettings setIndentDeterminator(@Nonnull IXMLIndentDeterminator aIndentDeterminator) Set the dynamic (per-element) indent determinator to be used.- Parameters:
aIndentDeterminator- The object to use. May not benull.- Returns:
- this
-
getIncorrectCharacterHandling
- Specified by:
getIncorrectCharacterHandlingin interfaceIXMLWriterSettings- Returns:
- The incorrect character handling to be used. May not be
null.
-
setIncorrectCharacterHandling
@Nonnull public final XMLWriterSettings setIncorrectCharacterHandling(@Nonnull EXMLIncorrectCharacterHandling eIncorrectCharacterHandling) Set the way how to handle invalid characters.- Parameters:
eIncorrectCharacterHandling- The invalid character handling. May not benull.- Returns:
- this
-
getCharset
- Specified by:
getCharsetin interfaceIXMLWriterSettings- Returns:
- The charset to use. May never be
null.
-
setCharset
Set the serialization charset.- Parameters:
aCharset- The charset to be used. May not benull.- Returns:
- this
-
getNamespaceContext
- Specified by:
getNamespaceContextin interfaceIXMLWriterSettings- Returns:
- The namespace context to be used. Never
null.
-
setNamespaceContext
@Nonnull public final XMLWriterSettings setNamespaceContext(@Nullable NamespaceContext aNamespaceContext) Set the namespace context to be used.- Parameters:
aNamespaceContext- The namespace context to be used. May benull.- Returns:
- this
-
isUseDoubleQuotesForAttributes
public boolean isUseDoubleQuotesForAttributes()- Specified by:
isUseDoubleQuotesForAttributesin interfaceIXMLWriterSettings- Returns:
trueif attribute values should be enclosed in double quotes,falseif single quotes should be used.
-
setUseDoubleQuotesForAttributes
@Nonnull public final XMLWriterSettings setUseDoubleQuotesForAttributes(boolean bUseDoubleQuotesForAttributes) -
getBracketModeDeterminator
- Specified by:
getBracketModeDeterminatorin interfaceIXMLWriterSettings- Returns:
- The dynamic (per-element) bracket mode determinator to use. This
must be changed when e.g. serializing HTML. Never
null.
-
setBracketModeDeterminator
@Nonnull public final XMLWriterSettings setBracketModeDeterminator(@Nonnull IXMLBracketModeDeterminator aBracketModeDeterminator) -
isSpaceOnSelfClosedElement
public boolean isSpaceOnSelfClosedElement()Description copied from interface:IXMLWriterSettingsDetermine if a self closed element (an element having no children) should be emitted with a space at the end (<br />) or not (<br/>)- Specified by:
isSpaceOnSelfClosedElementin interfaceIXMLWriterSettings- Returns:
trueif a space should be emitted,falseif no space should be emitted.
-
setSpaceOnSelfClosedElement
@Nonnull public final XMLWriterSettings setSpaceOnSelfClosedElement(boolean bSpaceOnSelfClosedElement) -
getNewLineMode
- Specified by:
getNewLineModein interfaceIXMLWriterSettings- Returns:
- The newline mode to be used. By default it is the platform specific
new line mode. Never
null.
-
setNewLineMode
@Nonnull public final XMLWriterSettings setNewLineMode(@Nonnull com.helger.commons.system.ENewLineMode eNewLineMode) -
getIndentationString
- Specified by:
getIndentationStringin interfaceIXMLWriterSettings- Returns:
- The string to be used for indentation of a single level. By default it is 2 spaces.
-
setIndentationString
@Nonnull public final XMLWriterSettings setIndentationString(@Nonnull @Nonempty String sIndentationString) -
isEmitNamespaces
public boolean isEmitNamespaces()Description copied from interface:IXMLWriterSettingsDetermine if namespaces should be emitted or not.- Specified by:
isEmitNamespacesin interfaceIXMLWriterSettings- Returns:
trueif namespaces should be emitted,falseif all created elements should reside in the default namespace.
-
setEmitNamespaces
-
isPutNamespaceContextPrefixesInRoot
public boolean isPutNamespaceContextPrefixesInRoot()Description copied from interface:IXMLWriterSettingsCheck if the flag for putting all namespace prefixes specified in the namespace context should be put in the root document. This setting only has an effect if a namespace context is defined and if it implements theIIterableNamespaceContextinterface!- Specified by:
isPutNamespaceContextPrefixesInRootin interfaceIXMLWriterSettings- Returns:
trueif it is enabled,falseif not.
-
setPutNamespaceContextPrefixesInRoot
@Nonnull public final XMLWriterSettings setPutNamespaceContextPrefixesInRoot(boolean bPutNamespaceContextPrefixesInRoot) -
isWriteCDATAAsText
public boolean isWriteCDATAAsText()Description copied from interface:IXMLWriterSettingsCheck if all CDATA children should be emitted as normal text or not. This is required for XML canonicalization.- Specified by:
isWriteCDATAAsTextin interfaceIXMLWriterSettings- Returns:
trueif CDATA should be written as text,falseto keep CDATA as it is.
-
setWriteCDATAAsText
-
isOrderAttributesAndNamespaces
public boolean isOrderAttributesAndNamespaces()Description copied from interface:IXMLWriterSettingsDetermine if attributes of elements and namespaces should be emitted in alphabetical order or not. This is required for XML canonicalization.- Specified by:
isOrderAttributesAndNamespacesin interfaceIXMLWriterSettings- Returns:
trueto order attributes,falseto keep the original order.
-
setOrderAttributesAndNamespaces
@Nonnull public final XMLWriterSettings setOrderAttributesAndNamespaces(boolean bOrderAttributesAndNamespaces) -
getClone
- Specified by:
getClonein interfacecom.helger.commons.lang.ICloneable<XMLWriterSettings>
-
equals
-
hashCode
public int hashCode() -
toString
-
createForHTML4
-
createForXHTML
-
createForHTML5
-
createForCanonicalization
The canonical form of an XML document is physical representation of the document produced by the method described in this specification. The changes are summarized in the following list:- The document is encoded in UTF-8
- Line breaks normalized to #xA on input, before parsing
- Attribute values are normalized, as if by a validating processor
- Character and parsed entity references are replaced
- CDATA sections are replaced with their character content
- The XML declaration and document type declaration are removed
- Empty elements are converted to start-end tag pairs
- Whitespace outside of the document element and within start and end tags is normalized
- All whitespace in character content is retained (excluding characters removed during line feed normalization)
- Attribute value delimiters are set to quotation marks (double quotes)
- Special characters in attribute values and character content are replaced by character references
- Superfluous namespace declarations are removed from each element
- Default attributes are added to each element
- Fixup of xml:base attributes [C14N-Issues] is performed
- Lexicographic order is imposed on the namespace declarations and attributes of each element
- Returns:
XMLWriterSettingsfor canonicalization
-