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

Last change on this file since 50:64aa756c60cc was 50:64aa756c60cc, checked in by casties, 12 years ago

annotations ui can show and delete annotations now.

File size: 2.2 KB
Line 
1/**
2 *
3 */
4package de.mpiwg.itgroup.annotations.restlet.annotations_ui;
5
6import java.util.List;
7
8import org.apache.log4j.Logger;
9import org.restlet.data.MediaType;
10import org.restlet.data.Reference;
11import org.restlet.representation.Representation;
12import org.restlet.representation.StringRepresentation;
13import org.restlet.resource.Get;
14import org.restlet.resource.ResourceException;
15import org.restlet.resource.ServerResource;
16
17import de.mpiwg.itgroup.annotations.Annotation;
18import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
19import de.mpiwg.itgroup.annotations.restlet.BaseRestlet;
20
21/**
22 * Resource class for the list of annotations.
23 *
24 * @author casties
25 *
26 */
27public 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}
Note: See TracBrowser for help on using the repository browser.