Search in sources :

Example 26 with Literal

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);
}
Also used : AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) Literal(org.apache.jena.rdf.model.Literal) Resource(org.apache.jena.rdf.model.Resource) Model(org.apache.jena.rdf.model.Model)

Example 27 with Literal

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));
}
Also used : ItemHolder(org.apache.jena.permissions.impl.ItemHolder) SecuredItemInvoker(org.apache.jena.permissions.impl.SecuredItemInvoker) SecuredLiteral(org.apache.jena.permissions.model.SecuredLiteral) Literal(org.apache.jena.rdf.model.Literal) SecuredLiteral(org.apache.jena.permissions.model.SecuredLiteral)

Example 28 with Literal

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));
}
Also used : Literal(org.apache.jena.rdf.model.Literal) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Store(org.apache.jena.sdb.Store) Property(org.apache.jena.rdf.model.Property) Test(org.junit.Test)

Example 29 with Literal

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());
}
Also used : Literal(org.apache.jena.rdf.model.Literal) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 30 with Literal

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;
}
Also used : Query(org.apache.jena.query.Query) Node(org.apache.jena.graph.Node) Reader(java.io.Reader) StringReader(java.io.StringReader) LinkedList(java.util.LinkedList) QueryExecution(org.apache.jena.query.QueryExecution) QuerySolution(org.apache.jena.query.QuerySolution) Literal(org.apache.jena.rdf.model.Literal) Model(org.apache.jena.rdf.model.Model) StringReader(java.io.StringReader) ResultSet(org.apache.jena.query.ResultSet)

Aggregations

Literal (org.apache.jena.rdf.model.Literal)42 Resource (org.apache.jena.rdf.model.Resource)17 Test (org.junit.Test)15 Model (org.apache.jena.rdf.model.Model)12 Property (org.apache.jena.rdf.model.Property)9 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)7 RDFNode (org.apache.jena.rdf.model.RDFNode)7 Node (org.apache.jena.graph.Node)6 HashSet (java.util.HashSet)4 QuerySolution (org.apache.jena.query.QuerySolution)4 Store (org.apache.jena.sdb.Store)3 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)2 SecuredLiteral (org.apache.jena.permissions.model.SecuredLiteral)2 Dataset (org.apache.jena.query.Dataset)2 Query (org.apache.jena.query.Query)2 QueryExecution (org.apache.jena.query.QueryExecution)2 ResultSet (org.apache.jena.query.ResultSet)2