19 package org.turro.elephant.direct;
21 import java.io.IOException;
22 import java.util.Collections;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import javax.servlet.ServletContext;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29 import org.turro.collections.parser.ParserException;
30 import org.turro.string.Strings;
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;
35 import org.turro.elephant.security.IUser;
36 import org.turro.marker.ElephantMarker;
37 import org.turro.plugin.contacts.IContact;
38 import org.turro.util.IdGenerator;
46 private final String tmplRoot;
47 private boolean needsUser =
false;
48 protected String
template =
"full";
51 this.tmplRoot = tmplRoot;
75 "$('#form_" + containerId +
"').serialize())" +
76 ".done(function(data) { $('#" + containerId +
"').html(data); });" +
88 public String
getAjaxUrl(String containerId, String values) {
90 return getAjaxUrl(containerId,
new KeyValueMap(values));
91 }
catch (ParserException ex) {
105 public String
getAjaxUrl(String containerId, KeyValueMap values) {
106 values.put(
"domid", containerId);
109 ".done(function(data) { $('#" + containerId +
"').html(data); });";
115 ".done(function(data) { eval(data); });";
121 }
catch (ParserException ex) {
144 return createURL(constructor, values, 7,
false);
148 return createURL(constructor, values, daysValid,
false);
170 return createURL(constructor, recipe,
new KeyValueMap(values), daysValid, withDomain);
171 }
catch (ParserException ex) {
215 marker.
put(
"actions",
this);
220 marker.
put(
"container", container);
221 String domid = (String) marker.
get(
"domid");
223 marker.
put(
"containerId", container ?
"cic_" + IdGenerator.generate() : domid);
242 if(extra !=
null) marker.
putAll(extra);
244 constructor.
getResponse().setContentType(
"text/html");
247 }
catch (IOException ex) {
253 this.needsUser = needsUser;
257 if(
template !=
null) this.
template =
template;
261 if(!needsUser || hasUser(constructor)) {
267 if(!needsUser || hasUser(constructor)) {
274 return (constructor !=
null) && (constructor.
getUser() !=
null);
285 public boolean myTurn(HttpServletRequest request) {
290 public void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
298 if(map ==
null &&
"POST".equals(constructor.
getRequest().getMethod())) {
299 map =
new KeyValueMap(Collections.EMPTY_MAP);
300 for(String key : constructor.
getRequest().getParameterMap().keySet()) {
301 map.put(key, constructor.
getRequest().getParameter(key));
306 String redirect = map.get(
Actions.REDIR_PAR);
307 if(!Strings.isBlank(redirect)) {
310 }
catch (IOException ex) {
static String createAction(String email, String redir)
static String createRightNowParameter(String values)
static boolean isRightNowAction(IConstructor constructor)
static final String USER_PAR
static KeyValueMap getRightNowAction(IConstructor constructor)
static KeyValueMap getAction(IConstructor constructor)
static String createRightNowAction(String values)
static String getServerBase(String scheme)
static IConstructor getConstructor(HttpServletRequest request, HttpServletResponse response)
static String getRootWebPath()
static String logMsg(String msg)
static String getEncoding()
ElephantMarker getMarker(IConstructor constructor)
void render(IConstructor constructor)
String createURL(IConstructor constructor, String values, int daysValid, boolean withDomain)
abstract void doExecute(IConstructor constructor, KeyValueMap map)
ElephantMarker getCleanMarkerFrom(IConstructor constructor)
void writeMarkerToResponse(IConstructor constructor, KeyValueMap map)
String createURL(IConstructor constructor, IContact recipe, KeyValueMap values, int daysValid, boolean withDomain)
String createURL(IConstructor constructor, String values, int daysValid)
String createURL(IConstructor constructor, String values)
void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response)
String parse(IConstructor constructor)
String getAjaxSubmitUrl(String containerId)
String getRedirContext(IConstructor constructor, boolean withDomain)
String createURL(IConstructor constructor, IContact recipe, String values, int daysValid, boolean withDomain)
String getAjaxUrl(String containerId, String values)
abstract String getIdentifier()
abstract void prepareCleanMarker(ElephantMarker marker, KeyValueMap map)
String getAjaxUrl(String containerId, KeyValueMap values)
String createFormAction()
String createRightNowURL(String values)
void execute(IConstructor constructor)
AbstractDirectContentCtrl(String tmplRoot)
String getAjaxEvalUrl(KeyValueMap values)
void writeMarkerToResponse(IConstructor constructor, KeyValueMap map, Map extra)
boolean myTurn(HttpServletRequest request)
String createPOST(String values)
String createRightNowURL(KeyValueMap values)
void setNeedsUser(boolean needsUser)
String createLinkTo(String link, KeyValueMap values)
void addContainerId(ElephantMarker marker, boolean container)
abstract void prepareMarker(ElephantMarker marker)
void setTemplate(String template)
static boolean isYourTurn(HttpServletRequest request, String path)
static final String DIRECT_CONTENT_PATH
static String createRelativeURL(String id)
void process(String rootTmpl, String tmpl)
IConstructor getConstructor()
String parse(String rootTmpl, String tmpl)
Object put(Object key, Object value)
HttpServletResponse getResponse()
void redirect(String path)
ElContext getCurrentContext()
HttpServletRequest getRequest()
String getParameter(String param)
static final String CONNECTOR_EMAIL