|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
AbsoluteURLBuilderImpl.java | 90% | 96% | 100% | 94.7% |
|
1 |
// Copyright 2004, 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
14 |
|
|
15 |
package org.apache.tapestry.services.impl;
|
|
16 |
|
|
17 |
import org.apache.tapestry.services.AbsoluteURLBuilder;
|
|
18 |
import org.apache.tapestry.web.WebRequest;
|
|
19 |
|
|
20 |
/**
|
|
21 |
* @author Howard M. Lewis Ship
|
|
22 |
* @since 4.0
|
|
23 |
*/
|
|
24 |
public class AbsoluteURLBuilderImpl implements AbsoluteURLBuilder |
|
25 |
{ |
|
26 |
private WebRequest _request;
|
|
27 |
|
|
28 | 141 |
public String constructURL(String URI, String scheme, String server, int port) |
29 |
{ |
|
30 |
// Though, really, what does a leading colon with no scheme before it
|
|
31 |
// mean?
|
|
32 |
|
|
33 | 141 |
if (URI.indexOf(':') >= 0)
|
34 | 0 |
return URI;
|
35 |
|
|
36 | 141 |
StringBuffer buffer = new StringBuffer();
|
37 |
|
|
38 |
// Should check the length here, first.
|
|
39 |
|
|
40 | 141 |
if (URI.length()> 2 && URI.substring(0, 2).equals("//")) |
41 |
{ |
|
42 | 1 |
buffer.append(scheme); |
43 | 1 |
buffer.append(':'); |
44 | 1 |
buffer.append(URI); |
45 | 1 |
return buffer.toString();
|
46 |
} |
|
47 |
|
|
48 | 140 |
buffer.append(scheme); |
49 | 140 |
buffer.append("://");
|
50 | 140 |
buffer.append(server); |
51 |
|
|
52 | 140 |
if (port > 0)
|
53 |
{ |
|
54 | 2 |
buffer.append(':'); |
55 | 2 |
buffer.append(port); |
56 |
} |
|
57 |
|
|
58 | 140 |
if (URI.charAt(0) != '/')
|
59 | 1 |
buffer.append('/'); |
60 |
|
|
61 | 140 |
buffer.append(URI); |
62 |
|
|
63 | 140 |
return buffer.toString();
|
64 |
} |
|
65 |
|
|
66 | 137 |
public String constructURL(String URI)
|
67 |
{ |
|
68 | 137 |
String scheme = _request.getScheme(); |
69 | 137 |
String server = _request.getServerName(); |
70 | 137 |
int port = _request.getServerPort();
|
71 |
|
|
72 |
// Keep things simple ... port 80 is accepted as the
|
|
73 |
// standard port for http so it can be ommitted.
|
|
74 |
// Some of the Tomcat code indicates that port 443 is the default
|
|
75 |
// for https, and that needs to be researched.
|
|
76 |
|
|
77 | 137 |
if (scheme.equals("http") && port == 80) |
78 | 136 |
port = 0; |
79 |
|
|
80 | 137 |
return constructURL(URI, scheme, server, port);
|
81 |
} |
|
82 |
|
|
83 | 39 |
public void setRequest(WebRequest request) |
84 |
{ |
|
85 | 39 |
_request = request; |
86 |
} |
|
87 |
} |
|