annotate src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsResource.java @ 94:fcb6fe10e08c

added config option for webapp URL prefix.
author casties
date Tue, 10 Feb 2015 17:45:56 +0100
parents 25eb2e1df106
children 199143c669e4
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
70
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
6 /*
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
7 * #%L
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
8 * AnnotationManager
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
9 * %%
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
10 * Copyright (C) 2012 - 2014 MPIWG Berlin
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
11 * %%
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
12 * This program is free software: you can redistribute it and/or modify
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
13 * it under the terms of the GNU Lesser General Public License as
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
14 * published by the Free Software Foundation, either version 3 of the
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
15 * License, or (at your option) any later version.
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
16 *
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
17 * This program is distributed in the hope that it will be useful,
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
20 * GNU General Lesser Public License for more details.
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
21 *
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
22 * You should have received a copy of the GNU General Lesser Public
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
23 * License along with this program. If not, see
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
24 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
25 * #L%
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
26 */
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 50
diff changeset
27
50
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
28 import java.util.List;
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 70
diff changeset
29 import java.util.logging.Logger;
50
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 import org.restlet.data.MediaType;
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
32 import org.restlet.data.Reference;
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
33 import org.restlet.representation.Representation;
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
34 import org.restlet.representation.StringRepresentation;
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
35 import org.restlet.resource.Get;
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
36 import org.restlet.resource.ResourceException;
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
37 import org.restlet.resource.ServerResource;
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
38
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
39 import de.mpiwg.itgroup.annotations.Annotation;
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
40 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
41 import de.mpiwg.itgroup.annotations.restlet.BaseRestlet;
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 /**
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
44 * Resource class for the list of annotations.
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
45 *
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
46 * @author casties
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 */
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
49 public class AnnotationsResource extends ServerResource {
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
50
94
fcb6fe10e08c added config option for webapp URL prefix.
casties
parents: 75
diff changeset
51 public static Logger logger = Logger.getLogger(AnnotationsResource.class.getCanonicalName());
50
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
52
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
53 private AnnotationStore store;
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
54
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
55 @Override
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
56 protected void doInit() throws ResourceException {
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
57 super.doInit();
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
58 // get store instance
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
59 if (store == null) {
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
60 store = ((BaseRestlet) getApplication()).getAnnotationStore();
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 }
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
63
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
64 /**
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
65 * GET with HTML content type. Lists all annotations.
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 * @param entity
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
68 * @return
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
69 */
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
70 @Get("html")
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
71 public Representation doGetHTML(Representation entity) {
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
72 String result = null;
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
73 // list all annotations
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
74 result = "<html><body>\n<h1>Annotations</h1>\n<table>";
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
75 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
76 List<Annotation> annotations = store.getAnnotations("id", "*");
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
77 for (Annotation annotation : annotations) {
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
78 Reference url = this.getReference().clone();
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
79 url.addSegment(annotation.getUrlId());
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
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,
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
81 annotation.getUri(), annotation.getBodyText(), annotation.getTargetBaseUri(), annotation.getTargetFragment(),
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
82 annotation.getCreatorName());
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
83 }
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
84 result += "</table>\n";
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
85 result += "</body>\n</html>";
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
86 return new StringRepresentation(result, MediaType.TEXT_HTML);
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
87 }
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
88
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents:
diff changeset
89 }