19 package org.turro.marker;
22 import java.io.IOException;
23 import java.io.PrintWriter;
24 import java.io.StringWriter;
25 import java.net.URLDecoder;
26 import java.net.URLEncoder;
27 import java.nio.charset.Charset;
28 import java.nio.charset.StandardCharsets;
29 import java.util.HashMap;
31 import java.util.Optional;
33 import java.util.UUID;
34 import java.util.logging.Level;
35 import java.util.logging.Logger;
36 import javax.servlet.ServletException;
37 import javax.servlet.http.HttpServletRequest;
38 import org.turro.collections.parser.ParserException;
39 import org.turro.string.Strings;
40 import org.turro.action.Actions;
41 import org.turro.action.ContentService;
42 import org.turro.action.EntityInfoContent;
43 import org.turro.action.EntityInfoType;
44 import org.turro.action.LinkType;
45 import org.turro.action.MailSenders;
46 import org.turro.action.Plugins;
47 import org.turro.collections.KeyValueMap;
48 import org.turro.elephant.context.Application;
49 import org.turro.elephant.context.ElephantContext;
50 import org.turro.elephant.context.IConstructor;
51 import org.turro.elephant.direct.DirectContents;
52 import org.turro.elephant.direct.IDirectContent;
53 import org.turro.elephant.impl.repository.Repository;
54 import org.turro.elephant.impl.util.Parser;
55 import org.turro.elephant.security.IUser;
56 import org.turro.elephant.user.menu.IUserMenu;
57 import org.turro.elephant.user.menu.UserMenus;
58 import org.turro.elephant.web.ElContext;
59 import org.turro.elephant.web.tags.SessionTags;
60 import org.turro.elephant.web.tags.TagsServlet;
61 import org.turro.file.Document;
62 import org.turro.help.HelpContext;
63 import org.turro.html.Colors;
64 import org.turro.html.HtmlContent;
65 import org.turro.log.WebLoggers;
66 import org.turro.plugin.contacts.IContact;
67 import org.turro.reflection.Reflections;
68 import org.turro.user.activity.ActivityType;
69 import org.turro.user.activity.UserActivityContent;
70 import org.turro.user.content.IElephantUserContent;
71 import org.turro.user.content.UserContents;
79 private static final Charset charset = StandardCharsets.UTF_8;
84 this.constructor = constructor;
92 HashMap map =
new HashMap();
93 map.put(
"type",
"qrcode");
99 HashMap map =
new HashMap();
100 map.put(
"type",
"image");
101 map.put(
"data", url);
126 return imageExists(image) ? image :
"/_zul/images/no_img.png";
130 return imageExists(image) ? image :
"/_zul/images/noimg/noimage.png";
134 if(Strings.isBlank(image))
return false;
135 image = image.contains(
"?") ? image.substring(0, image.indexOf(
"?")) : image;
156 HttpServletRequest request = constructor.
getRequest();
157 return request !=
null;
161 if(text.contains(
"{@")) {
162 StringWriter swriter =
new StringWriter();
163 try(PrintWriter writer =
new PrintWriter(swriter)) {
165 text = swriter.toString();
166 }
catch (IOException | ServletException ex) {
196 return Strings.identifier(value);
200 return UUID.randomUUID().toString();
223 public <T> T loadImplementation(String className) {
224 Class<T> jclass = Reflections.check(className);
228 public <T> T loadImplementation(String className, String label) {
229 Class<T> jclass = Reflections.check(className);
230 return Plugins.loadImplementation(jclass, label);
250 private KeyValueMap _keyValueMap;
262 return getMapFromObfuscated().get(parameter);
263 }
catch (Exception ex) {
269 private KeyValueMap getMapFromObfuscated() {
270 if(_keyValueMap ==
null) {
272 if(!Strings.isBlank(obfuscated)) {
275 }
catch (Exception ex) {
276 WebLoggers.info(
this).exception(ex).log();
320 if(!Strings.isBlank(obfuscated)) {
323 }
catch (Exception ex) {
332 if(request !=
null) {
335 return new KeyValueMap(
new HashMap());
339 final Map map =
new HashMap();
340 if(parameterMap !=
null) {
341 parameterMap.keySet().forEach((key) -> {
343 KeyValueMap kvm = MarkerHelper.getObfuscatedFrom(parameterMap.get(key)[0]);
348 map.put(key, parameterMap.get(key)[0]);
352 return new KeyValueMap(map);
356 return "$.post(\"" + context +
"\", { " + setObfuscatedParsPOST(values) +
" })";
369 public static String
createPOST(String
id, String domId, String values) {
373 public static String
createURL(String
id, String values) {
378 String directContentId, String values,
int daysValid,
boolean withDomain) {
379 String exrino =
null;
381 KeyValueMap kvm =
new KeyValueMap(values);
385 }
catch (ParserException ex) {
386 Logger.getLogger(
MarkerHelper.class.getName()).log(Level.SEVERE,
null, ex);
397 return Strings.truncate(text, max);
401 return HtmlContent.truncate(html, max);
405 return HtmlContent.plain(html, max);
410 public Colors.Color
color(String color) {
411 return Optional.ofNullable(Colors.of(color)).map(c -> c.color()).orElse(
null);
static String createAction(String email, String redir)
static String createRightNowParameter(String values)
static final String USER_PAR
static String createPars(String values, int days)
static String createEntryPoint(IConstructor constructor, String entryPoint, String valueStr)
static String createURL(IConstructor constructor, KeyValueMap values)
static String createURL(EntityInfoType type, LinkType link)
static String processMacros(IContact contact, String text, boolean web)
static< T > T loadImplementation(Class< T > jclass)
IConstructor getConstructor()
static Application getApplication()
abstract HttpServletRequest getHttpServletRequest()
static String getRelativePath(String path)
static String getRealPath(String path)
static String getServerBase(String scheme)
static String getServerUrl(String scheme)
static String getRootWebPath()
static String logMsg(String msg)
static byte[] decrypt(byte[] value)
static String removeWebContext(String path)
static String doCreateURL(String id, String values)
static IDirectContent getDirectContent(String id)
static String doCreatePOST(String id, String values)
static final String DIRECT_CONTENT_PATH
static void processMacros(IConstructor constructor, PrintWriter out, String text)
static String helpLink(String current)
WebLoggers exception(Throwable throwable)
static WebLoggers info(Object entity)
static String obsfuscatedPOST(String context, String values)
String getEntityInfoURL(String entityPath)
IDirectContent getPushNotification()
static String setObfuscatedPars(KeyValueMap parameters)
String truncateHTML(String html, int max)
String navigateAndSetWebTag(String fromTag, String path)
static final String OBFUSCATED_PAR
MarkerHelper(IConstructor constructor)
static KeyValueMap getObfuscatedParameters()
String processMacrosForWeb(String text)
Colors.Color color(String color)
IDirectContent getCookies()
String getUserActivityURL(IContact contact)
String obfuscateRightNowPars(String parameters)
String getHelpLink(ElContext context)
static String createPOST(String id, String domId, String values)
String getIdFrom(String value)
static String setObfuscatedRightNowPars(String parameters)
Set< IUserMenu > getUserMenu()
String getQRCodeFromCurrent()
IDirectContent getTracker()
String imageOrDefault(String image)
boolean imageExists(String image)
static String createDirectURL(IConstructor constructor, IContact contact, String directContentId, String values, int daysValid, boolean withDomain)
String imageOrEmpty(String image)
static String setObfuscatedRightNowPars(KeyValueMap parameters)
static KeyValueMap getAllParameters()
String getTrick(int seconds)
static String createURL(String id, String values)
static String setObfuscatedPars(String parameters)
IDirectContent getMessageQueue()
String getContent(String values)
IDirectContent getAnonymous()
String truncate(String text, int max)
String getImageFromUrl(String url)
String getObfuscatedParameter(String parameter)
String getContent(KeyValueMap values)
String truncateHTMLtoPlain(String html, int max)
String navigateToWebTag(String fromTag, String webTag)
Set< IElephantUserContent > getUserContents()
String getEntryPoint(String entryPoint, KeyValueMap values)
String getEntryPoint(String entryPoint, String values)
Set< String > getUserContentTags()
static String setObfuscatedParsPOST(String parameters)
static KeyValueMap getAllParameters(Map< String, String[]> parameterMap)
static KeyValueMap getObfuscatedParameters(HttpServletRequest request)
static KeyValueMap getObfuscatedFrom(String obfuscated)
Repository getRepository(String path)
String obfuscateParameters(String parameters)
static String createPOST(String id, String values)
String getQRCodeFromUrl(String url)
String downloadPath(Document document)
String createURL(IContact contact, ActivityType... types)
static Set< IElephantUserContent > getContents(IConstructor constructor, IContact contact)
static Set< String > getTags(IConstructor constructor, IContact contact)
ElContext getCurrentContext()
HttpServletRequest getRequest()
String getParameter(String param)
static final String CONNECTOR_EMAIL