/** * Turn a filename into a well-formed file: URL relative to the working directory. * * @param filename * @return String The filename as an absolute URL */ public static String resolveFileURL(String filename) throws IRIException { IRI r = globalResolver.resolve(filename); if (!r.getScheme().equalsIgnoreCase("file")) { // Pragmatic hack that copes with "c:" return resolveFileURL("./" + filename); } return r.toString(); }
private static Node createNode(String x) { try { IRI iri = resolver.resolve(x); return NodeFactory.createURI(iri.toString()); } catch (Exception ex) { ServletOps.errorBadRequest("SPARQL Update: bad IRI: " + x); return null; } }
private IRI resolveSilentNoCache(String uriStr) { IRI x = IRIResolver.iriFactory.create(uriStr); if (SysRIOT.AbsURINoNormalization) { // Always process "file:", even in strict mode. // file: is widely used in irregular forms. if (x.isAbsolute() && !uriStr.startsWith("file:")) return x; } return base.create(x); }
/* * No exception thrown by this method. */ private static IRI resolveIRI(String relStr, String baseStr) { IRI i = iriFactory.create(relStr); if (i.isAbsolute()) // removes excess . segments return globalResolver.getBaseIRI().create(i); IRI base = iriFactory.create(baseStr); if ("file".equalsIgnoreCase(base.getScheme())) return globalResolver.getBaseIRI().create(i); return base.create(i); }
@Override protected JsonObject execute(ValidationAction action) { JsonBuilder obj = new JsonBuilder(); obj.startObject(); String args[] = getArgs(action, paramIRI); if (args.length == 0) ServletOps.errorBadRequest("No IRIs supplied"); obj.key(jIRIs); obj.startArray(); for (String iriStr : args) { obj.startObject(); obj.key(jIRI).value(iriStr); IRI iri = iriFactory.create(iriStr); List<String> errors = new ArrayList<>(); List<String> warnings = new ArrayList<>(); if (iri.isRelative()) warnings.add("Relative IRI: " + iriStr); Iterator<Violation> vIter = iri.violations(true); for (; vIter.hasNext(); ) { Violation v = vIter.next(); String str = v.getShortMessage(); if (v.isError()) errors.add(str); else warnings.add(str); } obj.key(jErrors); obj.startArray(); for (String msg : errors) obj.value(msg); obj.finishArray(); obj.key(jWarnings); obj.startArray(); for (String msg : warnings) obj.value(msg); obj.finishArray(); obj.finishObject(); } obj.finishArray(); obj.finishObject(); return obj.build().getAsObject(); }
/** * Throw any exceptions resulting from IRI. * * @param iri * @return iri */ private static IRI exceptions(IRI iri) { if (!showExceptions) return iri; if (!iri.hasViolation(false)) return iri; String msg = iri.violations(false).next().getShortMessage(); throw new RiotException(msg); }
public String getBaseIRIasString() { IRI iri = getBaseIRI(); if (iri == null) return null; return iri.toString(); }
/** Check an IRI string (does not resolve it) */ public static boolean checkIRI(String iriStr) { IRI iri = parseIRI(iriStr); return iri.hasViolation(false); }