1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.fatwire.gst.foundation.controller.support;
17
18 import javax.servlet.ServletContext;
19
20 import org.apache.commons.logging.Log;
21
22 import com.fatwire.gst.foundation.controller.AppContext;
23 import com.fatwire.gst.foundation.facade.logging.LogUtil;
24
25
26
27
28
29 public class WebContextUtil {
30
31 protected static final Log LOG = LogUtil.getLog(WebContextUtil.class);
32 private WebContextUtil() {
33 super();
34 }
35
36 public static AppContext getWebAppContext(ServletContext ctx) {
37 Object o = ctx.getAttribute(WebAppContext.WEB_CONTEXT_NAME);
38 if (o == null) {
39 LOG.trace("Configuring WebAppContext from WebContextUtil; it is not explicitly configured in web.xml. Using default setup!");
40 return new WebAppContextLoader().configureWebAppContext(ctx);
41 }
42 if (o instanceof AppContext) {
43 return (AppContext) o;
44 }
45
46 throw new IncompleteConfigurationException("There was no " + WebAppContext.WEB_CONTEXT_NAME
47 + " object in the ServletContext found. Is the WebAppContextLoader listener configured in web.xml?");
48 }
49
50 }