org.opencms.util
Class CmsHtmlConverter

java.lang.Object
  extended byorg.opencms.util.CmsHtmlConverter

public class CmsHtmlConverter
extends java.lang.Object

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
Version:
$Revision: 1.30 $
Author:
Michael Emmerich, Alexander Kandzior

Field Summary
static java.lang.String PARAM_DISABLED
          Parameter value for disabled mode.
static java.lang.String PARAM_ENABLED
          Parameter value for enabled mode.
static java.lang.String PARAM_WORD
          Parameter value for WORD mode.
static java.lang.String PARAM_XHTML
          Parameter value for XHTML mode.
 
Constructor Summary
CmsHtmlConverter()
          Constructor, creates a new CmsHtmlConverter.
CmsHtmlConverter(java.lang.String encoding, java.lang.String mode)
          Constructor, creates a new CmsHtmlConverter.
 
Method Summary
 byte[] convertToByte(byte[] htmlInput)
          Converts the given html code according to the settings of this converter.
 byte[] convertToByte(java.lang.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(java.lang.String htmlInput)
          Converts the given html code according to the settings of this converter.
 java.lang.String convertToString(byte[] htmlInput)
          Converts the given html code according to the settings of this converter.
 java.lang.String convertToString(java.lang.String htmlInput)
          Converts the given html code according to the settings of this converter.
 java.lang.String convertToStringSilent(byte[] htmlInput)
          Converts the given html code according to the settings of this converter.
 java.lang.String convertToStringSilent(java.lang.String htmlInput)
          Converts the given html code according to the settings of this converter.
static java.lang.String getConversionSettings(CmsObject cms, CmsResource resource)
          Reads the content conversion property of a given resource and returns it's value.
 java.lang.String getEncoding()
          Returns the encoding used for the html code conversion.
static boolean isConversionEnabled(java.lang.String conversionMode)
          Tests if the content conversion is enabled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARAM_DISABLED

public static final java.lang.String PARAM_DISABLED
Parameter value for disabled mode.


PARAM_ENABLED

public static final java.lang.String PARAM_ENABLED
Parameter value for enabled mode.


PARAM_WORD

public static final java.lang.String PARAM_WORD
Parameter value for WORD mode.

See Also:
Constant Field Values

PARAM_XHTML

public static final java.lang.String PARAM_XHTML
Parameter value for XHTML mode.

See Also:
Constant Field Values
Constructor Detail

CmsHtmlConverter

public CmsHtmlConverter()
Constructor, creates a new CmsHtmlConverter.

The encoding used by default is CmsEncoder.ENCODING_UTF_8.


CmsHtmlConverter

public CmsHtmlConverter(java.lang.String encoding,
                        java.lang.String mode)
Constructor, creates a new CmsHtmlConverter.

Possible values for the conversion mode are:

Values can be combined with the ; separator, so it's possible to convert to xhtml and clean from word at the same time.

Parameters:
encoding - the encoding used for the html code conversion
mode - the conversion mode to use
Method Detail

getConversionSettings

public static java.lang.String getConversionSettings(CmsObject cms,
                                                     CmsResource resource)
Reads the content conversion property of a given resource and returns it's value.

A default value (disabled) is returned if the property could not be read.

Parameters:
cms - the CmsObject
resource - the resource in the vfs
Returns:
the content conversion property value

isConversionEnabled

public static boolean isConversionEnabled(java.lang.String conversionMode)
Tests if the content conversion is enabled.

Parameters:
conversionMode - the content conversion mode string
Returns:
ture or false

convertToByte

public byte[] convertToByte(byte[] htmlInput)
                     throws java.io.UnsupportedEncodingException
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 contining the converted html
Throws:
java.io.UnsupportedEncodingException - if the encoding set for the conversion is not supported

convertToByte

public byte[] convertToByte(java.lang.String htmlInput)
                     throws java.io.UnsupportedEncodingException
Converts the given html code according to the settings of this converter.

Parameters:
htmlInput - html input stored in a string
Returns:
array of bytes contining the converted html
Throws:
java.io.UnsupportedEncodingException - if the encoding set for the conversion is not supported

convertToByteSilent

public byte[] convertToByteSilent(byte[] htmlInput)
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 contining the converted html

convertToByteSilent

public byte[] convertToByteSilent(java.lang.String htmlInput)
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 contining the converted html

convertToString

public java.lang.String convertToString(byte[] htmlInput)
                                 throws java.io.UnsupportedEncodingException
Converts the given html code according to the settings of this converter.

Parameters:
htmlInput - html input stored in an array of bytes
Returns:
string contining the converted html
Throws:
java.io.UnsupportedEncodingException - if the encoding set for the conversion is not supported

convertToString

public java.lang.String convertToString(java.lang.String htmlInput)
                                 throws java.io.UnsupportedEncodingException
Converts the given html code according to the settings of this converter.

Parameters:
htmlInput - html input stored in a string
Returns:
string contining the converted html
Throws:
java.io.UnsupportedEncodingException - if the encoding set for the conversion is not supported

convertToStringSilent

public java.lang.String convertToStringSilent(byte[] htmlInput)
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 contining the converted html

convertToStringSilent

public java.lang.String convertToStringSilent(java.lang.String htmlInput)
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 contining the converted html

getEncoding

public java.lang.String getEncoding()
Returns the encoding used for the html code conversion.

Returns:
the encoding used for the html code conversion