String urlString, final PageURLType pageURLType) {
// Rewrite only if there's an instance of rewriter specified.
if (pageURLRewriter != null) {
// Create an instance of MarinerURL with the URL to rewrite.
MarinerURL originalURL = new MarinerURL(urlString);
// Now, the issue with the MarinerURL is, that it can not be used to
// represent arbitrary URIs, like:
// - javascript:alert()
// - mailto:john.smith@gmail.com
//
// When creating an instance of MarinerURL on such URIs, it appends
// a slash character after the colon, so the URI looks like:
// - javascript:/alert()
// - mailto:/john.smith@gmail.com
//
// Since nothing can be done here, we do rewrite only those URLs,
// which were not damaged by creating an instance of MarinerURL on it.
//
// The ideal solution would be to refactor the MCS code to use
// java.set.URI instead.
if (originalURL.getExternalForm().equals(urlString)) {
MarinerURL rewrittenURL = pageURLRewriter.
rewriteURL(context.getRequestContext(),
originalURL,
PageURLDetailsFactory.
createPageURLDetails(pageURLType));
urlString = rewrittenURL.getExternalForm();
}
}
return urlString;
}