cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ulrich Mayring <u...@denic.de>
Subject code to handle absolute and relative URLs
Date Fri, 14 Jul 2000 16:34:43 GMT
Hi all,

here's a method that can be used to parse a href attribute and return an
URL string. If something like this were used in all the inclusion
mechanisms, then we'd support relative and absolute URIs everywhere.
This method needs the current HttpServletRequest, if that is not
available everywhere, then it could probably be rewritten to use XSPUtil
methods.

private String getURI(String href, HttpServletRequest request) {
	String scheme = request.getScheme();
	String servername = request.getServerName();
	String port = "";
	Integer i = new Integer(request.getServerPort());
	if (! (i.intValue() == 80)) port = ":" + i.toString();
	if (href.startsWith("/")) {
		return scheme + "://" + servername + port + href;
		}
	else {
		String path = request.getRequestURI();
		path = path.substring(0,path.lastIndexOf("/")+1) + href;
		return scheme + "://" + servername + port + path;
		}
	}

Ulrich

-- 
Ulrich Mayring
DENIC eG, Systementwicklung

Mime
View raw message