|
|||||||||||||||||||
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 javax.servlet.http.HttpServletRequest;
|
|
18 |
|
|
19 |
import org.apache.tapestry.services.AbsoluteURLBuilder;
|
|
20 |
|
|
21 |
/**
|
|
22 |
* @author Howard M. Lewis Ship
|
|
23 |
* @since 3.1
|
|
24 |
*/
|
|
25 |
public class AbsoluteURLBuilderImpl implements AbsoluteURLBuilder |
|
26 |
{ |
|
27 |
private HttpServletRequest _request;
|
|
28 |
|
|
29 | 6 |
public String constructURL(String URI, String scheme, String server, int port) |
30 |
{ |
|
31 |
// Though, really, what does a leading colon with no scheme before it
|
|
32 |
// mean?
|
|
33 |
|
|
34 | 6 |
if (URI.indexOf(':') >= 0)
|
35 | 0 |
return URI;
|
36 |
|
|
37 | 6 |
StringBuffer buffer = new StringBuffer();
|
38 |
|
|
39 |
// Should check the length here, first.
|
|
40 |
|
|
41 | 6 |
if (URI.substring(0, 2).equals("//")) |
42 |
{ |
|
43 | 1 |
buffer.append(scheme); |
44 | 1 |
buffer.append(':'); |
45 | 1 |
buffer.append(URI); |
46 | 1 |
return buffer.toString();
|
47 |
} |
|
48 |
|
|
49 | 5 |
buffer.append(scheme); |
50 | 5 |
buffer.append("://");
|
51 | 5 |
buffer.append(server); |
52 |
|
|
53 | 5 |
if (port > 0)
|
54 |
{ |
|
55 | 2 |
buffer.append(':'); |
56 | 2 |
buffer.append(port); |
57 |
} |
|
58 |
|
|
59 | 5 |
if (URI.charAt(0) != '/')
|
60 | 1 |
buffer.append('/'); |
61 |
|
|
62 | 5 |
buffer.append(URI); |
63 |
|
|
64 | 5 |
return buffer.toString();
|
65 |
} |
|
66 |
|
|
67 | 2 |
public String constructURL(String URI)
|
68 |
{ |
|
69 | 2 |
String scheme = _request.getScheme(); |
70 | 2 |
String server = _request.getServerName(); |
71 | 2 |
int port = _request.getServerPort();
|
72 |
|
|
73 |
// Keep things simple ... port 80 is accepted as the
|
|
74 |
// standard port for http so it can be ommitted.
|
|
75 |
// Some of the Tomcat code indicates that port 443 is the default
|
|
76 |
// for https, and that needs to be researched.
|
|
77 |
|
|
78 | 2 |
if (scheme.equals("http") && port == 80) |
79 | 1 |
port = 0; |
80 |
|
|
81 | 2 |
return constructURL(URI, scheme, server, port);
|
82 |
} |
|
83 |
|
|
84 | 2 |
public void setRequest(HttpServletRequest request) |
85 |
{ |
|
86 | 2 |
_request = request; |
87 |
} |
|
88 |
} |
|