source: AnnotationManagerN4J/src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsResource.java @ 99:199143c669e4

Last change on this file since 99:199143c669e4 was 99:199143c669e4, checked in by casties, 9 years ago

added links to admin interface.

File size: 3.0 KB
Line 
1/**
2 *
3 */
4package de.mpiwg.itgroup.annotations.restlet.annotations_ui;
5
6/*
7 * #%L
8 * AnnotationManager
9 * %%
10 * Copyright (C) 2012 - 2014 MPIWG Berlin
11 * %%
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License as
14 * published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 * GNU General Lesser Public License for more details.
21 *
22 * You should have received a copy of the GNU General Lesser Public
23 * License along with this program.  If not, see
24 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
25 * #L%
26 */
27
28import java.util.List;
29import java.util.logging.Logger;
30
31import org.restlet.data.MediaType;
32import org.restlet.data.Reference;
33import org.restlet.representation.Representation;
34import org.restlet.representation.StringRepresentation;
35import org.restlet.resource.Get;
36import org.restlet.resource.ResourceException;
37import org.restlet.resource.ServerResource;
38
39import de.mpiwg.itgroup.annotations.Annotation;
40import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
41import de.mpiwg.itgroup.annotations.restlet.BaseRestlet;
42
43/**
44 * Resource class for the list of annotations.
45 *
46 * @author casties
47 *
48 */
49public class AnnotationsResource extends ServerResource {
50
51    public static Logger logger = Logger.getLogger(AnnotationsResource.class.getCanonicalName());
52
53    private AnnotationStore store;
54
55    @Override
56    protected void doInit() throws ResourceException {
57        super.doInit();
58        // get store instance
59        if (store == null) {
60            store = ((BaseRestlet) getApplication()).getAnnotationStore();
61        }
62    }
63
64    /**
65     * GET with HTML content type. Lists all annotations.
66     *
67     * @param entity
68     * @return
69     */
70    @Get("html")
71    public Representation doGetHTML(Representation entity) {
72        String result = null;
73        // list all annotations
74        result = "<html><body>\n<h1>Annotations</h1>\n<table>";
75        result += "<tr><th>uri</th><th>text</th><th>target</th><th>fragment</th><th>creator</th></tr>";
76        List<Annotation> annotations = store.getAnnotations("id", "*");
77        for (Annotation annotation : annotations) {
78            Reference url = this.getReference().clone();
79            url.addSegment(annotation.getUrlId());
80            result += String.format("<tr><td><a href=\"%s\">%s</a></td><td>%s</td><td><a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url,
81                    annotation.getUri(), annotation.getBodyText(), annotation.getTargetBaseUri(), annotation.getTargetBaseUri(), 
82                    annotation.getTargetFragment(), annotation.getCreatorName());
83        }
84        result += "</table>\n";
85        result += "</body>\n</html>";
86        return new StringRepresentation(result, MediaType.TEXT_HTML);
87    }
88
89}
Note: See TracBrowser for help on using the repository browser.