50
|
1 /**
|
|
2 *
|
|
3 */
|
|
4 package de.mpiwg.itgroup.annotations.restlet.annotations_ui;
|
|
5
|
|
6 import java.util.List;
|
|
7
|
|
8 import org.apache.log4j.Logger;
|
|
9 import org.restlet.data.MediaType;
|
|
10 import org.restlet.data.Reference;
|
|
11 import org.restlet.representation.Representation;
|
|
12 import org.restlet.representation.StringRepresentation;
|
|
13 import org.restlet.resource.Get;
|
|
14 import org.restlet.resource.ResourceException;
|
|
15 import org.restlet.resource.ServerResource;
|
|
16
|
|
17 import de.mpiwg.itgroup.annotations.Annotation;
|
|
18 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
|
|
19 import de.mpiwg.itgroup.annotations.restlet.BaseRestlet;
|
|
20
|
|
21 /**
|
|
22 * Resource class for the list of annotations.
|
|
23 *
|
|
24 * @author casties
|
|
25 *
|
|
26 */
|
|
27 public class AnnotationsResource extends ServerResource {
|
|
28
|
|
29 public static Logger logger = Logger.getLogger(AnnotationsResource.class);
|
|
30
|
|
31 private AnnotationStore store;
|
|
32
|
|
33 @Override
|
|
34 protected void doInit() throws ResourceException {
|
|
35 super.doInit();
|
|
36 // get store instance
|
|
37 if (store == null) {
|
|
38 store = ((BaseRestlet) getApplication()).getAnnotationStore();
|
|
39 }
|
|
40 }
|
|
41
|
|
42 /**
|
|
43 * GET with HTML content type. Lists all annotations.
|
|
44 *
|
|
45 * @param entity
|
|
46 * @return
|
|
47 */
|
|
48 @Get("html")
|
|
49 public Representation doGetHTML(Representation entity) {
|
|
50 String result = null;
|
|
51 // list all annotations
|
|
52 result = "<html><body>\n<h1>Annotations</h1>\n<table>";
|
|
53 result += "<tr><th>uri</th><th>text</th><th>target</th><th>fragment</th><th>creator</th></tr>";
|
|
54 List<Annotation> annotations = store.getAnnotations("id", "*");
|
|
55 for (Annotation annotation : annotations) {
|
|
56 Reference url = this.getReference().clone();
|
|
57 url.addSegment(annotation.getUrlId());
|
|
58 result += String.format("<tr><td><a href=\"%s\">%s</a></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", url,
|
|
59 annotation.getUri(), annotation.getBodyText(), annotation.getTargetBaseUri(), annotation.getTargetFragment(),
|
|
60 annotation.getCreatorName());
|
|
61 }
|
|
62 result += "</table>\n";
|
|
63 result += "</body>\n</html>";
|
|
64 return new StringRepresentation(result, MediaType.TEXT_HTML);
|
|
65 }
|
|
66
|
|
67 }
|