String getProviderURL(LdapName baseDN) throws NamingException
    {
        StringBuilder ldapURL = new StringBuilder();

        try
        {
            for ( String host : hosts )
            {
                // If a host-definition contains a port (eg: example.org:389 vs example.org) then use that port, rather than the port that's configured in ldap.port
                final String[] split = host.split(":");
                String specificHost = host;
                int specificPort = this.port;
                if (split.length == 2) {
                    try {
                        final int number = Integer.parseInt(split[1]);
                        if (number > 0 && number < 65535) {
                            specificHost = split[0];
                            specificPort = number;
                        }
                    } catch (NumberFormatException e) {
                        Log.trace("Unable to determine port number from value '{}'. Expected format: 'hostname' or 'hostname:port'", host);
                    }
                }
                // Create a correctly-encoded ldap URL for the PROVIDER_URL
                final URI uri = new URI(sslEnabled ? "ldaps" : "ldap", null, specificHost, specificPort, "/" + baseDN.toString(), null, null);
                ldapURL.append(uri.toASCIIString());
                ldapURL.append(" ");
            }
            return ldapURL.toString().trim();
        }
        catch ( Exception e )
        {
            Log.error( "Unable to generate provider URL for baseDN: '{}'.", baseDN, e );
            throw new NamingException( "Unable to generate provider URL for baseDN: '"+baseDN+"': " + e.getMessage() );
        }
    }
Returns a properly encoded URL for use as the PROVIDER_URL.
If the encoding fails then the URL will contain the raw base dn.

@param baseDN the base dn to use in the URL.
@return the properly encoded URL for use in as PROVIDER_URL.
xmppserver/src/main/java/org/jivesoftware/openfire/ldap/LdapManager.java