// assume the subject is the object as denoted by the pid
subject = PID.toURI(pid);
}
try {
RelationshipTuple[] tuples = m_management.getRelationships(context, subject, predicate);
TripleIterator it = new TupleArrayTripleIterator(new ArrayList<RelationshipTuple>(Arrays.asList(tuples)));
ByteArrayOutputStream out = new ByteArrayOutputStream();
format = format.toLowerCase();
RDFFormat outputFormat;
MediaType mediaType;
if (format.equalsIgnoreCase("xml") || format.equals("rdf/xml")) {
outputFormat = RDFFormat.RDF_XML;
mediaType = new MediaType("application", "rdf+xml");
} else if (format.equals("n-triples") || format.equals("ntriples")) {
outputFormat = RDFFormat.N_TRIPLES;
mediaType = MediaType.TEXT_PLAIN_TYPE;
} else if (format.equals("turtle")) {
outputFormat = RDFFormat.TURTLE;
mediaType = new MediaType("application", "x-turtle");
} else if (format.equals("sparql")) {
outputFormat = RDFFormat.SPARQL;
mediaType = new MediaType("application", "sparql-results+xml");
} else {
throw new IllegalArgumentException("unknown format: " + format);
}
it.toStream(out, outputFormat);
return Response.ok(out.toString("UTF-8"), mediaType).build();
} catch (ServerException e) {
return handleException(e, flash);
} catch (TrippiException e) {
return handleException(e, flash);