Package org.opencms.util
Class CmsHtmlConverter
java.lang.Object
org.opencms.util.CmsHtmlConverter
HTML cleaner and pretty printer.
Used to clean up HTML code (e.g. remove word tags) and optionally create XHTML from HTML.
- Since:
- 6.0.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Parameter value for disabled mode.static final String
Parameter value for enabled mode.static final String
Parameter value for replace paragraph mode.static final String
Parameter value for WORD mode.static final String
Parameter value for XHTML mode.static final char
The separator used for the configured modes String. -
Constructor Summary
ConstructorDescriptionConstructor, creates a new CmsHtmlConverter.CmsHtmlConverter
(String encoding, String mode) Constructor, creates a new CmsHtmlConverter. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
convertToByte
(byte[] htmlInput) Converts the given HTML code according to the settings of this converter.byte[]
convertToByte
(String htmlInput) Converts the given HTML code according to the settings of this converter.byte[]
convertToByteSilent
(byte[] htmlInput) Converts the given HTML code according to the settings of this converter.byte[]
convertToByteSilent
(String htmlInput) Converts the given HTML code according to the settings of this converter.convertToString
(byte[] htmlInput) Converts the given HTML code according to the settings of this converter.convertToString
(String htmlInput) Converts the given HTML code according to the settings of the converter.convertToStringSilent
(byte[] htmlInput) Converts the given HTML code according to the settings of this converter.convertToStringSilent
(String htmlInput) Converts the given HTML code according to the settings of this converter.static String
getConversionSettings
(CmsObject cms, CmsResource resource) Reads the content conversion property of a given resource and returns its value.Returns the encoding used for the HTML code conversion.getMode()
Returns the conversion mode to use.static boolean
isConversionEnabled
(String conversionMode) Tests if the content conversion is enabled.
-
Field Details
-
PARAM_DISABLED
Parameter value for disabled mode. -
PARAM_ENABLED
Parameter value for enabled mode. -
PARAM_REPLACE_PARAGRAPHS
Parameter value for replace paragraph mode.- See Also:
-
PARAM_WORD
Parameter value for WORD mode.- See Also:
-
PARAM_XHTML
Parameter value for XHTML mode.- See Also:
-
SEPARATOR_MODES
The separator used for the configured modes String.- See Also:
-
-
Constructor Details
-
CmsHtmlConverter
public CmsHtmlConverter()Constructor, creates a new CmsHtmlConverter.The encoding used by default is
CmsEncoder.ENCODING_UTF_8
. -
CmsHtmlConverter
Constructor, creates a new CmsHtmlConverter.Possible values for the default conversion mode are:
PARAM_DISABLED
: The conversion is disabled.PARAM_ENABLED
: Conversion is enabled without transformation, so HTML is pretty printed only.PARAM_XHTML
: Conversion from HTML to XHTML is enabled.PARAM_WORD
: Cleanup of word like HTML tags is enabled.- Other values can be used by the implementing converter class.
;
separator, so it is e.g. possible to convert to XHTML and clean from word at the same time.- Parameters:
encoding
- the encoding used for the HTML code conversionmode
- the conversion mode to use
-
-
Method Details
-
getConversionSettings
Reads the content conversion property of a given resource and returns its value.A default value (disabled) is returned if the property could not be read.
- Parameters:
cms
- the CmsObjectresource
- the resource in the VFS- Returns:
- the content conversion property value
-
isConversionEnabled
Tests if the content conversion is enabled.- Parameters:
conversionMode
- the content conversion mode string- Returns:
- true or false
-
convertToByte
Converts the given HTML code according to the settings of this converter.- Parameters:
htmlInput
- HTML input stored in an array of bytes- Returns:
- array of bytes containing the converted HTML
- Throws:
UnsupportedEncodingException
- if the encoding set for the conversion is not supported
-
convertToByte
Converts the given HTML code according to the settings of this converter.- Parameters:
htmlInput
- HTML input stored in a string- Returns:
- array of bytes containing the converted HTML
- Throws:
UnsupportedEncodingException
- if the encoding set for the conversion is not supported
-
convertToByteSilent
Converts the given HTML code according to the settings of this converter.If an any error occurs during the conversion process, the original input is returned unmodified.
- Parameters:
htmlInput
- HTML input stored in an array of bytes- Returns:
- array of bytes containing the converted HTML
-
convertToByteSilent
Converts the given HTML code according to the settings of this converter.If an any error occurs during the conversion process, the original input is returned unmodified.
- Parameters:
htmlInput
- HTML input stored in a string- Returns:
- array of bytes containing the converted HTML
-
convertToString
Converts the given HTML code according to the settings of this converter.- Parameters:
htmlInput
- HTML input stored in an array of bytes- Returns:
- string containing the converted HTML
- Throws:
UnsupportedEncodingException
- if the encoding set for the conversion is not supported
-
convertToString
Converts the given HTML code according to the settings of the converter.- Parameters:
htmlInput
- HTML input stored in a string- Returns:
- string containing the converted HTML
- Throws:
UnsupportedEncodingException
- if the encoding set for the conversion is not supported
-
convertToStringSilent
Converts the given HTML code according to the settings of this converter.If an any error occurs during the conversion process, the original input is returned unmodified.
- Parameters:
htmlInput
- HTML input stored in an array of bytes- Returns:
- string containing the converted HTML
-
convertToStringSilent
Converts the given HTML code according to the settings of this converter.If an any error occurs during the conversion process, the original input is returned unmodified.
- Parameters:
htmlInput
- HTML input stored in string- Returns:
- string containing the converted HTML
-
getEncoding
Returns the encoding used for the HTML code conversion.- Returns:
- the encoding used for the HTML code conversion
-
getMode
Returns the conversion mode to use.- Returns:
- the conversion mode to use
-