/** * Tries to match the extension of a file name against the list of RDF formats that can be written. * * @param fileName * A file name. * @return An BooleanQueryResultFormat object if a match was found, or {@link Optional#empty()} otherwise. * @see #getBooleanWriterFormatForFileName(String, BooleanQueryResultFormat) */ public static Optional<QueryResultFormat> getBooleanWriterFormatForFileName(String fileName) { return BooleanQueryResultWriterRegistry.getInstance().getFileFormatForFileName(fileName); }
/** * Tries to match a MIME type against the list of boolean query result formats that can be written. * * @param mimeType * A MIME type, e.g. "application/sparql-results+xml". * @return An BooleanQueryResultFormat object if a match was found, or {@link Optional#empty()} otherwise. * @see #getBooleanWriterFormatForMIMEType(String, BooleanQueryResultFormat) */ public static Optional<QueryResultFormat> getBooleanWriterFormatForMIMEType(String mimeType) { return BooleanQueryResultWriterRegistry.getInstance().getFileFormatForMIMEType(mimeType); }
/** * Convenience methods for creating BooleanQueryResultWriter objects. This method uses the registry * returned by {@link BooleanQueryResultWriterRegistry#getInstance()} to get a factory for the specified * format and uses this factory to create the appropriate writer. * * @return A BooleanQueryResultWriter matching the given format. * @throws UnsupportedQueryResultFormatException * If no writer is available for the specified boolean query result format. */ public static BooleanQueryResultWriter createBooleanWriter(QueryResultFormat format, OutputStream out) throws UnsupportedQueryResultFormatException { BooleanQueryResultWriterFactory factory = BooleanQueryResultWriterRegistry.getInstance().get( format).orElseThrow( () -> new UnsupportedQueryResultFormatException( "No writer factory available for boolean query result format " + format)); return factory.getWriter(out); }
registry = BooleanQueryResultWriterRegistry.getInstance(); view = BooleanQueryResultView.getInstance();
/** * Convenience methods for creating BooleanQueryResultWriter objects. This method uses the registry * returned by {@link BooleanQueryResultWriterRegistry#getInstance()} to get a factory for the specified * format and uses this factory to create the appropriate writer. * * @return A BooleanQueryResultWriter matching the given format. * @throws UnsupportedQueryResultFormatException * If no writer is available for the specified boolean query result format. */ public static BooleanQueryResultWriter createBooleanWriter(QueryResultFormat format, OutputStream out) throws UnsupportedQueryResultFormatException { BooleanQueryResultWriterFactory factory = BooleanQueryResultWriterRegistry.getInstance().get( format).orElseThrow( () -> new UnsupportedQueryResultFormatException( "No writer factory available for boolean query result format " + format)); return factory.getWriter(out); }
registry = BooleanQueryResultWriterRegistry.getInstance(); view = BooleanQueryResultView.getInstance();
/** * Convenience methods for creating QueryResultWriter objects. This method uses the registry returned by * {@link TupleQueryResultWriterRegistry#getInstance()} to get a factory for the specified format and uses * this factory to create the appropriate writer. * * @return A QueryResultWriter matching the given format. * @throws UnsupportedQueryResultFormatException * If no writer is available for the specified tuple query result format. */ public static QueryResultWriter createWriter(QueryResultFormat format, OutputStream out) throws UnsupportedQueryResultFormatException { Supplier<UnsupportedQueryResultFormatException> exception = () -> new UnsupportedQueryResultFormatException( "No writer factory available for query result format " + format); if (format instanceof TupleQueryResultFormat) { TupleQueryResultWriterFactory factory = TupleQueryResultWriterRegistry.getInstance().get( (TupleQueryResultFormat)format).orElseThrow(exception); return factory.getWriter(out); } else if (format instanceof BooleanQueryResultFormat) { BooleanQueryResultWriterFactory factory = BooleanQueryResultWriterRegistry.getInstance().get( (BooleanQueryResultFormat)format).orElseThrow(exception); return factory.getWriter(out); } throw exception.get(); }
/** * Tries to match the extension of a file name against the list of RDF formats that can be written. * * @param fileName * A file name. * @return An BooleanQueryResultFormat object if a match was found, or {@link Optional#empty()} otherwise. * @see #getBooleanWriterFormatForFileName(String, BooleanQueryResultFormat) */ public static Optional<QueryResultFormat> getBooleanWriterFormatForFileName(String fileName) { return BooleanQueryResultWriterRegistry.getInstance().getFileFormatForFileName(fileName); }
/** * Tries to match a MIME type against the list of boolean query result formats that can be written. * * @param mimeType * A MIME type, e.g. "application/sparql-results+xml". * @return An BooleanQueryResultFormat object if a match was found, or {@link Optional#empty()} otherwise. * @see #getBooleanWriterFormatForMIMEType(String, BooleanQueryResultFormat) */ public static Optional<QueryResultFormat> getBooleanWriterFormatForMIMEType(String mimeType) { return BooleanQueryResultWriterRegistry.getInstance().getFileFormatForMIMEType(mimeType); }
/** * Convenience methods for creating QueryResultWriter objects. This method uses the registry returned by * {@link TupleQueryResultWriterRegistry#getInstance()} to get a factory for the specified format and uses * this factory to create the appropriate writer. * * @return A QueryResultWriter matching the given format. * @throws UnsupportedQueryResultFormatException * If no writer is available for the specified tuple query result format. */ public static QueryResultWriter createWriter(QueryResultFormat format, OutputStream out) throws UnsupportedQueryResultFormatException { Supplier<UnsupportedQueryResultFormatException> exception = () -> new UnsupportedQueryResultFormatException( "No writer factory available for query result format " + format); if (format instanceof TupleQueryResultFormat) { TupleQueryResultWriterFactory factory = TupleQueryResultWriterRegistry.getInstance().get( (TupleQueryResultFormat)format).orElseThrow(exception); return factory.getWriter(out); } else if (format instanceof BooleanQueryResultFormat) { BooleanQueryResultWriterFactory factory = BooleanQueryResultWriterRegistry.getInstance().get( (BooleanQueryResultFormat)format).orElseThrow(exception); return factory.getWriter(out); } throw exception.get(); }
QueryResultFormat format = getFormat(BooleanQueryResultWriterRegistry.getInstance(), exchange.getRequestURI().getPath(), acceptedMimeTypes, BooleanQueryResultFormat.SPARQL, exchange.getResponseHeaders()); exchange.sendResponseHeaders(HTTP_OK_STATUS, 0); try (BufferedOutputStream response = new BufferedOutputStream(exchange.getResponseBody())) { BooleanQueryResultWriter w = BooleanQueryResultWriterRegistry.getInstance().get(format).get().getWriter(response); w.setWriterConfig(writerConfig); w.write(((BooleanQuery) query).evaluate());