19 package org.turro.elephant.direct;
21 import java.io.IOException;
22 import java.util.List;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import javax.json.Json;
26 import javax.json.JsonArrayBuilder;
27 import javax.json.JsonObjectBuilder;
28 import javax.servlet.ServletContext;
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31 import org.turro.action.Actions;
32 import org.turro.collections.KeyValueMap;
33 import org.turro.elephant.context.ElephantContext;
34 import org.turro.elephant.context.IConstructor;
51 public boolean itsMe(String
id) {
56 public boolean myTurn(HttpServletRequest request) {
61 public void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
69 if(map !=
null &&
"true".equals(map.get(
"ds"))) {
70 if(map.containsKey(
"sroot") && map.containsKey(
"sitem")) {
80 protected abstract List
doSearch(KeyValueMap map, String query);
84 protected String
generateJson(String rootElement, String itemElement, List results) {
85 JsonObjectBuilder builder = Json.createObjectBuilder();
86 JsonArrayBuilder array = Json.createArrayBuilder();
88 builder.add(rootElement, array);
89 return builder.build().toString();
92 protected JsonObjectBuilder
createJsonItem(String itemElement, Object item) {
93 if(item instanceof String) {
94 return Json.createObjectBuilder().add(itemElement, (String) item);
95 }
else if(item instanceof Double) {
96 return Json.createObjectBuilder().add(itemElement, (Double) item);
97 }
else if(item instanceof Integer) {
98 return Json.createObjectBuilder().add(itemElement, (Integer) item);
99 }
else if(item instanceof Boolean) {
100 return Json.createObjectBuilder().add(itemElement, (Boolean) item);
102 return Json.createObjectBuilder().add(itemElement, item.toString());
108 response.setContentType(
"application/json");
110 response.getWriter().write(json);
111 }
catch (IOException ex) {
static boolean isRightNowAction(IConstructor constructor)
static KeyValueMap getRightNowAction(IConstructor constructor)
static KeyValueMap getAction(IConstructor constructor)
static String createRightNowAction(String values)
static IConstructor getConstructor(HttpServletRequest request, HttpServletResponse response)
static String getRootWebPath()
void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response)
String generateJson(String rootElement, String itemElement, List results)
boolean myTurn(HttpServletRequest request)
void execute(IConstructor constructor)
void writeJsonResponse(HttpServletResponse response, String json)
abstract String getIdentifier()
JsonObjectBuilder createJsonItem(String itemElement, Object item)
abstract List doSearch(KeyValueMap map, String query)
String createQueryURL(String values)
static boolean isYourTurn(HttpServletRequest request, String path)
static final String DIRECT_CONTENT_PATH
HttpServletResponse getResponse()
String getParameter(String param)