Search in sources :

Example 6 with IRI

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>");
    }
}
Also used : IRI(org.apache.jena.iri.IRI)

Example 7 with IRI

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);
}
Also used : Violation(org.apache.jena.iri.Violation) IRI(org.apache.jena.iri.IRI)

Example 8 with IRI

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");
    }
}
Also used : IRI(org.apache.jena.iri.IRI) SQLException(java.sql.SQLException) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node) Calendar(java.util.Calendar) Time(java.sql.Time) ParameterizedSparqlString(org.apache.jena.query.ParameterizedSparqlString) URI(java.net.URI) BigDecimal(java.math.BigDecimal) Date(java.sql.Date) URL(java.net.URL) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 9 with IRI

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;
}
Also used : IRI(org.apache.jena.iri.IRI) CheckerIRI(org.apache.jena.riot.checker.CheckerIRI)

Example 10 with 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;
}
Also used : IRI(org.apache.jena.iri.IRI)

Aggregations

IRI (org.apache.jena.iri.IRI)51 Violation (org.apache.jena.iri.Violation)12 IRIFactory (org.apache.jena.iri.IRIFactory)9 IOException (java.io.IOException)3 Node (org.apache.jena.graph.Node)3 Test (org.junit.Test)3 PrintStream (java.io.PrintStream)2 MalformedURLException (java.net.MalformedURLException)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 Lang (org.apache.jena.riot.Lang)2 RiotException (org.apache.jena.riot.RiotException)2 CheckerIRI (org.apache.jena.riot.checker.CheckerIRI)2 IRI (org.apache.jena.riot.tokens.TokenType.IRI)2 InputStream (java.io.InputStream)1 BigDecimal (java.math.BigDecimal)1 URI (java.net.URI)1 URL (java.net.URL)1 Date (java.sql.Date)1 SQLException (java.sql.SQLException)1 Time (java.sql.Time)1