Util.java 1.56 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.replication.ReplicationException
 */
package com.adobe.cq.dam.aod.replication;

import com.day.cq.replication.ReplicationException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Util {
    private static final Pattern HTTP_SCHEME = Pattern.compile("^https?://.+");

    public static <T> T initRef() {
        return null;
    }

    public static URL serverUrl(String transportUri) throws ReplicationException {
        try {
            URI uri;
            URI tUri = new URI(transportUri);
            String authority = tUri.getSchemeSpecificPart();
            if (!HTTP_SCHEME.matcher(authority).matches()) {
                authority = "http:" + authority;
            }
            Util.require((uri = new URI(authority)).getHost() != null, "Host must be specified in transport URI: " + transportUri);
            return new URL(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath() + "/publish-receiver");
        }
        catch (URISyntaxException e) {
            throw new ReplicationException("Invalid transport URI: '" + transportUri + "', caused by: " + e);
        }
        catch (MalformedURLException e) {
            throw new AssertionError(e);
        }
    }

    private static void require(boolean cond, String message) {
        if (!cond) {
            throw new IllegalArgumentException(message);
        }
    }
}