1 15 package org.apache.tapestry.services.impl; 16 17 import org.apache.tapestry.services.AbsoluteURLBuilder; 18 import org.apache.tapestry.web.WebRequest; 19 20 24 public class AbsoluteURLBuilderImpl implements AbsoluteURLBuilder 25 { 26 private WebRequest _request; 27 28 public String constructURL(String URI, String scheme, String server, int port) 29 { 30 33 if (URI.indexOf(':') >= 0) 34 return URI; 35 36 StringBuffer buffer = new StringBuffer (); 37 38 40 if (URI.length()> 2 && URI.substring(0, 2).equals("//")) 41 { 42 buffer.append(scheme); 43 buffer.append(':'); 44 buffer.append(URI); 45 return buffer.toString(); 46 } 47 48 buffer.append(scheme); 49 buffer.append("://"); 50 buffer.append(server); 51 52 if (port > 0) 53 { 54 buffer.append(':'); 55 buffer.append(port); 56 } 57 58 if (URI.charAt(0) != '/') 59 buffer.append('/'); 60 61 buffer.append(URI); 62 63 return buffer.toString(); 64 } 65 66 public String constructURL(String URI) 67 { 68 String scheme = _request.getScheme(); 69 String server = _request.getServerName(); 70 int port = _request.getServerPort(); 71 72 77 if (scheme.equals("http") && port == 80) 78 port = 0; 79 80 return constructURL(URI, scheme, server, port); 81 } 82 83 public void setRequest(WebRequest request) 84 { 85 _request = request; 86 } 87 } | Popular Tags |