public static List<RDFFormat> filterAvailableParsers(List<RDFFormat> rdfFormats) { final List<RDFFormat> result = new ArrayList<>(); final RDFParserRegistry parserRegistry = RDFParserRegistry.getInstance(); for (RDFFormat f : rdfFormats) { if (parserRegistry.has(f)) { result.add(f); } } return result; }
private RDFFormat findRDFFormat(final String s) { Optional<RDFFormat> f; f = RDFParserRegistry.getInstance().getFileFormatForMIMEType(s); if (!f.isPresent()) { f = RDFParserRegistry.getInstance().getFileFormatForFileName("example." + s); } if (!f.isPresent()) { throw new IllegalArgumentException("no matching RDF format for '" + s + "'"); } return f.get(); }
/** * Parse the HTTP response entity returned by the web service call and return its contents as a * Sesame RDF repository. The content type returned by the web service is passed as argument to * help the implementation decide how to parse the data. * * @param resourceUri * @param triples * @param in input stream as returned by the remote webservice * @param contentType content type as returned in the HTTP headers of the remote * webservice @return an RDF repository containing an RDF representation of the dataset * located at the remote resource. * @throws java.io.IOException in case an error occurs while reading the input stream */ @Override public List<String> parseResponse( final String resourceUri, String requestUrl, Model triples, InputStream in, String contentType) throws DataRetrievalException { RDFFormat format = RDFParserRegistry.getInstance().getFileFormatForMIMEType(contentType, RDFFormat.RDFXML); try { ModelCommons.add( triples, in, resourceUri, format, new Predicate<Statement>() { @Override public boolean test(Statement param) { return StringUtils.equals(param.getSubject().stringValue(), resourceUri); } }); return Collections.emptyList(); } catch (RDFParseException e) { throw new DataRetrievalException("parse error while trying to parse remote RDF content", e); } catch (IOException e) { throw new DataRetrievalException("I/O error while trying to read remote RDF content", e); } }