/** * Creates a streaming handler that requests results in specified RDF format. * * @param format Format to return the data in. */ public AGRawStreamer(final RDFFormat format) { this(format.getDefaultMIMEType()); }
private RDFFormat getBackwardCompatibleFormat(RDFFormat format) { // In Sesame 2.8, the default MIME-type for N-Triples changed. To stay // backward compatible, we 'fake' the // default MIME-type back to the older value (text/plain) when running in // compatibility mode. if (NTRIPLES.equals(format)) { // create a new format constant with identical properties as the // N-Triples format, just with a different // default MIME-type. return new RDFFormat(NTRIPLES.getName(), Arrays.asList("text/plain"), NTRIPLES.getCharset(), NTRIPLES.getFileExtensions(), NTRIPLES.supportsNamespaces(), NTRIPLES.supportsContexts()); } return format; }
@Override public RDFFormat getRDFFormat() { RDFFormat t = RDFFormat.TRIX; return new RDFFormat(t.getName(), t.getMIMETypes(), t.getCharset(), Arrays.asList("trix"), t.getStandardURI(), t.supportsNamespaces(), t.supportsNamespaces()); }
protected AbstractRioRDFDocumentFormatFactory(RDFFormat rioFormat, boolean isTextual) { super(rioFormat.getMIMETypes(), isTextual, rioFormat.getName()); this.rioFormat = rioFormat; formatName = this.rioFormat.getName(); }
/** * Constructor for super-classes to specify which * {@link RDFFormat} they support. * * @param format The {@link RDFFormat} that this instance supports. */ public RioRDFPrefixDocumentFormat(RDFFormat format) { this.format = format; formatName = this.format.getName(); }
String mimeType = rdfFormat.getDefaultMIMEType(); if (rdfFormat.hasCharset()) { Charset charset = rdfFormat.getCharset(); mimeType += "; charset=" + charset.name(); if (rdfFormat.getDefaultFileExtension() != null) { filename += "." + rdfFormat.getDefaultFileExtension();
if (requireContext && !format.supportsContexts()) { if (preferredFormat != null && !preferredFormat.equals(format)) { if (!format.supportsNamespaces()) { if (RDFXML.equals(format)) { for (String mimeType : format.getMIMETypes()) { String acceptParam = mimeType;
for (String mimeType : dataFormat.getMIMETypes()) { con.addRequestProperty("Accept", mimeType); List<String> acceptParams = RDFFormat.getAcceptParams(rdfFormats, true, null); for (String acceptParam : acceptParams) { con.addRequestProperty("Accept", acceptParam);
public void upload(final Reader contents, String baseURI, final RDFFormat dataFormat, boolean overwrite, JSONObject attributes, Resource... contexts) throws RDFParseException, AGHttpException { final Charset charset = dataFormat.hasCharset() ? dataFormat .getCharset() : Charset.forName("UTF-8"); RequestEntity entity = new RequestEntity() { public long getContentLength() { return -1; // don't know } public String getContentType() { String format = dataFormat.getDefaultMIMEType(); return format + "; charset=" + charset.name(); } public boolean isRepeatable() { return false; } public void writeRequest(OutputStream out) throws IOException { OutputStreamWriter writer = new OutputStreamWriter(out, charset); IOUtil.transfer(contents, writer); writer.flush(); } }; upload(entity, baseURI, overwrite, null, null, null, attributes, contexts); }
private RDFFormat getFormat(String mimetype) { if (mimetype != null) { log.info("mimetipe in request: " + mimetype); for (RDFFormat parser : availableParsers) { if (parser.getMIMETypes().contains(mimetype)) { log.info("parser to be used: " + parser.getDefaultMIMEType()); return parser; } } } log.info("Unrecognized serialization in accept header param. Defaulting to Turtle serialization"); return RDFFormat.TURTLE; } }
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(); }
@Override public List<String> getMIMETypes() { return format.getMIMETypes(); }
new QueueCursor<>(new LinkedBlockingQueue<>(1)), parser, in, format.getCharset(), baseURI); boolean allGood = false; try {
String iri = extractionContext.getDocumentIRI().stringValue(); if (format.hasFileExtension("xhtml") || format.hasMIMEType("application/xhtml+xml")) { Charset charset = format.getCharset(); if (charset == null) { charset = StandardCharsets.UTF_8; } else if (format.hasFileExtension("jsonld") || format.hasMIMEType("application/ld+json")) { in = new JsonCommentStripperInputStream(in);
RDFFormat format = RDFFormat.matchMIMEType(mimeType, rdfFormats).orElseThrow( () -> new RepositoryException( "Server responded with an unsupported file format: " + mimeType)); if (format.hasCharset() && entity != null && entity.getContentType() != null) {
/** * Given the default file extension of an RDF format, returns the corresponding * {@link RDFFormat}. This factory method detour is necessary because {@link RDFFormat} should * be used as a model, but is not serializable. * * @return an {@link RDFFormat} */ private static final RDFFormat getRdfFormatForFileExt(String fileExt) { return EXPORT_FORMATS.stream().filter(f -> f.getDefaultFileExtension().equals(fileExt)) .findAny().get(); } private static final List<RDFFormat> EXPORT_FORMATS = Arrays
private HttpResponse sendGraphQueryViaHttp(HttpUriRequest method, boolean requireContext, Set<RDFFormat> rdfFormats) throws RepositoryException, IOException, QueryInterruptedException, MalformedQueryException { List<String> acceptParams = RDFFormat.getAcceptParams(rdfFormats, requireContext, getPreferredRDFFormat()); method.addHeader(ACCEPT_PARAM_NAME, String.join(", ", acceptParams)); try { return executeOK(method); } catch (RepositoryException | MalformedQueryException | QueryInterruptedException e) { throw e; } catch (RDF4JException e) { throw new RepositoryException(e); } }
/** * @return the set of all supported file extensions from * {@link #RDF_FORMATS}. */ private static Set<String> buildSupportedFileExtensions() { return ImmutableSet.copyOf(RDF_FORMATS.stream().flatMap(rdfFormat -> rdfFormat.getFileExtensions().stream()).collect(Collectors.toList())); } }
/** * Determine whether an input file can be split. If the input format is * configured to be anything other than N-Triples or N-Quads, then the * structure of the file is important and it cannot be split arbitrarily. * Otherwise, default to the superclass logic to determine whether splitting * is appropriate. * @return true if configured to use a line-based input format and the * superclass implementation returns true. */ @Override protected boolean isSplitable(JobContext context, Path filename) { RDFFormat rdfFormat = getRDFFormat(context); if (RDFFormat.NTRIPLES.equals(rdfFormat) || RDFFormat.NQUADS.equals(rdfFormat)) { return super.isSplitable(context, filename); } return false; }
/** * Constructor for super-classes to specify which * {@link RDFFormat} they support. * * @param format The {@link RDFFormat} that this instance supports. */ public RioRDFNonPrefixDocumentFormat(RDFFormat format) { this.format = format; formatName = this.format.getName(); }