use of org.apache.jena.riot.RiotException in project jena by apache.
the class SPARQL_GSP_RW method addDataIntoNonTxn.
/** Add data where the destination does not support full transactions.
* In particular, with no abort, and actions probably going to the real storage
* parse errors can lead to partial updates. Instead, parse to a temporary
* graph, then insert that data.
* @param action
* @param cleanDest Whether to remove data first (true = PUT, false = POST)
* @return whether the target existed beforehand.
*/
protected static UploadDetails addDataIntoNonTxn(HttpAction action, boolean overwrite) {
Graph graphTmp = GraphFactory.createGraphMem();
StreamRDF dest = StreamRDFLib.graph(graphTmp);
UploadDetails details;
try {
details = Upload.incomingData(action, dest);
} catch (RiotException ex) {
ServletOps.errorBadRequest(ex.getMessage());
return null;
}
// Now insert into dataset
action.beginWrite();
Target target = determineTarget(action);
boolean existedBefore = false;
try {
if (action.log.isDebugEnabled())
action.log.debug(" ->" + target);
existedBefore = target.exists();
if (overwrite && existedBefore)
clearGraph(target);
FusekiLib.addDataInto(graphTmp, target.dsg, target.graphName);
details.setExistedBefore(existedBefore);
action.commit();
return details;
} catch (Exception ex) {
// but it might and there is no harm safely trying.
try {
action.abort();
} catch (Exception ex2) {
}
ServletOps.errorOccurred(ex.getMessage());
return null;
} finally {
action.endWrite();
}
}
use of org.apache.jena.riot.RiotException in project jena by apache.
the class StreamRDFLimited method triple.
@Override
public void triple(Triple triple) {
count++;
if (count > limit)
throw new RiotException("Limit (" + limit + ") reached");
super.triple(triple);
}
use of org.apache.jena.riot.RiotException 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.riot.RiotException in project jena by apache.
the class NodeFactoryExtra method parseNode.
/**
* Parse a string into a node.
* <p>
* Allows surrounding white space.
* </p>
*
* @param nodeString Node string to parse
* @param pmap Prefix Map, null to use no prefix mappings
* @return Parsed Node
* @throws RiotException Thrown if a valid node cannot be parsed
*/
public static Node parseNode(String nodeString, PrefixMap pmap) {
Tokenizer tokenizer = TokenizerFactory.makeTokenizerString(nodeString);
if (!tokenizer.hasNext())
throw new RiotException("Empty RDF term");
Token token = tokenizer.next();
Node node = token.asNode(pmap);
if (node == null)
throw new RiotException("Bad RDF Term: " + nodeString);
if (tokenizer.hasNext())
throw new RiotException("Trailing characters in string: " + nodeString);
if (node.isURI()) {
// Lightly test for bad URIs.
String x = node.getURI();
if (x.indexOf(' ') >= 0)
throw new RiotException("Space(s) in IRI: " + nodeString);
}
return node;
}
use of org.apache.jena.riot.RiotException in project jena by apache.
the class DataValidatorHTML method executeHTML.
//static final String paramSyntaxExtended = "extendedSyntax" ;
public static void executeHTML(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
try {
// if ( log.isInfoEnabled() )
// log.info("data validation request") ;
String syntax = FusekiLib.safeParameter(httpRequest, paramSyntax);
if (syntax == null || syntax.equals(""))
syntax = RDFLanguages.NQUADS.getName();
Lang language = RDFLanguages.shortnameToLang(syntax);
if (language == null) {
httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Unknown syntax: " + syntax);
return;
}
Reader input = createInput(httpRequest, httpResponse);
ServletOutputStream outStream = httpResponse.getOutputStream();
ErrorHandlerMsg errorHandler = new ErrorHandlerMsg(outStream);
// Capture logging errors.
PrintStream stderr = System.err;
System.setErr(new PrintStream(outStream));
// Headers
setHeaders(httpResponse);
outStream.println("<html>");
printHead(outStream, "Jena Data Validator Report");
outStream.println("<body>");
outStream.println("<h1>RIOT Parser Report</h1>");
outStream.println("<p>Line and column numbers refer to original input</p>");
outStream.println("<p> </p>");
// Need to escape HTML.
OutputStream output1 = new OutputStreamNoHTML(new BufferedOutputStream(outStream));
StreamRDF output = StreamRDFWriter.getWriterStream(output1, Lang.NQUADS);
try {
startFixed(outStream);
RDFParser parser = RDFParser.create().lang(language).errorHandler(errorHandler).resolveURIs(false).build();
RiotException exception = null;
startFixed(outStream);
try {
output.start();
parser.parse(output);
output.finish();
output1.flush();
outStream.flush();
System.err.flush();
} catch (RiotException ex) {
ex.printStackTrace(stderr);
exception = ex;
}
} finally {
finishFixed(outStream);
System.err.flush();
System.setErr(stderr);
}
outStream.println("</body>");
outStream.println("</html>");
} catch (Exception ex) {
serviceLog.warn("Exception in validationRequest", ex);
}
}
Aggregations