Ignore:
Timestamp:
Dec 5, 2012, 2:36:43 PM (11 years ago)
Author:
casties
Branch:
default
Message:

deal with special characters in urls.

File:
1 edited

Legend:

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

    r58 r65  
    44package de.mpiwg.itgroup.annotations.restlet;
    55
     6import java.io.UnsupportedEncodingException;
     7import java.net.URLDecoder;
    68import java.util.List;
    79
     
    1820import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
    1921
    20 
    2122/**
    2223 * API for accessing tags in the Annotation store.
    2324 *
    2425 * @author dwinter
    25  *
     26 * 
    2627 */
    2728public class AnnotatorTags extends AnnotatorResourceImpl {
     
    3132
    3233    /**
    33      * GET with JSON content-type.
     34     * GET with JSON content-type. 
    3435     * Parameters:
    35      *   user: short user name
     36     *   user: short user name 
    3637     *   uri: user uri
    37      *  
     38     *
    3839     * @param entity
    3940     * @return
     
    4344        logger.debug("AnnotatorGroups doGetJSON!");
    4445        setCorsHeaders();
    45        
     46
    4647        String jsonId = (String) getRequest().getAttributes().get("id");
    47         //String id = decodeJsonId(jsonId);
     48        // String id = decodeJsonId(jsonId);
    4849        String id = jsonId;
    4950        logger.debug("annotation-id=" + id);
    5051
    51         if (id==null){
    52         return getAllTags();
     52        if (id == null) {
     53            return getAllTags();
    5354        } else {
    54 
    55                 return getTag(id);
     55            // URL decode
     56            try {
     57                id = URLDecoder.decode(id, "UTF-8");
     58            } catch (UnsupportedEncodingException e) {
     59                // this shouldn't happen
     60            }
     61            return getTag(id);
    5662        }
    5763    }
    58    
    59     protected Representation getTag(String id){
    60           AnnotationStore store = getAnnotationStore();
    61           String tagUri = BaseRestlet.TAGS_URI_PREFIX + id;
    62           Node tagNode = store.getTagNodeByUri(tagUri);
    63           Tag tag = store.createTagFromNode(tagNode);
    64           JSONObject jo = new JSONObject();
    65           try {
    66               jo.put("id", tag.getId());
    67               jo.put("name", tag.getName());
    68               jo.put("uri", tag.getUri());
    69           } catch (JSONException e) {
    70           }
    71          
    72           return new JsonRepresentation(jo);
     64
     65    protected Representation getTag(String id) {
     66        AnnotationStore store = getAnnotationStore();
     67        String tagUri = BaseRestlet.TAGS_URI_PREFIX + id;
     68        Node tagNode = store.getTagNodeByUri(tagUri);
     69        Tag tag = store.createTagFromNode(tagNode);
     70        JSONObject jo = new JSONObject();
     71        try {
     72            jo.put("id", tag.getId());
     73            jo.put("name", tag.getName());
     74            jo.put("uri", tag.getUri());
     75        } catch (JSONException e) {
     76        }
     77
     78        return new JsonRepresentation(jo);
    7379    }
    74         protected Representation getAllTags() {
    75                 JSONArray results = new JSONArray();
     80
     81    protected Representation getAllTags() {
     82        JSONArray results = new JSONArray();
    7683        AnnotationStore store = getAnnotationStore();
    77        
    78        
    79             List<Tag> tags = store.getTags(null, null);
    80             for (Tag tag : tags) {
    81                 JSONObject jo = new JSONObject();
    82                 try {
    83                     jo.put("id", tag.getId());
    84                     jo.put("name", tag.getName());
    85                     jo.put("uri", tag.getUri());
    86                 } catch (JSONException e) {
    87                 }
    88                 results.put(jo);
     84
     85        List<Tag> tags = store.getTags(null, null);
     86        for (Tag tag : tags) {
     87            JSONObject jo = new JSONObject();
     88            try {
     89                jo.put("id", tag.getId());
     90                jo.put("name", tag.getName());
     91                jo.put("uri", tag.getUri());
     92            } catch (JSONException e) {
    8993            }
    90        
     94            results.put(jo);
     95        }
     96
    9197        // assemble result object
    9298        JSONObject result = new JSONObject();
     
    101107        logger.debug(result);
    102108        return new JsonRepresentation(result);
    103         }               
    104        
     109    }
    105110
    106    
    107111}
Note: See TracChangeset for help on using the changeset viewer.