annotate src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsResource.java @ 50:64aa756c60cc

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