Java Code Examples for org.openrdf.rio.RDFFormat#getMIMETypes()
The following examples show how to use
org.openrdf.rio.RDFFormat#getMIMETypes() .
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: OntologyLoader.java From anno4j with Apache License 2.0 | 5 votes |
private String getAcceptHeader() { StringBuilder sb = new StringBuilder(); String preferred = RDFFormat.RDFXML.getDefaultMIMEType(); sb.append(preferred).append(";q=0.2"); Set<RDFFormat> rdfFormats = RDFParserRegistry.getInstance().getKeys(); for (RDFFormat format : rdfFormats) { for (String type : format.getMIMETypes()) { if (!preferred.equals(type)) { sb.append(", ").append(type); } } } return sb.toString(); }
Example 2
Source File: OWLCompiler.java From anno4j with Apache License 2.0 | 4 votes |
private void packOntologies(Map<URL, RDFFormat> rdfSources, File dir, String META_INF_ONTOLOGIES) throws IOException { File list = new File(dir, META_INF_ONTOLOGIES); list.getParentFile().mkdirs(); PrintStream inf = new PrintStream(new FileOutputStream(list)); try { for (URL rdf : rdfSources.keySet()) { try { RDFFormat format = rdfSources.get(rdf); String path = "META-INF/ontologies/"; URLConnection conn = rdf.openConnection(); if (format != null) { for (String type : format.getMIMETypes()) { conn.addRequestProperty("Accept", type); } } InputStream in = conn.getInputStream(); try { String name = getLocalName(rdf.toExternalForm()); if (format != null && !format.equals(RDFFormat.forFileName(name))) { name += "." + format.getDefaultFileExtension(); } File file = new File(dir, path + name); file.getParentFile().mkdirs(); OutputStream out = new FileOutputStream(file); try { int read; byte[] buf = new byte[1024]; while ((read = in.read(buf)) >= 0) { out.write(buf, 0, read); } } finally { out.close(); } inf.println(path + name); } finally { in.close(); } } catch (ConnectException exc) { throw new IOException("Cannot connect to " + rdf, exc); } } } finally { inf.close(); } }
Example 3
Source File: AcceptHeaderFactory.java From database with GNU General Public License v2.0 | 4 votes |
/** * * @param rdfFormats * @param requireContext * @param preferredFormat * @return */ public static List<String> getAcceptParams( final Iterable<RDFFormat> rdfFormats, // final boolean requireContext,// final RDFFormat preferredFormat// ) { final List<String> acceptParams = new LinkedList<String>(); for (RDFFormat format : rdfFormats) { // Determine a q-value that reflects the necessity of context // support and the user specified preference int qValue = defaultQValue; if (requireContext && !format.supportsContexts()) { // Prefer context-supporting formats over pure triple-formats qValue -= 5; } if (preferredFormat != null && !preferredFormat.equals(format)) { // Prefer specified format over other formats qValue -= 2; } if (!format.supportsNamespaces()) { // We like reusing namespace prefixes qValue -= 1; } for (String mimeType : format.getMIMETypes()) { // Default is the bare mime type. String acceptParam = mimeType; if (qValue < 10) { // Annotate with the factional quality score. acceptParam += ";q=0." + qValue; } acceptParams.add(acceptParam); } } return acceptParams; }