com.crabshue.commons.xml.schema.ProtocolUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-xml Show documentation
Show all versions of commons-xml Show documentation
Library for XML documents operations.
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;
}
}