Search in sources :

Example 1 with RdfXmlSerializer

use of org.qi4j.library.rdf.serializer.RdfXmlSerializer 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);
}
Also used : Statement(org.openrdf.model.Statement) RdfXmlSerializer(org.qi4j.library.rdf.serializer.RdfXmlSerializer) EntityReference(org.qi4j.api.entity.EntityReference) EntityState(org.qi4j.spi.entity.EntityState) PrintWriter(java.io.PrintWriter) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 2 with RdfXmlSerializer

use of org.qi4j.library.rdf.serializer.RdfXmlSerializer 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);
}
Also used : EntityDescriptor(org.qi4j.api.entity.EntityDescriptor) Statement(org.openrdf.model.Statement) RdfXmlSerializer(org.qi4j.library.rdf.serializer.RdfXmlSerializer) PrintWriter(java.io.PrintWriter) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 3 with RdfXmlSerializer

use of org.qi4j.library.rdf.serializer.RdfXmlSerializer 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;
}
Also used : RDFHandlerException(org.openrdf.rio.RDFHandlerException) WriterRepresentation(org.restlet.representation.WriterRepresentation) Statement(org.openrdf.model.Statement) RdfXmlSerializer(org.qi4j.library.rdf.serializer.RdfXmlSerializer) EmptyRepresentation(org.restlet.representation.EmptyRepresentation) StringRepresentation(org.restlet.representation.StringRepresentation) WriterRepresentation(org.restlet.representation.WriterRepresentation) Representation(org.restlet.representation.Representation) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer)

Aggregations

PrintWriter (java.io.PrintWriter)3 Statement (org.openrdf.model.Statement)3 RdfXmlSerializer (org.qi4j.library.rdf.serializer.RdfXmlSerializer)3 Test (org.junit.Test)2 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)2 IOException (java.io.IOException)1 Writer (java.io.Writer)1 RDFHandlerException (org.openrdf.rio.RDFHandlerException)1 EntityDescriptor (org.qi4j.api.entity.EntityDescriptor)1 EntityReference (org.qi4j.api.entity.EntityReference)1 EntityState (org.qi4j.spi.entity.EntityState)1 EmptyRepresentation (org.restlet.representation.EmptyRepresentation)1 Representation (org.restlet.representation.Representation)1 StringRepresentation (org.restlet.representation.StringRepresentation)1 WriterRepresentation (org.restlet.representation.WriterRepresentation)1