Search in sources :

Example 6 with IRIException

use of org.apache.jena.irix.IRIException 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)

Aggregations

IRIException (org.apache.jena.irix.IRIException)6 IRIx (org.apache.jena.irix.IRIx)5 PrintStream (java.io.PrintStream)1 Arrays (java.util.Arrays)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 IRIs (org.apache.jena.irix.IRIs)1 org.apache.jena.riot (org.apache.jena.riot)1 Lang (org.apache.jena.riot.Lang)1 RiotException (org.apache.jena.riot.RiotException)1 StreamRDFCounting (org.apache.jena.riot.lang.StreamRDFCounting)1