Search in sources :

Example 1 with RDFXMLWriter

use of org.openrdf.rio.rdfxml.RDFXMLWriter in project gocd by gocd.

the class SesameGraph method dump.

public void dump(Writer writer) {
    try {
        if (contextResource.length == 0) {
            RepositoryResult<org.openrdf.model.Resource> results = conn.getContextIDs();
            while (results.hasNext()) {
                org.openrdf.model.Resource context = results.next();
                writer.append("Dumping context:" + context + "\n");
                conn.export(new RDFXMLWriter(writer), context);
            }
            dumpTriplesNotInContext(writer);
        } else {
            for (int i = 0; i < contextResource.length; i++) {
                writer.append("Dumping context:" + contextResource[i].stringValue() + "\n");
                conn.export(new RDFXMLWriter(writer), contextResource);
            }
        }
    } catch (Exception e) {
        throw new ShineRuntimeException(e);
    }
}
Also used : ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) RDFXMLWriter(org.openrdf.rio.rdfxml.RDFXMLWriter) Resource(com.thoughtworks.studios.shine.semweb.Resource) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) RepositoryException(org.openrdf.repository.RepositoryException) TupleQueryResultHandlerException(org.openrdf.query.TupleQueryResultHandlerException) MoreThanOneResultFoundException(com.thoughtworks.studios.shine.semweb.MoreThanOneResultFoundException) MalformedSPARQLException(com.thoughtworks.studios.shine.semweb.MalformedSPARQLException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) OpenRDFException(org.openrdf.OpenRDFException) NoSuchElementException(java.util.NoSuchElementException) MalformedQueryException(org.openrdf.query.MalformedQueryException) RDFHandlerException(org.openrdf.rio.RDFHandlerException) IOException(java.io.IOException) UnsupportedSPARQLStatementException(com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException)

Example 2 with RDFXMLWriter

use of org.openrdf.rio.rdfxml.RDFXMLWriter in project gocd by gocd.

the class SesameGraph method dumpTriplesNotInContext.

private void dumpTriplesNotInContext(Writer writer) {
    try {
        writer.append("Statements not in any context: \n");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    RDFXMLWriter xmlWriter = new RDFXMLWriter(writer);
    xmlWriter.startRDF();
    try {
        RepositoryResult<Statement> result = conn.getStatements(null, null, null, false);
        while (result.hasNext()) {
            Statement statement = result.next();
            if (statement.getContext() == null) {
                xmlWriter.handleStatement(statement);
            }
        }
    } catch (RepositoryException | RDFHandlerException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            xmlWriter.endRDF();
        } catch (RDFHandlerException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) RDFHandlerException(org.openrdf.rio.RDFHandlerException) RDFXMLWriter(org.openrdf.rio.rdfxml.RDFXMLWriter) Statement(org.openrdf.model.Statement) RepositoryException(org.openrdf.repository.RepositoryException) IOException(java.io.IOException)

Aggregations

ShineRuntimeException (com.thoughtworks.studios.shine.ShineRuntimeException)2 IOException (java.io.IOException)2 RepositoryException (org.openrdf.repository.RepositoryException)2 RDFHandlerException (org.openrdf.rio.RDFHandlerException)2 RDFXMLWriter (org.openrdf.rio.rdfxml.RDFXMLWriter)2 MalformedSPARQLException (com.thoughtworks.studios.shine.semweb.MalformedSPARQLException)1 MoreThanOneResultFoundException (com.thoughtworks.studios.shine.semweb.MoreThanOneResultFoundException)1 Resource (com.thoughtworks.studios.shine.semweb.Resource)1 UnsupportedSPARQLStatementException (com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException)1 NoSuchElementException (java.util.NoSuchElementException)1 OpenRDFException (org.openrdf.OpenRDFException)1 Statement (org.openrdf.model.Statement)1 MalformedQueryException (org.openrdf.query.MalformedQueryException)1 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)1 TupleQueryResultHandlerException (org.openrdf.query.TupleQueryResultHandlerException)1