org.apache.jena.riot.RiotException Java Examples
The following examples show how to use
org.apache.jena.riot.RiotException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParserProfileTurtleStarExtImpl.java From RDFstarTools with Apache License 2.0 | 6 votes |
@Override protected void checkTriple(Node subject, Node predicate, Node object, long line, long col) { if ( subject == null || (!subject.isURI() && !subject.isBlank() && !(subject instanceof Node_Triple)) ) { getErrorHandler().error("Subject is not a URI, blank node, or triple", line, col); throw new RiotException("Bad subject: " + subject); } if ( predicate == null || (!predicate.isURI()) ) { getErrorHandler().error("Predicate not a URI", line, col); throw new RiotException("Bad predicate: " + predicate); } if ( object == null || (!object.isURI() && !object.isBlank() && !object.isLiteral() && !(object instanceof Node_Triple)) ) { getErrorHandler().error("Object is not a URI, blank node, literal, or triple", line, col); throw new RiotException("Bad object: " + object); } }
Example #2
Source File: JenaIOService.java From trellis with Apache License 2.0 | 6 votes |
@Override public Stream<Triple> read(final InputStream input, final RDFSyntax syntax, final String base) { requireNonNull(input, "The input stream may not be null!"); requireNonNull(syntax, "The syntax value may not be null!"); try { final org.apache.jena.graph.Graph graph = createDefaultGraph(); final Lang lang = JenaCommonsRDF.toJena(syntax).orElseThrow(() -> new TrellisRuntimeException("Unsupported RDF Syntax: " + syntax.mediaType())); RDFParser.source(input).lang(lang).base(base).parse(graph); // Check the graph for any new namespace definitions final Set<String> namespaces = new HashSet<>(nsService.getNamespaces().values()); graph.getPrefixMapping().getNsPrefixMap().forEach((prefix, namespace) -> { if (shouldAddNamespace(namespaces, namespace, base)) { LOGGER.debug("Setting prefix ({}) for namespace {}", prefix, namespace); nsService.setPrefix(prefix, namespace); } }); return JenaCommonsRDF.fromJena(graph).stream().map(Triple.class::cast); } catch (final RiotException | AtlasException | IllegalArgumentException ex) { throw new TrellisRuntimeException(ex); } }
Example #3
Source File: ContextUtils.java From sparql-generate with Apache License 2.0 | 6 votes |
public static void loadGraph(Context context, String sourceURI, String baseURI, StreamRDF dest) { if(getDataset(context).containsNamedModel(sourceURI)) { final Model model = getDataset(context).getNamedModel(sourceURI); StreamRDFOps.sendGraphToStream(model.getGraph(), dest); return; } if(!isRootContext(context)) { Context parentContext = (Context) context.get(PARENT_CONTEXT); loadGraph(parentContext, sourceURI, baseURI, dest); return; } final SPARQLExtStreamManager sm = (SPARQLExtStreamManager) context.get(SysRIOT.sysStreamManager); final String acceptHeader = "text/turtle;q=1.0,application/rdf+xml;q=0.9,*/*;q=0.1"; final LookUpRequest request = new LookUpRequest(sourceURI, acceptHeader); try (TypedInputStream tin = sm.open(request);) { if(tin == null) { LOG.warn("Could not locate graph " + request); return; } Lang lang = RDFLanguages.contentTypeToLang(tin.getMediaType()); RDFParser.create().source(tin).base(baseURI).context(context).lang(lang).parse(dest); } catch (RiotException ex) { LOG.warn("Error while loading graph " + sourceURI, ex); } }
Example #4
Source File: RDFToManifest.java From incubator-taverna-language with Apache License 2.0 | 6 votes |
protected static Model jsonLdAsJenaModel(InputStream jsonIn, URI base) throws IOException, RiotException { Model model = ModelFactory.createDefaultModel(); ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); try { // TAVERNA-971: set context classloader so jarcache.json is consulted // even through OSGi Thread.currentThread().setContextClassLoader(RDFToManifest.class.getClassLoader()); // Now we can parse the JSON-LD without network access RDFDataMgr.read(model, jsonIn, base.toASCIIString(), Lang.JSONLD); } finally { // Restore old context class loader (if any) Thread.currentThread().setContextClassLoader(oldCl); } return model; }
Example #5
Source File: RdflintParserRdfxml.java From rdflint with MIT License | 5 votes |
private void oneProperty(ARPOptions options, // SUPPRESS CHECKSTYLE ParameterName String pName, // SUPPRESS CHECKSTYLE ParameterName Object value) { if (!pName.startsWith("ERR_") && !pName.startsWith("IGN_") && !pName.startsWith("WARN_")) { return; } int cond = ParseException.errorCode(pName); if (cond == -1) { throw new RiotException("No such ARP property: '" + pName + "'"); } int val; if (value instanceof String) { if (!((String) value).startsWith("EM_")) { throw new RiotException( "Value for ARP property does not start EM_: '" + pName + "' = '" + value + "'"); } val = ParseException.errorCode((String) value); if (val == -1) { throw new RiotException( "Illegal value for ARP property: '" + pName + "' = '" + value + "'"); } } else if (value instanceof Integer) { val = ((Integer) value).intValue(); switch (val) { case ARPErrorNumbers.EM_IGNORE: case ARPErrorNumbers.EM_WARNING: case ARPErrorNumbers.EM_ERROR: case ARPErrorNumbers.EM_FATAL: break; default: throw new RiotException( "Illegal value for ARP property: '" + pName + "' = '" + value + "'"); } } else { throw new RiotException( "Property \"" + pName + "\" cannot have value: " + value.toString()); } options.setErrorMode(cond, val); }
Example #6
Source File: WebAcService.java From trellis with Apache License 2.0 | 5 votes |
static Dataset generateDefaultRootAuthorizationsDataset(final String resource) { final Dataset dataset = rdf.createDataset(); final Model model = createDefaultModel(); try (final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)) { if (is != null) { LOGGER.debug("Using classpath resource for default root ACL: {}", resource); RDFParser.source(is).lang(TURTLE).base(TRELLIS_DATA_PREFIX).parse(model); } else { LOGGER.debug("Using external resource for default root ACL: {}", resource); RDFParser.source(resource).lang(TURTLE).base(TRELLIS_DATA_PREFIX).parse(model); } fromJena(model.getGraph()).stream().map(triple -> rdf.createQuad(Trellis.PreferAccessControl, triple.getSubject(), triple.getPredicate(), triple.getObject())).forEach(dataset::add); } catch (final IOException | RiotException ex) { LOGGER.warn("Couldn't initialize root ACL with {}, falling back to default: {}", resource, ex.getMessage()); } finally { model.close(); } // Fallback to manual creation if (dataset.size() == 0) { dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Read)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Write)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Control)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Append)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.agentClass, FOAF.Agent)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.default_, root)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.accessTo, root)); } return dataset; }
Example #7
Source File: RiotExceptionMapper.java From Processor with Apache License 2.0 | 5 votes |
@Override public Response toResponse(RiotException ex) { return getResponseBuilder(DatasetFactory.create(toResource(ex, Response.Status.BAD_REQUEST, ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#BadRequest")). getModel())). status(Response.Status.BAD_REQUEST). build(); }
Example #8
Source File: WfdescSerialiser.java From incubator-taverna-language with Apache License 2.0 | 5 votes |
public void save(WorkflowBundle wfBundle, OutputStream output) throws WriterException { OntModel model; final URI baseURI; if (wfBundle.getMainWorkflow() != null) { Workflow mainWorkflow = wfBundle.getMainWorkflow(); baseURI = uriTools.uriForBean(mainWorkflow); model = save(wfBundle); } else { throw new WriterException("wfdesc format requires a main workflow"); } model.setNsPrefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#"); model.setNsPrefix("xsd", "http://www.w3.org/2001/XMLSchema#"); model.setNsPrefix("owl", "http://www.w3.org/2002/07/owl#"); model.setNsPrefix("prov", "http://www.w3.org/ns/prov#"); model.setNsPrefix("wfdesc", "http://purl.org/wf4ever/wfdesc#"); model.setNsPrefix("wf4ever", "http://purl.org/wf4ever/wf4ever#"); model.setNsPrefix("roterms", "http://purl.org/wf4ever/roterms#"); model.setNsPrefix("dc", "http://purl.org/dc/elements/1.1/"); model.setNsPrefix("dcterms", "http://purl.org/dc/terms/"); model.setNsPrefix("comp", "http://purl.org/DP/components#"); model.setNsPrefix("dep", "http://scape.keep.pt/vocab/dependencies#"); model.setNsPrefix("biocat", "http://biocatalogue.org/attribute/"); model.setNsPrefix("", "#"); try { model.write(output, Lang.TURTLE.getName(), baseURI.toString()); } catch (RiotException e) { throw new WriterException("Can't write to output", e); } }
Example #9
Source File: ModelSetImplJena.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void writeTo(OutputStream out, Syntax syntax) throws IOException, ModelRuntimeException, SyntaxNotSupportedException { if (syntax == null) { throw new NullPointerException("syntax may not be null"); } Lang jenaLang = getJenaLang(syntax); // if (RDFLanguages.isTriples(jenaLang)) { // /* // * NB: Writing a ModelSet to a triple serialization loses the // * context of any quads if present. // */ // Iterator<Model> it = this.getModels(); // while (it.hasNext()) { // Model model = it.next(); // model.writeTo(out, syntax); // } // this.getDefaultModel().writeTo(out, syntax); // } // FIXME stuehmer: write unit test to see if this can be removed // else { try { RDFDataMgr.write(out, this.dataset, jenaLang); } catch (RiotException e) { throw new SyntaxNotSupportedException( "error writing syntax " + syntax + ": " + e.getMessage()); } }
Example #10
Source File: ResultSetWritersSPARQLStar.java From RDFstarTools with Apache License 2.0 | 4 votes |
@Override public ResultSetWriter create(Lang lang) { if ( lang.equals(SPARQLResultSetText) ) return writerText; throw new RiotException( "Lang not registered (ResultSet writer)" ); }
Example #11
Source File: TokenWriterText.java From rdf-delta with Apache License 2.0 | 4 votes |
private static void exception(IOException ex) { throw new RiotException(ex); }
Example #12
Source File: TokenWriterText.java From rdf-delta with Apache License 2.0 | 4 votes |
private void notImplemented(Token token) { throw new RiotException("Unencodable token: " + token); }