/** * */ package de.mpiwg.itgroup.annotations.restlet.annotations_ui; /* * #%L * AnnotationManager * %% * Copyright (C) 2012 - 2014 MPIWG Berlin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * . * #L% */ import java.util.List; import java.util.logging.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.getCanonicalName()); 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 = "\n

Annotations

\n"; result += ""; List annotations = store.getAnnotations("id", "*"); for (Annotation annotation : annotations) { Reference url = this.getReference().clone(); url.addSegment(annotation.getUrlId()); result += String.format("\n", url, annotation.getUri(), annotation.getBodyText(), annotation.getTargetBaseUri(), annotation.getTargetBaseUri(), annotation.getTargetFragment(), annotation.getCreatorName()); } result += "
uritexttargetfragmentcreator
%s%s%s%s%s
\n"; result += "\n"; return new StringRepresentation(result, MediaType.TEXT_HTML); } }