Search in sources :

Example 11 with RiotException

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;
}
Also used : RiotException(org.apache.jena.riot.RiotException) Node(org.apache.jena.graph.Node) Token(org.apache.jena.riot.tokens.Token) Tokenizer(org.apache.jena.riot.tokens.Tokenizer)

Example 12 with RiotException

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);
}
Also used : RiotException(org.apache.jena.riot.RiotException) StreamRDF(org.apache.jena.riot.system.StreamRDF) RiotException(org.apache.jena.riot.RiotException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 13 with RiotException

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);
}
Also used : RiotException(org.apache.jena.riot.RiotException) StreamRDF(org.apache.jena.riot.system.StreamRDF) RiotException(org.apache.jena.riot.RiotException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 14 with RiotException

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();
    }
}
Also used : Graph(org.apache.jena.graph.Graph) RiotException(org.apache.jena.riot.RiotException) StreamRDF(org.apache.jena.riot.system.StreamRDF) RiotException(org.apache.jena.riot.RiotException)

Example 15 with RiotException

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);
}
Also used : RiotException(org.apache.jena.riot.RiotException)

Aggregations

RiotException (org.apache.jena.riot.RiotException)33 Node (org.apache.jena.graph.Node)10 IOException (java.io.IOException)7 StreamRDF (org.apache.jena.riot.system.StreamRDF)7 Graph (org.apache.jena.graph.Graph)4 Model (org.apache.jena.rdf.model.Model)4 Lang (org.apache.jena.riot.Lang)4 Token (org.apache.jena.riot.tokens.Token)4 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)4 Dataset (org.apache.jena.query.Dataset)3 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)2 IRI (org.apache.jena.iri.IRI)2 Tokenizer (org.apache.jena.riot.tokens.Tokenizer)2 Var (org.apache.jena.sparql.core.Var)2 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 JsonLdError (com.github.jsonldjava.core.JsonLdError)1 RDFDataset (com.github.jsonldjava.core.RDFDataset)1 BufferedReader (java.io.BufferedReader)1 InputStream (java.io.InputStream)1