/** * Create a new VocabularyBuilder, reading the vocab definition from the provided file * * @param filename the input file to read the vocab from * @param format the format of the vocab file, may be {@code null} * @throws java.io.IOException if the file could not be read * @throws RDFParseException if the format of the vocab could not be detected or is unknown. */ public VocabBuilder(String filename, String format) throws IOException, RDFParseException { this(filename, format != null ? Rio.getParserFormatForMIMEType(format) : null); }
/** * returns a parser for a given mimetype; null if no parser defined * @param mimetype * @return */ @Override public RDFFormat getParser(String mimetype) { return Rio.getParserFormatForMIMEType(mimetype); }
/** * returns a parser for a given mimetype; null if no parser defined * @param mimetype * @return */ @Override public RDFFormat getParser(String mimetype) { return Rio.getParserFormatForMIMEType(mimetype); }
/** * Get the RDF format from a user specfication (either mime type or short cut) * @param spec * @return */ private static RDFFormat getRDFFormat(String spec) { if(StringUtils.equalsIgnoreCase(spec,"turtle")) { return RDFFormat.TURTLE; } else if(StringUtils.equalsIgnoreCase(spec,"n3")) { return RDFFormat.N3; } else if(StringUtils.equalsIgnoreCase(spec,"nquads")) { return RDFFormat.NQUADS; } else if(StringUtils.equalsIgnoreCase(spec,"rdf")) { return RDFFormat.RDFXML; } else if(StringUtils.equalsIgnoreCase(spec,"xml")) { return RDFFormat.RDFXML; } else if(StringUtils.equalsIgnoreCase(spec,"geonames")) { return GeonamesFormat.FORMAT; } else if(spec != null) { return Rio.getParserFormatForMIMEType(spec); } else { return null; } }
/** * Get the RDF format from a user specfication (either mime type or short cut) * @param spec * @return */ private static RDFFormat getRDFFormat(String spec) { if(StringUtils.equalsIgnoreCase(spec,"turtle")) { return RDFFormat.TURTLE; } else if(StringUtils.equalsIgnoreCase(spec,"n3")) { return RDFFormat.N3; } else if(StringUtils.equalsIgnoreCase(spec,"nquads")) { return RDFFormat.NQUADS; } else if(StringUtils.equalsIgnoreCase(spec,"rdf")) { return RDFFormat.RDFXML; } else if(StringUtils.equalsIgnoreCase(spec,"xml")) { return RDFFormat.RDFXML; } else if(StringUtils.equalsIgnoreCase(spec,"geonames")) { return GeonamesFormat.FORMAT; } else if(spec != null) { return Rio.getParserFormatForMIMEType(spec); } else { return null; } }
/** * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher}, * to match the provided matcher against an serialized RDF-String. * * @param mimeType the MimeType used to guess the RDFFormat for de-serializing the RDF * @param baseUri the baseUri used for de-serializing the RDF * @param matcher the Matcher to wrap * @see Rio#getParserFormatForMIMEType(String) * @see org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher#wrap(org.openrdf.rio.RDFFormat, String, org.hamcrest.Matcher) */ public static <T extends String, V extends RepositoryConnection> Matcher<T> rdfStringMatches(String mimeType, String baseUri, Matcher<V> matcher) { final RDFFormat format = Rio.getParserFormatForMIMEType(mimeType); if (format == null) throw new UnsupportedRDFormatException(mimeType); return RdfStringMatcher.wrap(format, baseUri, matcher); }
/** * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher}, * to match the provided matcher against an serialized RDF-String. * * @param mimeType the MimeType used to guess the RDFFormat for de-serializing the RDF * @param baseUri the baseUri used for de-serializing the RDF * @param matcher the Matcher to wrap * @see Rio#getParserFormatForMIMEType(String) * @see org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher#wrap(org.openrdf.rio.RDFFormat, String, org.hamcrest.Matcher) */ public static <T extends String, V extends RepositoryConnection> Matcher<T> rdfStringMatches(String mimeType, String baseUri, Matcher<V> matcher) { final RDFFormat format = Rio.getParserFormatForMIMEType(mimeType); if (format == null) throw new UnsupportedRDFormatException(mimeType); return RdfStringMatcher.wrap(format, baseUri, matcher); }
private TripleProducer getProducer(String content) { RDFFormat sesameFormat = Rio. getParserFormatForMIMEType( this.format.getMime(), RDFFormat.TURTLE); TripleProducer producer=null; switch(unmarshallStyle) { case PARSER_BASED: producer=new ParserBasedTripleProducer(content,sesameFormat,this.baseURI.toString()); break; case REPOSITORY_BASED: producer=new RepositoryBasedTripleProducer(content,sesameFormat,this.baseURI.toString()); break; default: throw new AssertionError("Unsupported unmarshalling style '"+unmarshallStyle+"'"); } return producer; }
/** * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher}, * to match the provided matcher against an serialized RDF-String. * * @param mimeType the MimeType used to guess the RDFFormat for de-serializing the RDF * @param baseUri the baseUri used for de-serializing the RDF * @param matchers the Matchers to wrap * @see Rio#getParserFormatForMIMEType(String) * @see org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher#wrap(org.openrdf.rio.RDFFormat, String, org.hamcrest.Matcher) */ @SafeVarargs public static <T extends String, V extends RepositoryConnection> Matcher<T> rdfStringMatches(String mimeType, String baseUri, Matcher<V>... matchers) { final RDFFormat format = Rio.getParserFormatForMIMEType(mimeType); if (format == null) throw new UnsupportedRDFormatException(mimeType); return RdfStringMatcher.wrap(format, baseUri, CoreMatchers.allOf(matchers)); }
/** * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher}, * to match the provided matcher against an serialized RDF-String. * * @param mimeType the MimeType used to guess the RDFFormat for de-serializing the RDF * @param baseUri the baseUri used for de-serializing the RDF * @param matchers the Matchers to wrap * @see Rio#getParserFormatForMIMEType(String) * @see org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher#wrap(org.openrdf.rio.RDFFormat, String, org.hamcrest.Matcher) */ @SafeVarargs public static <T extends String, V extends RepositoryConnection> Matcher<T> rdfStringMatches(String mimeType, String baseUri, Matcher<V>... matchers) { final RDFFormat format = Rio.getParserFormatForMIMEType(mimeType); if (format == null) throw new UnsupportedRDFormatException(mimeType); return RdfStringMatcher.wrap(format, baseUri, CoreMatchers.allOf(matchers)); }
/** * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher}, * to match the provided matcher against an serialized RDF-String. * * @param mimeType the MimeType used to guess the RDFFormat for de-serializing the RDF * @param baseUri the baseUri used for de-serializing the RDF * @param matcher1 the Matcher to wrap * @param matcher2 the Matcher to wrap * @see Rio#getParserFormatForMIMEType(String) * @see org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher#wrap(org.openrdf.rio.RDFFormat, String, org.hamcrest.Matcher) */ public static <T extends String, V extends RepositoryConnection> Matcher<T> rdfStringMatches(String mimeType, String baseUri, Matcher<V> matcher1, Matcher<V> matcher2) { final RDFFormat format = Rio.getParserFormatForMIMEType(mimeType); if (format == null) throw new UnsupportedRDFormatException(mimeType); return RdfStringMatcher.wrap(format, baseUri, CoreMatchers.allOf(matcher1, matcher2)); }
/** * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher}, * to match the provided matcher against an serialized RDF-String. * * @param mimeType the MimeType used to guess the RDFFormat for de-serializing the RDF * @param baseUri the baseUri used for de-serializing the RDF * @param matcher1 the Matcher to wrap * @param matcher2 the Matcher to wrap * @see Rio#getParserFormatForMIMEType(String) * @see org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher#wrap(org.openrdf.rio.RDFFormat, String, org.hamcrest.Matcher) */ public static <T extends String, V extends RepositoryConnection> Matcher<T> rdfStringMatches(String mimeType, String baseUri, Matcher<V> matcher1, Matcher<V> matcher2) { final RDFFormat format = Rio.getParserFormatForMIMEType(mimeType); if (format == null) throw new UnsupportedRDFormatException(mimeType); return RdfStringMatcher.wrap(format, baseUri, CoreMatchers.allOf(matcher1, matcher2)); }
final String fmt = prop.getProperty("format"); if (fmt != null) { RDFFormat rdfFormat = Rio.getParserFormatForMIMEType(fmt); if (rdfFormat != null) { format = rdfFormat.getDefaultMIMEType();
public FileBackend(URL url, String mimetype) { super(); RDFFormat format = null; if(mimetype != null) { format = Rio.getParserFormatForMIMEType(mimetype); } try { Repository repository = new SailRepository(new MemoryStore()); repository.initialize(); setRepository(repository); RepositoryConnection connection = repository.getConnection(); try { connection.add(url,null,format); } finally { connection.close(); } } catch (RDFParseException e) { log.error("error parsing RDF input data from url {}",url,e); } catch (IOException e) { log.error("I/O error while reading input data from url {}", url, e); } catch (RepositoryException e) { log.error("error initialising connection to Sesame in-memory repository",e); } }
public FileBackend(File file, String mimetype) { super(); RDFFormat format = null; if(mimetype != null) { format = Rio.getParserFormatForMIMEType(mimetype); } try { Repository repository = new SailRepository(new MemoryStore()); repository.initialize(); setRepository(repository); RepositoryConnection connection = repository.getConnection(); try { connection.add(file,null,format); } finally { connection.close(); } } catch (RDFParseException e) { log.error("error parsing RDF input data from file {}",file,e); } catch (IOException e) { log.error("I/O error while reading input data from file {}", file, e); } catch (RepositoryException e) { log.error("error initialising connection to Sesame in-memory repository",e); } }
request.getInputStream(), baseURI, Rio.getParserFormatForMIMEType(request.getContentType()).orElseThrow( Rio.unsupportedFormat(request.getContentType()))); break; case DELETE: RDFParser parser = Rio.createParser( Rio.getParserFormatForMIMEType(request.getContentType()).orElseThrow( Rio.unsupportedFormat(request.getContentType())), conn.getValueFactory()); parser.setRDFHandler(new WildcardRDFRemover(conn));
@Test public void testParserFactoryRegisteredAlternate() { final RDFFormat fmt = Rio.getParserFormatForMIMEType("application/json"); Assert.assertNotNull("Could not find the RDF/JSON RDFFormat instance", fmt); final RDFParser parser = Rio.createParser(fmt); Assert.assertTrue(parser instanceof RDFJSONParser); }
@Test public void testParserFactoryRegistered() { final RDFFormat fmt = Rio.getParserFormatForMIMEType("application/rdf+json"); Assert.assertNotNull("Could not find the RDF/JSON RDFFormat instance", fmt); final RDFParser parser = Rio.createParser(fmt); Assert.assertTrue(parser instanceof RDFJSONParser); }
RDFFormat rdfFormat = Rio.getParserFormatForMIMEType(mimeType).orElseThrow( () -> new ClientHTTPException(SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported MIME type: " + mimeType));
private Collection<Annotation> parseInput(final Representation entity) throws ResourceException final RDFFormat inputFormat = Rio.getParserFormatForMIMEType(entity.getMediaType().getName());