View Javadoc
1   /*
2    * Copyright 2001-2011 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  package org.apache.juddi.v3.client.mapping;
18  
19  import java.net.MalformedURLException;
20  import java.net.URL;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  
25  public class URLLocalizerDefaultImpl implements URLLocalizer {
26  
27  	URL baseUrl;
28  	
29  	public URLLocalizerDefaultImpl() {
30  		super();
31  	}
32  	public URLLocalizerDefaultImpl(URL baseUrl) {
33  		super();
34  		this.baseUrl = baseUrl;
35  	}
36  
37  	private Log log = LogFactory.getLog(this.getClass());
38  	
39  	public String rewrite (URL urlIn) {
40  		return rewriteURL(urlIn).toExternalForm();
41  	}
42  	
43  	public String rewriteToWSDLURL (URL urlIn) {
44  		URL url = rewriteURL(urlIn);
45  		return url.toExternalForm() + "?wsdl";
46  	}
47  	
48  	public URL rewriteURL(URL urlIn) {
49  		URL url = null;
50  		if (baseUrl!=null && url == null) {
51  			try {
52  				url = new URL(baseUrl.getProtocol(),
53  							baseUrl.getHost(),
54  							baseUrl.getPort(),
55  							urlIn.getPath());
56  			} catch (MalformedURLException e) {
57  				log.error(e.getMessage(),e);
58  			}
59  		} else {
60  			url = urlIn;
61  		}
62  		return url;
63  	}
64  
65  	public void setBaseUrl(URL baseUrl) {
66  		this.baseUrl = baseUrl;
67  	}
68  
69  
70  }