if (urlConfig != null && urlConfig.isSetUrlEncodeUrls()) {
encoded = !urlConfig.getUrlEncodeUrls();
}
FreezableMutableURI uri = new FreezableMutableURI();
uri.setEncoding( response.getCharacterEncoding() );
uri.setURI( path, encoded );
if ( params != null )
{
uri.addParameters( params, false );
}
if ( fragment != null )
{
uri.setFragment( uri.encode( fragment ) );
}
URIContext uriContext = URIContextFactory.getInstance( forXML );
if ( uri.isAbsolute() )
{
return uri.getURIString( uriContext );
}
if ( path.length() != 0 && path.charAt( 0 ) != '/' )
{
String reqUri = request.getRequestURI();
String reqPath = reqUri.substring( 0, reqUri.lastIndexOf( '/' ) + 1 );
uri.setPath( reqPath + uri.getPath() );
}
boolean needsToBeSecure = needsToBeSecure( servletContext, request, uri.getPath(), true );
URLRewriterService.rewriteURL( servletContext, request, response, uri, urlType, needsToBeSecure );
String key = getURLTemplateKey( urlType, needsToBeSecure );
return URLRewriterService.getTemplatedURL( request, uri, key, uriContext );
}