Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added modelstreamingoutput to create a streming response from a RDF m…
…odel
  • Loading branch information
fasseg committed May 17, 2013
1 parent dd050b8 commit ff1807e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
Expand Up @@ -39,7 +39,7 @@
import org.fcrepo.http.RDFMediaType;
import org.fcrepo.jaxb.search.FieldSearchResult;
import org.fcrepo.jaxb.search.ObjectFields;
import org.fcrepo.provider.GraphStreamingOutput;
import org.fcrepo.provider.ModelStreamingOutput;
import org.fcrepo.provider.VelocityViewer;
import org.fcrepo.utils.FedoraJcrTypes;
import org.slf4j.Logger;
Expand Down Expand Up @@ -113,9 +113,8 @@ public Response searchSubmitRdf(@FormParam("terms") final String terms,
store.addGraph(objResource.asNode(),fo.getGraphStore(new HttpGraphSubjects(FedoraNodes.class, uriInfo)).getDefaultGraph());
}

/* prepare the model for out put by using a GraphStore */
final GraphStreamingOutput graphOut = new GraphStreamingOutput(store, bestPossibleResponse.getMediaType());
return Response.ok(graphOut).build();
/* prepare the model for output by using a GraphStore */
return Response.ok(new ModelStreamingOutput(model, bestPossibleResponse.getMediaType())).build();
}finally{
session.logout();
}
Expand Down
@@ -0,0 +1,37 @@
/**
*
*/
package org.fcrepo.provider;

import java.io.IOException;
import java.io.OutputStream;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.StreamingOutput;

import org.apache.jena.riot.WebContent;

import com.hp.hpl.jena.rdf.model.Model;


/**
* @author frank asseg
*
*/
public class ModelStreamingOutput implements StreamingOutput{
private final Model model;
private final String contentType;

public ModelStreamingOutput(final Model model,final MediaType mediaType) {
super();
this.model = model;
this.contentType = WebContent.contentTypeToLang(mediaType.toString()).getName().toUpperCase();
}

@Override
public void write(OutputStream output) throws IOException,
WebApplicationException {
this.model.write(output, this.contentType);
}
}

0 comments on commit ff1807e

Please sign in to comment.