source: AnnotationManagerN4J/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotationStoreGroups.java @ 21:1ac626309352

Last change on this file since 21:1ac626309352 was 21:1ac626309352, checked in by casties, 12 years ago

more work on HTML UI (doesn't work yet).

File size: 2.3 KB
Line 
1/**
2 *
3 */
4package de.mpiwg.itgroup.annotations.restlet;
5
6import java.util.List;
7
8import javax.servlet.ServletContext;
9
10import org.apache.log4j.Logger;
11import org.restlet.data.Form;
12import org.restlet.data.MediaType;
13import org.restlet.representation.Representation;
14import org.restlet.representation.StringRepresentation;
15import org.restlet.resource.Get;
16import org.restlet.resource.ServerResource;
17
18import de.mpiwg.itgroup.annotations.Group;
19import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
20
21/**
22 * @author casties
23 *
24 */
25public class AnnotationStoreGroups extends ServerResource {
26
27    public static Logger logger = Logger.getLogger(AnnotationStoreGroups.class);
28
29    private AnnotationStore store;
30
31    @Get("html")
32    public Representation doGetHTML(Representation entity){
33        Form form = getRequest().getResourceRef().getQueryAsForm();
34        // id from URI /annotations/groups/{id}
35        String id = (String) getRequest().getAttributes().get("id");
36        logger.debug("group-id=" + id);
37        String result="<html><body>\n<h1>Groups</h1>\n<table>";
38        result += "<tr><th>id</th><th>name</th><th>uri</th></tr>";
39        store = getAnnotationStore();
40        if (id == null) {
41            // list all groups
42            List<Group> groups = store.getGroups("uri", "*");
43            for (Group group : groups) {
44                String groupLink = group.getId();
45                result += String.format("<tr><td><a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", groupLink, group.getId(), group.getName(), group.getUri());
46            }
47        } else {
48            // just one group
49            List<Group> groups = store.getGroups("uri", "*");
50            for (Group group : groups) {
51                String groupLink = group.getId();
52                result += String.format("<tr><td><a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", groupLink, group.getId(), group.getName(), group.getUri());
53            }
54        }
55        result += "</table>\n</body>\n</html>";
56       
57        logger.debug("sending:");
58        logger.debug(result);
59        return new StringRepresentation(result,MediaType.TEXT_HTML);
60    }
61
62    protected AnnotationStore getAnnotationStore() {
63        if (store == null) {
64            store = ((BaseRestlet) getApplication()).getAnnotationStore();
65        }
66        return store;
67    }
68}
Note: See TracBrowser for help on using the repository browser.