Search in sources :

Example 6 with IRIx

use of org.apache.jena.irix.IRIx in project jena by apache.

the class NodeFunctions method resolveCheckIRI.

// 
private static String resolveCheckIRI(String baseIRI, String iriStr) {
    try {
        IRIx iri = IRIx.create(iriStr);
        IRIx base = (baseIRI != null) ? IRIx.create(baseIRI) : IRIs.getSystemBase();
        IRIx result = base.resolve(iri);
        if (!result.isReference())
            throw new IRIException("Not suitable: " + result.str());
        return result.str();
    } catch (IRIException ex) {
        throw new ExprEvalException("Bad IRI: " + iriStr);
    }
}
Also used : IRIException(org.apache.jena.irix.IRIException) IRIx(org.apache.jena.irix.IRIx) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 7 with IRIx

use of org.apache.jena.irix.IRIx in project jena by apache.

the class QueryFactory method parse.

/**
 * Parse a query from the given string by calling the parser.
 *
 * @param query            Existing, uninitialized query
 * @param queryString      The query string
 * @param baseURI          URI for relative URI expansion
 * @param syntaxURI        URI for the syntax
 * @throws QueryException  Thrown when a parse error occurs
 */
public static Query parse(Query query, String queryString, String baseURI, Syntax syntaxURI) {
    if (syntaxURI == null)
        syntaxURI = query.getSyntax();
    else
        query.setSyntax(syntaxURI);
    SPARQLParser parser = SPARQLParser.createParser(syntaxURI);
    if (parser == null)
        throw new UnsupportedOperationException("Unrecognized syntax for parsing: " + syntaxURI);
    if (query.getBase() == null) {
        IRIx queryBase = null;
        try {
            queryBase = (baseURI != null) ? IRIs.resolveIRI(baseURI) : IRIs.getSystemBase();
        } catch (Exception ex) {
        }
        if (queryBase == null)
            queryBase = IRIx.create("http://localhost/query/defaultBase#");
        query.setBase(queryBase);
    }
    return parser.parse(query, queryString);
}
Also used : SPARQLParser(org.apache.jena.sparql.lang.SPARQLParser) IRIx(org.apache.jena.irix.IRIx) NotFoundException(org.apache.jena.shared.NotFoundException)

Example 8 with IRIx

use of org.apache.jena.irix.IRIx in project jena by apache.

the class FmtUtils method abbrevByBase.

public static String abbrevByBase(String uriStr, String base) {
    try {
        IRIx baseIRI = IRIx.create(base);
        if (baseIRI == null)
            return null;
        IRIx relInput = IRIx.create(uriStr);
        IRIx relativized = baseIRI.relativize(relInput);
        return (relativized == null) ? null : relativized.toString();
    } catch (IRIException ex) {
        return null;
    }
}
Also used : IRIException(org.apache.jena.irix.IRIException) IRIx(org.apache.jena.irix.IRIx)

Example 9 with IRIx

use of org.apache.jena.irix.IRIx in project jena by apache.

the class GraphTarget method xresolve.

/**
 * Resolve URI. Calculate a base URI from the dataset URI and resolve uri against that.
 */
private static String xresolve(String uriStr, HttpAction action) {
    // Strictly, a bit naughty on the URI resolution, but more sensible.
    // Make the base the URI of the dataset.
    // Strictly, the base includes service and query string but that is unhelpful.
    // wholeRequestURL(request);
    IRIx uri;
    try {
        uri = IRIx.create(uriStr);
        if (uri.isReference())
            return uri.str();
    } catch (IRIException ex) {
        FmtLog.warn(Fuseki.actionLog, "Bad URI: '" + uriStr);
        ServletOps.errorBadRequest("Bad IRI: " + uriStr + " : " + ex.getMessage());
        return null;
    }
    String baseStr = action.getRequestRequestURL().toString();
    Endpoint ep = action.getEndpoint();
    if (!ep.isUnnamed() && baseStr.endsWith(ep.getName())) {
        // Remove endpoint name
        baseStr = baseStr.substring(0, baseStr.length() - ep.getName().length());
    }
    // Make sure it ends in "/", treating the dataset as a container.
    if (!baseStr.endsWith("/"))
        baseStr = baseStr + "/";
    try {
        IRIx base = IRIx.create(baseStr);
        IRIx uri2 = base.resolve(uri);
        if (!uri2.isReference()) {
            FmtLog.warn(Fuseki.actionLog, "Bad URI (after resolving): '" + uriStr);
            ServletOps.errorBadRequest("Bad IRI: " + uriStr);
        }
        return uri2.str();
    } catch (IRIException ex) {
        ServletOps.errorBadRequest("Bad IRI: " + uriStr + " : " + ex.getMessage());
        return null;
    }
}
Also used : IRIException(org.apache.jena.irix.IRIException) Endpoint(org.apache.jena.fuseki.server.Endpoint) IRIx(org.apache.jena.irix.IRIx)

Example 10 with IRIx

use of org.apache.jena.irix.IRIx in project jena by apache.

the class UpdateFactory method setupParser.

/**
 * Append update operations to a request
 */
protected static UpdateParser setupParser(Prologue prologue, String baseURI, Syntax syntax) {
    UpdateParser parser = UpdateParser.createParser(syntax);
    if (parser == null)
        throw new UnsupportedOperationException("Unrecognized syntax for parsing update: " + syntax);
    if (prologue.getBase() == null) {
        IRIx base;
        // continue.
        try {
            base = (baseURI != null) ? IRIs.resolveIRI(baseURI) : IRIs.getSystemBase();
        } catch (Exception ex) {
            base = IRIx.create("http://localhost/update/defaultBase#");
        }
        prologue.setBase(base);
    }
    return parser;
}
Also used : IRIx(org.apache.jena.irix.IRIx) UpdateParser(org.apache.jena.sparql.lang.UpdateParser)

Aggregations

IRIx (org.apache.jena.irix.IRIx)10 IRIException (org.apache.jena.irix.IRIException)5 PrintStream (java.io.PrintStream)1 BigDecimal (java.math.BigDecimal)1 URI (java.net.URI)1 URL (java.net.URL)1 Arrays (java.util.Arrays)1 Calendar (java.util.Calendar)1 List (java.util.List)1 Function (java.util.function.Function)1 Stream (java.util.stream.Stream)1 IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)1 StreamOps (org.apache.jena.atlas.lib.StreamOps)1 LogCtl (org.apache.jena.atlas.logging.LogCtl)1 ArgDecl (org.apache.jena.cmd.ArgDecl)1 CmdException (org.apache.jena.cmd.CmdException)1 CmdGeneral (org.apache.jena.cmd.CmdGeneral)1 Endpoint (org.apache.jena.fuseki.server.Endpoint)1 Graph (org.apache.jena.graph.Graph)1 Node (org.apache.jena.graph.Node)1