try {
// use commons-httpclient's URI instead of java.net.URI, as it can
// actually accept *unescaped* URIs, such as the "mappedPath" and
// return them in proper escaped form, including the path, via
// toString()
final URI uri = new URI(mappedPath, false);
// 1. mangle the namespaces in the path
String path = mangleNamespaces(uri.getPath());
// 2. prepend servlet context path if we have a request
if (request != null && request.getContextPath() != null && request.getContextPath().length() > 0) {
path = request.getContextPath().concat(path);
}
// update the path part of the URI
uri.setPath(path);
mappedPath = uri.toString();
} catch (final URIException e) {
logger.warn("map: Unable to mangle namespaces for " + mappedPath + " returning unmangled", e);
}
logger.debug("map: Returning URL {} as mapping for path {}", mappedPath, resourcePath);