org.eclipse.rdf4j.rio.RDFWriterRegistry Java Examples

The following examples show how to use org.eclipse.rdf4j.rio.RDFWriterRegistry. 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: ConfigController.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private ModelAndView handleQuery(HttpServletRequest request, HttpServletResponse response)
		throws ClientHTTPException {

	RDFWriterFactory rdfWriterFactory = ProtocolUtil.getAcceptableService(request, response,
			RDFWriterRegistry.getInstance());
	String repId = RepositoryInterceptor.getRepositoryID(request);
	RepositoryConfig repositoryConfig = repositoryManager.getRepositoryConfig(repId);

	Model configData = modelFactory.createEmptyModel();
	String baseURI = request.getRequestURL().toString();
	Resource ctx = SimpleValueFactory.getInstance().createIRI(baseURI + "#" + repositoryConfig.getID());

	repositoryConfig.export(configData, ctx);
	Map<String, Object> model = new HashMap<>();
	model.put(ConfigView.FORMAT_KEY, rdfWriterFactory.getRDFFormat());
	model.put(ConfigView.CONFIG_DATA_KEY, configData);
	model.put(ConfigView.HEADERS_ONLY, METHOD_HEAD.equals(request.getMethod()));
	return new ModelAndView(ConfigView.getInstance(), model);
}
 
Example #2
Source File: StatementsController.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Get all statements and export them as RDF.
 *
 * @return a model and view for exporting the statements.
 */
private ModelAndView getExportStatementsResult(Repository repository, HttpServletRequest request,
		HttpServletResponse response) throws ClientHTTPException {
	ProtocolUtil.logRequestParameters(request);

	ValueFactory vf = repository.getValueFactory();

	Resource subj = ProtocolUtil.parseResourceParam(request, SUBJECT_PARAM_NAME, vf);
	IRI pred = ProtocolUtil.parseURIParam(request, PREDICATE_PARAM_NAME, vf);
	Value obj = ProtocolUtil.parseValueParam(request, OBJECT_PARAM_NAME, vf);
	Resource[] contexts = ProtocolUtil.parseContextParam(request, CONTEXT_PARAM_NAME, vf);
	boolean useInferencing = ProtocolUtil.parseBooleanParam(request, INCLUDE_INFERRED_PARAM_NAME, true);

	RDFWriterFactory rdfWriterFactory = ProtocolUtil.getAcceptableService(request, response,
			RDFWriterRegistry.getInstance());

	Map<String, Object> model = new HashMap<>();
	model.put(ExportStatementsView.SUBJECT_KEY, subj);
	model.put(ExportStatementsView.PREDICATE_KEY, pred);
	model.put(ExportStatementsView.OBJECT_KEY, obj);
	model.put(ExportStatementsView.CONTEXTS_KEY, contexts);
	model.put(ExportStatementsView.USE_INFERENCING_KEY, Boolean.valueOf(useInferencing));
	model.put(ExportStatementsView.FACTORY_KEY, rdfWriterFactory);
	model.put(ExportStatementsView.HEADERS_ONLY, METHOD_HEAD.equals(request.getMethod()));
	return new ModelAndView(ExportStatementsView.getInstance(), model);
}
 
Example #3
Source File: GraphController.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Get all statements and export them as RDF.
 *
 * @return a model and view for exporting the statements.
 */
private ModelAndView getExportStatementsResult(Repository repository, HttpServletRequest request,
		HttpServletResponse response) throws ClientHTTPException {
	ProtocolUtil.logRequestParameters(request);

	ValueFactory vf = repository.getValueFactory();

	IRI graph = getGraphName(request, vf);

	RDFWriterFactory rdfWriterFactory = ProtocolUtil.getAcceptableService(request, response,
			RDFWriterRegistry.getInstance());

	Map<String, Object> model = new HashMap<>();

	model.put(ExportStatementsView.CONTEXTS_KEY, new Resource[] { graph });
	model.put(ExportStatementsView.FACTORY_KEY, rdfWriterFactory);
	model.put(ExportStatementsView.USE_INFERENCING_KEY, true);
	model.put(ExportStatementsView.HEADERS_ONLY, METHOD_HEAD.equals(request.getMethod()));
	return new ModelAndView(ExportStatementsView.getInstance(), model);
}
 
Example #4
Source File: HalyardExport.java    From Halyard with Apache License 2.0 6 votes vote down vote up
private static String listRDFOut() {
    StringBuilder sb = new StringBuilder();
    for (RDFFormat fmt : RDFWriterRegistry.getInstance().getKeys()) {
        sb.append("* ").append(fmt.getName()).append(" (");
        boolean first = true;
        for (String ext : fmt.getFileExtensions()) {
            if (first) {
                first = false;
            } else {
                sb.append(", ");
            }
            sb.append('.').append(ext);
        }
        sb.append(")\n");
    }
    return sb.toString();
}
 
Example #5
Source File: TransactionController.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get all statements and export them as RDF.
 *
 * @return a model and view for exporting the statements.
 */
private ModelAndView getExportStatementsResult(Transaction transaction, HttpServletRequest request,
		HttpServletResponse response) throws ClientHTTPException {
	ProtocolUtil.logRequestParameters(request);

	ValueFactory vf = SimpleValueFactory.getInstance();

	Resource subj = ProtocolUtil.parseResourceParam(request, SUBJECT_PARAM_NAME, vf);
	IRI pred = ProtocolUtil.parseURIParam(request, PREDICATE_PARAM_NAME, vf);
	Value obj = ProtocolUtil.parseValueParam(request, OBJECT_PARAM_NAME, vf);
	Resource[] contexts = ProtocolUtil.parseContextParam(request, CONTEXT_PARAM_NAME, vf);
	boolean useInferencing = ProtocolUtil.parseBooleanParam(request, INCLUDE_INFERRED_PARAM_NAME, true);

	RDFWriterFactory rdfWriterFactory = ProtocolUtil.getAcceptableService(request, response,
			RDFWriterRegistry.getInstance());

	Map<String, Object> model = new HashMap<>();
	model.put(TransactionExportStatementsView.SUBJECT_KEY, subj);
	model.put(TransactionExportStatementsView.PREDICATE_KEY, pred);
	model.put(TransactionExportStatementsView.OBJECT_KEY, obj);
	model.put(TransactionExportStatementsView.CONTEXTS_KEY, contexts);
	model.put(TransactionExportStatementsView.USE_INFERENCING_KEY, Boolean.valueOf(useInferencing));
	model.put(TransactionExportStatementsView.FACTORY_KEY, rdfWriterFactory);
	model.put(TransactionExportStatementsView.HEADERS_ONLY, METHOD_HEAD.equals(request.getMethod()));

	model.put(TransactionExportStatementsView.TRANSACTION_KEY, transaction);
	return new ModelAndView(TransactionExportStatementsView.getInstance(), model);
}
 
Example #6
Source File: RepositoryModel.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Resolves an RDF2Go {@link Syntax} to an RDF4J {@link RDFFormat}.
 *
 * @param syntax The RDF2Go Syntax to resolve.
 * @return A RDFFormat for the specified syntax.
 * @throws SyntaxNotSupportedException When the Syntax could not be resolved to a
 *                                     RDFFormat.
 */
public static RDFFormat getRDFFormat(Syntax syntax) throws SyntaxNotSupportedException {
	RDFWriterRegistry registry = RDFWriterRegistry.getInstance();
	for (String mimeType : syntax.getMimeTypes()) {
		Optional<RDFFormat> format = registry.getFileFormatForMIMEType(mimeType);
		if (format.isPresent()) {
			return format.get();
		}
	}
	throw new SyntaxNotSupportedException("This version of Sesame seems to have no "
			+ "support for " + syntax);
}
 
Example #7
Source File: RDFQueryLogFactory.java    From semagrow with Apache License 2.0 4 votes vote down vote up
public RDFWriterFactory getRDFWriterFactory(RDFQueryLogConfig config) {
    RDFWriterRegistry writerRegistry = RDFWriterRegistry.getInstance();
    RDFWriterFactory writerFactory = writerRegistry.get(config.getRdfFormat()).get();
    return writerFactory;
}