use of org.apache.jena.iri.IRI in project jena by apache.
the class TestCreator method uri.
private void uri(Attributes att) {
String absolute = att.getValue("absolute");
String base = att.getValue("base");
String relative = att.getValue("relative");
doIt(absolute);
if (base != null) {
out.println("<Resolve>");
IRI b = doIt(base);
IRI r = doIt(relative);
out.println("<Result>");
IRI result = b.create(r);
doIt(result);
out.println("</Result>");
IRI rAgain = b.relativize(result, RelativizeFlags);
if (r.equals(rAgain)) {
out.println("<Relativize same='true'/>");
} else {
out.println("<Relativize>");
doIt(rAgain);
out.println("</Relativize>");
}
out.println("</Resolve>");
}
}
use of org.apache.jena.iri.IRI in project jena by apache.
the class TestExample method runTest.
private void runTest(IRIFactory f, boolean expectError, boolean expectWarning, String desc) {
IRI iri = f.create(uri);
boolean implemented = violation.isImplemented();
expectError = expectError && implemented;
expectWarning = expectWarning && (!expectError) && implemented;
if (good) {
expectError = expectWarning = false;
}
boolean hasError = false;
boolean hasWarning = false;
Iterator<Violation> it = iri.violations(true);
while (it.hasNext()) {
Violation v = it.next();
if (v.getViolationCode() == violation.getCode()) {
if (v.isError()) {
if (!expectError)
fail("Unexpected error, " + desc);
hasError = true;
} else {
if (!expectWarning)
fail("Unexpected warning, " + desc);
hasWarning = true;
}
break;
}
}
if (expectWarning && !hasWarning)
fail("No warning detected: " + expectError);
if (expectError && !hasError)
fail("No error detected: " + expectError);
}
use of org.apache.jena.iri.IRI in project jena by apache.
the class JenaPreparedStatement method setObject.
@Override
public void setObject(int parameterIndex, Object value) throws SQLException {
if (value == null)
throw new SQLException("Setting a null value is not permitted");
if (value instanceof Node) {
this.setParameter(parameterIndex, (Node) value);
} else if (value instanceof RDFNode) {
this.setParameter(parameterIndex, ((RDFNode) value).asNode());
} else if (value instanceof String) {
this.setParameter(parameterIndex, NodeFactory.createLiteral((String) value));
} else if (value instanceof Boolean) {
this.setParameter(parameterIndex, NodeFactory.createLiteral(Boolean.toString((Boolean) value), XSDDatatype.XSDboolean));
} else if (value instanceof Long) {
this.setParameter(parameterIndex, NodeFactoryExtra.intToNode((Long) value));
} else if (value instanceof Integer) {
this.setParameter(parameterIndex, NodeFactoryExtra.intToNode((Integer) value));
} else if (value instanceof Short) {
this.setParameter(parameterIndex, NodeFactory.createLiteral(Short.toString((Short) value), XSDDatatype.XSDshort));
} else if (value instanceof Byte) {
this.setParameter(parameterIndex, NodeFactory.createLiteral(Byte.toString((Byte) value), XSDDatatype.XSDbyte));
} else if (value instanceof BigDecimal) {
this.setParameter(parameterIndex, NodeFactory.createLiteral(((BigDecimal) value).toPlainString(), XSDDatatype.XSDdecimal));
} else if (value instanceof Float) {
this.setParameter(parameterIndex, NodeFactoryExtra.floatToNode((Float) value));
} else if (value instanceof Double) {
this.setParameter(parameterIndex, NodeFactoryExtra.doubleToNode((Double) value));
} else if (value instanceof Date) {
Calendar c = Calendar.getInstance();
c.setTimeInMillis(((Date) value).getTime());
this.setParameter(parameterIndex, NodeFactoryExtra.dateTimeToNode(c));
} else if (value instanceof Time) {
Calendar c = Calendar.getInstance();
c.setTimeInMillis(((Time) value).getTime());
this.setParameter(parameterIndex, NodeFactoryExtra.timeToNode(c));
} else if (value instanceof Calendar) {
this.setParameter(parameterIndex, NodeFactoryExtra.dateTimeToNode((Calendar) value));
} else if (value instanceof URL) {
this.setParameter(parameterIndex, NodeFactory.createURI(value.toString()));
} else if (value instanceof URI) {
this.setParameter(parameterIndex, NodeFactory.createURI(value.toString()));
} else if (value instanceof IRI) {
this.setParameter(parameterIndex, NodeFactory.createURI(value.toString()));
} else {
throw new SQLException("setObject() received a value that could not be converted to a RDF node for use in a SPARQL query");
}
}
use of org.apache.jena.iri.IRI in project jena by apache.
the class ParserProfileStd method makeIRI.
@Override
public IRI makeIRI(String uriStr, long line, long col) {
IRI iri = resolver.resolveSilent(uriStr);
// Some specific problems and specific error messages,.
if (uriStr.contains(" ")) {
// Specific check for spaces.
errorHandler.warning("Bad IRI: <" + uriStr + "> Spaces are not legal in URIs/IRIs.", line, col);
return iri;
}
if (!checking)
return iri;
// At this point, IRI "errors" are warnings.
// A tuned set of checking.
CheckerIRI.iriViolations(iri, errorHandler, line, col);
return iri;
}
use of org.apache.jena.iri.IRI in project jena by apache.
the class FastAbbreviatingPrefixMap method expand.
@Override
public String expand(String prefix, String localName) {
prefix = canonicalPrefix(prefix);
IRI x = prefixes.get(prefix);
if (x == null)
return null;
return x.toString() + localName;
}
Aggregations