Class 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 Detail

      • DEFAULT_ALLOWED_TYPES_WILDCARD

        protected static final String[] DEFAULT_ALLOWED_TYPES_WILDCARD
    • Constructor Detail

      • XmlDocumentReader

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

      • 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