1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.rest.delivery.jcr; |
35 |
|
|
36 |
|
import java.io.IOException; |
37 |
|
import java.io.OutputStream; |
38 |
|
import java.lang.annotation.Annotation; |
39 |
|
import java.lang.reflect.Type; |
40 |
|
|
41 |
|
import javax.jcr.NodeIterator; |
42 |
|
import javax.json.Json; |
43 |
|
import javax.json.stream.JsonGenerator; |
44 |
|
import javax.ws.rs.Produces; |
45 |
|
import javax.ws.rs.WebApplicationException; |
46 |
|
import javax.ws.rs.core.Context; |
47 |
|
import javax.ws.rs.core.MediaType; |
48 |
|
import javax.ws.rs.core.MultivaluedMap; |
49 |
|
import javax.ws.rs.ext.MessageBodyWriter; |
50 |
|
import javax.ws.rs.ext.Provider; |
51 |
|
import javax.ws.rs.ext.Providers; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
@Provider |
58 |
|
@Produces({MediaType.APPLICATION_JSON}) |
|
|
| 62.5% |
Uncovered Elements: 6 (16) |
Complexity: 6 |
Complexity Density: 0.5 |
|
59 |
|
public class NodesResultWriter implements MessageBodyWriter<NodesResult> { |
60 |
|
|
61 |
|
@Context |
62 |
|
private Providers providers; |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
0 |
@Override... |
65 |
|
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { |
66 |
0 |
return NodesResult.class.isAssignableFrom(type); |
67 |
|
} |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
69 |
0 |
@Override... |
70 |
|
public long getSize(NodesResult nodeIterator, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { |
71 |
|
|
72 |
0 |
return -1; |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.33 |
|
75 |
2 |
@Override... |
76 |
|
public void writeTo(NodesResult nodesResult, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { |
77 |
|
|
78 |
2 |
MessageBodyWriter<NodeIterator> nodeIteratorWriter = providers.getMessageBodyWriter(NodeIterator.class, genericType, annotations, mediaType); |
79 |
2 |
NodeIterator nodeIterator = nodesResult.getResults(); |
80 |
|
|
81 |
2 |
try (JsonGenerator jsonGenerator = Json.createGenerator(entityStream)) { |
82 |
2 |
OutputStream wrappedEntityStream = new OutputStreamWrapper(entityStream, jsonGenerator); |
83 |
|
|
84 |
2 |
jsonGenerator.writeStartObject(); |
85 |
|
|
86 |
|
|
87 |
2 |
jsonGenerator.writeStartArray("results"); |
88 |
2 |
nodeIteratorWriter.writeTo(nodeIterator, type, genericType, annotations, mediaType, httpHeaders, wrappedEntityStream); |
89 |
2 |
jsonGenerator.writeEnd(); |
90 |
|
} |
91 |
|
} |
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
0 |
void setProviders(Providers providers) {... |
97 |
0 |
this.providers = providers; |
98 |
|
} |
99 |
|
} |