50
|
1 /**
|
|
2 *
|
|
3 */
|
|
4 package de.mpiwg.itgroup.annotations.restlet.annotations_ui;
|
|
5
|
70
|
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
|
50
|
28 import java.util.List;
|
75
|
29 import java.util.logging.Logger;
|
50
|
30
|
101
|
31 import org.restlet.data.Form;
|
50
|
32 import org.restlet.data.MediaType;
|
|
33 import org.restlet.data.Reference;
|
|
34 import org.restlet.representation.Representation;
|
|
35 import org.restlet.representation.StringRepresentation;
|
|
36 import org.restlet.resource.Get;
|
|
37 import org.restlet.resource.ResourceException;
|
|
38 import org.restlet.resource.ServerResource;
|
|
39
|
|
40 import de.mpiwg.itgroup.annotations.Annotation;
|
|
41 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
|
101
|
42 import de.mpiwg.itgroup.annotations.restlet.AnnotatorResourceImpl;
|
50
|
43 import de.mpiwg.itgroup.annotations.restlet.BaseRestlet;
|
|
44
|
|
45 /**
|
|
46 * Resource class for the list of annotations.
|
|
47 *
|
|
48 * @author casties
|
|
49 *
|
|
50 */
|
|
51 public class AnnotationsResource extends ServerResource {
|
|
52
|
94
|
53 public static Logger logger = Logger.getLogger(AnnotationsResource.class.getCanonicalName());
|
50
|
54
|
|
55 private AnnotationStore store;
|
|
56
|
|
57 @Override
|
|
58 protected void doInit() throws ResourceException {
|
|
59 super.doInit();
|
|
60 // get store instance
|
|
61 if (store == null) {
|
|
62 store = ((BaseRestlet) getApplication()).getAnnotationStore();
|
|
63 }
|
|
64 }
|
|
65
|
|
66 /**
|
|
67 * GET with HTML content type. Lists all annotations.
|
|
68 *
|
|
69 * @param entity
|
|
70 * @return
|
|
71 */
|
|
72 @Get("html")
|
|
73 public Representation doGetHTML(Representation entity) {
|
101
|
74 Form form = getRequest().getResourceRef().getQueryAsForm();
|
|
75 int limit = AnnotatorResourceImpl.getInt(form.getFirstValue("limit", "100"));
|
|
76 int offset = AnnotatorResourceImpl.getInt(form.getFirstValue("offset", "0"));
|
|
77 int max = offset + limit;
|
|
78 int numannots = store.getAnnotationCount();
|
|
79 String baseUrl = this.getReference().getHierarchicalPart();
|
|
80 StringBuilder result = null;
|
50
|
81 // list all annotations
|
101
|
82 result = new StringBuilder("<html><body>\n<h1>Annotations</h1>\n");
|
|
83 result.append("<p>");
|
|
84 if (offset > 0) {
|
|
85 result.append(String.format(" <a href=\"%s?offset=%s&limit=%s\">prev</a> ", baseUrl, Math.max(offset - limit, 0), limit));
|
|
86 }
|
|
87 result.append(String.format("| %s - %s of %s annotations |", offset, (offset + limit), numannots));
|
|
88 if (max < numannots) {
|
|
89 result.append(String.format(" <a href=\"%s?offset=%s&limit=%s\">next</a>", baseUrl, Math.min(max, numannots), limit));
|
|
90 }
|
|
91 result.append("</p>\n");
|
|
92 result.append("<table>");
|
|
93 result.append("<tr><th>uri</th><th>text</th><th>target</th><th>fragment</th><th>creator</th></tr>");
|
|
94 List<Annotation> annotations = store.getAnnotations("id", "*", limit, offset);
|
50
|
95 for (Annotation annotation : annotations) {
|
|
96 Reference url = this.getReference().clone();
|
|
97 url.addSegment(annotation.getUrlId());
|
101
|
98 result.append(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,
|
99
|
99 annotation.getUri(), annotation.getBodyText(), annotation.getTargetBaseUri(), annotation.getTargetBaseUri(),
|
101
|
100 annotation.getTargetFragment(), annotation.getCreatorName()));
|
50
|
101 }
|
101
|
102 result.append("</table>\n");
|
|
103 result.append("</body>\n</html>");
|
50
|
104 return new StringRepresentation(result, MediaType.TEXT_HTML);
|
|
105 }
|
|
106
|
|
107 }
|