From: <fa...@vh...> - 2005-09-12 15:20:02
|
Author: fabrice Date: 2005-09-12 17:11:00 +0200 (Mon, 12 Sep 2005) New Revision: 798 Modified: ccm-core/trunk/src/com/arsdigita/web/URL.java Log: Use dynamic host provider to get the host URL in emails Modified: ccm-core/trunk/src/com/arsdigita/web/URL.java =================================================================== --- ccm-core/trunk/src/com/arsdigita/web/URL.java 2005-09-12 15:10:24 UTC (rev 797) +++ ccm-core/trunk/src/com/arsdigita/web/URL.java 2005-09-12 15:11:00 UTC (rev 798) @@ -691,6 +691,46 @@ } /** + * Method similar to there(), but which checks the + * waf.web.dynamic_host_provider parameter to generate + * the site name and port dynamically. + * + * @see com.arsdigita.web.DispatcherServlet + * @param sreq the servlet request + * @param path a <code>String</code> path to which to dispatch + * @param params a <code>ParameterMap</code> of parameters to use; + * this value may be null + * @return a <code>URL</code> with a path to dispatch to + */ + public static final URL dynamicHostThere(final HttpServletRequest sreq, + final String path, + final ParameterMap params) { + final WebConfig config = Web.getConfig(); + DynamicHostProvider provider = Web.getConfig().getDynamicHostProvider(); + + if (provider == null) { + return there(sreq, path, params); + } + + Assert.assertNotNull(sreq, "HttpServletRequest sreq"); + Assert.assertNotNull(config, "WebConfig config"); + + if (params != null) { + params.runListeners(sreq); + } + + final HttpHost host = new HttpHost(sreq); + + return new URL(sreq.getScheme(), + provider.getName(), + provider.getPort(), + config.getDispatcherContextPath(), + config.getDispatcherServletPath(), + path, + params); + } + + /** * <p>Creates a URL with no local parameters to <code>path</code> * under the CCM main dispatcher. This method implicitly creates * an empty parameter map (not a null one); this empty map may be |