Index: src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotationsByTags.java
===================================================================
--- src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotationsByTags.java	(revision 28)
+++ src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotationsByTags.java	(revision 28)
@@ -0,0 +1,105 @@
+package de.mpiwg.itgroup.annotations.restlet;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.neo4j.graphdb.Node;
+import org.restlet.data.Form;
+import org.restlet.data.Parameter;
+import org.restlet.data.Status;
+import org.restlet.ext.json.JsonRepresentation;
+import org.restlet.representation.Representation;
+import org.restlet.resource.Get;
+import org.restlet.resource.ServerResource;
+
+import de.mpiwg.itgroup.annotations.Annotation;
+import de.mpiwg.itgroup.annotations.NS;
+import de.mpiwg.itgroup.annotations.Tag;
+import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
+import de.mpiwg.itgroup.annotations.restlet.utils.JSONObjectComparator;
+
+/**
+ * API for accessing tags in the Annotation store.
+ * 
+ * @author dwinter
+ *
+ */
+public class AnnotatorAnnotationsByTags extends AnnotatorResourceImpl {
+    protected String getAllowedMethodsForHeader() {
+        return "OPTIONS,GET";
+    }
+    
+    @Get("json")
+    public Representation doGetJSON(Representation entity) {
+        logger.debug("AnnotatorAnnotatonsBytag doGetJSON!");
+        setCorsHeaders();
+       
+        String jsonId = (String) getRequest().getAttributes().get("id");
+        
+        Form form = getRequest().getResourceRef().getQueryAsForm();
+        String sortBy=null;
+        for (Parameter parameter : form) {
+          if (parameter.getName().equals("sortBy")){
+          sortBy =  parameter.getValue();
+          }
+        }
+        
+        //String id = decodeJsonId(jsonId);
+        String id = jsonId;
+        logger.debug("annotation-id=" + id);
+        
+        AnnotationStore store = getAnnotationStore();
+  	  	String tagUri=NS.MPIWG_TAGS_URL+id;
+        List<Annotation> annotations = store.getAnnotationsByTag(tagUri);
+        
+		//JSONArray results = new JSONArray();
+        ArrayList<JSONObject> results = new ArrayList<JSONObject>();
+        
+		for (Annotation annot : annotations) {
+            JSONObject jo = createAnnotatorJson(annot,false);
+            results.add(jo);
+        }
+    
+	if (sortBy!=null){
+		sortAnnotations(results,sortBy);
+	}
+		
+	JSONArray resultsJa = new JSONArray();
+	for (JSONObject result:results){
+		resultsJa.put(result);
+	}
+	
+    // assemble result object
+    JSONObject result = new JSONObject();
+    try {
+        result.put("rows", resultsJa);
+        result.put("total", resultsJa.length());
+    } catch (JSONException e) {
+        setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error");
+        return null;
+    }
+    logger.debug("sending:");
+    logger.debug(result);
+    return new JsonRepresentation(result);
+}
+
+    
+	/**
+	 * Sortiere array nach einem Parameter in den Annotationen
+	 * @param results
+	 * @return
+	 */
+	private void sortAnnotations(List<JSONObject> results,String attribute) {
+		JSONObjectComparator comp = new JSONObjectComparator(attribute);
+		
+		
+	
+		java.util.Collections.sort( results, comp);
+		
+		
+
+	}        	
+}
Index: src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorRestlet.java
===================================================================
--- src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorRestlet.java	(revision 18)
+++ src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorRestlet.java	(revision 28)
@@ -42,5 +42,8 @@
         router.attach("/search", AnnotatorSearch.class);
         router.attach("/groups", AnnotatorGroups.class);
-
+        router.attach("/tags", AnnotatorTags.class);
+        router.attach("/tags/{id}", AnnotatorTags.class);
+        router.attach("/tags/{id}", AnnotatorTags.class);
+        router.attach("/tags/{id}/annotations", AnnotatorAnnotationsByTags.class);
         router.attach("/", AnnotatorInfo.class);
         // authenticator.setNext(router);
Index: src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorTags.java
===================================================================
--- src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorTags.java	(revision 28)
+++ src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorTags.java	(revision 28)
@@ -0,0 +1,112 @@
+/**
+ * ReST API for accessing groups in the Annotation store.
+ */
+package de.mpiwg.itgroup.annotations.restlet;
+
+import java.util.List;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.neo4j.graphdb.Node;
+import org.restlet.data.Form;
+import org.restlet.data.Status;
+import org.restlet.ext.json.JsonRepresentation;
+import org.restlet.representation.Representation;
+import org.restlet.resource.Get;
+
+import de.mpiwg.itgroup.annotations.Actor;
+import de.mpiwg.itgroup.annotations.Group;
+import de.mpiwg.itgroup.annotations.NS;
+import de.mpiwg.itgroup.annotations.Tag;
+import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
+import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore.NodeTypes;
+
+
+/**
+ * API for accessing tags in the Annotation store.
+ * 
+ * @author dwinter
+ *
+ */
+public class AnnotatorTags extends AnnotatorResourceImpl {
+    protected String getAllowedMethodsForHeader() {
+        return "OPTIONS,GET";
+    }
+
+    /**
+     * GET with JSON content-type.
+     * Parameters: 
+     *   user: short user name
+     *   uri: user uri
+     *   
+     * @param entity
+     * @return
+     */
+    @Get("json")
+    public Representation doGetJSON(Representation entity) {
+        logger.debug("AnnotatorGroups doGetJSON!");
+        setCorsHeaders();
+       
+        String jsonId = (String) getRequest().getAttributes().get("id");
+        //String id = decodeJsonId(jsonId);
+        String id = jsonId;
+        logger.debug("annotation-id=" + id);
+
+        if (id==null){
+        return getAllTags();
+        } else {
+
+        	return getTag(id);
+        }
+    }
+    
+    protected Representation getTag(String id){
+    	  AnnotationStore store = getAnnotationStore();
+    	  String tagUri=NS.MPIWG_TAGS_URL+id;
+          Node tagNode = store.getTagNodeByUri(tagUri);
+          Tag tag = store.createTagFromNode(tagNode);
+          JSONObject jo = new JSONObject();
+          try {
+              jo.put("id", tag.getId());
+              jo.put("name", tag.getName());
+              jo.put("uri", tag.getUri());
+          } catch (JSONException e) {
+          }
+          
+          return new JsonRepresentation(jo);
+    }
+	protected Representation getAllTags() {
+		JSONArray results = new JSONArray();
+        AnnotationStore store = getAnnotationStore();
+        
+       
+            List<Tag> tags = store.getTags(null, null);
+            for (Tag tag : tags) {
+                JSONObject jo = new JSONObject();
+                try {
+                    jo.put("id", tag.getId());
+                    jo.put("name", tag.getName());
+                    jo.put("uri", tag.getUri());
+                } catch (JSONException e) {
+                }
+                results.put(jo);
+            }
+        
+        // assemble result object
+        JSONObject result = new JSONObject();
+        try {
+            result.put("rows", results);
+            result.put("total", results.length());
+        } catch (JSONException e) {
+            setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error");
+            return null;
+        }
+        logger.debug("sending:");
+        logger.debug(result);
+        return new JsonRepresentation(result);
+	}        	
+        
+
+    
+}
Index: src/main/java/de/mpiwg/itgroup/annotations/restlet/utils/JSONObjectComparator.java
===================================================================
--- src/main/java/de/mpiwg/itgroup/annotations/restlet/utils/JSONObjectComparator.java	(revision 28)
+++ src/main/java/de/mpiwg/itgroup/annotations/restlet/utils/JSONObjectComparator.java	(revision 28)
@@ -0,0 +1,38 @@
+package de.mpiwg.itgroup.annotations.restlet.utils;
+
+import java.util.Comparator;
+
+import de.mpiwg.itgroup.annotations.Annotation;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+public class JSONObjectComparator implements Comparator<JSONObject>{
+   
+	private String attributeToSort;
+	public JSONObjectComparator(String attribute){
+		this.attributeToSort=attribute;
+	}
+	
+	public int compare( JSONObject a, JSONObject b ) {
+        // je quadratischer, desto grösser
+		String sortA;
+		try {
+			sortA = a.getString(attributeToSort);
+		} catch (JSONException e) {
+			sortA ="";
+		}
+		String sortB;
+		try {
+			sortB = b.getString(attributeToSort);
+		} catch (JSONException e) {
+			sortB="";
+		}
+        
+		
+        return sortA.compareToIgnoreCase(sortB);
+    }
+        
+  
+	
+}
