Mercurial > hg > AnnotationManagerN4J
view src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsResource.java @ 50:64aa756c60cc
annotations ui can show and delete annotations now.
author | casties |
---|---|
date | Thu, 27 Sep 2012 17:12:08 +0200 |
parents | |
children | 2b1e6df5e21a |
line wrap: on
line source
/** * */ package de.mpiwg.itgroup.annotations.restlet.annotations_ui; import java.util.List; import org.apache.log4j.Logger; import org.restlet.data.MediaType; import org.restlet.data.Reference; import org.restlet.representation.Representation; import org.restlet.representation.StringRepresentation; import org.restlet.resource.Get; import org.restlet.resource.ResourceException; import org.restlet.resource.ServerResource; import de.mpiwg.itgroup.annotations.Annotation; import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; import de.mpiwg.itgroup.annotations.restlet.BaseRestlet; /** * Resource class for the list of annotations. * * @author casties * */ public class AnnotationsResource extends ServerResource { public static Logger logger = Logger.getLogger(AnnotationsResource.class); private AnnotationStore store; @Override protected void doInit() throws ResourceException { super.doInit(); // get store instance if (store == null) { store = ((BaseRestlet) getApplication()).getAnnotationStore(); } } /** * GET with HTML content type. Lists all annotations. * * @param entity * @return */ @Get("html") public Representation doGetHTML(Representation entity) { String result = null; // list all annotations result = "<html><body>\n<h1>Annotations</h1>\n<table>"; result += "<tr><th>uri</th><th>text</th><th>target</th><th>fragment</th><th>creator</th></tr>"; List<Annotation> annotations = store.getAnnotations("id", "*"); for (Annotation annotation : annotations) { Reference url = this.getReference().clone(); url.addSegment(annotation.getUrlId()); 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, annotation.getUri(), annotation.getBodyText(), annotation.getTargetBaseUri(), annotation.getTargetFragment(), annotation.getCreatorName()); } result += "</table>\n"; result += "</body>\n</html>"; return new StringRepresentation(result, MediaType.TEXT_HTML); } }