1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rest.internal.representations.comments; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.io.InputStream; |
24 |
|
import java.lang.annotation.Annotation; |
25 |
|
import java.lang.reflect.Type; |
26 |
|
|
27 |
|
import javax.inject.Named; |
28 |
|
import javax.inject.Singleton; |
29 |
|
import javax.ws.rs.Consumes; |
30 |
|
import javax.ws.rs.WebApplicationException; |
31 |
|
import javax.ws.rs.core.MediaType; |
32 |
|
import javax.ws.rs.core.MultivaluedMap; |
33 |
|
import javax.ws.rs.ext.Provider; |
34 |
|
|
35 |
|
import org.xwiki.component.annotation.Component; |
36 |
|
import org.xwiki.rest.internal.representations.TextPlainReader; |
37 |
|
import org.xwiki.rest.model.jaxb.Comment; |
38 |
|
import org.xwiki.rest.model.jaxb.ObjectFactory; |
39 |
|
|
40 |
|
|
41 |
|
@version |
42 |
|
|
43 |
|
@Component |
44 |
|
@Named("org.xwiki.rest.internal.representations.comments.TextPlainCommentReader") |
45 |
|
@Provider |
46 |
|
@Consumes(MediaType.TEXT_PLAIN) |
47 |
|
@Singleton |
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
48 |
|
public class TextPlainCommentReader extends TextPlainReader<Comment> |
49 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
21 |
@Override... |
51 |
|
public boolean isReadable(Class< ? > type, Type genericType, Annotation[] annotations, MediaType mediaType) |
52 |
|
{ |
53 |
21 |
return Comment.class.isAssignableFrom(type); |
54 |
|
} |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
56 |
1 |
@Override... |
57 |
|
public Comment readFrom(Class<Comment> type, Type genericType, Annotation[] annotations, MediaType mediaType, |
58 |
|
MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, |
59 |
|
WebApplicationException |
60 |
|
{ |
61 |
1 |
ObjectFactory objectFactory = new ObjectFactory(); |
62 |
1 |
Comment comment = objectFactory.createComment(); |
63 |
|
|
64 |
1 |
String text = getEntityAsString(entityStream); |
65 |
|
|
66 |
1 |
comment.setText(text); |
67 |
|
|
68 |
1 |
return comment; |
69 |
|
} |
70 |
|
|
71 |
|
} |