BrightSide Workbench Full Report + Source Code
org.turro.elephant.context.ElephantContext Class Reference
Inheritance diagram for org.turro.elephant.context.ElephantContext:
Collaboration diagram for org.turro.elephant.context.ElephantContext:

Public Member Functions

 ElephantContext ()
 
void contextDestroyed (ServletContextEvent event)
 
void contextInitialized (ServletContextEvent event)
 

Static Public Member Functions

static Jsons siteInfo ()
 
static ServletContext getCurrent ()
 
static IConstructor createConstructor ()
 
static List< String > getMetas ()
 
static String removeWebContext (String path)
 
static String getRealPath (String path)
 
static String getRelativePath (String path)
 
static String getContextVariable (IConstructor constructor)
 
static String getRootWebPath ()
 
static String getRootResourcePath ()
 
static Object getAttribute (String key)
 
static void setAttribute (String key, Object value)
 
static void removeAttribute (String key)
 
static String getSiteName ()
 
static String getSiteForcedDomain ()
 
static String getSiteDescription ()
 
static String getSiteKeywords ()
 
static String getSiteFonts ()
 
static String getSiteIcon ()
 
static String getSiteWelcome ()
 
static String getSiteInternalFiles ()
 
static String getEncoding ()
 
static String getContextLoad ()
 
static String getSiteLocales ()
 
static boolean isValidLocale (Locale locale)
 
static String getSiteSignin ()
 
static String getSiteSyndicate ()
 
static String getDirectoryQualification ()
 
static String getTemplatesRoot ()
 
static boolean getUseSSL ()
 
static boolean getUseSSO ()
 
static boolean getLiveLinks ()
 
static Locale getContactLocale ()
 
static Currency getContactCurrency ()
 
static boolean hasSignup ()
 
static String getServerBase (String scheme)
 
static String getServerUrl (String scheme)
 
static URI toUri (String localPath) throws URISyntaxException
 
static byte[] encrypt (byte[] value)
 
static byte[] decrypt (byte[] value)
 
static String encrypt (String value)
 
static String decrypt (String value)
 
static File file (String path)
 
static String logMsg (String msg)
 
static void resetSite ()
 
static void resetSchemes ()
 
static void initServerSchemas (HttpServletRequest request)
 
static String getEntityWebContext (String path)
 
static String getEntityWebContext (Path path)
 
static IConstructor getConstructor (HttpServletRequest request, HttpServletResponse response)
 

Detailed Description

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

Definition at line 59 of file ElephantContext.java.

Constructor & Destructor Documentation

◆ ElephantContext()

org.turro.elephant.context.ElephantContext.ElephantContext ( )

Definition at line 67 of file ElephantContext.java.

67  {
68  }

Member Function Documentation

◆ contextDestroyed()

void org.turro.elephant.context.ElephantContext.contextDestroyed ( ServletContextEvent  event)

Definition at line 71 of file ElephantContext.java.

71  {
72  _context = null;
73  }

◆ contextInitialized()

void org.turro.elephant.context.ElephantContext.contextInitialized ( ServletContextEvent  event)

Definition at line 76 of file ElephantContext.java.

76  {
77  _context = event.getServletContext();
78  loadSiteConfiguration();
79  Configurator.init(ElephantContext.getRealPath("/WEB-INF/elephant/conf/configurator/context.json"));
80  }
Here is the call graph for this function:

◆ createConstructor()

static IConstructor org.turro.elephant.context.ElephantContext.createConstructor ( )
static

Definition at line 99 of file ElephantContext.java.

99  {
100  return ElephantContext.getConstructor(null, null);
101  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decrypt() [1/2]

static byte [] org.turro.elephant.context.ElephantContext.decrypt ( byte[]  value)
static

Definition at line 269 of file ElephantContext.java.

269  {
270  return (value != null && ((value.length % 8) == 0)) ?
271  Cipher.symetricDecrypt(value) : null;
272  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decrypt() [2/2]

static String org.turro.elephant.context.ElephantContext.decrypt ( String  value)
static

Definition at line 279 of file ElephantContext.java.

279  {
280  if(!Strings.isBlank(value)) {
281  byte[] bytes = decrypt(new Base64().decode(value.getBytes()));
282  return bytes != null ? new String(bytes) : "";
283  }
284  return null;
285  }
Here is the call graph for this function:

◆ encrypt() [1/2]

static byte [] org.turro.elephant.context.ElephantContext.encrypt ( byte[]  value)
static

Definition at line 265 of file ElephantContext.java.

265  {
266  return Cipher.symetricEncrypt(value);
267  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ encrypt() [2/2]

static String org.turro.elephant.context.ElephantContext.encrypt ( String  value)
static

Definition at line 274 of file ElephantContext.java.

274  {
275  return !Strings.isBlank(value) ? new String(
276  new Base64().encode(encrypt(value.getBytes()))) : "";
277  }
Here is the call graph for this function:

◆ file()

static File org.turro.elephant.context.ElephantContext.file ( String  path)
static

Definition at line 287 of file ElephantContext.java.

287  {
288  return new File(getRealPath(path));
289  }
Here is the call graph for this function:

◆ getAttribute()

static Object org.turro.elephant.context.ElephantContext.getAttribute ( String  key)
static

Definition at line 145 of file ElephantContext.java.

145  {
146  return _context.getAttribute(key);
147  }
Here is the caller graph for this function:

◆ getConstructor()

static IConstructor org.turro.elephant.context.ElephantContext.getConstructor ( HttpServletRequest  request,
HttpServletResponse  response 
)
static

Definition at line 563 of file ElephantContext.java.

563  {
564  IConstructor impl = CollectionUtil.from(Instances.fresh().byAnnotation(ElephantConstructor.class, IConstructor.class)).first();
565  if(impl != null) {
566  impl.setRequest(request);
567  impl.setResponse(response);
568  }
569  return impl;
570  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getContactCurrency()

static Currency org.turro.elephant.context.ElephantContext.getContactCurrency ( )
static

Definition at line 237 of file ElephantContext.java.

237  {
238  return Currency.getInstance((String) getAttribute("contact_currency"));
239  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getContactLocale()

static Locale org.turro.elephant.context.ElephantContext.getContactLocale ( )
static

Definition at line 233 of file ElephantContext.java.

233  {
234  return new Locale((String) getAttribute("contact_language"), (String) getAttribute("contact_country"));
235  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getContextLoad()

static String org.turro.elephant.context.ElephantContext.getContextLoad ( )
static

Definition at line 193 of file ElephantContext.java.

193  {
194  return (String) getAttribute("site_context-load");
195  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getContextVariable()

static String org.turro.elephant.context.ElephantContext.getContextVariable ( IConstructor  constructor)
static

Definition at line 133 of file ElephantContext.java.

133  {
134  return constructor.getCurrentContext().getPath();
135  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCurrent()

static ServletContext org.turro.elephant.context.ElephantContext.getCurrent ( )
static

Definition at line 95 of file ElephantContext.java.

95  {
96  return _context;
97  }
Here is the caller graph for this function:

◆ getDirectoryQualification()

static String org.turro.elephant.context.ElephantContext.getDirectoryQualification ( )
static

Definition at line 213 of file ElephantContext.java.

213  {
214  return (String) getAttribute("site_directory-qualification");
215  }
Here is the call graph for this function:

◆ getEncoding()

static String org.turro.elephant.context.ElephantContext.getEncoding ( )
static

Definition at line 189 of file ElephantContext.java.

189  {
190  return (String) getAttribute("site_encoding");
191  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getEntityWebContext() [1/2]

static String org.turro.elephant.context.ElephantContext.getEntityWebContext ( Path  path)
static

Definition at line 412 of file ElephantContext.java.

412  {
413  return ElephantProperties.getContextProperty(ENTITY_WEB_CONTEXT, path.getRoot());
414  }
Here is the call graph for this function:

◆ getEntityWebContext() [2/2]

static String org.turro.elephant.context.ElephantContext.getEntityWebContext ( String  path)
static
Parameters
pathEntity path. Allows multiple path separated by comma. The first path have preference, and so on. The method returns when a web path value is encountered on null if none.
Returns
The web path for the entity, by input priority.

Definition at line 401 of file ElephantContext.java.

401  {
402  String[] paths = path.split(",");
403  for(String p : paths) {
404  String ep = getEntityWebContext(new Path(p));
405  if(!Strings.isBlank(ep)) {
406  return ep;
407  }
408  }
409  return null;
410  }
static String getEntityWebContext(String path)
Here is the caller graph for this function:

◆ getLiveLinks()

static boolean org.turro.elephant.context.ElephantContext.getLiveLinks ( )
static

Definition at line 229 of file ElephantContext.java.

229  {
230  return "true".equals((String) getAttribute("site_live-links"));
231  }
Here is the call graph for this function:

◆ getMetas()

static List<String> org.turro.elephant.context.ElephantContext.getMetas ( )
static

Definition at line 103 of file ElephantContext.java.

103  {
104  return _metas;
105  }
Here is the caller graph for this function:

◆ getRealPath()

static String org.turro.elephant.context.ElephantContext.getRealPath ( String  path)
static

Definition at line 115 of file ElephantContext.java.

115  {
116  String real = getCurrent().getRealPath(path);
117  if(real != null) {
118  real = real.replaceAll("\\\\", "/");
119  if(real.endsWith("/"))
120  real = real.substring(0, real.length() - 1);
121  }
122  return real;
123  }
Here is the call graph for this function:

◆ getRelativePath()

static String org.turro.elephant.context.ElephantContext.getRelativePath ( String  path)
static

Definition at line 125 of file ElephantContext.java.

125  {
126  String remove = getRealPath("/");
127  if(path.startsWith(remove)) {
128  return path.substring(remove.length());
129  }
130  return null;
131  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getRootResourcePath()

static String org.turro.elephant.context.ElephantContext.getRootResourcePath ( )
static

Definition at line 141 of file ElephantContext.java.

141  {
142  return getRootWebPath();
143  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getRootWebPath()

static String org.turro.elephant.context.ElephantContext.getRootWebPath ( )
static

Definition at line 137 of file ElephantContext.java.

137  {
138  return _context.getContextPath();
139  }

◆ getServerBase()

static String org.turro.elephant.context.ElephantContext.getServerBase ( String  scheme)
static

Definition at line 246 of file ElephantContext.java.

246  {
247  if(scheme.equals("http") && getUseSSL()) {
248  scheme = "https";
249  }
250  String server = schemes.get(scheme);
251  if(server == null) {
252  server = scheme + "://" + getSiteForcedDomain();
253  }
254  return server;
255  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getServerUrl()

static String org.turro.elephant.context.ElephantContext.getServerUrl ( String  scheme)
static

Definition at line 257 of file ElephantContext.java.

257  {
258  return getServerBase(scheme) + getRootWebPath();
259  }
static String getServerBase(String scheme)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSiteDescription()

static String org.turro.elephant.context.ElephantContext.getSiteDescription ( )
static

Definition at line 165 of file ElephantContext.java.

165  {
166  return (String) getAttribute("site_description");
167  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSiteFonts()

static String org.turro.elephant.context.ElephantContext.getSiteFonts ( )
static

Definition at line 173 of file ElephantContext.java.

173  {
174  return (String) getAttribute("site_fonts");
175  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSiteForcedDomain()

static String org.turro.elephant.context.ElephantContext.getSiteForcedDomain ( )
static

Definition at line 161 of file ElephantContext.java.

161  {
162  return (String) getAttribute("site_forced-domain");
163  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSiteIcon()

static String org.turro.elephant.context.ElephantContext.getSiteIcon ( )
static

Definition at line 177 of file ElephantContext.java.

177  {
178  return (String) getAttribute("site_icon");
179  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSiteInternalFiles()

static String org.turro.elephant.context.ElephantContext.getSiteInternalFiles ( )
static

Definition at line 185 of file ElephantContext.java.

185  {
186  return (String) getAttribute("site-files");
187  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSiteKeywords()

static String org.turro.elephant.context.ElephantContext.getSiteKeywords ( )
static

Definition at line 169 of file ElephantContext.java.

169  {
170  return (String) getAttribute("site_keywords");
171  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSiteLocales()

static String org.turro.elephant.context.ElephantContext.getSiteLocales ( )
static

Definition at line 197 of file ElephantContext.java.

197  {
198  return (String) getAttribute("site_locales");
199  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSiteName()

static String org.turro.elephant.context.ElephantContext.getSiteName ( )
static

Definition at line 157 of file ElephantContext.java.

157  {
158  return (String) getAttribute("site_name");
159  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSiteSignin()

static String org.turro.elephant.context.ElephantContext.getSiteSignin ( )
static

Definition at line 205 of file ElephantContext.java.

205  {
206  return (String) getAttribute("site_signin");
207  }
Here is the call graph for this function:

◆ getSiteSyndicate()

static String org.turro.elephant.context.ElephantContext.getSiteSyndicate ( )
static

Definition at line 209 of file ElephantContext.java.

209  {
210  return (String) getAttribute("site_syndicate");
211  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSiteWelcome()

static String org.turro.elephant.context.ElephantContext.getSiteWelcome ( )
static

Definition at line 181 of file ElephantContext.java.

181  {
182  return (String) getAttribute("site_welcome");
183  }
Here is the call graph for this function:

◆ getTemplatesRoot()

static String org.turro.elephant.context.ElephantContext.getTemplatesRoot ( )
static

Definition at line 217 of file ElephantContext.java.

217  {
218  return (String) getAttribute("site_templatesRoot");
219  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getUseSSL()

static boolean org.turro.elephant.context.ElephantContext.getUseSSL ( )
static

Definition at line 221 of file ElephantContext.java.

221  {
222  return "true".equals((String) getAttribute("site_use-ssl"));
223  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getUseSSO()

static boolean org.turro.elephant.context.ElephantContext.getUseSSO ( )
static

Definition at line 225 of file ElephantContext.java.

225  {
226  return "true".equals((String) getAttribute("site_use-sso"));
227  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasSignup()

static boolean org.turro.elephant.context.ElephantContext.hasSignup ( )
static

Definition at line 241 of file ElephantContext.java.

241  {
242  return Folder.from(ElephantContext.getRealPath("/user/signup")).exists() &&
243  "true".equals((String) getAttribute("site_has_signup"));
244  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initServerSchemas()

static void org.turro.elephant.context.ElephantContext.initServerSchemas ( HttpServletRequest  request)
static

Definition at line 370 of file ElephantContext.java.

370  {
371  if(!schemes.containsKey(request.getScheme())) {
372  schemes.put(request.getScheme(), request.getScheme() + "://" +
373  request.getServerName() + getServerPort(request));
374  }
375  }
Here is the caller graph for this function:

◆ isValidLocale()

static boolean org.turro.elephant.context.ElephantContext.isValidLocale ( Locale  locale)
static

Definition at line 201 of file ElephantContext.java.

201  {
202  return getSiteLocales().contains(locale.getLanguage());
203  }
Here is the call graph for this function:

◆ logMsg()

static String org.turro.elephant.context.ElephantContext.logMsg ( String  msg)
static

Definition at line 291 of file ElephantContext.java.

291  {
292  return "[" + getSiteName() + "]" + (Strings.isBlank(msg) ? "" : ": " + msg);
293  }
Here is the call graph for this function:

◆ removeAttribute()

static void org.turro.elephant.context.ElephantContext.removeAttribute ( String  key)
static

Definition at line 153 of file ElephantContext.java.

153  {
154  _context.removeAttribute(key);
155  }
Here is the caller graph for this function:

◆ removeWebContext()

static String org.turro.elephant.context.ElephantContext.removeWebContext ( String  path)
static

Definition at line 107 of file ElephantContext.java.

107  {
108  String remove = getRootWebPath();
109  if(!Strings.isBlank(remove) && path.startsWith(remove)) {
110  return path.substring(remove.length());
111  }
112  return path;
113  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetSchemes()

static void org.turro.elephant.context.ElephantContext.resetSchemes ( )
static

Definition at line 299 of file ElephantContext.java.

299  {
300  schemes.clear();
301  }
Here is the caller graph for this function:

◆ resetSite()

static void org.turro.elephant.context.ElephantContext.resetSite ( )
static

Definition at line 295 of file ElephantContext.java.

295  {
296  loadSiteConfiguration();
297  }
Here is the caller graph for this function:

◆ setAttribute()

static void org.turro.elephant.context.ElephantContext.setAttribute ( String  key,
Object  value 
)
static

Definition at line 149 of file ElephantContext.java.

149  {
150  _context.setAttribute(key, value);
151  }
Here is the caller graph for this function:

◆ siteInfo()

static Jsons org.turro.elephant.context.ElephantContext.siteInfo ( )
static

Definition at line 84 of file ElephantContext.java.

84  {
85  return Jsons.object()
86  .add("name", ElephantContext.getSiteName())
87  .add("description", ElephantContext.getSiteDescription())
88  .add("icon", ElephantContext.getServerBase("http") + ElephantContext.getSiteIcon())
89  .add("url", ElephantContext.getServerUrl("http"))
90  .add("locales", ElephantContext.getSiteLocales());
91  }
Here is the call graph for this function:

◆ toUri()

static URI org.turro.elephant.context.ElephantContext.toUri ( String  localPath) throws URISyntaxException
static

Definition at line 261 of file ElephantContext.java.

261  {
262  return new URI(getServerBase("http") + getRootWebPath() + localPath);
263  }
Here is the call graph for this function:

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