All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.crabshue.commons.xml.schema.ProtocolUtils Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
package com.crabshue.commons.xml.schema;

import java.net.URL;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Utility class for protocol operations.
 *
 */
public class ProtocolUtils {

    private static Logger logger = LoggerFactory.getLogger(ProtocolUtils.class);

    protected ProtocolUtils() {
    }

    /**
     * Check whether a URL points to a remote resource or not. Remote means that it starts with http: or https:.
     *
     * @param url the URL
     * @return {@code true} if remote resource; {@code false} otherwise
     */
    public static boolean isResourceRemote(final URL url) {
        Validate.notNull(url);

        final boolean ret = StringUtils.startsWith(url.toString(), Protocol.HTTP.getPrefix())
            || StringUtils.startsWith(url.toString(), Protocol.HTTPS.getPrefix());

        logger.debug("URL [{}] is remote ? [{}]", url, ret);
        return ret;
    }

    /**
     * Check whether a URL (String) points to a remote resource or not. Remote means that it starts with http: or https:.
     *
     * @param url the URL
     * @return {@code true} if remote resource; {@code false} otherwise
     */
    public static boolean isResourceRemote(final String url) {
        Validate.notNull(url);

        final boolean ret = StringUtils.startsWith(url, Protocol.HTTP.getPrefix())
            || StringUtils.startsWith(url, Protocol.HTTPS.getPrefix());

        logger.debug("URL [{}] is remote ? [{}]", url, ret);
        return ret;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy