use of org.apache.jena.sparql.syntax.ElementTriplesBlock in project jena by apache.
the class ElementTransformSubst method transform.
@Override
public Element transform(ElementTriplesBlock el) {
ElementTriplesBlock etb = new ElementTriplesBlock();
boolean changed = false;
for (Triple t : el.getPattern()) {
Triple t2 = transform(t);
changed = changed || t != t2;
etb.addTriple(t2);
}
if (changed)
return etb;
return el;
}
use of org.apache.jena.sparql.syntax.ElementTriplesBlock in project jena by apache.
the class TestParameterizedSparqlString method test_param_string_injection_05.
@Test
public void test_param_string_injection_05() {
// This injection attempt results in a valid query but a failed
// injection
String str = "PREFIX : <http://example/>\nSELECT * WHERE { <s> <p> ?var2 . }";
ParameterizedSparqlString pss = new ParameterizedSparqlString(str);
pss.setLiteral("var2", "hello\" . ?s ?p ?o");
Query q = pss.asQuery();
Element el = q.getQueryPattern();
if (el instanceof ElementTriplesBlock) {
Assert.assertEquals(1, ((ElementTriplesBlock) q.getQueryPattern()).getPattern().size());
} else if (el instanceof ElementGroup) {
Assert.assertEquals(1, ((ElementGroup) el).getElements().size());
el = ((ElementGroup) el).getElements().get(0);
if (el instanceof ElementTriplesBlock) {
Assert.assertEquals(1, ((ElementTriplesBlock) el).getPattern().size());
}
}
}
use of org.apache.jena.sparql.syntax.ElementTriplesBlock in project jena by apache.
the class WhereClauseTest method testBindExprVar.
@ContractTest
public void testBindExprVar() {
Var v = Var.alloc("foo");
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addBind(new E_Random(), v);
assertContainsRegex(OPEN_CURLY + BIND + OPEN_PAREN + "rand\\(\\)" + SPACE + "AS" + SPACE + var("foo") + CLOSE_PAREN + CLOSE_CURLY, builder.buildString());
builder.setVar(v, NodeFactory.createURI("three"));
Query q = builder.build();
ElementGroup eg = (ElementGroup) q.getQueryPattern();
List<Element> lst = eg.getElements();
assertEquals("Should only be one element", 1, lst.size());
assertTrue("Should have an ElementTriplesBlock", lst.get(0) instanceof ElementTriplesBlock);
ElementTriplesBlock etb = (ElementTriplesBlock) lst.get(0);
assertTrue("ElementGroup should be empty", etb.isEmpty());
}
use of org.apache.jena.sparql.syntax.ElementTriplesBlock in project jena by apache.
the class UpdateEngineWorker method elementFromQuads.
protected Element elementFromQuads(List<Quad> quads) {
ElementGroup el = new ElementGroup();
ElementTriplesBlock x = new ElementTriplesBlock();
// Maybe empty??
el.addElement(x);
Node g = Quad.defaultGraphNodeGenerated;
for (Quad q : quads) {
if (q.getGraph() != g) {
g = q.getGraph();
x = new ElementTriplesBlock();
if (g == null || g == Quad.defaultGraphNodeGenerated)
el.addElement(x);
else {
ElementNamedGraph eng = new ElementNamedGraph(g, x);
el.addElement(eng);
}
}
x.addTriple(q.asTriple());
}
return el;
}
use of org.apache.jena.sparql.syntax.ElementTriplesBlock in project jena by apache.
the class WhereClauseTest method testBindStringVar.
@ContractTest
public void testBindStringVar() throws ParseException {
Var v = Var.alloc("foo");
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addBind("rand()", v);
assertContainsRegex(OPEN_CURLY + BIND + OPEN_PAREN + "rand\\(\\)" + SPACE + "AS" + SPACE + var("foo") + CLOSE_PAREN + CLOSE_CURLY, builder.buildString());
builder.setVar(v, NodeFactory.createURI("three"));
Query q = builder.build();
ElementGroup eg = (ElementGroup) q.getQueryPattern();
List<Element> lst = eg.getElements();
assertEquals("Should only be one element", 1, lst.size());
assertTrue("Should have an ElementTriplesBlock", lst.get(0) instanceof ElementTriplesBlock);
ElementTriplesBlock etb = (ElementTriplesBlock) lst.get(0);
assertTrue("ElementGroup should be empty", etb.isEmpty());
}
Aggregations