Mercurial > hg > AnnotationManager
diff src/de/mpiwg/itgroup/annotationManager/restlet/AddAndSearchAnnotations.java @ 3:e5f0906c107c
Neue Startseite
Header bei Post werden jetzt richtig gesetzt.
author | dwinter |
---|---|
date | Fri, 25 Nov 2011 08:43:25 +0100 |
parents | 6888ae3287b8 |
children | c32080f364c6 |
line wrap: on
line diff
--- a/src/de/mpiwg/itgroup/annotationManager/restlet/AddAndSearchAnnotations.java Thu Nov 24 11:39:12 2011 +0100 +++ b/src/de/mpiwg/itgroup/annotationManager/restlet/AddAndSearchAnnotations.java Fri Nov 25 08:43:25 2011 +0100 @@ -40,14 +40,6 @@ private Logger logger = Logger.getRootLogger(); - /** - * - * json hash: username: name des users xpointer: xpointer auf den Ausschnitt - * (incl. der URL des Dokumentes) text: text der annotation annoturl: url - * auf eine Annotation falls extern - * - * @return - */ @Options @@ -82,7 +74,7 @@ RDFSearcher searcher = new RDFSearcher("file:///annotations"); //TODO should ge into config file String retString="<html><body><table>"; - String lineFormat="<tr><td>%s</td>" + + String lineFormat="<tr><td><a href=\"%s\">%s</a></td>" + "<td><a href=\"%s\">%s</a></td><td>%s</td><td>%s</td><td><a href=\"%s\">%s</a></td><td><a href=\"%s\">%s</a></td></div>"; try { @@ -96,11 +88,10 @@ List<String> xpointer = new ArrayList<String>(); if (annot.xpointers==null || annot.xpointers.size()==0) - retString+=String.format(lineFormat, userName,annot.url,annot.url,annot.time,annot.text,annot.xpointer,annot.xpointer,annot.annotationUri,annot.annotationUri); + retString+=String.format(lineFormat, userName,userName,annot.url,annot.url,annot.time,annot.text,annot.xpointer,annot.xpointer,annot.annotationUri,annot.annotationUri); else { for(String xpointerString:annot.xpointers){ - retString+=String.format(lineFormat, userName,annot.url,annot.url,annot.time,annot.text,xpointerString,xpointerString,annot.annotationUri,annot.annotationUri); - + retString+=String.format(lineFormat, userName,userName,annot.url,annot.url,annot.time,annot.text,xpointerString,xpointerString,annot.annotationUri,annot.annotationUri); } } @@ -124,6 +115,49 @@ return new StringRepresentation(retString,MediaType.TEXT_HTML); } + /** + * Erzeugt aus einer Annotation, das fŸr den Annotator notwendige JSON-Format + * @param annot + * @return + */ + public JSONObject annot2AnnotatorJSON(Convert.Annotation annot){ + JSONObject jo = new JSONObject(); + try { + jo.put("text", annot.text); + jo.put("uri",annot.url); + + JSONObject userObject= new JSONObject(); + userObject.put("id",annot.creator); + + RestServer restServer = (RestServer) getApplication(); + + String userID= annot.creator; + if (userID.startsWith(NS.MPIWG_PERSONS)){ + userID=userID.replace(NS.MPIWG_PERSONS, ""); //entferne NAMESPACE + } + String userName=restServer.getUserNameFromLdap(userID); + userObject.put("name",userName); + + jo.put("user",userObject); + + List<String> xpointer = new ArrayList<String>(); + + if (annot.xpointers==null || annot.xpointers.size()==0) + xpointer.add(annot.xpointer); + else { + for(String xpointerString:annot.xpointers){ + xpointer.add(xpointerString); + } + } + jo.put("ranges", transformToRanges(xpointer)); + jo.put("id", annot.annotationUri); + return jo; + } catch (JSONException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } + } @Get("json") public Representation doGetJSON(Representation entity){ @@ -147,35 +181,41 @@ ja = new JSONArray(); for (Convert.Annotation annot:annots){ - JSONObject jo = new JSONObject(); - jo.put("text", annot.text); - jo.put("uri",annot.url); - - JSONObject userObject= new JSONObject(); - userObject.put("id",annot.creator); - - RestServer restServer = (RestServer) getApplication(); - - String userID= annot.creator; - if (userID.startsWith(NS.MPIWG_PERSONS)){ - userID=userID.replace(NS.MPIWG_PERSONS, ""); //entferne NAMESPACE +// JSONObject jo = new JSONObject(); +// jo.put("text", annot.text); +// jo.put("uri",annot.url); +// +// JSONObject userObject= new JSONObject(); +// userObject.put("id",annot.creator); +// +// RestServer restServer = (RestServer) getApplication(); +// +// String userID= annot.creator; +// if (userID.startsWith(NS.MPIWG_PERSONS)){ +// userID=userID.replace(NS.MPIWG_PERSONS, ""); //entferne NAMESPACE +// } +// String userName=restServer.getUserNameFromLdap(userID); +// userObject.put("name",userName); +// +// jo.put("user",userObject); +// +// List<String> xpointer = new ArrayList<String>(); +// +// if (annot.xpointers==null || annot.xpointers.size()==0) +// xpointer.add(annot.xpointer); +// else { +// for(String xpointerString:annot.xpointers){ +// xpointer.add(xpointerString); +// } +// } +// jo.put("ranges", transformToRanges(xpointer)); + JSONObject jo = annot2AnnotatorJSON(annot); + if (jo!=null){ + ja.put(annot2AnnotatorJSON(annot)); + } else { + setStatus(Status.SERVER_ERROR_INTERNAL,"JSon Error"); + return null; } - String userName=restServer.getUserNameFromLdap(userID); - userObject.put("name",userName); - - jo.put("user",userObject); - - List<String> xpointer = new ArrayList<String>(); - - if (annot.xpointers==null || annot.xpointers.size()==0) - xpointer.add(annot.xpointer); - else { - for(String xpointerString:annot.xpointers){ - xpointer.add(xpointerString); - } - } - jo.put("ranges", transformToRanges(xpointer)); - ja.put(jo); } } catch (TripleStoreHandlerException e) { // TODO Auto-generated catch block @@ -187,12 +227,7 @@ e.printStackTrace(); setStatus(Status.SERVER_ERROR_INTERNAL,"TripleStoreSearch Error"); return null; - } catch (JSONException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - setStatus(Status.SERVER_ERROR_INTERNAL,"JSon Error"); - return null; - } + } JSONObject retObject = new JSONObject(); try { @@ -262,24 +297,41 @@ } + + /** + * + * json hash: username: name des users xpointer: xpointer auf den Ausschnitt + * (incl. der URL des Dokumentes) text: text der annotation annoturl: url + * auf eine Annotation falls extern + * + * @return + */ + @Post("json") public Representation doPostJson(Representation entity) { - String retVal = doPost(entity); - JSONObject jo; - try { - jo = new JSONObject("{\"annotUrl\":\"" + retVal + "\"}"); - } catch (JSONException e) { - setStatus(Status.SERVER_ERROR_INTERNAL); + Annotation retVal = doPost(entity); + + +// JSONObject jo; +// try { +// jo = new JSONObject("{\"annotUrl\":\"" + retVal + "\"}"); +// } catch (JSONException e) { +// setStatus(Status.SERVER_ERROR_INTERNAL); +// return null; +// } + + if (retVal==null) return null; - } + JSONObject jo = annot2AnnotatorJSON(retVal); JsonRepresentation retRep = new JsonRepresentation(jo); return retRep; } @Post("html") public Representation doPostHtml(Representation entity) { - String retVal = doPost(entity); + Annotation retValAnnot = doPost(entity); + String retVal=retValAnnot.annotationUri; if (retVal == null) { return null; } @@ -292,7 +344,9 @@ return retRep; } - public String doPost(Representation entity) { + public Convert.Annotation doPost(Representation entity) { + + doOptions(entity); Convert.Annotation annot; // versuche basic authentifizierung und hole den Benutzer von dort. @@ -490,7 +544,7 @@ /** * uses the specification from the annotator project. * - * @see{https://github.com/okfn/annotator/wiki/Annotation-format The user + * @see{https://github.com/okfn/annotator/wiki/Annotation-format} The user * object must * contain an * id and