{
PrintWriter out = new PrintWriter( outputStream );
out.println( "<?xml version='1.0' encoding='UTF-8'?>" );
out.println( "<?xml-stylesheet type=\"text/xsl\" href=\"query/sparqlhtml.xsl\"?>" );
out.flush();
TupleQueryResultWriter qrWriter = new SPARQLResultsXMLWriter( new XMLWriter( outputStream )
{
@Override
public void startDocument()
throws IOException
{
// Ignore
}
} );
QueryResultUtil.report( queryResult, qrWriter );
}
catch( Exception e )
{
throw new IOException( e );
}
finally
{
try
{
conn.close();
}
catch( RepositoryException e )
{
// Ignore
}
}
}
};
}
else if( variant.getMediaType().equals( MediaType.APPLICATION_RDF_XML ) )
{
return new OutputRepresentation( MediaType.APPLICATION_XML )
{
@Override
public void write( OutputStream outputStream )
throws IOException
{
try
{
TupleQueryResultWriter qrWriter = new SPARQLResultsXMLWriter( new XMLWriter( outputStream ) );
QueryResultUtil.report( queryResult, qrWriter );
}
catch( Exception e )
{
throw new IOException( e );
}
finally
{
try
{
conn.close();
}
catch( RepositoryException e )
{
// Ignore
}
}
}
};
}
else if( variant.getMediaType().equals( RestApplication.APPLICATION_SPARQL_JSON ) )
{
return new OutputRepresentation( RestApplication.APPLICATION_SPARQL_JSON )
{
@Override
public void write( OutputStream outputStream )
throws IOException
{
try
{
TupleQueryResultWriter qrWriter = new SPARQLResultsJSONWriterFactory().getWriter( outputStream );
QueryResultUtil.report( queryResult, qrWriter );
}
catch( Exception e )
{
throw new IOException( e );