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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionThe default constructor of this class initializes theXStreamobject by calling:configureSecurity(com.thoughtworks.xstream.XStream)registerConverters(com.thoughtworks.xstream.XStream)registerAliases(com.thoughtworks.xstream.XStream) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidconfigureSecurity(com.thoughtworks.xstream.XStream xstream) Configures the security of theXStreaminstance to protect against vulnerabilities.@Nullable TreadFromXML(String xml) Reads the XML document containing a specific XML tag from the specified xml string and converts it to the according object.@Nullable TreadFromXML(URL xmlURL) Reads the XML document containing a specific XML tag from the specifiedURLand converts it to the according object.protected abstract voidregisterAliases(com.thoughtworks.xstream.XStream xstream) Registers any aliases at theXStreaminstance.protected abstract voidregisterConverters(com.thoughtworks.xstream.XStream xstream) Registers anyConverters at theXStreaminstance.protected voidsetClassLoader(ClassLoader classLoader) Sets the classloader forXStream.
-
Field Details
-
DEFAULT_ALLOWED_TYPES_WILDCARD
-
-
Constructor Details
-
XmlDocumentReader
public XmlDocumentReader()The default constructor of this class initializes theXStreamobject 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 theXStreaminstance 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 anyConverters at theXStreaminstance.- Parameters:
xstream- the XStream object to be configured
-
registerAliases
protected abstract void registerAliases(com.thoughtworks.xstream.XStream xstream) Registers any aliases at theXStreaminstance.- 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 specifiedURLand converts it to the according object.This method returns
nullif 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
-