Class XmlDocumentReader<T>
java.lang.Object
org.openhab.core.config.core.xml.util.XmlDocumentReader<T>
- Type Parameters:
T
- the result type of the conversion
The
XmlDocumentReader
is an abstract class used to read XML documents
of a certain type and converts them to its according objects.
This class uses XStream
and StAX
to parse and convert the XML document.
- Author:
- Michael Grammling - Initial contribution, Wouter Born - Configure XStream security
-
Field Summary
-
Constructor Summary
ConstructorDescriptionThe default constructor of this class initializes theXStream
object by calling:configureSecurity(com.thoughtworks.xstream.XStream)
registerConverters(com.thoughtworks.xstream.XStream)
registerAliases(com.thoughtworks.xstream.XStream)
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
configureSecurity
(com.thoughtworks.xstream.XStream xstream) Configures the security of theXStream
instance to protect against vulnerabilities.@Nullable T
readFromXML
(String xml) Reads the XML document containing a specific XML tag from the specified xml string and converts it to the according object.@Nullable T
readFromXML
(URL xmlURL) Reads the XML document containing a specific XML tag from the specifiedURL
and converts it to the according object.protected abstract void
registerAliases
(com.thoughtworks.xstream.XStream xstream) Registers any aliases at theXStream
instance.protected abstract void
registerConverters
(com.thoughtworks.xstream.XStream xstream) Registers anyConverter
s at theXStream
instance.protected void
setClassLoader
(ClassLoader classLoader) Sets the classloader forXStream
.
-
Field Details
-
DEFAULT_ALLOWED_TYPES_WILDCARD
-
-
Constructor Details
-
XmlDocumentReader
public XmlDocumentReader()The default constructor of this class initializes theXStream
object by calling:
-
-
Method Details
-
setClassLoader
Sets the classloader forXStream
.- Parameters:
classLoader
- the classloader to set (must not be null)
-
configureSecurity
protected void configureSecurity(com.thoughtworks.xstream.XStream xstream) Configures the security of theXStream
instance to protect against vulnerabilities.- Parameters:
xstream
- the XStream object to be configured- See Also:
-
registerConverters
protected abstract void registerConverters(com.thoughtworks.xstream.XStream xstream) Registers anyConverter
s at theXStream
instance.- Parameters:
xstream
- the XStream object to be configured
-
registerAliases
protected abstract void registerAliases(com.thoughtworks.xstream.XStream xstream) Registers any aliases at theXStream
instance.- Parameters:
xstream
- the XStream object to be configured
-
readFromXML
public @Nullable T readFromXML(URL xmlURL) throws com.thoughtworks.xstream.converters.ConversionException Reads the XML document containing a specific XML tag from the specifiedURL
and converts it to the according object.This method returns
null
if the given URL isnull
.- Parameters:
xmlURL
- the URL pointing to the XML document to be read (could be null)- Returns:
- the conversion result object (could be null)
- Throws:
com.thoughtworks.xstream.converters.ConversionException
- if the specified document contains invalid content
-
readFromXML
public @Nullable T readFromXML(String xml) throws com.thoughtworks.xstream.converters.ConversionException Reads the XML document containing a specific XML tag from the specified xml string and converts it to the according object.- Parameters:
xml
- a string containing the XML document to be read.- Returns:
- the conversion result object (could be null).
- Throws:
com.thoughtworks.xstream.XStreamException
- if the object cannot be deserialized.com.thoughtworks.xstream.converters.ConversionException
- if the specified document contains invalid content
-