Class SettingsEditor


  • public class SettingsEditor
    extends AbstractMavenEditor
    Specialized editor for Maven settings.xml files.

    The SettingsEditor extends the base Editor class with Maven settings-specific functionality, including automatic element ordering according to Maven conventions, intelligent blank line insertion, and convenience methods for common settings operations.

    Key features:

    • Settings-aware element ordering - Automatically orders elements according to Maven settings conventions
    • Formatting preservation - Maintains original formatting, whitespace, and comments
    • Intelligent blank lines - Adds appropriate blank lines between element groups
    • Convenience methods - Easy-to-use methods for servers, mirrors, proxies, and profiles

    Example usage:

    
     // Create a new settings document
     SettingsEditor editor = new SettingsEditor();
     editor.createSettingsDocument();
     Element root = editor.root();
    
     // Add elements with automatic ordering
     editor.insertSettingsElement(root, LOCAL_REPOSITORY, "/custom/repo");
     editor.insertSettingsElement(root, OFFLINE, "false");
    
     // Add servers with convenience methods
     Element servers = editor.insertSettingsElement(root, SERVERS);
     editor.addServer(servers, "my-server", "username", "password");
    
     String result = editor.toXml();
     
    Since:
    0.1
    • Nested Class Summary

      • Nested classes/interfaces inherited from class eu.maveniverse.domtrip.Editor

        eu.maveniverse.domtrip.Editor.EditorCommentBuilder, eu.maveniverse.domtrip.Editor.EditorElementBuilder, eu.maveniverse.domtrip.Editor.EditorTextBuilder, eu.maveniverse.domtrip.Editor.NodeBuilder
    • Constructor Summary

      Constructors 
      Constructor Description
      SettingsEditor()
      Creates a new SettingsEditor with default configuration.
      SettingsEditor​(eu.maveniverse.domtrip.Document document)
      Creates a new SettingsEditor for the specified document.
      SettingsEditor​(eu.maveniverse.domtrip.Document document, eu.maveniverse.domtrip.DomTripConfig config)
      Creates a new SettingsEditor for the specified document with the given configuration.
      SettingsEditor​(eu.maveniverse.domtrip.DomTripConfig config)
      Creates a new SettingsEditor with the specified configuration.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      eu.maveniverse.domtrip.Element addMirror​(eu.maveniverse.domtrip.Element mirrorsElement, java.lang.String id, java.lang.String name, java.lang.String url, java.lang.String mirrorOf)
      Adds a mirror configuration.
      eu.maveniverse.domtrip.Element addProfile​(eu.maveniverse.domtrip.Element profilesElement, java.lang.String id)
      Adds a profile configuration.
      eu.maveniverse.domtrip.Element addProperty​(eu.maveniverse.domtrip.Element propertiesElement, java.lang.String propertyName, java.lang.String propertyValue)
      Adds a property to a properties element.
      eu.maveniverse.domtrip.Element addProxy​(eu.maveniverse.domtrip.Element proxiesElement, java.lang.String id, java.lang.String protocol, java.lang.String host, int port)
      Adds a proxy configuration.
      eu.maveniverse.domtrip.Element addServer​(eu.maveniverse.domtrip.Element serversElement, java.lang.String id, java.lang.String username, java.lang.String password)
      Adds a server configuration.
      void createSettingsDocument()
      Creates a new Maven settings document with proper namespace.
      eu.maveniverse.domtrip.Element findChildElement​(eu.maveniverse.domtrip.Element parent, java.lang.String elementName)
      Finds a direct child element by name.
      protected java.util.List<java.lang.String> getOrderListForParent​(eu.maveniverse.domtrip.Element parent)
      Gets the appropriate element order list for the given parent element.
      eu.maveniverse.domtrip.Element insertSettingsElement​(eu.maveniverse.domtrip.Element parent, java.lang.String elementName)
      Inserts an element with settings-aware ordering and formatting.
      eu.maveniverse.domtrip.Element insertSettingsElement​(eu.maveniverse.domtrip.Element parent, java.lang.String elementName, java.lang.String textContent)
      Inserts an element with settings-aware ordering, formatting, and text content.
      • Methods inherited from class eu.maveniverse.domtrip.Editor

        add, addBlankLineAfter, addBlankLineBefore, addComment, addElement, addElement, addElement, addElement, addElements, addQNameElements, commentOutElement, commentOutElements, config, createDocument, document, documentStats, insertElementAfter, insertElementAfter, insertElementAt, insertElementAt, insertElementBefore, insertElementBefore, isWellFormed, removeAttribute, removeElement, root, select, selectFirst, setAttribute, setAttributes, setTextContent, toXml, toXml, toXmlPretty, uncommentElement, walk
      • Methods inherited from class java.lang.Object

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

      • SettingsEditor

        public SettingsEditor()
        Creates a new SettingsEditor with default configuration.
      • SettingsEditor

        public SettingsEditor​(eu.maveniverse.domtrip.DomTripConfig config)
        Creates a new SettingsEditor with the specified configuration.
        Parameters:
        config - the configuration to use
      • SettingsEditor

        public SettingsEditor​(eu.maveniverse.domtrip.Document document)
        Creates a new SettingsEditor for the specified document.
        Parameters:
        document - the document to edit
      • SettingsEditor

        public SettingsEditor​(eu.maveniverse.domtrip.Document document,
                              eu.maveniverse.domtrip.DomTripConfig config)
        Creates a new SettingsEditor for the specified document with the given configuration.
        Parameters:
        document - the document to edit
        config - the configuration to use
    • Method Detail

      • createSettingsDocument

        public void createSettingsDocument()
                                    throws eu.maveniverse.domtrip.DomTripException
        Creates a new Maven settings document with proper namespace.

        This method creates a new document with the settings root element and sets up the appropriate Maven settings namespace.

        Throws:
        eu.maveniverse.domtrip.DomTripException
      • insertSettingsElement

        public eu.maveniverse.domtrip.Element insertSettingsElement​(eu.maveniverse.domtrip.Element parent,
                                                                    java.lang.String elementName)
                                                             throws eu.maveniverse.domtrip.DomTripException
        Inserts an element with settings-aware ordering and formatting.

        This method automatically determines the correct position for the element based on Maven settings conventions and adds appropriate blank lines.

        Parameters:
        parent - the parent element
        elementName - the name of the element to insert
        Returns:
        the newly created element
        Throws:
        eu.maveniverse.domtrip.DomTripException
      • insertSettingsElement

        public eu.maveniverse.domtrip.Element insertSettingsElement​(eu.maveniverse.domtrip.Element parent,
                                                                    java.lang.String elementName,
                                                                    java.lang.String textContent)
                                                             throws eu.maveniverse.domtrip.DomTripException
        Inserts an element with settings-aware ordering, formatting, and text content.
        Parameters:
        parent - the parent element
        elementName - the name of the element to insert
        textContent - the text content for the element (can be null)
        Returns:
        the newly created element
        Throws:
        eu.maveniverse.domtrip.DomTripException
      • addServer

        public eu.maveniverse.domtrip.Element addServer​(eu.maveniverse.domtrip.Element serversElement,
                                                        java.lang.String id,
                                                        java.lang.String username,
                                                        java.lang.String password)
                                                 throws eu.maveniverse.domtrip.DomTripException
        Adds a server configuration.
        Parameters:
        serversElement - the servers parent element
        id - the server ID
        username - the username (can be null)
        password - the password (can be null)
        Returns:
        the newly created server element
        Throws:
        eu.maveniverse.domtrip.DomTripException
      • addMirror

        public eu.maveniverse.domtrip.Element addMirror​(eu.maveniverse.domtrip.Element mirrorsElement,
                                                        java.lang.String id,
                                                        java.lang.String name,
                                                        java.lang.String url,
                                                        java.lang.String mirrorOf)
                                                 throws eu.maveniverse.domtrip.DomTripException
        Adds a mirror configuration.
        Parameters:
        mirrorsElement - the mirrors parent element
        id - the mirror ID
        name - the mirror name
        url - the mirror URL
        mirrorOf - the repositories this mirror serves
        Returns:
        the newly created mirror element
        Throws:
        eu.maveniverse.domtrip.DomTripException
      • addProxy

        public eu.maveniverse.domtrip.Element addProxy​(eu.maveniverse.domtrip.Element proxiesElement,
                                                       java.lang.String id,
                                                       java.lang.String protocol,
                                                       java.lang.String host,
                                                       int port)
                                                throws eu.maveniverse.domtrip.DomTripException
        Adds a proxy configuration.
        Parameters:
        proxiesElement - the proxies parent element
        id - the proxy ID
        protocol - the proxy protocol
        host - the proxy host
        port - the proxy port
        Returns:
        the newly created proxy element
        Throws:
        eu.maveniverse.domtrip.DomTripException
      • addProfile

        public eu.maveniverse.domtrip.Element addProfile​(eu.maveniverse.domtrip.Element profilesElement,
                                                         java.lang.String id)
                                                  throws eu.maveniverse.domtrip.DomTripException
        Adds a profile configuration.
        Parameters:
        profilesElement - the profiles parent element
        id - the profile ID
        Returns:
        the newly created profile element
        Throws:
        eu.maveniverse.domtrip.DomTripException
      • addProperty

        public eu.maveniverse.domtrip.Element addProperty​(eu.maveniverse.domtrip.Element propertiesElement,
                                                          java.lang.String propertyName,
                                                          java.lang.String propertyValue)
                                                   throws eu.maveniverse.domtrip.DomTripException
        Adds a property to a properties element.
        Parameters:
        propertiesElement - the properties parent element
        propertyName - the property name
        propertyValue - the property value
        Returns:
        the newly created property element
        Throws:
        eu.maveniverse.domtrip.DomTripException
      • findChildElement

        public eu.maveniverse.domtrip.Element findChildElement​(eu.maveniverse.domtrip.Element parent,
                                                               java.lang.String elementName)
        Finds a direct child element by name.
        Parameters:
        parent - the parent element
        elementName - the name of the child element to find
        Returns:
        the child element if found, null otherwise
      • getOrderListForParent

        protected java.util.List<java.lang.String> getOrderListForParent​(eu.maveniverse.domtrip.Element parent)
        Gets the appropriate element order list for the given parent element.
        Specified by:
        getOrderListForParent in class AbstractMavenEditor
        Parameters:
        parent - the parent element
        Returns:
        the ordered list of element names, or null if no specific ordering is defined