use of org.openrdf.model.Statement in project qi4j-sdk by Qi4j.
the class EntitySerializerTest method testEntitySerializer.
@Test
public void testEntitySerializer() throws RDFHandlerException {
EntityReference entityReference = new EntityReference("test2");
EntityState entityState = entityStore.newUnitOfWork(UsecaseBuilder.newUsecase("Test"), module, System.currentTimeMillis()).entityStateOf(entityReference);
Iterable<Statement> graph = serializer.serialize(entityState);
String[] prefixes = new String[] { "rdf", "dc", " vc" };
String[] namespaces = new String[] { Rdfs.RDF, DcRdf.NAMESPACE, "http://www.w3.org/2001/vcard-rdf/3.0#" };
new RdfXmlSerializer().serialize(graph, new PrintWriter(System.out), prefixes, namespaces);
}
use of org.openrdf.model.Statement in project qi4j-sdk by Qi4j.
the class EntityTypeSerializerTest method testEntityTypeSerializer.
@Test
public void testEntityTypeSerializer() throws RDFHandlerException {
EntityDescriptor entityDescriptor = module.entityDescriptor(TestEntity.class.getName());
Iterable<Statement> graph = serializer.serialize(entityDescriptor);
String[] prefixes = new String[] { "rdf", "dc", " vc", "qi4j" };
String[] namespaces = new String[] { Rdfs.RDF, DcRdf.NAMESPACE, "http://www.w3.org/2001/vcard-rdf/3.0#", Qi4jEntityType.NAMESPACE };
new RdfXmlSerializer().serialize(graph, new PrintWriter(System.out), prefixes, namespaces);
}
use of org.openrdf.model.Statement in project qi4j-sdk by Qi4j.
the class EntityResource method representRdfXml.
private Representation representRdfXml(final EntityState entity) throws ResourceException {
Representation representation = new WriterRepresentation(MediaType.APPLICATION_RDF_XML) {
@Override
public void write(Writer writer) throws IOException {
try {
Iterable<Statement> statements = entitySerializer.serialize(entity);
new RdfXmlSerializer().serialize(statements, writer);
} catch (RDFHandlerException e) {
throw new IOException(e);
}
}
};
representation.setCharacterSet(CharacterSet.UTF_8);
return representation;
}
use of org.openrdf.model.Statement in project backstage by zepheira.
the class Database method internalBuildPropertyRecords.
private void internalBuildPropertyRecords(SailConnection sc) {
_propertyRecords = new LinkedList<PropertyRecord>();
_propertyIDToRecord = new HashMap<String, PropertyRecord>();
CloseableIteration<? extends Statement, SailException> i;
try {
i = sc.getStatements(null, null, null, true);
} catch (SailException e) {
_logger.error("Failed to get all statements in order to get property records", e);
return;
}
Set<URI> predicates = new HashSet<URI>();
try {
while (i.hasNext()) {
Statement s = i.next();
predicates.add(s.getPredicate());
}
} catch (SailException e) {
_logger.warn("Failed to iterate through statements", e);
} finally {
try {
i.close();
} catch (SailException e) {
_logger.warn("Failed to close statement iterator", e);
}
}
for (URI predicate : predicates) {
PropertyRecord r = createPropertyRecord(predicate, sc);
if (r != null) {
_propertyRecords.add(r);
_propertyIDToRecord.put(r.id, r);
}
}
}
use of org.openrdf.model.Statement in project backstage by zepheira.
the class Database method createPropertyRecord.
private PropertyRecord createPropertyRecord(URI predicate, SailConnection sc) {
String id = getPropertyId(predicate, sc);
String label = SailUtilities.getStringObject(sc, predicate, RDFS.LABEL, id);
String valueType = SailUtilities.getStringObject(sc, predicate, ExhibitOntology.VALUE_TYPE, "text");
Properties properties = new Properties();
CloseableIteration<? extends Statement, SailException> i = null;
try {
i = sc.getStatements(predicate, null, null, true);
} catch (SailException e) {
_logger.error("Failed to get all statements in order to get property record", e);
return null;
}
if (i != null) {
try {
while (i.hasNext()) {
Statement s = i.next();
URI p = s.getPredicate();
Value o = s.getObject();
if (!p.equals(RDFS.LABEL) && !p.equals(ExhibitOntology.ID) && !p.equals(ExhibitOntology.VALUE_TYPE)) {
properties.put(p.getLocalName(), SailUtilities.valueToString(o));
}
}
} catch (SailException e) {
_logger.warn("Failed to iterate through statements", e);
} finally {
try {
i.close();
} catch (SailException e) {
_logger.warn("Failed to close statement iterator", e);
}
}
}
return new PropertyRecord(predicate, id, label, valueType, properties);
}
Aggregations