01: /*
02: * $Id: UserInfoEndpointURIBuilder.java 10489 2008-01-23 17:53:38Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
10:
11: package org.mule.endpoint;
12:
13: import org.mule.api.endpoint.MalformedEndpointException;
14:
15: import java.net.URI;
16: import java.util.Properties;
17:
18: /**
19: * <code>UserInfoEndpointBuilder</code> builds an endpoint with the userinfo and
20: * host details. This endpoint builder is used where endpoints as of the form :
21: * xxx://ross:secret@host:1000
22: */
23: public class UserInfoEndpointURIBuilder extends
24: AbstractEndpointURIBuilder {
25: //TODO THis endpoint builder is redundant I think. We should be able to use the URL endpoint builder.
26: //It depends on where deriving classes can work with the URL endpoint builder, but there are a lot of similarities
27: protected void setEndpoint(URI uri, Properties props)
28: throws MalformedEndpointException {
29: // Added by Lajos 2006-12-14 per Ross
30: if (uri.getHost() == null) {
31: if (props.getProperty("address") == null) {
32: throw new MalformedEndpointException(uri.toString());
33: } else {
34: return;
35: }
36: }
37:
38: // Check and handle '@' symbols in the user info
39: address = uri.getHost();
40: int a = address.indexOf(".");
41: int b = (a == -1 ? -1 : address.indexOf(".", a + 1));
42: if (b > -1) {
43: address = address.substring(a + 1);
44: }
45:
46: if (uri.getPort() != -1) {
47: // set the endpointUri to be a proper url if host and port are set
48: this .address += ":" + uri.getPort();
49: }
50:
51: if (userInfo != null) {
52: int x = userInfo.indexOf(":");
53: if (x > -1) {
54: String user = userInfo.substring(0, x);
55: if (user.indexOf("@") > -1) {
56: address = user;
57: } else {
58: address = user + "@" + address;
59: }
60: } else {
61: if (userInfo.indexOf("@") > -1) {
62: address = userInfo;
63: } else {
64: address = userInfo + "@" + address;
65: }
66: }
67: }
68: }
69: }
|