use of org.apache.jena.riot.Lang.TURTLE in project trellis by trellis-ldp.
the class WebAcService method generateDefaultRootAuthorizationsDataset.
static Dataset generateDefaultRootAuthorizationsDataset(final String resource) {
final Dataset dataset = rdf.createDataset();
final Model model = createDefaultModel();
try (final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)) {
if (is != null) {
LOGGER.debug("Using classpath resource for default root ACL: {}", resource);
RDFParser.source(is).lang(TURTLE).base(TRELLIS_DATA_PREFIX).parse(model);
} else {
LOGGER.debug("Using external resource for default root ACL: {}", resource);
RDFParser.source(resource).lang(TURTLE).base(TRELLIS_DATA_PREFIX).parse(model);
}
fromJena(model.getGraph()).stream().map(triple -> rdf.createQuad(Trellis.PreferAccessControl, triple.getSubject(), triple.getPredicate(), triple.getObject())).forEach(dataset::add);
} catch (final IOException | RiotException ex) {
LOGGER.warn("Couldn't initialize root ACL with {}, falling back to default: {}", resource, ex.getMessage());
} finally {
model.close();
}
// Fallback to manual creation
if (dataset.size() == 0) {
dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Read));
dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Write));
dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Control));
dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Append));
dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.agentClass, FOAF.Agent));
dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.default_, root));
dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.accessTo, root));
}
return dataset;
}
Aggregations