Skip to content

Commit

Permalink
merge the two export methods into one
Browse files Browse the repository at this point in the history
  • Loading branch information
armisael committed Nov 25, 2014
1 parent 9a8e494 commit 0a6c034
Showing 1 changed file with 23 additions and 37 deletions.
60 changes: 23 additions & 37 deletions src/org/deri/grefine/rdf/exporters/RdfExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@
import com.google.refine.model.Project;
import com.google.refine.model.Row;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RdfExporter implements WriterExporter{

private RDFFormat format;
private ApplicationContext applicationContext;

final static Logger logger = LoggerFactory.getLogger("RdfExporter");

public RdfExporter(ApplicationContext ctxt, RDFFormat f){
this.format = f;
this.applicationContext = ctxt;
Expand All @@ -48,51 +52,33 @@ public ApplicationContext getApplicationContext() {

public void export(Project project, Properties options, Engine engine,
OutputStream outputStream) throws IOException {
RdfSchema schema;
try{
schema = Util.getProjectSchema(applicationContext,project);
}catch(VocabularyIndexException ve){
throw new IOException("Unable to create index for RDF schema",ve);
}
Repository model = buildModel(project, engine, schema);
try{
RepositoryConnection con = model.getConnection();
try{
RDFWriter writer = Rio.createWriter(format, outputStream);
for(Vocabulary v:schema.getPrefixesMap().values()){
writer.handleNamespace(v.getName(), v.getUri());
}
con.export(writer);
}finally{
con.close();
}
}catch(RepositoryException ex){
throw new RuntimeException(ex);
}catch(RDFHandlerException ex){
throw new RuntimeException(ex);
}
export(project, options, engine, Rio.createWriter(format, outputStream));
}


public void export(Project project, Properties options, Engine engine,
Writer writer) throws IOException {
public void export(Project project, Properties options, Engine engine,
Writer writer) throws IOException {
export(project, options, engine, Rio.createWriter(format, writer));
}

private void export(Project project, Properties options, Engine engine,
RDFWriter writer) throws IOException {
RdfSchema schema;
try{
schema = Util.getProjectSchema(applicationContext,project);
}catch(VocabularyIndexException ve){
throw new IOException("Unable to create index for RDF schema",ve);
}
Repository model = buildModel(project, engine, schema);
try{
RepositoryConnection con = model.getConnection();
try{
RDFWriter w = Rio.createWriter(format, writer);
for(Vocabulary v:schema.getPrefixesMap().values()){
w.handleNamespace(v.getName(),v.getUri());
}
con.export(w);
}finally{
con.close();
for(Vocabulary v:schema.getPrefixesMap().values()){
writer.handleNamespace(v.getName(), v.getUri());
}

Repository model = buildModel(project, engine, schema);
RepositoryConnection con = model.getConnection();
try{
con.export(writer);
}finally{
con.close();
}
}catch(RepositoryException ex){
throw new RuntimeException(ex);
Expand Down

0 comments on commit 0a6c034

Please sign in to comment.