Changeset 5:bbf0cc5bee29 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
r4 r5 9 9 import java.security.InvalidKeyException; 10 10 import java.security.SignatureException; 11 import java.text.SimpleDateFormat; 11 12 import java.util.ArrayList; 13 import java.util.Calendar; 12 14 import java.util.List; 13 15 import java.util.regex.Matcher; … … 178 180 */ 179 181 public JSONObject createAnnotatorJson(Annotation annot) { 182 // return user as a JSON object (otherwise just as string) 180 183 boolean makeUserObject = true; 181 184 JSONObject jo = new JSONObject(); … … 198 201 userObject.put("id", userId); 199 202 // get full name 200 RestServer restServer = (RestServer) getApplication(); 201 String userName = restServer.getUserNameFromLdap(userId); 203 String userName = annot.getCreatorName(); 204 if (userName == null) { 205 RestServer restServer = (RestServer) getApplication(); 206 userName = restServer.getFullNameFromLdap(userId); 207 } 202 208 userObject.put("name", userName); 203 209 // save user object … … 241 247 try { 242 248 for (String xpointer : xpointers) { 243 String decoded = URLDecoder.decode(xpointer, "utf-8"); 249 //String decoded = URLDecoder.decode(xpointer, "utf-8"); 250 String decoded = xpointer; 244 251 Matcher m = rg.matcher(decoded); 245 252 … … 266 273 // TODO Auto-generated catch block 267 274 e.printStackTrace(); 268 } catch (UnsupportedEncodingException e) { 269 // TODO Auto-generated catch block 270 e.printStackTrace(); 271 } 272 275 } 273 276 return ja; 274 277 } … … 282 285 try { 283 286 for (String xpointer : xpointers) { 284 String decoded = URLDecoder.decode(xpointer, "utf-8"); 287 //String decoded = URLDecoder.decode(xpointer, "utf-8"); 288 String decoded = xpointer; 285 289 Matcher m = rg.matcher(decoded); 286 290 … … 300 304 // TODO Auto-generated catch block 301 305 e.printStackTrace(); 302 } catch (UnsupportedEncodingException e) { 303 // TODO Auto-generated catch block 304 e.printStackTrace(); 305 } 306 306 } 307 307 return ja; 308 308 } 309 309 310 protected String parseArea(JSONObject area) throws JSONException , UnsupportedEncodingException{310 protected String parseArea(JSONObject area) throws JSONException { 311 311 String x = area.getString("x"); 312 312 String y = area.getString("y"); … … 317 317 height = area.getString("height"); 318 318 } 319 String fragment = URLEncoder.encode(String.format("xywh=fraction:%s,%s,%s,%s", x, y, width, height), "utf-8");319 String fragment = String.format("xywh=fraction:%s,%s,%s,%s", x, y, width, height); 320 320 return fragment; 321 321 } 322 322 323 protected String parseRange(JSONObject range) throws JSONException , UnsupportedEncodingException{323 protected String parseRange(JSONObject range) throws JSONException { 324 324 String start = range.getString("start"); 325 325 String end = range.getString("end"); … … 327 327 String endOffset = range.getString("endOffset"); 328 328 329 String fragment = URLEncoder.encode(String.format(329 String fragment = String.format( 330 330 "xpointer(start-point(string-range(\"%s\",%s,1))/range-to(end-point(string-range(\"%s\",%s,1))))", start, 331 startOffset, end, endOffset) , "utf-8");331 startOffset, end, endOffset); 332 332 return fragment; 333 333 } 334 334 335 335 /** 336 * creates an Annotation object with data from JSON.336 * Creates an Annotation object with data from JSON. 337 337 * 338 338 * uses the specification from the annotator project: {@link https … … 352 352 } 353 353 354 /** 355 * Updates an Annotation object with data from JSON. 356 * 357 * uses the specification from the annotator project: {@link https 358 * ://github.com/okfn/annotator/wiki/Annotation-format} 359 * 360 * The username will be transformed to an URI if not given already as URI, 361 * if not it will set to the MPIWG namespace defined in 362 * de.mpiwg.itgroup.annotationManager.Constants.NS 363 * 364 * @param annot 365 * @param jo 366 * @return 367 * @throws JSONException 368 * @throws UnsupportedEncodingException 369 */ 354 370 public Annotation updateAnnotation(Annotation annot, JSONObject jo, Representation entity) throws JSONException, 355 371 UnsupportedEncodingException { 356 // annotateduri372 // target uri 357 373 if (jo.has("uri")) { 358 374 annot.setTargetBaseUri(jo.getString("uri")); … … 397 413 username = authUser; 398 414 } 399 // username should be a URI, if not it will set to the MPIWG namespace 400 // defined in 401 // de.mpiwg.itgroup.annotationManager.Constants.NS 415 // try to get full name 416 if (username != null) { 417 RestServer restServer = (RestServer) getApplication(); 418 String fullName = restServer.getFullNameFromLdap(username); 419 annot.setCreatorName(fullName); 420 } 421 // userUri should be a URI, if not it will set to the MPIWG namespace 402 422 if (userUri == null) { 403 423 if (username.startsWith("http")) { … … 408 428 } 409 429 // TODO: should we overwrite the creator? 430 if (annot.getCreatorUri() == null) { 431 annot.setCreatorUri(userUri); 432 } 433 434 if (annot.getCreated() == null) { 435 // set creation date 436 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); 437 String ct = format.format(Calendar.getInstance().getTime()); 438 annot.setCreated(ct); 439 } 410 440 411 441 // create xpointer from the first range/area
Note: See TracChangeset
for help on using the changeset viewer.