/** * Guess at the {@link RDFFormat}. * * @param filename * Some filename. * * @return The {@link RDFFormat} -or- <code>null</code> iff * {@link #fallback} is <code>null</code> and the no format * was recognized for the <i>filename</i> */ public RDFFormat getRDFFormat(String filename) { final RDFFormat rdfFormat = // fallback == null // ? RDFFormat.forFileName(filename) // : RDFFormat.forFileName(filename, fallback)// ; return rdfFormat; }
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(); }
if (requireContext && !format.supportsContexts()) { if (preferredFormat != null && !preferredFormat.equals(format)) { if (!format.supportsNamespaces()) { for (String mimeType : format.getMIMETypes()) {
public GraphQueryTask(final BigdataSailRepositoryConnection cxn, final String namespace, final long timestamp, final String baseURI, final boolean includeInferred, final Map<String, Value> bindings, final ASTContainer astContainer, final QueryType queryType, final RDFFormat format, final HttpServletRequest req, final HttpServletResponse resp, final OutputStream os) { super(cxn, namespace, timestamp, baseURI, includeInferred, bindings, astContainer, queryType, format.getDefaultMIMEType(), format.getCharset(), format .getDefaultFileExtension(), req, resp, os); }
private RDFFormat findRdfFormat(URL url, URLConnection conn, RDFFormat defaultFormat) { RDFFormat format = RDFFormat.forMIMEType(conn.getContentType()); if (format == null) { format = RDFFormat.forFileName(url.getFile(), defaultFormat); } return format; } }
@Override public QueryResultFormat getQueryResultFormat() { return new QueryResultFormat("QueryResultFormat", format.getDefaultMIMEType(), Charset.defaultCharset(), format.getDefaultFileExtension()); }
fmt = RDFFormat.forFileName(uriStr, fallback); .getAcceptParams(RDFFormat.values(), quads/* requireContext */, fmt/* preferredRDFFormat */); fmt = RDFFormat.forMIMEType(mimeType, fallback); contentEncoding = fmt.getCharset().name();
String mimeType = rdfFormat.getDefaultMIMEType(); if (rdfFormat.hasCharset()) { Charset charset = rdfFormat.getCharset(); mimeType += "; charset=" + charset.name(); if (rdfFormat.getDefaultFileExtension() != null) { filename += "." + rdfFormat.getDefaultFileExtension();
URLConnection conn = rdf.openConnection(); if (format != null) { for (String type : format.getMIMETypes()) { conn.addRequestProperty("Accept", type); try { String name = getLocalName(rdf.toExternalForm()); if (format != null && !format.equals(RDFFormat.forFileName(name))) { name += "." + format.getDefaultFileExtension();
/** Test the default mime type for each {@link RDFFormat}. */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void test_conneg_rdf_data_01() { for (RDFFormat format : RDFFormat.values()) { final ConnegUtil util = new ConnegUtil(format.getDefaultMIMEType()); assertEquals(format.getName(), format, util.getRDFFormat()); if (!format.getName().equals("JSON")) { assertNull(format.getName(), util.getTupleQueryResultFormat()); } assertSameArray(new ConnegScore[] {// new ConnegScore(1f, format) },// util.getScores(RDFFormat.class)); } }
/** * Resolves a RDF2Go Syntax to an OpenRDF RDFFormat. * * @param syntax * The RDF2Go Syntax to resolve. * @return A RDFFormat for the specified syntax. * @throws ModelRuntimeException * When the Syntax could not be resolved to a RDFFormat. */ public static RDFFormat getRDFFormat(Syntax syntax) throws ModelRuntimeException { String mimeType = syntax.getMimeType(); return RDFFormat.forMIMEType(mimeType); }
if (rdfFormat.isPresent()) { RDFFormat format = rdfFormat.get(); if (format.equals(RDFFormat.RDFA)) { return 1; } else if (format.equals(RDFFormat.TURTLE)) { return 2; } else if (format.equals(RDFFormat.TURTLE)) { return 3; } else if (format.equals(RDFFormat.RDFJSON)) { return 4; } else if (format.equals(RDFFormat.TRIG)) { return 8; } else if (format.equals(RDFFormat.NQUADS)) { return 9; } else {
public String toString() { return "'" + this.format.getName() + "' verbatim rdfizer"; } }
public Header getContentType() { return new BasicHeader("Content-Type", dataFormat.getDefaultMIMEType() + "; charset=" + charset.name()); }
private static void checkFileParseable(@Nullable final File file, @Nullable final String formatString) { if (file == null) { if (formatString == null) { throw new IllegalArgumentException("Cannot detect RDF format " + "and compression of STDIN: please specify option -s"); } return; } checkFileExist(file); final RDFFormat defaultFormat = detectRDFFormat(formatString, null); final Compression defaultCompression = detectCompression(formatString, null); final RDFFormat format = RDFFormat.forFileName(file.getName()); if (format == null && defaultFormat == null) { throw new IllegalArgumentException("Unknown RDF format for file " + file); } else if (format != null && defaultFormat != null && !format.equals(defaultFormat)) { System.err.println("Warning: detected RDF format for file " + file + " doesn't match specified format"); } final Compression compression = Compression.forFileName(file.getName(), Compression.NONE); if (defaultCompression != null && !compression.equals(defaultCompression)) { System.err.println("Warning: detected compression format for file " + file + " doesn't match specified format"); } }
@Override public Model exportDataset(String dataset) { RDFFormat format = RDFFormat.TURTLE; try { final java.net.URI target = credentials.buildUrl(getDatasetUriBuilder(dataset)); log.debug("Exporting {} data from dataset {}", format.getName(), dataset); final String entity = client.get(target, format.getDefaultMIMEType()); return Rio.parse(new StringReader(entity), target.toString(), format, new ParserConfig(), ValueFactoryImpl.getInstance(), new ParseErrorLogger()); } catch (IllegalArgumentException | URISyntaxException | RDFParseException | IOException e) { throw new RuntimeException(e); } }
/** * returns a list of all mimetypes which can be parsed by implemented parsers * @return */ @Override public List<String> getAcceptTypes() { Set<String> acceptTypes = new LinkedHashSet<>(); for(RDFFormat format : RDFParserRegistry.getInstance().getKeys()) { // Ignore binary formats if(format.hasCharset()) { acceptTypes.addAll(format.getMIMETypes()); } } return new ArrayList<>(acceptTypes); }
if (kb.isStatementIdentifiers() && !RDFFormat.RDFXML.equals(format)) throw new IllegalArgumentException( "SIDs mode requires RDF/XML interchange."); if (kb.isQuads() && !format.supportsContexts()) throw new IllegalArgumentException( "RDFFormat does not support quads: " + format);
private Representation representNonInformationResource(final MediaType type) { RDFFormat format = RDFMediaTypes.findRdfFormat(type); if (null == format) { throw new IllegalStateException("no RDF format for media type " + type); } String suffix = format.getDefaultFileExtension(); if (null == suffix) { throw new IllegalStateException("no suffix for RDF format " + type); } getResponse().redirectSeeOther(selfURI + "." + suffix); return null; }
@Override protected String getAccept() { StringBuilder sb = new StringBuilder(); Set<RDFFormat> rdfFormats = registry.getKeys(); for (RDFFormat format : rdfFormats) { for (String mimeType : format.getMIMETypes()) { if (sb.length() > 0) { sb.append(", "); } sb.append(mimeType); } } return sb.toString(); }