1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.neo4j.server.rest.repr;
21
22 import javax.ws.rs.WebApplicationException;
23 import javax.ws.rs.core.Response;
24 import javax.ws.rs.core.Response.Status;
25
26 import org.neo4j.server.database.AbstractInjectableProvider;
27
28 import com.sun.jersey.api.core.HttpContext;
29
30 public final class OutputFormatProvider extends AbstractInjectableProvider<OutputFormat>
31 {
32 private final RepresentationFormatRepository repository;
33
34 public OutputFormatProvider( RepresentationFormatRepository repository )
35 {
36 super( OutputFormat.class );
37 this.repository = repository;
38 }
39
40 @Override
41 public OutputFormat getValue( HttpContext context )
42 {
43 try
44 {
45 return repository.outputFormat( context.getRequest().getAcceptableMediaTypes(),
46 context.getRequest().getBaseUri() );
47 }
48 catch ( MediaTypeNotSupportedException e )
49 {
50 throw new WebApplicationException( Response.status( Status.NOT_ACCEPTABLE ).entity(
51 e.getMessage() ).build() );
52 }
53 }
54 }