Search in sources :

Example 41 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class SecuredModelImpl method remove.

/**
 * @sec.graph Update
 * @sec.triple Delete on every statement in statements.
 * @throws UpdateDeniedException
 * @throws DeleteDeniedException
 * @throws AuthenticationRequiredException if user is not authenticated and is
 *                                         required to be.
 */
@Override
public SecuredModel remove(final List<Statement> statements) throws UpdateDeniedException, DeleteDeniedException, AuthenticationRequiredException {
    checkUpdate();
    if (!canDelete(Triple.ANY)) {
        for (final Statement s : statements) {
            checkDelete(s);
        }
    }
    holder.getBaseItem().remove(statements);
    return holder.getSecuredItem();
}
Also used : ReifiedStatement(org.apache.jena.rdf.model.ReifiedStatement) SecuredReifiedStatement(org.apache.jena.permissions.model.SecuredReifiedStatement) Statement(org.apache.jena.rdf.model.Statement) SecuredStatement(org.apache.jena.permissions.model.SecuredStatement)

Example 42 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class SecuredModelImpl method remove.

/**
 * @sec.graph Update
 * @sec.triple Delete on every statement in baseModel.
 * @throws UpdateDeniedException
 * @throws DeleteDeniedException
 * @throws AuthenticationRequiredException if user is not authenticated and is
 *                                         required to be.
 */
@Override
public SecuredModel remove(final Model m) throws UpdateDeniedException, DeleteDeniedException, AuthenticationRequiredException {
    checkUpdate();
    if (!canDelete(Triple.ANY)) {
        final StmtIterator iter = m.listStatements();
        try {
            while (iter.hasNext()) {
                final Statement stmt = iter.next();
                checkDelete(stmt);
            }
        } finally {
            iter.close();
        }
    }
    holder.getBaseItem().remove(m);
    return holder.getSecuredItem();
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) ReifiedStatement(org.apache.jena.rdf.model.ReifiedStatement) SecuredReifiedStatement(org.apache.jena.permissions.model.SecuredReifiedStatement) Statement(org.apache.jena.rdf.model.Statement) SecuredStatement(org.apache.jena.permissions.model.SecuredStatement)

Example 43 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class ShaclTests method processEntries.

private static void processEntries(String file, Resource manifest, List<ShaclTestItem> testCases) {
    StmtIterator entriesStmts = manifest.listProperties(MF.entries);
    for (; entriesStmts.hasNext(); ) {
        Statement s = entriesStmts.nextStatement();
        processEntry(file, s.getResource(), testCases);
    }
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Statement(org.apache.jena.rdf.model.Statement)

Example 44 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class ShaclTests method manifest.

private static void manifest(String manifestFile, List<String> manifests, List<ShaclTestItem> testCases) {
    if (manifests.contains(manifestFile))
        return;
    manifests.add(manifestFile);
    // System.err.println("Load: "+manifestFile);
    Model model = RDFDataMgr.loadModel(manifestFile);
    List<String> includedFiles = new ArrayList<>();
    StmtIterator manifestStmts = model.listStatements(null, RDF.type, MF.Manifest);
    for (; manifestStmts.hasNext(); ) {
        Statement stmt = manifestStmts.next();
        Resource manifest = stmt.getSubject();
        parseIncludes(manifest, manifests, testCases);
        processEntries(manifestFile, manifest, testCases);
    }
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) ArrayList(java.util.ArrayList) Resource(org.apache.jena.rdf.model.Resource)

Example 45 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class DefineAnalyzersAssembler method open.

public static boolean open(Assembler a, Resource list) {
    Resource current = list;
    boolean isMultilingualSupport = false;
    while (current != null && !current.equals(RDF.nil)) {
        Statement firstStmt = current.getProperty(RDF.first);
        if (firstStmt == null) {
            throw new TextIndexException("parameter list not well formed: " + current);
        }
        RDFNode first = firstStmt.getObject();
        if (!first.isResource()) {
            throw new TextIndexException("parameter specification must be an anon resource : " + first);
        }
        // process the current list element to add an analyzer
        Resource adding = (Resource) first;
        if (adding.hasProperty(TextVocab.pAnalyzer)) {
            Statement analyzerStmt = adding.getProperty(TextVocab.pAnalyzer);
            RDFNode analyzerNode = analyzerStmt.getObject();
            if (!analyzerNode.isResource()) {
                throw new TextIndexException("addAnalyzers text:analyzer must be an analyzer spec resource: " + analyzerNode);
            }
            // calls GenericAnalyzerAssembler
            Analyzer analyzer = (Analyzer) a.open((Resource) analyzerNode);
            if (adding.hasProperty(TextVocab.pDefAnalyzer)) {
                Statement defStmt = adding.getProperty(TextVocab.pDefAnalyzer);
                Resource id = defStmt.getResource();
                if (id.getURI() != null) {
                    Util.defineAnalyzer(id, analyzer);
                } else {
                    throw new TextIndexException("addAnalyzers text:defineAnalyzer property must be a uri resource: " + adding);
                }
            }
            if (adding.hasProperty(TextVocab.pAddLang)) {
                Statement langStmt = adding.getProperty(TextVocab.pAddLang);
                String langCode = langStmt.getString();
                if (StringUtils.isNotBlank(langCode)) {
                    Util.addAnalyzer(langCode, analyzer);
                    isMultilingualSupport = true;
                    if (adding.hasProperty(TextVocab.pSearchFor)) {
                        Statement searchForStmt = adding.getProperty(TextVocab.pSearchFor);
                        List<String> tags = getStringList(searchForStmt, "text:searchFor");
                        Util.addSearchForTags(langCode, tags);
                    }
                    if (adding.hasProperty(TextVocab.pAuxIndex)) {
                        Statement auxIndexStmt = adding.getProperty(TextVocab.pAuxIndex);
                        List<String> tags = getStringList(auxIndexStmt, "text:auxIndex");
                        Util.addAuxIndexes(langCode, tags);
                        log.trace("addAuxIndexes for {} with tags: {}", langCode, tags);
                    }
                    if (adding.hasProperty(TextVocab.pIndexAnalyzer)) {
                        Statement indexStmt = adding.getProperty(TextVocab.pIndexAnalyzer);
                        Resource key = indexStmt.getResource();
                        Analyzer indexer = Util.getDefinedAnalyzer(key);
                        Util.addIndexAnalyzer(langCode, indexer);
                        log.trace("addIndexAnalyzer lang: {} with analyzer: {}", langCode, indexer);
                    }
                } else {
                    throw new TextIndexException("text:addLang property must be a non-blank string: " + adding);
                }
            }
        }
        Statement restStmt = current.getProperty(RDF.rest);
        if (restStmt == null) {
            throw new TextIndexException("parameter list not terminated by rdf:nil");
        }
        RDFNode rest = restStmt.getObject();
        if (!rest.isResource()) {
            throw new TextIndexException("parameter list node is not a resource : " + rest);
        }
        current = (Resource) rest;
    }
    Util.finishCaching();
    return isMultilingualSupport;
}
Also used : TextIndexException(org.apache.jena.query.text.TextIndexException) Statement(org.apache.jena.rdf.model.Statement) Resource(org.apache.jena.rdf.model.Resource) Analyzer(org.apache.lucene.analysis.Analyzer) RDFNode(org.apache.jena.rdf.model.RDFNode)

Aggregations

Statement (org.apache.jena.rdf.model.Statement)141 Model (org.apache.jena.rdf.model.Model)56 Resource (org.apache.jena.rdf.model.Resource)46 StmtIterator (org.apache.jena.rdf.model.StmtIterator)46 Test (org.junit.Test)39 RDFNode (org.apache.jena.rdf.model.RDFNode)29 Dataset (org.apache.jena.query.Dataset)28 ArrayList (java.util.ArrayList)25 Property (org.apache.jena.rdf.model.Property)18 ReifiedStatement (org.apache.jena.rdf.model.ReifiedStatement)17 Triple (org.apache.jena.graph.Triple)16 WonMessageValidator (won.protocol.validation.WonMessageValidator)14 TextIndexException (org.apache.jena.query.text.TextIndexException)12 Ignore (org.junit.Ignore)10 ReadDeniedException (org.apache.jena.shared.ReadDeniedException)8 Iterator (java.util.Iterator)7 SecuredReifiedStatement (org.apache.jena.permissions.model.SecuredReifiedStatement)7 SecuredStatement (org.apache.jena.permissions.model.SecuredStatement)7 Literal (org.apache.jena.rdf.model.Literal)7 SecuredPrefixMappingTest (org.apache.jena.permissions.graph.SecuredPrefixMappingTest)6