Class XMLFormatPreserver


  • public final class XMLFormatPreserver
    extends java.lang.Object
    Best-effort preservation of the original layout (comments, blank lines and attribute order) of server.xml and context configuration files when StoreConfig rewrites them.

    The freshly generated XML is always the source of truth for the content. Both the previous version and the freshly generated version are parsed, the elements of both documents are matched and the freshly generated document is re-serialized using the layout of the previous version.

    The preservation is best-effort. Whenever the previous version is missing, cannot be parsed, or the result cannot be verified, the freshly generated XML is returned unchanged.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String preserve​(java.io.File originalFile, java.lang.String newXml, java.lang.String encoding)
      Preserves the layout of the previous version of a configuration file for the freshly generated XML.
      static java.lang.String preserve​(java.lang.String originalXml, java.lang.String newXml, java.lang.String encoding)
      Preserves the layout of the previous version of an XML document for the freshly generated XML.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • preserve

        public static java.lang.String preserve​(java.io.File originalFile,
                                                java.lang.String newXml,
                                                java.lang.String encoding)
        Preserves the layout of the previous version of a configuration file for the freshly generated XML.
        Parameters:
        originalFile - The previous version of the configuration file, may be null
        newXml - The freshly generated XML
        encoding - The character encoding of the configuration file
        Returns:
        The freshly generated XML, re-laid-out using the previous version when possible, otherwise the freshly generated XML unchanged
      • preserve

        public static java.lang.String preserve​(java.lang.String originalXml,
                                                java.lang.String newXml,
                                                java.lang.String encoding)
        Preserves the layout of the previous version of an XML document for the freshly generated XML.
        Parameters:
        originalXml - The previous version of the XML document, may be null
        newXml - The freshly generated XML
        encoding - The character encoding used in the XML declaration of the result
        Returns:
        The freshly generated XML, re-laid-out using the previous version when possible, otherwise the freshly generated XML unchanged