public final class Config
extends java.lang.Object
All of the properties in this class are static, affecting all objects and threads. Multiple concurrent configurations are not possible.
Properties that relate to user agent
compatibility issues are stored in instances of the Config.CompatibilityMode
class.
This allows all of the properties in the compatibility mode to be set as a block by setting the static
CurrentCompatibilityMode
property to a different instance.
Config.CompatibilityMode
Modifier and Type | Class and Description |
---|---|
static interface |
Config.CharacterReferenceEncodingBehaviour
Specifies the interface for defining character reference encoding behaviour.
|
static class |
Config.CompatibilityMode
Represents a set of configuration parameters that relate to
user agent compatibility issues.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ColumnMultipleValueSeparator
Determines the string used to separate a single column's multiple values in the output of the
FormFields.getColumnValues(Map) method. |
static java.lang.String |
ColumnValueFalse
Determines the string that represents the value
false in the output of the FormFields.getColumnValues(Map) method. |
static java.lang.String |
ColumnValueTrue
Determines the string that represents the value
true in the output of the FormFields.getColumnValues(Map) method. |
static boolean |
ConvertNonBreakingSpaces
Determines whether the
CharacterReference.decode(CharSequence) and similar methods convert non-breaking space ( ) character references to normal spaces. |
static Config.CharacterReferenceEncodingBehaviour |
CurrentCharacterReferenceEncodingBehaviour
Determines the currently active character reference encoding behaviour.
|
static Config.CompatibilityMode |
CurrentCompatibilityMode
Determines the currently active compatibility mode.
|
static Config.CharacterReferenceEncodingBehaviour |
DEFAULT_CHARACTER_REFERENCE_ENCODING_BEHAVIOUR
The default character reference encoding behaviour.
|
static boolean |
IsApostropheEncoded
Determines whether apostrophes are encoded when calling the
CharacterReference.encode(CharSequence, boolean insideAttributeValue) method. |
static boolean |
IsHTMLEmptyElementTagRecognised
Determines whether all empty-element tags are recognised.
|
static Config.CharacterReferenceEncodingBehaviour |
LEGACY_CHARACTER_REFERENCE_ENCODING_BEHAVIOUR
Character reference encoding behaviour consistent with parser version 3.3 or earlier.
|
static LoggerProvider |
LoggerProvider
Determines the
LoggerProvider that is used to create the default Logger object for each new Source object. |
static java.lang.String |
NewLine
Determines the string used to represent a newline in text output throughout the library.
|
public static java.lang.String ColumnMultipleValueSeparator
FormFields.getColumnValues(Map)
method.
The situation where a single column has multiple values only arises if FormField.getUserValueCount()
>1
on the relevant form field, which usually indicates a poorly designed form.
The default value is ",
" (a comma, not including the quotes).
Must not be null
.
public static java.lang.String ColumnValueTrue
true
in the output of the FormFields.getColumnValues(Map)
method.
The default value is "true
" (without the quotes).
Must not be null
.
public static java.lang.String ColumnValueFalse
false
in the output of the FormFields.getColumnValues(Map)
method.
The default value is null
, which represents no output at all.
public static boolean ConvertNonBreakingSpaces
CharacterReference.decode(CharSequence)
and similar methods convert non-breaking space (
) character references to normal spaces.
The default value is true
.
When this property is set to false
, non-breaking space (
)
character references are decoded as non-breaking space characters (U+00A0) instead of being converted to normal spaces (U+0020).
The default behaviour of the library reflects the fact that non-breaking space character references are almost always used in HTML documents as a non-collapsing white space character. Converting them to the correct character code U+00A0, which is represented by a visible character in many older character sets, was confusing to most users who expected to see only normal spaces. The most common example of this is its visualisation as the character á in the MS-DOS CP437 character set.
The functionality of the following methods is affected:
CharacterReference.appendCharTo(Appendable)
CharacterReference.decode(CharSequence)
CharacterReference.decode(CharSequence, boolean insideAttributeValue)
CharacterReference.decodeCollapseWhiteSpace(CharSequence)
CharacterReference.reencode(CharSequence)
Attribute.getValue()
Attributes.getValue(String name)
Attributes.populateMap(Map, boolean convertNamesToLowerCase)
StartTag.getAttributeValue(String attributeName)
Element.getAttributeValue(String attributeName)
FormControl.getPredefinedValues()
OutputDocument.replace(Attributes, boolean convertNamesToLowerCase)
Renderer.getConvertNonBreakingSpaces()
TextExtractor.getConvertNonBreakingSpaces()
public static Config.CompatibilityMode CurrentCompatibilityMode
The default setting is Config.CompatibilityMode.IE
(MS Internet Explorer 6.0).
Must not be null
.
public static boolean IsApostropheEncoded
CharacterReference.encode(CharSequence, boolean insideAttributeValue)
method.
A value of false
means apostrophe
(U+0027) characters are not encoded.
The only time apostrophes need to be encoded is within an attribute value delimited by
single quotes (apostrophes), so in most cases ignoring apostrophes is perfectly safe and
enhances the readability of the source document.
Note that apostrophes are always encoded as a numeric character reference, never as the
character entity reference '
.
The default value is false
.
public static final Config.CharacterReferenceEncodingBehaviour LEGACY_CHARACTER_REFERENCE_ENCODING_BEHAVIOUR
This setting encodes a character if a character entity reference exists for the character, or the unicode code point is greater than U+007F.
The only exception to this is an apostrophe (U+0027),
which is only encoded if the static IsApostropheEncoded
property is currently set to true
.
The insideAttributeValue
argument is ignored in this implementation.
To use this behaviour, set the static CurrentCharacterReferenceEncodingBehaviour
configuration variable to this constant
during application initialisation. It cannot be configured differently for separate threads in the one application.
CharacterReference.CurrentCharacterReferenceEncodingBehaviour=CharacterReference.LEGACY_CHARACTER_REFERENCE_ENCODING_BEHAVIOUR
public static final Config.CharacterReferenceEncodingBehaviour DEFAULT_CHARACTER_REFERENCE_ENCODING_BEHAVIOUR
This setting encodes only the following characters:
&
)
<
)
>
)
"
), if the insideAttributeValue
argument of the
CharacterReference.encode(CharSequence, boolean insideAttributeValue)
method is set to true
IsApostropheEncoded
property is currently set to true
.
All other characters are left unencoded.
This default encoding behaviour only encodes the essential characters necessary to maintain valid HTML, assuming the encoding of the document is Unicode or some other encoding that can represent all of the characters in the document.
Right angle bracket (>
) characters are also encoded although technically they don't need to be.
This is done to enhance readability of the HTML, as unencoded angle brackets make it visually difficult to recognise tags in the HTML.
This default encoding behaviour is different to the default behaviour in parser versions 3.3 and earlier. The legacy behaviour assumed 7-bit ASCII encoding of the document which is now very uncommon, resulting in the unnecessary encoding of many characters. If your application is experiencing problems due to this change, consider using the legacy behaviour instead.
public static Config.CharacterReferenceEncodingBehaviour CurrentCharacterReferenceEncodingBehaviour
This setting determines which characters are encoded when calling the CharacterReference.encode(CharSequence, boolean insideAttributeValue)
method.
The default setting is DEFAULT_CHARACTER_REFERENCE_ENCODING_BEHAVIOUR
.
Must not be null
.
public static boolean IsHTMLEmptyElementTagRecognised
The major browsers do not recognise empty-element tags (those having the characters "/>" at the end of the start tag) if the element is defined by the HTML specification to have a required or an optional end tag. This is the case even in XHTML documents, which can cause a lot of confusion.
Setting this property to true
forces the parser to recognise all syntactical empty-element tags,
regardless of whether the element is defined by the HTML specification to have a required or optional end tag.
Use of this feature is however not recommended as it makes the parser behaviour inconsistent with that of most browsers.
The default value is false
.
StartTag.isEmptyElementTag()
public static LoggerProvider LoggerProvider
LoggerProvider
that is used to create the default Logger
object for each new Source
object.
The LoggerProvider
interface contains several predefined LoggerProvider
instances which this property can be set to,
mostly representing wrappers to common logging frameworks.
The default value is null
, which results in the auto-detection of the most appropriate logging mechanism according to the following algorithm:
org.slf4j.impl.StaticLoggerBinder
is detected:
org.slf4j.impl.JDK14LoggerFactory
is detected, use LoggerProvider.JAVA
.
org.slf4j.impl.Log4jLoggerFactory
is detected, use LoggerProvider.LOG4J
.
org.slf4j.impl.JCLLoggerFactory
is NOT detected, use LoggerProvider.SLF4J
.
org.apache.commons.logging.Log
is detected:
Create an instance of it using the commons-loggingLogFactory
class.
- If the created
Log
is of typeorg.apache.commons.logging.impl.Jdk14Logger
, useLoggerProvider.JAVA
.- If the created
Log
is of typeorg.apache.commons.logging.impl.Log4JLogger
, useLoggerProvider.LOG4J
.- otherwise, use
LoggerProvider.JCL
.
org.apache.log4j.Logger
is detected, use LoggerProvider.LOG4J
.
LoggerProvider.JAVA
.
Source.setLogger(Logger)
public static java.lang.String NewLine
The default value is the standard new line character sequence of the host platform, determined by System.getProperty("line.separator")
.