Changeset 418
- Timestamp:
- 2008-06-22 19:18:57 (5 years ago)
- Location:
- trunk/samples/kauri-dbforms-sample/src/main
- Files:
-
- 2 edited
-
java/org/kauriproject/samples/dbforms/BusinessRestlet.java (modified) (4 diffs)
-
kauri/router.groovy (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/samples/kauri-dbforms-sample/src/main/java/org/kauriproject/samples/dbforms/BusinessRestlet.java
r410 r418 45 45 public class BusinessRestlet extends Restlet { 46 46 47 private static final Pattern PERSON_PATTERN = Pattern.compile("^/person/([\\d]+)\\??.*$"); 48 private static final Pattern ADDRESS_PATTERN = Pattern.compile("^/address/([\\d]+)\\??.*$"); 49 private static final Pattern GENERIC_PATTERN = Pattern.compile("^/([^/]+)/(?:([\\d]+))?(?:\\?.*)?$"); 47 private static final Pattern GENERIC_PATTERN = Pattern.compile("^/([^/?]+)/(?:([\\d]+))?(?:\\?.*)?$"); 50 48 51 49 private static final String rootURI = "km:/jpaRestlet/"; … … 166 164 private void handleGet(Request request, Response response) { 167 165 String path = request.getResourceRef().getRemainingPart(); 168 Matcher personMatcher = PERSON_PATTERN.matcher(path); 169 Matcher addressMatcher = ADDRESS_PATTERN.matcher(path); 170 String templateLocation = "kms:/public" + path + ".xml"; 171 166 if (path.endsWith("?")) { 167 path = path.substring(0, path.length() - 1); 168 } 169 Matcher matcher = GENERIC_PATTERN.matcher(path); 170 String templateLocation; 172 171 Map<String, Object> map = new HashMap<String, Object>(); 173 172 if (path.equals("/addresses")) { … … 176 175 map.put("addressList", object); 177 176 } 177 templateLocation = "kms:/public/addresses.xml"; 178 178 } else if (path.equals("/persons")) { 179 179 Object object = doInnerRequest("person", MediaType.APPLICATION_JAVA_OBJECT); … … 181 181 map.put("personList", object); 182 182 } 183 } else if (path.equals("/person") || path.equals("/address")) { 184 map.put("jsondata", null); 185 } else if (personMatcher.matches()) { 186 String uri = "person/" + personMatcher.group(1); 183 templateLocation = "kms:/public/persons.xml"; 184 } else if (matcher.matches()) { 185 String uri = matcher.group(1) + "/" + matcher.group(2); 187 186 JSONObject jso = (JSONObject) doInnerRequest(uri, MediaType.APPLICATION_JSON); 188 187 map.put("jsondata", jso); 189 templateLocation = "kms:/public/person.xml"; 190 } else if (addressMatcher.matches()) { 191 String uri = "address/" + addressMatcher.group(1); 192 JSONObject jso = (JSONObject) doInnerRequest(uri, MediaType.APPLICATION_JSON); 193 map.put("jsondata", jso); 194 templateLocation = "kms:/public/address.xml"; 188 templateLocation = "kms:/public/" + matcher.group(1) + ".xml"; 189 } else { 190 map.put("jsondata", null); 191 templateLocation = "kms:/public/" + path + ".xml"; 195 192 } 196 193 -
trunk/samples/kauri-dbforms-sample/src/main/kauri/router.groovy
r389 r418 3 3 builder.router(context: moduleContext) { 4 4 template(uri: "/", template: "kms:/public/index.xml", 5 mediaType: "text/html", postAttach : { route -> route.getTemplate().setMatchingMode(Template.MODE_ EQUALS) })5 mediaType: "text/html", postAttach : { route -> route.getTemplate().setMatchingMode(Template.MODE_STARTS_WITH) }) 6 6 7 7 /* template(uri: "/template/{templateId}", template: "kms:/public/{templateId}.xml",
Note: See TracChangeset
for help on using the changeset viewer.