Class XmlDocumentReader<T>

java.lang.Object
org.openhab.core.config.core.xml.util.XmlDocumentReader<T>
Type Parameters:
T - the result type of the conversion

@NonNullByDefault public abstract class XmlDocumentReader<@NonNull T> extends Object
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
    Modifier and Type
    Field
    Description
    protected static final String[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    The default constructor of this class initializes the XStream object by calling: #configureSecurity() #registerConverters() #registerAliases()
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    configureSecurity(com.thoughtworks.xstream.XStream xstream)
    Configures the security of the XStream instance to protect against vulnerabilities.
    @Nullable T
    readFromXML(URL xmlURL)
    Reads the XML document containing a specific XML tag from the specified URL and converts it to the according object.
    protected abstract void
    registerAliases(com.thoughtworks.xstream.XStream xstream)
    Registers any aliases at the XStream instance.
    protected abstract void
    registerConverters(com.thoughtworks.xstream.XStream xstream)
    Registers any Converters at the XStream instance.
    protected void
    Sets the classloader for XStream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_ALLOWED_TYPES_WILDCARD

      protected static final String[] DEFAULT_ALLOWED_TYPES_WILDCARD
  • Constructor Details

    • XmlDocumentReader

      public XmlDocumentReader()
      The default constructor of this class initializes the XStream object by calling:
      1. #configureSecurity()
      2. #registerConverters()
      3. #registerAliases()
  • Method Details

    • setClassLoader

      protected void setClassLoader(ClassLoader classLoader)
      Sets the classloader for XStream.
      Parameters:
      classLoader - the classloader to set (must not be null)
    • configureSecurity

      protected void configureSecurity(com.thoughtworks.xstream.XStream xstream)
      Configures the security of the XStream instance to protect against vulnerabilities.
      Parameters:
      xstream - the XStream object to be configured
    • registerConverters

      protected abstract void registerConverters(com.thoughtworks.xstream.XStream xstream)
      Registers any Converters at the XStream instance.
      Parameters:
      xstream - the XStream object to be configured
    • registerAliases

      protected abstract void registerAliases(com.thoughtworks.xstream.XStream xstream)
      Registers any aliases at the XStream 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 specified URL and converts it to the according object.

      This method returns null if the given URL is null.

      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