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);
}
}
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);
}
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;
}
}
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;
}
}
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;
}
Aggregations