Changeset 63:9f8c9611848a in AnnotationManagerN4J for src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java
r61 r63 387 387 String y = geom.getString("y"); 388 388 fragment = String.format("xywh=fraction:%s,%s,0,0", x, y); 389 } else if (type.equalsIgnoreCase(" point")) {389 } else if (type.equalsIgnoreCase("rectangle")) { 390 390 String x = geom.getString("x"); 391 391 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"); 394 394 fragment = String.format("xywh=fraction:%s,%s,%s,%s", x, y, width, height); 395 395 } else { … … 417 417 String startOffset = range.getString("startOffset"); 418 418 String endOffset = range.getString("endOffset"); 419 420 419 String fragment = String.format( 421 420 "xpointer(start-point(string-range(\"%s\",%s,1))/range-to(end-point(string-range(\"%s\",%s,1))))", start, … … 560 559 try { 561 560 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 } 566 568 } 567 569 } catch (JSONException e) { … … 570 572 try { 571 573 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 } 576 581 } 577 582 } catch (JSONException e) { … … 581 586 try { 582 587 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 } 587 595 } 588 596 } catch (JSONException e) { 589 597 // nothing to do 590 598 } 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 592 604 /* 593 605 * permissions … … 650 662 } 651 663 652 public float getFloat(String s) {664 public static float getFloat(String s) { 653 665 try { 654 666 return Float.parseFloat(s); … … 657 669 return 0f; 658 670 } 671 672 public static int getInt(String s) { 673 try { 674 return Integer.parseInt(s); 675 } catch (NumberFormatException e) { 676 } 677 return 0; 678 } 659 679 }
Note: See TracChangeset
for help on using the changeset viewer.