1
2
3
4
5
6
7
8
9
10
11 package org.mule.endpoint;
12
13 import org.mule.api.endpoint.MalformedEndpointException;
14 import org.mule.util.StringUtils;
15
16 import java.net.URI;
17 import java.util.Properties;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21
22
23
24
25
26
27 public class ResourceNameEndpointURIBuilder extends AbstractEndpointURIBuilder
28 {
29
30 protected static final Log logger = LogFactory.getLog(ResourceNameEndpointURIBuilder.class);
31
32 public static final String RESOURCE_INFO_PROPERTY = "resourceInfo";
33
34 protected void setEndpoint(URI uri, Properties props) throws MalformedEndpointException
35 {
36 address = StringUtils.EMPTY;
37 String host = uri.getHost();
38 if (host != null && !"localhost".equals(host))
39 {
40 address = host;
41 }
42
43 String path = uri.getPath();
44 String authority = uri.getAuthority();
45
46 if (path != null && path.length() != 0)
47 {
48 if (address.length() > 0)
49 {
50 address += "/";
51 }
52 address += path.substring(1);
53 }
54 else if (authority != null && !authority.equals(address))
55 {
56 address += authority;
57
58 int atCharIndex = -1;
59 if (address != null && address.length() != 0 && ((atCharIndex = address.indexOf("@")) > -1))
60 {
61 userInfo = address.substring(0, atCharIndex);
62 address = address.substring(atCharIndex + 1);
63 }
64
65 }
66
67
68 int y = address.indexOf("@");
69 if (y > -1)
70 {
71 userInfo = address.substring(0, y);
72 }
73
74 y++;
75
76 String credentials = uri.getUserInfo();
77 if (credentials != null && credentials.length() != 0)
78 {
79 userInfo = credentials;
80 }
81
82 int x = address.indexOf(":", y);
83 if (x > -1)
84 {
85 String resourceInfo = address.substring(y, x);
86 props.setProperty("resourceInfo", resourceInfo);
87 address = address.substring(x + 1);
88 }
89 }
90 }