/** Checks if a {@link Resource} is a given type. **/ public static boolean isType(Resource resource, String type) { return resource.listProperties(RDF.type) .toList() .stream() .anyMatch(s -> s.getResource().getURI().equalsIgnoreCase(type)); }
private static List<Resource> getContainedResource(Model model, String url) { ImmutableList.Builder<Resource> results = new ImmutableList.Builder<>(); Resource self = model.getResource(url); self.listProperties(model.createProperty("http://www.w3.org/ns/ldp#contains")) .forEachRemaining(s-> results.add(s.getResource())); /*List<Statement> containedStatements = getProperties( self, "http://www.w3.org/ns/ldp#contains"); for (Statement s : containedStatements) { results.add(s.getResource()); }*/ return results.build(); }
private List<VCard> parseAddressBook(Resource selfResource, SolidUtilities utilities) throws IOException { String peopleUri = selfResource.getProperty(NAME_EMAIL_INDEX_PROPERTY).getResource().getURI(); Model peopleModel = utilities.getModel(peopleUri); List<VCard> vcards = new ArrayList<>(); ResIterator subjects = peopleModel.listSubjects(); while (subjects.hasNext()) { Resource subject = subjects.nextResource(); Model personModel = utilities.getModel(subject.getURI()); Resource personResource = SolidUtilities.getResource(subject.getURI(), personModel); if (personResource == null) { throw new IllegalStateException(subject.getURI() + " not found in " + subject.toString()); } vcards.add(parsePerson(personResource)); } return vcards; }
while (nameIterator.hasNext()) { Statement nameStatement = nameIterator.nextStatement(); Resource structuredNameResource = nameStatement.getResource(); StructuredName structuredName = new StructuredName(); if (structuredNameResource.hasProperty(VCARD4.family_name)) { Resource emailResource = emailStatement.getResource(); if (emailResource.isResource()) { Statement valueStatement = getValueStatement(emailResource); if (emailResource.hasProperty(RDF.type)) { emailResource.listProperties(RDF.type).forEachRemaining(typeProperty -> email.getTypes().add(EmailType.find(typeProperty.getResource().getLocalName()))); Resource telephoneResource = telephoneStatement.getResource(); if (telephoneResource.isResource()) { Statement valueStatement = getValueStatement(telephoneResource); telephoneResource.listProperties(RDF.type).forEachRemaining(typeProperty -> telephoneObject.getTypes().add( TelephoneType.find(typeProperty.getResource().getLocalName())));
@Override @Deprecated public SecuredResource getDefaultResource(final ResourceF f) throws ReadDeniedException, AuthenticationRequiredException { // getDefaultStatement() calls checkRead return SecuredResourceImpl.getInstance(getModel(), getDefaultStatement().getResource(f)); }
@Override @Deprecated public SecuredResource getResource(final ResourceF f) { return SecuredResourceImpl.getInstance(getModel(), holder.getBaseItem() .getResource(f)); }
private void addRulesFromURLs( Resource value ) { Iterator<Statement> that = getRuleSetURLStatements( value ); while (that.hasNext()) addRules( Rule.rulesFromURL( that.next().getResource().getURI() ) ); }
private List<Model> getSubModels( Assembler a, Resource root, Mode mode ) { List<Model> result = new ArrayList<>(); for (StmtIterator it = root.listProperties( JA.subModel ); it.hasNext();) result.add( a.openModel( it.nextStatement().getResource(), mode ) ); return result; }
private void addRulesFromURLs( Resource value ) { Iterator<Statement> that = getRuleSetURLStatements( value ); while (that.hasNext()) addRules( Rule.rulesFromURL( that.next().getResource().getURI() ) ); }
private List<Model> getSubModels( Assembler a, Resource root, Mode mode ) { List<Model> result = new ArrayList<>(); for (StmtIterator it = root.listProperties( JA.subModel ); it.hasNext();) result.add( a.openModel( it.nextStatement().getResource(), mode ) ); return result; }
private void incrementCurrent() { if (!endOfList()) { current = current.getRequiredProperty(RDF.rest).getResource() .as(RDFList.class); } }
@Override public Object open(Assembler a, Resource root, Mode mode) { if (root.hasProperty(TextVocab.pUseAnalyzer)) { Statement useStmt = root.getProperty(TextVocab.pUseAnalyzer); Resource key = useStmt.getResource(); return Util.getDefinedAnalyzer(key); } return null; }
@Override public void addedStatement( Statement added ) { if (added.getPredicate().equals( getProfile().IMPORTS() )) { getDocumentManager().loadImport( OntModelImpl.this, added.getResource().getURI() ); } }
@Override public void removedStatement( Statement removed ) { if (removed.getPredicate().equals( getProfile().IMPORTS() )) { getDocumentManager().unloadImport( OntModelImpl.this, removed.getResource().getURI() ); } } }
public void testGetResource() { Assert.assertEquals(r, model.createStatement(r, RDF.value, r) .getResource()); }
void initExpectedFromModel() { StmtIterator si = testID.listProperties(errorCodes); if (si.hasNext()) { expected = new HashSet<>(); while (si.hasNext()) { String uri = si.nextStatement().getResource().getURI(); String fieldName = uri.substring(uri.lastIndexOf('#') + 1); expected.add(new Integer(ParseException.errorCode(fieldName))); } } } void initExpected() {
public static String getAsStringValue(Resource r, Property p) { if ( !atmostOneProperty(r, p) ) throw new NotUniqueException(r, p) ; Statement s = r.getProperty(p) ; if ( s == null ) return null ; if ( s.getObject().isResource() ) return s.getResource().getURI() ; return s.getString() ; }
String create(Property p) { Resource file = testID.getRequiredProperty(p).getResource(); Resource t = file.getRequiredProperty(RDF.type).getResource(); if (ntriple.equals(t)) { return "\"" + file.getURI() + "\",false"; } else if (rdfxml.equals(t)) { return "\"" + file.getURI() + "\",true"; } else { return "Unrecognized file type: " + t; } } Model read(Property p) throws IOException {
protected RDFList getListRoot( final Model m ) { final Resource root = m.getResource(TestList.NS + "root"); Assert.assertNotNull("Root resource should not be null", root); final Resource listHead = root.getRequiredProperty( m.getProperty(TestList.NS + "p")).getResource(); final RDFList l = listHead.as(RDFList.class); Assert.assertNotNull("as(RDFList) should not return null for root", l); return l; }
public void testCreateStatementResource() { final Resource tv = model.createResource(); final Statement s = model.createStatement(r, p, tv); Assert.assertEquals(r, s.getSubject()); Assert.assertEquals(p, s.getPredicate()); Assert.assertEquals(tv, s.getResource()); }