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
|
|
31 import org.restlet.data.MediaType;
|
|
32 import org.restlet.data.Reference;
|
|
33 import org.restlet.representation.Representation;
|
|
34 import org.restlet.representation.StringRepresentation;
|
|
35 import org.restlet.resource.Get;
|
|
36 import org.restlet.resource.ResourceException;
|
|
37 import org.restlet.resource.ServerResource;
|
|
38
|
|
39 import de.mpiwg.itgroup.annotations.Annotation;
|
|
40 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
|
|
41 import de.mpiwg.itgroup.annotations.restlet.BaseRestlet;
|
|
42
|
|
43 /**
|
|
44 * Resource class for the list of annotations.
|
|
45 *
|
|
46 * @author casties
|
|
47 *
|
|
48 */
|
|
49 public class AnnotationsResource extends ServerResource {
|
|
50
|
94
|
51 public static Logger logger = Logger.getLogger(AnnotationsResource.class.getCanonicalName());
|
50
|
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>%s</td><td>%s</td><td>%s</td></tr>\n", url,
|
|
81 annotation.getUri(), annotation.getBodyText(), annotation.getTargetBaseUri(), annotation.getTargetFragment(),
|
|
82 annotation.getCreatorName());
|
|
83 }
|
|
84 result += "</table>\n";
|
|
85 result += "</body>\n</html>";
|
|
86 return new StringRepresentation(result, MediaType.TEXT_HTML);
|
|
87 }
|
|
88
|
|
89 }
|