xpertss.json.schema.format.common.URIAttribute 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.common;
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.format.FormatAttribute;
import xpertss.json.schema.processors.data.FullData;
import com.github.fge.msgsimple.bundle.MessageBundle;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Validator for the {@code uri} format attribute.
*
* Note that each and any URI is allowed. In particular, it is not required
* that the URI be absolute or normalized.
*/
public final class URIAttribute extends AbstractFormatAttribute {
private static final FormatAttribute INSTANCE = new URIAttribute();
public static FormatAttribute getInstance()
{
return INSTANCE;
}
private URIAttribute()
{
super("uri", NodeType.STRING);
}
@Override
public void validate(ProcessingReport report, MessageBundle bundle, FullData data)
throws ProcessingException
{
String value = data.getInstance().getNode().textValue();
try {
new URI(value);
} catch (URISyntaxException ignored) {
report.error(newMsg(data, bundle, "err.format.invalidURI")
.putArgument("value", value));
}
}
}