use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class SecuredAssembler method open.
@Override
public Model open(Assembler a, Resource root, Mode mode) {
Resource rootModel = getUniqueResource(root, BASE_MODEL);
if (rootModel == null) {
throw new AssemblerException(root, String.format(NO_X_PROVIDED, BASE_MODEL, root));
}
Model baseModel = a.openModel(rootModel, Mode.ANY);
Literal modelName = getUniqueLiteral(root, JA.modelName);
if (modelName == null) {
throw new AssemblerException(root, String.format(NO_X_PROVIDED, JA.modelName, root));
}
Literal factoryName = getUniqueLiteral(root, EVALUATOR_FACTORY);
Resource evaluatorImpl = getUniqueResource(root, EVALUATOR_IMPL);
if (factoryName == null && evaluatorImpl == null) {
throw new AssemblerException(root, String.format("Either a %s or a %s must be provided for %s", EVALUATOR_FACTORY, EVALUATOR_IMPL, root));
}
if (factoryName != null && evaluatorImpl != null) {
throw new AssemblerException(root, String.format("May not specify both a %s and a %s for %s", EVALUATOR_FACTORY, EVALUATOR_IMPL, root));
}
SecurityEvaluator securityEvaluator = null;
if (factoryName != null) {
securityEvaluator = executeEvaluatorFactory(root, factoryName);
}
if (evaluatorImpl != null) {
securityEvaluator = getEvaluatorImpl(a, evaluatorImpl);
}
return Factory.getInstance(securityEvaluator, modelName.asLiteral().getString(), baseModel);
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class SecuredLiteralImpl method getInstance.
/**
* Get an instance of SecuredLiteral
*
* @param securedModel
* the item providing the security context.
* @param literal
* the literal to secure
* @return SecuredLiteral
*/
public static SecuredLiteral getInstance(final SecuredModel securedModel, final Literal literal) {
if (securedModel == null) {
throw new IllegalArgumentException("Secured securedModel may not be null");
}
if (literal == null) {
throw new IllegalArgumentException("literal may not be null");
}
// check that literal has a securedModel.
Literal goodLiteral = literal;
if (goodLiteral.getModel() == null) {
goodLiteral = securedModel.createTypedLiteral(literal.getLexicalForm(), literal.getDatatype());
}
final ItemHolder<Literal, SecuredLiteral> holder = new ItemHolder<>(goodLiteral);
final SecuredLiteralImpl checker = new SecuredLiteralImpl(securedModel, holder);
// one.
if (goodLiteral instanceof SecuredLiteral) {
if (checker.isEquivalent((SecuredLiteral) goodLiteral)) {
return (SecuredLiteral) goodLiteral;
}
}
return holder.setSecuredItem(new SecuredItemInvoker(literal.getClass(), checker));
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class TestAssembler method model_6.
@Test
public void model_6() {
Model assem = FileManager.get().loadModel(dir + "graph-assembler.ttl");
Resource xNamed = assem.getResource("http://example/test#graphNamed");
Store store = create(assem);
// Named graph: Check they are connected to the same place in the store
Model model2 = (Model) Assembler.general.open(xNamed);
Model model3 = (Model) Assembler.general.open(xNamed);
Resource s = model2.createResource();
Property p = model2.createProperty("http://example/p");
// Check two models connected to the same graph
Literal o2 = model2.createLiteral("xyz");
model2.add(s, p, o2);
assertTrue(model3.contains(s, p, o2));
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class TestDatasetWithLuceneStoredLiterals method testLiteralValueWithLanguage.
@Test
public void testLiteralValueWithLanguage() {
// test capturing of the literal value in a variable, with language tag
final String testName = "testLiteralValueWithLanguage";
final String turtle = StrUtils.strjoinNL(TURTLE_PROLOG, "<" + RESOURCE_BASE + testName + ">", " rdfs:label 'English language text'@en", ".");
String queryString = StrUtils.strjoinNL(QUERY_PROLOG, "SELECT ?s ?literal", "WHERE {", " (?s ?score ?literal) text:query ('text') .", "}");
Set<String> expectedURIs = new HashSet<>();
expectedURIs.addAll(Arrays.asList(RESOURCE_BASE + testName));
Map<String, Literal> literals = doTestSearchWithLiterals(turtle, queryString, expectedURIs);
Literal value = literals.get(RESOURCE_BASE + testName);
assertNotNull(value);
assertEquals(NodeFactory.createLiteral("English language text", "en"), value.asNode());
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class TestDatasetWithLuceneStoredLiterals method doTestSearchWithLiteralsMultiple.
protected List<Node> doTestSearchWithLiteralsMultiple(String turtle, String queryString, String expectedEntityURI) {
List<Node> literals = new LinkedList<>();
Model model = dataset.getDefaultModel();
Reader reader = new StringReader(turtle);
dataset.begin(ReadWrite.WRITE);
model.read(reader, "", "TURTLE");
dataset.commit();
Query query = QueryFactory.create(queryString);
dataset.begin(ReadWrite.READ);
try (QueryExecution qexec = QueryExecutionFactory.create(query, dataset)) {
ResultSet results = qexec.execSelect();
int count;
for (count = 0; results.hasNext(); count++) {
QuerySolution soln = results.nextSolution();
String entityURI = soln.getResource("s").getURI();
assertEquals(expectedEntityURI, entityURI);
Literal literal = soln.getLiteral("literal");
assertNotNull(literal);
literals.add(literal.asNode());
}
} finally {
dataset.end();
}
return literals;
}
Aggregations