/** * Specifies the mime type of the content and returns the handle * as a fluent convenience. * @param mimetype the mime type of the content * @return this handle */ public DOMHandle withMimetype(String mimetype) { setMimetype(mimetype); return this; }
/** * Specifies the mime type of the content and returns the handle * as a fluent convenience. * @param mimetype the mime type of the content * @return this handle */ public DOMHandle withMimetype(String mimetype) { setMimetype(mimetype); return this; }
@Test public void testSPARQLWithBindings() throws Exception { SPARQLQueryDefinition qdef3 = smgr.newQueryDefinition("construct { ?s ?p ?o } where { <subjectExample0> ?p ?o } "); qdef3.setIncludeDefaultRulesets(false); qdef3.setCollections(graphUri); StringHandle results1 = smgr.executeConstruct(qdef3, new StringHandle()); SPARQLQueryDefinition qdef4 = smgr.newQueryDefinition("select ?s ?p ?o { ?s ?p ?o . filter (?s = ?b) }"); qdef4.setCollections(graphUri); SPARQLBindings bindings = qdef4.getBindings(); bindings.bind("b", "http://example.org/s1"); qdef4.setBindings(bindings); // or use a builder qdef4 = qdef4.withBinding("c", "http://example.org/o2").withBinding("d", "http://example.org/o3"); DOMHandle handle = new DOMHandle(); handle.setMimetype(SPARQLMimeTypes.SPARQL_XML); Document jsonResults2 = smgr.executeSelect(qdef4, handle).get(); NodeList results = jsonResults2.getDocumentElement().getLastChild().getChildNodes(); // the number of children of the element "bindings" int numResults2 = results.getLength(); // because we said 'filter (?s = ?b)' we should only get one result assertEquals(1, numResults2); Node s = results.item(0).getChildNodes().item(0); Node o = results.item(0).getChildNodes().item(1); Node p = results.item(0).getChildNodes().item(2); assertEquals("http://example.org/s1", s.getTextContent()); assertEquals("http://example.org/p1", o.getTextContent()); assertEquals("http://example.org/o1", p.getTextContent()); }