01: /*
02: * Created on Oct 26, 2005
03: */
04: package uk.org.ponder.rsf.servlet;
05:
06: import javax.servlet.http.HttpServletRequest;
07:
08: import uk.org.ponder.rsf.viewstate.BaseURLProvider;
09: import uk.org.ponder.rsf.viewstate.support.StaticBaseURLProvider;
10: import uk.org.ponder.servletutil.ServletUtil;
11:
12: /** A request-scope bean which automatically infers the base URL to be
13: * used for this request from the current HttpServletRequest.
14: * <p>It is a little useful for this to be a request-scope bean so that
15: * the computation of the URLs it not performed repeatedly on query.
16: * @author Antranig Basman (antranig@caret.cam.ac.uk)
17: *
18: */
19:
20: public class AutoBaseURLProvider implements BaseURLProvider {
21: private HttpServletRequest request;
22:
23: public void setHttpServletRequest(HttpServletRequest request) {
24: this .request = request;
25: }
26:
27: private StaticBaseURLProvider sbup;
28:
29: public void init() {
30: sbup = new StaticBaseURLProvider();
31: String baseurl = ServletUtil.getBaseURL2(request);
32: String resourcebaseurl = ServletUtil
33: .getContextBaseURL2(request);
34: sbup.setBaseURL(baseurl);
35: sbup.setResourceBaseURL(resourcebaseurl);
36: }
37:
38: /** A one-shot method that will create a static BaseURLProvider good for
39: * the current request.
40: */
41:
42: public BaseURLProvider getBaseURLProvider() {
43: return sbup;
44: }
45:
46: public String getBaseURL() {
47: return sbup.getBaseURL();
48: }
49:
50: public String getResourceBaseURL() {
51: return sbup.getResourceBaseURL();
52: }
53:
54: }
|