Java源码示例:org.openrdf.query.resultio.TupleQueryResultParserRegistry
示例1
/**
* Create an LDPathWrapper Object
* @param backend the linkeddata backend
*/
public LDPathWrapper(final LDCacheBackend backend) {
// Register the Sesame RDF Parsers manually
// TODO: use the OSGi service registry as described in:
// http://blog.osgi.org/2013/02/javautilserviceloader-in-osgi.html
RDFParserRegistry.getInstance().add(new RDFXMLParserFactory());
RDFParserRegistry.getInstance().add(new NTriplesParserFactory());
RDFParserRegistry.getInstance().add(new TurtleParserFactory());
RDFParserRegistry.getInstance().add(new N3ParserFactory());
RDFParserRegistry.getInstance().add(new SesameJSONLDParserFactory());
RDFParserRegistry.getInstance().add(new RDFJSONParserFactory());
RDFParserRegistry.getInstance().add(new SesameRDFaParserFactory());
RDFParserRegistry.getInstance().add(new TriGParserFactory());
BooleanQueryResultParserRegistry.getInstance().add(new SPARQLBooleanXMLParserFactory());
TupleQueryResultParserRegistry.getInstance().add(new SPARQLResultsXMLParserFactory());
ldpath = new LDPath<Value>(backend);
}
示例2
/**
* test get Graph Query.
* @throws Exception The test would fails if Exception occurs
*/
@Test
public void testGraphQuery() throws Exception {
//insert some statments first
for (final String tripleAsString : _data) {
final Statement triple = parseNX(tripleAsString).iterator().next();
TRIPLE_STORE.addData(triple);
}
//test Graph Query
String queryString = "SELECT ?x ?y WHERE { ?x ?p ?y } ";
String uri = BASE_URI + Protocol.REPOSITORIES + "/" + REPO_ID;
File tmp = WebTestUtils.tmpFile();
final ServletOutputStream servletOutputStream = new StubServletOutputStream(tmp);
final HttpServletRequest request = mockHttpRequest(uri, METHOD_POST);
when(request.getContentType()).thenReturn(MIMETYPE_WWW_FORM);
when(request.getParameter(Protocol.QUERY_LANGUAGE_PARAM_NAME)).thenReturn(QueryLanguage.SPARQL.toString());
when(request.getParameter(Protocol.QUERY_PARAM_NAME)).thenReturn(queryString);
when(request.getParameter(Protocol.ACCEPT_PARAM_NAME)).thenReturn("application/x-binary-rdf-results-table");
Vector<String> vec = new Vector<String>();
when(request.getParameterNames()).thenReturn(vec.elements());
when(request.getCharacterEncoding()).thenReturn(UTF_8);
final HttpServletResponse response = mock(HttpServletResponse.class);
when(response.getOutputStream()).thenReturn(servletOutputStream);
_classUnderTest.service(request, response);
Set<TupleQueryResultFormat> tqrFormats = TupleQueryResultParserRegistry.getInstance().getKeys();
TupleQueryResultFormat format = TupleQueryResultFormat.matchMIMEType("application/x-binary-rdf-results-table", tqrFormats);
TupleQueryResultParser parser = QueryResultIO.createParser(format, valueFactory);
FileInputStream in = new FileInputStream(tmp);
BackgroundTupleResult tRes = new BackgroundTupleResult(parser, in, null);
parser.setQueryResultHandler(tRes);
parser.parseQueryResult(in);
assertTrue(tRes.hasNext());
verify(response).setStatus(HttpServletResponse.SC_OK);
servletOutputStream.close();
}
示例3
/**
* Return an accept header which establishes a preference pattern for
* solution set data. The accept header will not include any formats for
* which we can not discover a parser.
* <p>
* Note: You CAN NOT just combine the accept headers for boolean results and
* solution sets together because the boolean format overlaps the solution
* set format (they are both [application/sparql-results+xml] so putting
* them together blurs the quality annotations.
*/
public static String getDefaultSolutionsAcceptHeader() {
// Copy into a Set.
final Set<TupleQueryResultFormat> values = new LinkedHashSet<TupleQueryResultFormat>(
TupleQueryResultFormat.values());
final TupleQueryResultParserRegistry registry = TupleQueryResultParserRegistry
.getInstance();
final Iterator<TupleQueryResultFormat> itr = values.iterator();
while (itr.hasNext()) {
final TupleQueryResultFormat format = itr.next();
if (registry.get(format) == null) {
/*
* Remove any format for which there is no registered parser.
*
* Note: For example, the JSON parser does not exist for openrdf
* 2.6.3.
*/
itr.remove();
}
}
final List<String> list2 = AcceptHeaderFactory.getAcceptParams(values,
TupleQueryResultFormat.BINARY);
return toString(list2);
}