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 InputFormatProvider extends AbstractInjectableProvider<InputFormat>
31 {
32 private final RepresentationFormatRepository repository;
33
34 public InputFormatProvider( RepresentationFormatRepository repository )
35 {
36 super( InputFormat.class );
37 this.repository = repository;
38 }
39
40 @Override
41 public InputFormat getValue( HttpContext context )
42 {
43 try
44 {
45 return repository.inputFormat( context.getRequest().getMediaType() );
46 }
47 catch ( MediaTypeNotSupportedException e )
48 {
49 throw new WebApplicationException(
50 Response.status( Status.UNSUPPORTED_MEDIA_TYPE ).entity( e.getMessage() ).build() );
51 }
52 }
53 }