@Test public void parseLargeRequestTest() throws UnsupportedEncodingException { String expected = "{\"query\":{\"keywords\":\"test\",\"followedBy\":\"p1\"," + "\"recipient\":[{\"name\":\"p1\",\"type\":\"PERSON\"},{\"name\":\"p2\"" + ",\"type\":\"PERSON\"},{\"name\":\"g1\",\"type\":\"GROUP\"}]}" + ",\"maxId\":\"20\",\"minId\":\"10\"}"; JSONObject req = sut.parseRequest("/resources/stream/guid/query/recipient/" + "PERSON:p1,PERSON:p2,GROUP:g1/" + "followedBy/p1/keywords/test/minId/10/maxId/20", 5); Assert.assertEquals(expected, req.toString()); }
public JSONObject parseRequest(final String path, final int start) throws UnsupportedEncodingException { JSONObject json = new JSONObject(); JSONObject query = new JSONObject(); String[] parts = Pattern.compile("/").split(path); for (int i = start; i < parts.length - 1; i += 2) { log.debug("Found key: " + parts[i]); if (isMultipleEntityKeyword(parts[i])) { query.accumulate(parts[i], parseEntities(parts[i + 1])); } else if (isGlobalKeyword(parts[i])) { json.accumulate(parts[i], parts[i + 1]); } else if (isKeyword(parts[i])) { query.accumulate(parts[i], URLDecoder.decode(parts[i + 1], "UTF-8")); } else { throw new ValidationException("Unable to parse request, unrecognized keyword: " + parts[i]); } } json.accumulate("query", query); return json; }
RestletQueryRequestParser { public JSONObject parseRequest(final String path, final int start) throws UnsupportedEncodingException { JSONObject json = new JSONObject(); JSONObject query = new JSONObject(); String[] parts = Pattern.compile("/").split(path); for (int i = start; i < parts.length - 1; i += 2) { log.debug("Found key: " + parts[i]); if (isMultipleEntityKeyword(parts[i])) { query.accumulate(parts[i], parseEntities(parts[i + 1])); } else if (isGlobalKeyword(parts[i])) { json.accumulate(parts[i], parts[i + 1]); } else if (isKeyword(parts[i])) { query.accumulate(parts[i], URLDecoder.decode(parts[i + 1], "UTF-8")); } else { throw new ValidationException("Unable to parse request, unrecognized keyword: " + parts[i]); } } json.accumulate("query", query); return json; } }
RestletQueryRequestParser { public JSONObject parseRequest(final String path, final int start) throws UnsupportedEncodingException { JSONObject json = new JSONObject(); JSONObject query = new JSONObject(); String[] parts = Pattern.compile("/").split(path); for (int i = start; i < parts.length - 1; i += 2) { log.debug("Found key: " + parts[i]); if (isMultipleEntityKeyword(parts[i])) { query.accumulate(parts[i], parseEntities(parts[i + 1])); } else if (isGlobalKeyword(parts[i])) { json.accumulate(parts[i], parts[i + 1]); } else if (isKeyword(parts[i])) { query.accumulate(parts[i], URLDecoder.decode(parts[i + 1], "UTF-8")); } else { throw new ValidationException("Unable to parse request, unrecognized keyword: " + parts[i]); } } json.accumulate("query", query); return json; } RestletQueryRequestParser(final Collection<String> inGlobalKeywords,
            final Collection<String> inMultipleEntityKeywords, final Collection<String> inKeywords); }
RestletQueryRequestParser { public JSONObject parseRequest(final String path, final int start) throws UnsupportedEncodingException { JSONObject json = new JSONObject(); JSONObject query = new JSONObject(); String[] parts = Pattern.compile("/").split(path); for (int i = start; i < parts.length - 1; i += 2) { log.debug("Found key: " + parts[i]); if (isMultipleEntityKeyword(parts[i])) { query.accumulate(parts[i], parseEntities(parts[i + 1])); } else if (isGlobalKeyword(parts[i])) { json.accumulate(parts[i], parts[i + 1]); } else if (isKeyword(parts[i])) { query.accumulate(parts[i], URLDecoder.decode(parts[i + 1], "UTF-8")); } else { throw new ValidationException("Unable to parse request, unrecognized keyword: " + parts[i]); } } json.accumulate("query", query); return json; } RestletQueryRequestParser(final Collection<String> inGlobalKeywords,
            final Collection<String> inMultipleEntityKeywords, final Collection<String> inKeywords); JSONObject parseRequest(final String path, final int start); boolean isMultipleEntityKeyword(final String keyword); boolean isGlobalKeyword(final String keyword); boolean isKeyword(final String keyword); }
RestletQueryRequestParser { public JSONObject parseRequest(final String path, final int start) throws UnsupportedEncodingException { JSONObject json = new JSONObject(); JSONObject query = new JSONObject(); String[] parts = Pattern.compile("/").split(path); for (int i = start; i < parts.length - 1; i += 2) { log.debug("Found key: " + parts[i]); if (isMultipleEntityKeyword(parts[i])) { query.accumulate(parts[i], parseEntities(parts[i + 1])); } else if (isGlobalKeyword(parts[i])) { json.accumulate(parts[i], parts[i + 1]); } else if (isKeyword(parts[i])) { query.accumulate(parts[i], URLDecoder.decode(parts[i + 1], "UTF-8")); } else { throw new ValidationException("Unable to parse request, unrecognized keyword: " + parts[i]); } } json.accumulate("query", query); return json; } RestletQueryRequestParser(final Collection<String> inGlobalKeywords,
            final Collection<String> inMultipleEntityKeywords, final Collection<String> inKeywords); JSONObject parseRequest(final String path, final int start); boolean isMultipleEntityKeyword(final String keyword); boolean isGlobalKeyword(final String keyword); boolean isKeyword(final String keyword);  }