Mercurial > hg > AnnotationManagerN4J
diff src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java @ 65:c0dd5314bada
deal with special characters in urls.
author | casties |
---|---|
date | Wed, 05 Dec 2012 15:36:43 +0100 |
parents | 9f8c9611848a |
children | 2b1e6df5e21a |
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java Mon Dec 03 18:42:20 2012 +0100 +++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java Wed Dec 05 15:36:43 2012 +0100 @@ -5,6 +5,8 @@ package de.mpiwg.itgroup.annotations.restlet; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.util.ArrayList; import java.util.List; @@ -49,9 +51,18 @@ logger.debug("AnnotatorAnnotations doGetJSON!"); setCorsHeaders(); // id from URI /annotations/{id} + String id = null; String jsonId = (String) getRequest().getAttributes().get("id"); - String id = decodeJsonId(jsonId); - logger.debug("annotation-id=" + id); + if (jsonId != null) { + // URL decode + try { + jsonId = URLDecoder.decode(jsonId, "UTF-8"); + } catch (UnsupportedEncodingException e) { + // this shouldn't happen + } + id = decodeJsonId(jsonId); + logger.debug("annotation-id=" + id); + } // do authentication Person authUser = Person.createPersonWithId(this.checkAuthToken(entity)); @@ -86,12 +97,13 @@ private Representation getAllAnnotations(Person authUser, int limit, int offset, String sortBy) { AnnotationStore store = getAnnotationStore(); ArrayList<JSONObject> results = new ArrayList<JSONObject>(); - + // read all annotations List<Annotation> annotations = store.getAnnotations(null, null); for (Annotation annotation : annotations) { // check permission - if (!annotation.isActionAllowed("read", authUser, store)) continue; + if (!annotation.isActionAllowed("read", authUser, store)) + continue; // add annotation to list JSONObject jo = createAnnotatorJson(annotation, false); results.add(jo); @@ -101,15 +113,17 @@ if (sortBy != null) { JSONObjectComparator.sortAnnotations(results, sortBy); } - + // put in JSON list JSONArray rows = new JSONArray(); int cnt = 0; for (JSONObject result : results) { cnt += 1; - if (offset > 0 && cnt < offset) continue; + if (offset > 0 && cnt < offset) + continue; rows.put(result); - if (limit > 0 && cnt >= limit) break; + if (limit > 0 && cnt >= limit) + break; } // assemble result object