org.eclipse.rdf4j.common.lang.FileFormat Java Examples

The following examples show how to use org.eclipse.rdf4j.common.lang.FileFormat. 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: QueryResultView.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
protected void setContentDisposition(Map model, HttpServletResponse response, FileFormat fileFormat)
		throws IOException {
	// Report as attachment to make use in browser more convenient
	String filename = (String) model.get(FILENAME_HINT_KEY);

	if (filename == null || filename.length() == 0) {
		filename = "result";
	}

	if (fileFormat.getDefaultFileExtension() != null) {
		filename += "." + fileFormat.getDefaultFileExtension();
	}

	response.setHeader("Content-Disposition", "attachment; filename=" + filename);
}
 
Example #2
Source File: QueryResultView.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void setContentType(HttpServletResponse response, FileFormat fileFormat) throws IOException {
	String mimeType = fileFormat.getDefaultMIMEType();
	if (fileFormat.hasCharset()) {
		Charset charset = fileFormat.getCharset();
		mimeType += "; charset=" + charset.name();
	}
	response.setContentType(mimeType);
}
 
Example #3
Source File: HttpServerUtilTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
	FileFormatServiceRegistry<? extends FileFormat, ?> registry = TupleQueryResultWriterRegistry.getInstance();

	tupleQueryMimeTypes = new ArrayList<>(16);
	for (FileFormat format : registry.getKeys()) {
		tupleQueryMimeTypes.addAll(format.getMIMETypes());
	}
}
 
Example #4
Source File: RdfFormatUtils.java    From rya with Apache License 2.0 5 votes vote down vote up
/**
 * Tries to determine the appropriate RDF file format based on the extension
 * of a file name. The supplied fallback format will be returned when the
 * file name extension was not recognized.
 * @param fileName A file name.
 * @return An {@link RDFFormat} that matches the file name extension, or the
 * fallback format if the extension was not recognized.
 */
public static RDFFormat forFileName(final String fileName, final RDFFormat fallback) {
    final Optional<RDFFormat> match = FileFormat.matchFileName(fileName, RDF_FORMATS);
    if (match.isPresent()) {
        return match.get();
    } else {
        return fallback;
    }
}
 
Example #5
Source File: FileFormatServiceRegistry.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Tries to match a MIME type against the list of registered file formats.
 *
 * @param mimeType A MIME type, e.g. "text/plain".
 * @return The matching {@link FileFormat}, or {@link Optional#empty()} if no match was found.
 */
public Optional<FF> getFileFormatForMIMEType(String mimeType) {
	return FileFormat.matchMIMEType(mimeType, this.getKeys());
}
 
Example #6
Source File: FileFormatServiceRegistry.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Tries to match the extension of a file name against the list of registred file formats.
 *
 * @param fileName A file name.
 * @return The matching {@link FileFormat}, or {@link Optional#empty()} if no match was found.
 */
public Optional<FF> getFileFormatForFileName(String fileName) {
	return FileFormat.matchFileName(fileName, this.getKeys());
}