BrightSide Workbench Full Report + Source Code
org.turro.elephant.direct.AbstractDirect Class Referenceabstract
Inheritance diagram for org.turro.elephant.direct.AbstractDirect:
Collaboration diagram for org.turro.elephant.direct.AbstractDirect:

Public Member Functions

 AbstractDirect ()
 
boolean isRedirectToCurrent ()
 
void setRedirectToCurrent (boolean redirectToCurrent)
 
String createFormAction ()
 
String createPOST (String values)
 
String getAjaxSubmitUrl (String containerId)
 
String getAjaxUrl (String containerId, String values)
 
String getAjaxUrl (String containerId, KeyValueMap values)
 
String getAjaxEvalUrl (KeyValueMap values)
 
String createRightNowURL (String values)
 
String createRightNowURL (KeyValueMap values)
 
String createLinkTo (String link, KeyValueMap values)
 
String createURL ()
 
String createURL (IConstructor constructor, String values)
 
String createURL (IConstructor constructor, String values, int daysValid)
 
String createURL (IConstructor constructor, String values, int daysValid, boolean withDomain)
 
String createURL (IConstructor constructor, IContact recipe, String values, int daysValid, boolean withDomain)
 
String createURL (IConstructor constructor, IContact recipe, KeyValueMap values, int daysValid, boolean withDomain)
 
boolean itsMe (String id)
 
boolean myTurn (HttpServletRequest request)
 
void execute (ServletContext context, HttpServletRequest request, HttpServletResponse response)
 
void execute (IConstructor constructor)
 

Protected Member Functions

String getRedirContext (IConstructor constructor, boolean withDomain)
 
String generateJson (String rootElement, String itemElement, List results)
 
JsonObjectBuilder createJsonItem (String itemElement, Object item)
 
void writeJsonResponse (HttpServletResponse response, String json)
 
abstract String getIdentifier ()
 
abstract void doExecute (IConstructor constructor, KeyValueMap map)
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 46 of file AbstractDirect.java.

Constructor & Destructor Documentation

◆ AbstractDirect()

org.turro.elephant.direct.AbstractDirect.AbstractDirect ( )

Definition at line 50 of file AbstractDirect.java.

50  {
51  }

Member Function Documentation

◆ createFormAction()

String org.turro.elephant.direct.AbstractDirect.createFormAction ( )

Definition at line 61 of file AbstractDirect.java.

61  {
62  return DirectContents.createRelativeURL(getIdentifier());
63  }
Here is the call graph for this function:

◆ createJsonItem()

JsonObjectBuilder org.turro.elephant.direct.AbstractDirect.createJsonItem ( String  itemElement,
Object  item 
)
protected

Definition at line 198 of file AbstractDirect.java.

198  {
199  if(item instanceof String) {
200  return Json.createObjectBuilder().add(itemElement, (String) item);
201  } else if(item instanceof Double) {
202  return Json.createObjectBuilder().add(itemElement, (Double) item);
203  } else if(item instanceof Integer) {
204  return Json.createObjectBuilder().add(itemElement, (Integer) item);
205  } else if(item instanceof Boolean) {
206  return Json.createObjectBuilder().add(itemElement, (Boolean) item);
207  } else {
208  return Json.createObjectBuilder().add(itemElement, item.toString());
209  }
210  }
Here is the caller graph for this function:

◆ createLinkTo()

String org.turro.elephant.direct.AbstractDirect.createLinkTo ( String  link,
KeyValueMap  values 
)

Definition at line 140 of file AbstractDirect.java.

140  {
141  return ElephantContext.getRootWebPath() +
142  link + "?" + Actions.createAction(values);
143  }

◆ createPOST()

String org.turro.elephant.direct.AbstractDirect.createPOST ( String  values)

Definition at line 65 of file AbstractDirect.java.

65  {
66  return "$.post('" + ElephantContext.getRootWebPath() + DirectContents.DIRECT_CONTENT_PATH + getIdentifier() + "'," +
67  "{ exrino : '" + Actions.createRightNowParameter(values) + "' })";
68  }

◆ createRightNowURL() [1/2]

String org.turro.elephant.direct.AbstractDirect.createRightNowURL ( KeyValueMap  values)

Definition at line 134 of file AbstractDirect.java.

134  {
135  return ElephantContext.getRootWebPath() +
136  DirectContents.DIRECT_CONTENT_PATH + getIdentifier() +
137  "?" + Actions.createRightNowAction(values);
138  }

◆ createRightNowURL() [2/2]

String org.turro.elephant.direct.AbstractDirect.createRightNowURL ( String  values)

Definition at line 125 of file AbstractDirect.java.

125  {
126  try {
127  return createRightNowURL(new KeyValueMap(values));
128  } catch (ParserException ex) {
129  Logger.getLogger(AbstractDirect.class.getName()).log(Level.SEVERE, null, ex);
130  }
131  return null;
132  }

◆ createURL() [1/6]

String org.turro.elephant.direct.AbstractDirect.createURL ( )

Definition at line 145 of file AbstractDirect.java.

145  {
146  return ElephantContext.getRootWebPath() +
147  DirectContents.DIRECT_CONTENT_PATH + getIdentifier();
148  }
Here is the call graph for this function:

◆ createURL() [2/6]

String org.turro.elephant.direct.AbstractDirect.createURL ( IConstructor  constructor,
IContact  recipe,
KeyValueMap  values,
int  daysValid,
boolean  withDomain 
)

Definition at line 171 of file AbstractDirect.java.

171  {
172  values.put(Actions.USER_PAR, recipe.getConnector(IUser.CONNECTOR_EMAIL));
173  if(redirectToCurrent) values.put(Actions.REDIR_PAR, getRedirContext(constructor, withDomain));
174  return (withDomain ? ElephantContext.getServerBase("http") : "") +
175  ElephantContext.getRootWebPath() +
176  DirectContents.DIRECT_CONTENT_PATH + getIdentifier() +
177  "?" + Actions.createAction(values, daysValid, false);
178  }
String getRedirContext(IConstructor constructor, boolean withDomain)

◆ createURL() [3/6]

String org.turro.elephant.direct.AbstractDirect.createURL ( IConstructor  constructor,
IContact  recipe,
String  values,
int  daysValid,
boolean  withDomain 
)

Definition at line 162 of file AbstractDirect.java.

162  {
163  try {
164  return createURL(constructor, recipe, new KeyValueMap(values), daysValid, withDomain);
165  } catch (ParserException ex) {
166  Logger.getLogger(AbstractDirect.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
167  }
168  return null;
169  }

◆ createURL() [4/6]

String org.turro.elephant.direct.AbstractDirect.createURL ( IConstructor  constructor,
String  values 
)

Definition at line 150 of file AbstractDirect.java.

150  {
151  return createURL(constructor, values, 7, false);
152  }

◆ createURL() [5/6]

String org.turro.elephant.direct.AbstractDirect.createURL ( IConstructor  constructor,
String  values,
int  daysValid 
)

Definition at line 154 of file AbstractDirect.java.

154  {
155  return createURL(constructor, values, daysValid, false);
156  }

◆ createURL() [6/6]

String org.turro.elephant.direct.AbstractDirect.createURL ( IConstructor  constructor,
String  values,
int  daysValid,
boolean  withDomain 
)

Definition at line 158 of file AbstractDirect.java.

158  {
159  return createURL(constructor, (IContact) constructor.getUser(), values, daysValid, withDomain);
160  }

◆ doExecute()

abstract void org.turro.elephant.direct.AbstractDirect.doExecute ( IConstructor  constructor,
KeyValueMap  map 
)
abstractprotected

Reimplemented in org.turro.push.UserPushSubscription.

Here is the caller graph for this function:

◆ execute() [1/2]

void org.turro.elephant.direct.AbstractDirect.execute ( IConstructor  constructor)

Definition at line 239 of file AbstractDirect.java.

239  {
240  KeyValueMap map = Actions.isRightNowAction(constructor) ?
241  Actions.getRightNowAction(constructor) :
242  Actions.getAction(constructor);
243  if(map == null && "POST".equals(constructor.getRequest().getMethod())) {
244  map = new KeyValueMap(Collections.EMPTY_MAP);
245  if("application/json".equals(constructor.getRequest().getHeader("Content-Type"))) {
246  try {
247  map.put("json", IOUtils.toString(constructor.getRequest().getReader()));
248  } catch (IOException ex) {
249  Logger.getLogger(AbstractDirect.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
250  }
251  } else {
252  for(String key : constructor.getRequest().getParameterMap().keySet()) {
253  map.put(key, constructor.getRequest().getParameter(key));
254  }
255  }
256  }
257  if(map != null) {
258  doExecute(constructor, map);
259  String redirect = map.get(Actions.REDIR_PAR);
260  if(!Strings.isBlank(redirect)) {
261  try {
262  constructor.redirect(redirect);
263  } catch (IOException ex) {
264  Logger.getLogger(AbstractDirect.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
265  }
266  }
267  }
268  }
abstract void doExecute(IConstructor constructor, KeyValueMap map)
Here is the call graph for this function:

◆ execute() [2/2]

void org.turro.elephant.direct.AbstractDirect.execute ( ServletContext  context,
HttpServletRequest  request,
HttpServletResponse  response 
)

Implements org.turro.elephant.direct.IDirectContent.

Definition at line 235 of file AbstractDirect.java.

235  {
236  execute(ElephantContext.getConstructor(request, response));
237  }
void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response)
Here is the call graph for this function:

◆ generateJson()

String org.turro.elephant.direct.AbstractDirect.generateJson ( String  rootElement,
String  itemElement,
List  results 
)
protected

Definition at line 190 of file AbstractDirect.java.

190  {
191  JsonObjectBuilder builder = Json.createObjectBuilder();
192  JsonArrayBuilder array = Json.createArrayBuilder();
193  results.forEach(i -> array.add(createJsonItem(itemElement, i)));
194  builder.add(rootElement, array);
195  return builder.build().toString();
196  }
JsonObjectBuilder createJsonItem(String itemElement, Object item)
Here is the call graph for this function:

◆ getAjaxEvalUrl()

String org.turro.elephant.direct.AbstractDirect.getAjaxEvalUrl ( KeyValueMap  values)

Definition at line 119 of file AbstractDirect.java.

119  {
120  return "$.post('" + ElephantContext.getRootWebPath() + DirectContents.DIRECT_CONTENT_PATH + getIdentifier() + "'," +
121  "{ exrino : '" + Actions.createRightNowParameter(values) + "' })" +
122  ".done(function(data) { eval(data); });";
123  }

◆ getAjaxSubmitUrl()

String org.turro.elephant.direct.AbstractDirect.getAjaxSubmitUrl ( String  containerId)

FORM with id = 'form_containerId'. Must have a hidden input with domid = containerId, to resolve the container when is false while rendering and a hidden input with type value, to differentiate the action to process. A container with id = containerId must exist

Parameters
containerIdidentifier created when render container is true
Returns
The URL to use in the submit button

Definition at line 80 of file AbstractDirect.java.

80  {
81  return "$.post('" + ElephantContext.getRootWebPath() + DirectContents.DIRECT_CONTENT_PATH + getIdentifier() + "'," +
82  "$('#form_" + containerId + "').serialize())" +
83  ".done(function(data) { $('#" + containerId + "').html(data); });" +
84  "return false;";
85  }
Here is the call graph for this function:

◆ getAjaxUrl() [1/2]

String org.turro.elephant.direct.AbstractDirect.getAjaxUrl ( String  containerId,
KeyValueMap  values 
)

Ajax action with values passed in the URL. Includes domid = containerId, to resolve the container when is false while rendering.

Parameters
containerIdidentifier created when render container is true
valuesMap values to encrypt
Returns
The URL to use in the onclick event

Definition at line 112 of file AbstractDirect.java.

112  {
113  values.put("domid", containerId);
114  return "$.post('" + ElephantContext.getRootWebPath() + DirectContents.DIRECT_CONTENT_PATH + getIdentifier() + "'," +
115  "{ exrino : '" + Actions.createRightNowParameter(values) + "' })" +
116  ".done(function(data) { $('#" + containerId + "').html(data); });";
117  }

◆ getAjaxUrl() [2/2]

String org.turro.elephant.direct.AbstractDirect.getAjaxUrl ( String  containerId,
String  values 
)

Ajax action with values passed in the URL. Includes domid = containerId, to resolve the container when is false while rendering.

Parameters
containerIdidentifier created when render container is true
valuesValues in format name=value separated by semicolon
Returns
The URL to use in the onclick event

Definition at line 95 of file AbstractDirect.java.

95  {
96  try {
97  return getAjaxUrl(containerId, new KeyValueMap(values));
98  } catch (ParserException ex) {
99  Logger.getLogger(AbstractDirectContentCtrl.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(values), ex);
100  }
101  return "";
102  }
String getAjaxUrl(String containerId, String values)

◆ getIdentifier()

abstract String org.turro.elephant.direct.AbstractDirect.getIdentifier ( )
abstractprotected

Reimplemented in org.turro.push.UserPushSubscription.

Here is the caller graph for this function:

◆ getRedirContext()

String org.turro.elephant.direct.AbstractDirect.getRedirContext ( IConstructor  constructor,
boolean  withDomain 
)
protected

Definition at line 180 of file AbstractDirect.java.

180  {
181  if(withDomain) {
182  return ElephantContext.getServerBase("http") + constructor.getCurrentContext().getWebPath();
183  } else {
184  return constructor.getCurrentContext().getPath();
185  }
186  }
Here is the call graph for this function:

◆ isRedirectToCurrent()

boolean org.turro.elephant.direct.AbstractDirect.isRedirectToCurrent ( )

Definition at line 53 of file AbstractDirect.java.

53  {
54  return redirectToCurrent;
55  }

◆ itsMe()

boolean org.turro.elephant.direct.AbstractDirect.itsMe ( String  id)

Implements org.turro.elephant.direct.IDirectContent.

Definition at line 225 of file AbstractDirect.java.

225  {
226  return getIdentifier().equals(id);
227  }
Here is the call graph for this function:

◆ myTurn()

boolean org.turro.elephant.direct.AbstractDirect.myTurn ( HttpServletRequest  request)

Implements org.turro.elephant.direct.IDirectContent.

Definition at line 230 of file AbstractDirect.java.

230  {
231  return DirectContents.isYourTurn(request, getIdentifier());
232  }
Here is the call graph for this function:

◆ setRedirectToCurrent()

void org.turro.elephant.direct.AbstractDirect.setRedirectToCurrent ( boolean  redirectToCurrent)

Definition at line 57 of file AbstractDirect.java.

57  {
58  this.redirectToCurrent = redirectToCurrent;
59  }

◆ writeJsonResponse()

void org.turro.elephant.direct.AbstractDirect.writeJsonResponse ( HttpServletResponse  response,
String  json 
)
protected

Definition at line 212 of file AbstractDirect.java.

212  {
213  try {
214  response.setContentType("application/json");
215  //response.setCharacterEncoding(ElephantContext.getEncoding());
216  response.getWriter().write(json);
217  } catch (IOException ex) {
218  Logger.getLogger(AbstractDirectQuery.class.getName()).log(Level.SEVERE, null, ex);
219  }
220  }

The documentation for this class was generated from the following file: