Mercurial > hg > AnnotationManager
diff src/main/java/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorResourceImpl.java @ 33:e5f5848892a2
new annotation model basically works.
author | casties |
---|---|
date | Thu, 31 May 2012 19:08:48 +0200 |
parents | 40846c0b344d |
children |
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorResourceImpl.java Thu May 31 11:57:50 2012 +0200 +++ b/src/main/java/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorResourceImpl.java Thu May 31 19:08:48 2012 +0200 @@ -114,8 +114,7 @@ } /** - * checks Annotator Auth plugin authentication information from headers. - * returns userId if successful. + * checks Annotator Auth plugin authentication information from headers. returns userId if successful. * * @param entity * @return @@ -201,7 +200,15 @@ xpointers.add(xpointerString); } } - jo.put("ranges", transformToRanges(xpointers)); + if (!xpointers.isEmpty()) { + // we only look at the first xpointer + String xt = getXpointerType(xpointers.get(0)); + if (xt == "range") { + jo.put("ranges", transformToRanges(xpointers)); + } else if (xt == "area") { + jo.put("areas", transformToAreas(xpointers)); + } + } // encode Annotation URL (=id) in base64 String annotUrl = annot.getAnnotationUri(); String annotId = encodeJsonId(annotUrl); @@ -214,7 +221,6 @@ return null; } - private String getXpointerType(String xpointer) { if (xpointer.contains("#xpointer")) { return "range"; @@ -223,7 +229,7 @@ } return null; } - + private JSONArray transformToRanges(List<String> xpointers) { JSONArray ja = new JSONArray(); @@ -267,14 +273,46 @@ return ja; } + private JSONArray transformToAreas(List<String> xpointers) { + + JSONArray ja = new JSONArray(); + + Pattern rg = Pattern.compile("#xywh=(\\w*:)([\\d\\.]+),([\\d\\.]+),([\\d\\.]+),([\\d\\.]+)"); + + try { + for (String xpointer : xpointers) { + String decoded = URLDecoder.decode(xpointer, "utf-8"); + Matcher m = rg.matcher(decoded); + + if (m.find()) { + { + JSONObject jo = new JSONObject(); + String unit = m.group(1); + jo.put("x", m.group(2)); + jo.put("y", m.group(3)); + jo.put("width", m.group(4)); + jo.put("height", m.group(5)); + ja.put(jo); + } + } + } + } catch (JSONException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return ja; + } + /** * creates an Annotation object with data from JSON. * - * uses the specification from the annotator project: {@link https - * ://github.com/okfn/annotator/wiki/Annotation-format} + * uses the specification from the annotator project: {@link https ://github.com/okfn/annotator/wiki/Annotation-format} * - * The username will be transformed to an URI if not given already as URI, - * if not it will set to the MPIWG namespace defined in + * The username will be transformed to an URI if not given already as URI, if not it will set to the MPIWG namespace defined in * de.mpiwg.itgroup.annotationManager.Constants.NS * * @param jo @@ -365,7 +403,7 @@ if (jo.has("areas")) { JSONObject area = jo.getJSONArray("areas").getJSONObject(0); String x = area.getString("x"); - String y = area.getString("end"); + String y = area.getString("y"); String width = "0"; String height = "0"; if (area.has("width")) {