source: AnnotationManagerN4J/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotationStoreGroups.java @ 19:f0f55ab768c9

Last change on this file since 19:f0f55ab768c9 was 19:f0f55ab768c9, checked in by casties, 12 years ago

more work on HTML UI.

File size: 1.9 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           
48        }
49        result += "</table>\n</body>\n</html>";
50       
51        logger.debug("sending:");
52        logger.debug(result);
53        return new StringRepresentation(result,MediaType.TEXT_HTML);
54    }
55
56    protected AnnotationStore getAnnotationStore() {
57        if (store == null) {
58            store = ((BaseRestlet) getApplication()).getAnnotationStore();
59        }
60        return store;
61    }
62}
Note: See TracBrowser for help on using the repository browser.