Ignore:
Timestamp:
Nov 23, 2012, 4:55:04 PM (11 years ago)
Author:
casties
Branch:
default
Message:

fixed bug with new rectangle shapes. added limit, offset and sortBy parameters to annotator/ and annotator/search.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java

    r61 r63  
    387387            String y = geom.getString("y");
    388388            fragment = String.format("xywh=fraction:%s,%s,0,0", x, y);
    389         } else if (type.equalsIgnoreCase("point")) {
     389        } else if (type.equalsIgnoreCase("rectangle")) {
    390390            String x = geom.getString("x");
    391391            String y = geom.getString("y");
    392             String width = shape.getString("width");
    393             String height = shape.getString("height");
     392            String width = geom.getString("width");
     393            String height = geom.getString("height");
    394394            fragment = String.format("xywh=fraction:%s,%s,%s,%s", x, y, width, height);
    395395        } else {
     
    417417        String startOffset = range.getString("startOffset");
    418418        String endOffset = range.getString("endOffset");
    419 
    420419        String fragment = String.format(
    421420                "xpointer(start-point(string-range(\"%s\",%s,1))/range-to(end-point(string-range(\"%s\",%s,1))))", start,
     
    560559        try {
    561560            if (jo.has("ranges")) {
    562                 JSONObject ranges = jo.getJSONArray("ranges").getJSONObject(0);
    563                 annot.setFragmentType(FragmentTypes.XPOINTER);
    564                 String fragment = parseRange(ranges);
    565                 annot.setTargetFragment(fragment);
     561                JSONArray ranges = jo.getJSONArray("ranges");
     562                if (ranges.length() > 0) {
     563                    JSONObject range = ranges.getJSONObject(0);
     564                    annot.setFragmentType(FragmentTypes.XPOINTER);
     565                    String fragment = parseRange(range);
     566                    annot.setTargetFragment(fragment);
     567                }
    566568            }
    567569        } catch (JSONException e) {
     
    570572        try {
    571573            if (jo.has("shapes")) {
    572                 JSONObject shapes = jo.getJSONArray("shapes").getJSONObject(0);
    573                 annot.setFragmentType(FragmentTypes.AREA);
    574                 String fragment = parseShape(shapes);
    575                 annot.setTargetFragment(fragment);
     574                JSONArray shapes = jo.getJSONArray("shapes");
     575                if (shapes.length() > 0) {
     576                    JSONObject shape = shapes.getJSONObject(0);
     577                    annot.setFragmentType(FragmentTypes.AREA);
     578                    String fragment = parseShape(shape);
     579                    annot.setTargetFragment(fragment);
     580                }
    576581            }
    577582        } catch (JSONException e) {
     
    581586        try {
    582587            if (jo.has("areas")) {
    583                 JSONObject area = jo.getJSONArray("areas").getJSONObject(0);
    584                 annot.setFragmentType(FragmentTypes.AREA);
    585                 String fragment = parseArea(area);
    586                 annot.setTargetFragment(fragment);
     588                JSONArray areas = jo.getJSONArray("areas");
     589                if (areas.length() > 0) {
     590                    JSONObject area = areas.getJSONObject(0);
     591                    annot.setFragmentType(FragmentTypes.AREA);
     592                    String fragment = parseArea(area);
     593                    annot.setTargetFragment(fragment);
     594                }
    587595            }
    588596        } catch (JSONException e) {
    589597            // nothing to do
    590598        }
    591 
     599        // no fragment is an error
     600        if (annot.getFragmentType() == null || annot.getTargetFragment() == null) {
     601            throw new JSONException("Annotation has no valid target fragment!");
     602        }
     603       
    592604        /*
    593605         * permissions
     
    650662    }
    651663
    652     public float getFloat(String s) {
     664    public static float getFloat(String s) {
    653665        try {
    654666            return Float.parseFloat(s);
     
    657669        return 0f;
    658670    }
     671
     672    public static int getInt(String s) {
     673        try {
     674            return Integer.parseInt(s);
     675        } catch (NumberFormatException e) {
     676        }
     677        return 0;
     678    }
    659679}
Note: See TracChangeset for help on using the changeset viewer.