use of org.apache.jena.iri.IRI in project jena by apache.
the class BindingOutputStream method send.
@Override
public void send(Binding binding) {
try {
if (needOutputPMap) {
if (pmap != null) {
for (Map.Entry<String, IRI> e : pmap.getMapping().entrySet()) {
bw.write("PREFIX ");
bw.write(e.getKey());
bw.write(": <");
bw.write(e.getValue().toASCIIString());
bw.write("> .\n");
}
}
needOutputPMap = false;
}
// Is the current VARS applicable?
if (needVars(vars, binding)) {
vars = Iter.toList(binding.vars());
needOutputVars = true;
}
if (needOutputVars) {
// No vars, empty binding.
if (binding.size() == 0 && vars.size() == 0) {
bw.write(".\n");
needOutputVars = false;
return;
}
bw.write("VARS");
for (Var v2 : vars) {
bw.write(" ?");
bw.write(v2.getVarName());
}
bw.write(" .\n");
needOutputVars = false;
}
for (Var v : vars) {
Node n = binding.get(v);
if (n == null) {
bw.write("- ");
continue;
}
// NodeFormatters should write safe bNode labels.
nodeFormatter.format(bw, n);
bw.write(" ");
}
bw.write(".\n");
} catch (IOException ex) {
throw new RiotException(ex);
}
}
use of org.apache.jena.iri.IRI in project jena by apache.
the class FmtUtils method abbrevByBase.
public static String abbrevByBase(String uri, String base) {
if (hasScheme(uri))
return uri;
IRI baseIRI = IRIResolver.iriFactory.construct(base);
IRI rel = baseIRI.relativize(uri, relFlags);
String r = rel.toString();
return r;
}
use of org.apache.jena.iri.IRI in project jena by apache.
the class Main method check.
private void check(String string) {
IRI iri = factory.create(string);
if (iri.hasViolation(true)) {
System.out.println("n: " + string);
Iterator<Violation> it = iri.violations(true);
while (it.hasNext()) {
Violation v = it.next();
System.out.println(v.getLongMessage());
}
} else {
System.out.println("y: " + string);
}
}
use of org.apache.jena.iri.IRI in project jena by apache.
the class AbsXMLContext method resolveAsURI.
final IRI resolveAsURI(XMLHandler forErrors, Taint taintMe, String relUri, boolean checkBaseUse) throws SAXParseException {
IRI rslt = uri.create(relUri);
if (checkBaseUse)
checkBaseUse(forErrors, taintMe, relUri, rslt);
checkURI(forErrors, taintMe, rslt);
return rslt;
}
use of org.apache.jena.iri.IRI in project jena by apache.
the class AbsXMLContext method withBase.
// protected AbsXMLContext withBase(XMLHandler forErrors, String b)
// throws SAXParseException {
// TaintImpl taintB = new TaintImpl();
// IRI newB = resolveAsURI(forErrors, taintB, b, false);
// // TO DO update MALFORMED_CONTEXT
// if (newB.isVeryBad())
// return new XMLBaselessContext(forErrors,
// ERR_RESOLVING_AGAINST_MALFORMED_BASE, b);
// return new XMLContext(keepDocument(forErrors), document, newB
// .create(""), taintB, lang, langTaint);
// }
public AbsXMLContext withBase(XMLHandler forErrors, String b) throws SAXParseException {
TaintImpl taintB = new TaintImpl();
IRI newB = resolveAsURI(forErrors, taintB, b, false);
if (newB.isRelative())
return new XMLBaselessContext(forErrors, ERR_RESOLVING_AGAINST_RELATIVE_BASE, newB.create(""));
if (newB.hasViolation(false))
return new XMLBaselessContext(forErrors, ERR_RESOLVING_AGAINST_MALFORMED_BASE, newB);
return new XMLContext(keepDocument(forErrors), document, newB.create(""), taintB, lang, langTaint);
}
Aggregations