Mercurial > hg > AnnotationManagerN4J
view src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotationStoreGroups.java @ 19:f0f55ab768c9
more work on HTML UI.
author | casties |
---|---|
date | Thu, 06 Sep 2012 19:02:59 +0200 |
parents | aafa3884b2c4 |
children | 1ac626309352 |
line wrap: on
line source
/** * */ package de.mpiwg.itgroup.annotations.restlet; import java.util.List; import javax.servlet.ServletContext; import org.apache.log4j.Logger; import org.restlet.data.Form; import org.restlet.data.MediaType; import org.restlet.representation.Representation; import org.restlet.representation.StringRepresentation; import org.restlet.resource.Get; import org.restlet.resource.ServerResource; import de.mpiwg.itgroup.annotations.Group; import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; /** * @author casties * */ public class AnnotationStoreGroups extends ServerResource { public static Logger logger = Logger.getLogger(AnnotationStoreGroups.class); private AnnotationStore store; @Get("html") public Representation doGetHTML(Representation entity){ Form form = getRequest().getResourceRef().getQueryAsForm(); // id from URI /annotations/groups/{id} String id = (String) getRequest().getAttributes().get("id"); logger.debug("group-id=" + id); String result="<html><body>\n<h1>Groups</h1>\n<table>"; result += "<tr><th>id</th><th>name</th><th>uri</th></tr>"; store = getAnnotationStore(); if (id == null) { // list all groups List<Group> groups = store.getGroups("uri", "*"); for (Group group : groups) { String groupLink = group.getId(); 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()); } } result += "</table>\n</body>\n</html>"; logger.debug("sending:"); logger.debug(result); return new StringRepresentation(result,MediaType.TEXT_HTML); } protected AnnotationStore getAnnotationStore() { if (store == null) { store = ((BaseRestlet) getApplication()).getAnnotationStore(); } return store; } }