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 REST_Quads_RW method doPutPostTxn.
private void doPutPostTxn(HttpAction action, boolean clearFirst) {
UploadDetails details = null;
action.beginWrite();
try {
DatasetGraph dsg = action.getActiveDSG();
if (clearFirst)
dsg.clear();
StreamRDF dest = StreamRDFLib.dataset(dsg);
details = Upload.incomingData(action, dest);
action.commit();
ServletOps.success(action);
} catch (RiotException ex) {
// Parse error
action.abort();
ServletOps.errorBadRequest(ex.getMessage());
} catch (ActionErrorException ex) {
action.abort();
throw ex;
} catch (Exception ex) {
// Something else went wrong. Backout.
action.abort();
ServletOps.errorOccurred(ex.getMessage());
} finally {
action.endWrite();
}
ServletOps.uploadResponse(action, details);
}
use of org.apache.jena.riot.RiotException in project jena by apache.
the class REST_Quads_RW method doPutPostNonTxn.
private void doPutPostNonTxn(HttpAction action, boolean clearFirst) {
DatasetGraph dsgTmp = DatasetGraphFactory.create();
StreamRDF dest = StreamRDFLib.dataset(dsgTmp);
UploadDetails details;
try {
details = Upload.incomingData(action, dest);
} catch (RiotException ex) {
ServletOps.errorBadRequest(ex.getMessage());
return;
}
// Now insert into dataset
action.beginWrite();
try {
DatasetGraph dsg = action.getActiveDSG();
if (clearFirst)
dsg.clear();
FusekiLib.addDataInto(dsgTmp, dsg);
action.commit();
ServletOps.success(action);
} catch (Exception ex) {
// but it might and there is no harm safely trying.
try {
action.abort();
} catch (Exception ex2) {
}
ServletOps.errorOccurred(ex.getMessage());
} finally {
action.endWrite();
}
ServletOps.uploadResponse(action, details);
}
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);
}
Aggregations