xpertss.json.schema.format.helpers.SharedHostNameAttribute Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-schema Show documentation
Show all versions of json-schema Show documentation
A Java implementation of the JSON Schema specification.
The newest version!
package xpertss.json.schema.format.helpers;
import com.github.fge.jackson.NodeType;
import xpertss.json.schema.core.exceptions.ProcessingException;
import xpertss.json.schema.core.report.ProcessingReport;
import xpertss.json.schema.format.AbstractFormatAttribute;
import xpertss.json.schema.processors.data.FullData;
import com.github.fge.msgsimple.bundle.MessageBundle;
import com.google.common.net.InternetDomainName;
/**
* Validator for the {@code host-name} format attribute.
*
* Important note: the basis for host name format validation is RFC 1034. The RFC does not
* require that a host name have more than one domain name component. As
* such, {@code foo} is a valid hostname.
*
* Guava's {@link InternetDomainName} is used for validation.
*/
public final class SharedHostNameAttribute extends AbstractFormatAttribute {
public SharedHostNameAttribute(String fmt)
{
super(fmt, NodeType.STRING);
}
@Override
public void validate(ProcessingReport report, MessageBundle bundle, FullData data)
throws ProcessingException
{
String value = data.getInstance().getNode().textValue();
try {
InternetDomainName.from(value);
} catch (IllegalArgumentException ignored) {
report.error(newMsg(data, bundle, "err.format.invalidHostname")
.putArgument("value", value));
}
}
}